summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-24 10:51:18 (EDT)
committerEike Stepper2007-08-24 10:51:18 (EDT)
commit41b4e66e94d36f6bda3b73247ebba4a437cc15dd (patch)
treef41177849737413afbc1553fd0690aa5bf325e0c
parent1dca423cc5990eca23f82c019db89072bda70189 (diff)
downloadcdo-41b4e66e94d36f6bda3b73247ebba4a437cc15dd.zip
cdo-41b4e66e94d36f6bda3b73247ebba4a437cc15dd.tar.gz
cdo-41b4e66e94d36f6bda3b73247ebba4a437cc15dd.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassServerInfo.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java55
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FeatureServerInfo.java11
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/PackageServerInfo.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ServerInfo.java2
5 files changed, 71 insertions, 15 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassServerInfo.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassServerInfo.java
index 332b190..1aa6a9d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassServerInfo.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassServerInfo.java
@@ -20,11 +20,18 @@ public final class ClassServerInfo extends ServerInfo
{
private IMapping mapping;
- public ClassServerInfo(int id)
+ private ClassServerInfo(int id)
{
super(id);
}
+ public static ClassServerInfo setDBID(CDOClass cdoClass, int id)
+ {
+ ClassServerInfo serverInfo = new ClassServerInfo(id);
+ cdoClass.setServerInfo(serverInfo);
+ return serverInfo;
+ }
+
public static IMapping getMapping(CDOClass cdoClass)
{
return ((ClassServerInfo)cdoClass.getServerInfo()).mapping;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
index 8b1835e..e1e39af 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
@@ -28,11 +28,13 @@ import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IMapping;
+import org.eclipse.emf.cdo.server.db.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBRowHandler;
+import org.eclipse.net4j.db.IDBTable;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import java.sql.Connection;
@@ -40,6 +42,8 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
/**
* @author Eike Stepper
@@ -164,7 +168,7 @@ public class DBStoreAccessor implements IDBStoreAccessor
if (!cdoPackage.isSystem())
{
int id = store.getNextPackageID();
- cdoPackage.setServerInfo(new PackageServerInfo(id));
+ PackageServerInfo.setDBID(cdoPackage, id);
if (TRACER.isEnabled())
{
TRACER.format("Inserting package: {0} --> {1}", cdoPackage, id);
@@ -186,15 +190,14 @@ public class DBStoreAccessor implements IDBStoreAccessor
}
}
- // IMappingStrategy mappingStrategy = store.getMappingStrategy();
- // Collection<IDBTable> affectedTables = mappingStrategy.map(cdoPackages);
- // store.getDBAdapter().createTables(affectedTables, connection);
+ Set<IDBTable> affectedTables = mapPackages(cdoPackages);
+ store.getDBAdapter().createTables(affectedTables, connection);
}
protected void writeClass(CDOClassImpl cdoClass)
{
int id = store.getNextClassID();
- cdoClass.setServerInfo(new ClassServerInfo(id));
+ ClassServerInfo.setDBID(cdoClass, id);
CDOPackageImpl cdoPackage = cdoClass.getContainingPackage();
int packageID = ServerInfo.getDBID(cdoPackage);
@@ -224,7 +227,7 @@ public class DBStoreAccessor implements IDBStoreAccessor
protected void writeFeature(CDOFeatureImpl feature)
{
int id = store.getNextFeatureID();
- feature.setServerInfo(new FeatureServerInfo(id));
+ FeatureServerInfo.setDBID(feature, id);
int classID = ServerInfo.getDBID(feature.getContainingClass());
String name = feature.getName();
@@ -267,13 +270,12 @@ public class DBStoreAccessor implements IDBStoreAccessor
String where = CDODBSchema.PACKAGES_URI.getName() + " = '" + cdoPackage.getPackageURI() + "'";
Object[] values = DBUtil.select(connection, where, CDODBSchema.PACKAGES_ID, CDODBSchema.PACKAGES_NAME,
CDODBSchema.PACKAGES_ECORE);
- cdoPackage.setServerInfo(new PackageServerInfo((Integer)values[0]));
+ PackageServerInfo.setDBID(cdoPackage, (Integer)values[0]);
cdoPackage.setName((String)values[1]);
cdoPackage.setEcore((String)values[2]);
readClasses(cdoPackage);
- // CDOPackageImpl[] cdoPackages = { cdoPackage };
- // store.getMappingStrategy().map(cdoPackages);
+ mapPackages(cdoPackage);
}
protected void readClasses(final CDOPackageImpl cdoPackage)
@@ -287,7 +289,7 @@ public class DBStoreAccessor implements IDBStoreAccessor
String name = (String)values[2];
boolean isAbstract = getBoolean(values[3]);
CDOClassImpl cdoClass = new CDOClassImpl(cdoPackage, classifierID, name, isAbstract);
- cdoClass.setServerInfo(new ClassServerInfo(classID));
+ ClassServerInfo.setDBID(cdoClass, classID);
cdoPackage.addClass(cdoClass);
readSuperTypes(cdoClass, classID);
readFeatures(cdoClass, classID);
@@ -344,7 +346,7 @@ public class DBStoreAccessor implements IDBStoreAccessor
feature = new CDOFeatureImpl(cdoClass, featureID, name, type, many);
}
- feature.setServerInfo(new FeatureServerInfo((Integer)values[0]));
+ FeatureServerInfo.setDBID(feature, (Integer)values[0]);
cdoClass.addFeature(feature);
return true;
}
@@ -421,4 +423,35 @@ public class DBStoreAccessor implements IDBStoreAccessor
throw new IllegalArgumentException("Not a boolean value: " + value);
}
+
+ protected Set<IDBTable> mapPackages(CDOPackageImpl... cdoPackages)
+ {
+ Set<IDBTable> affectedTables = new HashSet();
+ if (cdoPackages != null && cdoPackages.length != 0)
+ {
+ for (CDOPackageImpl cdoPackage : cdoPackages)
+ {
+ Set<IDBTable> tables = mapClasses(cdoPackage.getClasses());
+ affectedTables.addAll(tables);
+ }
+ }
+
+ return affectedTables;
+ }
+
+ protected Set<IDBTable> mapClasses(CDOClassImpl... cdoClasses)
+ {
+ Set<IDBTable> affectedTables = new HashSet();
+ if (cdoClasses != null && cdoClasses.length != 0)
+ {
+ IMappingStrategy mappingStrategy = store.getMappingStrategy();
+ for (CDOClassImpl cdoClass : cdoClasses)
+ {
+ IMapping mapping = mappingStrategy.getMapping(cdoClass);
+ affectedTables.addAll(mapping.getAffectedTables());
+ }
+ }
+
+ return affectedTables;
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FeatureServerInfo.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FeatureServerInfo.java
index ecd595a..e9c01b5 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FeatureServerInfo.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/FeatureServerInfo.java
@@ -10,6 +10,8 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.internal.db;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+
import org.eclipse.net4j.db.IDBField;
import java.util.HashMap;
@@ -22,11 +24,18 @@ public final class FeatureServerInfo extends ServerInfo
{
private Map<Object, IDBField> fields;
- public FeatureServerInfo(int id)
+ private FeatureServerInfo(int id)
{
super(id);
}
+ public static FeatureServerInfo setDBID(CDOFeature cdoFeature, int id)
+ {
+ FeatureServerInfo serverInfo = new FeatureServerInfo(id);
+ cdoFeature.setServerInfo(serverInfo);
+ return serverInfo;
+ }
+
@Deprecated
public IDBField getField(Object context)
{
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/PackageServerInfo.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/PackageServerInfo.java
index 8bc6132..f530c60 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/PackageServerInfo.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/PackageServerInfo.java
@@ -21,11 +21,18 @@ public final class PackageServerInfo extends ServerInfo
{
private IDBSchema schema;
- public PackageServerInfo(int id)
+ private PackageServerInfo(int id)
{
super(id);
}
+ public static PackageServerInfo setDBID(CDOPackage cdoPackage, int id)
+ {
+ PackageServerInfo serverInfo = new PackageServerInfo(id);
+ cdoPackage.setServerInfo(serverInfo);
+ return serverInfo;
+ }
+
public static IDBSchema getSchema(CDOPackage cdoPackage)
{
return ((PackageServerInfo)cdoPackage.getServerInfo()).schema;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ServerInfo.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ServerInfo.java
index d0b02f9..eeba09d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ServerInfo.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ServerInfo.java
@@ -19,7 +19,7 @@ public abstract class ServerInfo
{
private int dbID;
- public ServerInfo(int dbID)
+ protected ServerInfo(int dbID)
{
this.dbID = dbID;
}