summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-14 14:52:13 (EDT)
committerEike Stepper2007-08-14 14:52:13 (EDT)
commit76eb45f224cfe21d7f660096a96f4cf4e24aee8c (patch)
tree06b49d8e9176646438ddf64da081c59dbabb729c
parentc64189b12feeda107921c16d4aa50133292529d7 (diff)
downloadcdo-76eb45f224cfe21d7f660096a96f4cf4e24aee8c.zip
cdo-76eb45f224cfe21d7f660096a96f4cf4e24aee8c.tar.gz
cdo-76eb45f224cfe21d7f660096a96f4cf4e24aee8c.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java44
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java45
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java154
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBField.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBField.java2
9 files changed, 248 insertions, 7 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
index 0908d55..4409407 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
@@ -63,7 +63,7 @@ public class CDODBSchema extends DBSchema
CLASSES.addField("id", IDBField.Type.INTEGER);
public static final IDBField CLASSES_PACKAGE = //
- CLASSES.addField("package", IDBField.Type.INTEGER);
+ CLASSES.addField("package", IDBField.Type.VARCHAR, 255);
public static final IDBField CLASSES_CLASSIFIER = //
CLASSES.addField("classifier", IDBField.Type.INTEGER);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
index 072f1e2..8ab170b 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
@@ -16,10 +16,13 @@ import org.eclipse.emf.cdo.server.IStoreWriter;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.net4j.db.DBException;
+import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
import javax.sql.DataSource;
+import java.sql.Connection;
+
/**
* @author Eike Stepper
*/
@@ -31,6 +34,12 @@ public class DBStore extends Store
private DataSource dataSource;
+ private int nextPackageID;
+
+ private int nextClassID;
+
+ private int nextFeatureID;
+
public DBStore(IDBAdapter dbAdapter, DataSource dataSource)
{
super(TYPE);
@@ -67,4 +76,39 @@ public class DBStore extends Store
{
return new DBStoreWriter(this, view);
}
+
+ public int getNextPackageID()
+ {
+ return nextPackageID++;
+ }
+
+ public int getNextClassID()
+ {
+ return nextClassID++;
+ }
+
+ public int getNextFeatureID()
+ {
+ return nextFeatureID++;
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ super.doActivate();
+ CDODBSchema.INSTANCE.create(dbAdapter, dataSource);
+ Connection connection = null;
+
+ try
+ {
+ connection = dataSource.getConnection();
+ nextPackageID = DBUtil.selectMaximum(connection, CDODBSchema.PACKAGES_ID) + 1;
+ nextClassID = DBUtil.selectMaximum(connection, CDODBSchema.CLASSES_ID) + 1;
+ nextFeatureID = DBUtil.selectMaximum(connection, CDODBSchema.FEATURES_ID) + 1;
+ }
+ finally
+ {
+ DBUtil.close(connection);
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java
index 5b259de..8bd5f38 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java
@@ -10,12 +10,16 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.internal.db;
+import org.eclipse.emf.cdo.internal.protocol.model.CDOClassImpl;
+import org.eclipse.emf.cdo.internal.protocol.model.CDOFeatureImpl;
import org.eclipse.emf.cdo.internal.protocol.model.CDOPackageImpl;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
+import org.eclipse.emf.cdo.protocol.CDOIDRange;
import org.eclipse.emf.cdo.server.IStoreWriter;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.net4j.db.DBException;
+import org.eclipse.net4j.db.DBUtil;
import java.sql.SQLException;
@@ -63,6 +67,47 @@ public class DBStoreWriter extends DBStoreReader implements IStoreWriter
public void writePackage(CDOPackageImpl cdoPackage)
{
+ CDOIDRange metaIDRange = cdoPackage.getMetaIDRange();
+ long lb = metaIDRange.getLowerBound().getValue();
+ long ub = metaIDRange.getUpperBound().getValue();
+
+ int id = store.getNextPackageID();
+ cdoPackage.setServerInfo(id);
+
+ DBUtil.insertRow(connection, CDODBSchema.PACKAGES, id, cdoPackage.getPackageURI(), cdoPackage.getName(), cdoPackage
+ .getEcore(), cdoPackage.isDynamic(), lb, ub);
+
+ for (CDOClassImpl cdoClass : cdoPackage.getClasses())
+ {
+ writeClass(cdoClass);
+ }
+ }
+
+ public void writeClass(CDOClassImpl cdoClass)
+ {
+ int id = store.getNextClassID();
+ cdoClass.setServerInfo(id);
+
+ DBUtil.insertRow(connection, CDODBSchema.CLASSES, id, cdoClass.getPackageURI(), cdoClass.getName(), cdoClass
+ .getEcore(), cdoClass.isDynamic());
+
+ for (CDOClassImpl superType : cdoClass.getSuperTypes())
+ {
+ writeSuperType(cdoClass, superType);
+ }
+
+ for (CDOFeatureImpl feature : cdoClass.getFeatures())
+ {
+ writeFeature(feature);
+ }
+ }
+
+ public void writeSuperType(CDOClassImpl type, CDOClassImpl superType)
+ {
+ }
+
+ public void writeFeature(CDOFeatureImpl feature)
+ {
}
public void writeRevision(CDORevisionImpl revision)
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java
index 6dc65fb..1682812 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java
@@ -26,7 +26,7 @@ public abstract class Store extends Lifecycle implements IStore
this.type = type;
}
- public String getType()
+ public String getStoreType()
{
return type;
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
index 139c951..c3a7a69 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
@@ -15,7 +15,7 @@ package org.eclipse.emf.cdo.server;
*/
public interface IStore
{
- public String getType();
+ public String getStoreType();
public IStoreReader getReader();
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java
index 05c9b2a..464f1d9 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java
@@ -31,7 +31,6 @@ public interface IStoreReader extends IStoreAccessor
* <b>Note:</b> The implementor is free to create and return package proxies
* that are demand loaded at a later point in time.
* <p>
- * TODO Decouple from {@link CDOPackageImpl}.
*
* @see CDOPackageImpl#CDOPackageImpl(CDOPackageManagerImpl, String, boolean,
* CDOIDRange)
@@ -42,7 +41,6 @@ public interface IStoreReader extends IStoreAccessor
* Demand loads a given package proxy that has been created on startup of the
* repository.
* <p>
- * TODO Decouple from {@link CDOPackageImpl}.
*/
public void readPackage(CDOPackageImpl cdoPackage);
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
index f799a4a..5b9deac 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
@@ -16,6 +16,11 @@ import org.eclipse.net4j.util.ReflectUtil;
import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.util.Map;
/**
@@ -58,4 +63,153 @@ public final class DBUtil
{
return IDBAdapter.REGISTRY.get(adapterName);
}
+
+ public static Exception close(Connection connection)
+ {
+ if (connection != null)
+ {
+ try
+ {
+ connection.close();
+ }
+ catch (Exception ex)
+ {
+ return ex;
+ }
+ }
+
+ return null;
+ }
+
+ public static Exception close(Statement statement)
+ {
+ if (statement != null)
+ {
+ try
+ {
+ statement.close();
+ }
+ catch (Exception ex)
+ {
+ return ex;
+ }
+ }
+
+ return null;
+ }
+
+ public static Exception close(ResultSet resultSet)
+ {
+ if (resultSet != null)
+ {
+ try
+ {
+ resultSet.close();
+ }
+ catch (Exception ex)
+ {
+ return ex;
+ }
+ }
+
+ return null;
+ }
+
+ public static int selectMaximum(Connection connection, IDBField field) throws DBException
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("SELECT MAX(");
+ builder.append(field);
+ builder.append(") FROM ");
+ builder.append(field.getTable());
+
+ String sql = builder.toString();
+ Statement stmt = null;
+ ResultSet rs = null;
+
+ try
+ {
+ stmt = connection.createStatement();
+
+ try
+ {
+ rs = stmt.executeQuery(sql);
+ if (!rs.first())
+ {
+ return 0;
+ }
+
+ return rs.getInt(1);
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ close(rs);
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ close(stmt);
+ }
+ }
+
+ public static void insertRow(Connection connection, IDBTable table, Object... args) throws DBException
+ {
+ IDBField[] fields = table.getFields();
+ if (fields.length != args.length)
+ {
+ throw new IllegalArgumentException("fields.length != args.length");
+ }
+
+ StringBuilder builder = new StringBuilder();
+ builder.append("INSERT INTO ");
+ builder.append(table);
+ builder.append(" VALUES (");
+
+ for (int i = 0; i < fields.length; i++)
+ {
+ if (i > 0)
+ {
+ builder.append(", ");
+ }
+
+ builder.append("?");
+ }
+
+ builder.append(")");
+
+ String sql = builder.toString();
+ PreparedStatement stmt = null;
+
+ try
+ {
+ stmt = connection.prepareStatement(sql);
+ for (int i = 0; i < fields.length; i++)
+ {
+ IDBField field = fields[i];
+ stmt.setObject(i, args[i], field.getType().getCode());
+ }
+
+ stmt.execute();
+ if (stmt.getUpdateCount() == 0)
+ {
+ throw new DBException("No row inserted into table " + table);
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ close(stmt);
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBField.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBField.java
index ba001fa..df6281b 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBField.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBField.java
@@ -17,7 +17,7 @@ public interface IDBField
{
public static final int DEFAULT = -1;
- public IDBTable geTable();
+ public IDBTable getTable();
public String getName();
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBField.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBField.java
index 8d09d7c..d86375e 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBField.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBField.java
@@ -44,7 +44,7 @@ public class DBField implements IDBField
this.position = position;
}
- public DBTable geTable()
+ public DBTable getTable()
{
return table;
}