summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2010-08-16 06:00:14 (EDT)
committerCaspar De Groot2010-08-16 06:00:14 (EDT)
commit66de880f109fdf3d07c41f1b757fc5da42dde3c8 (patch)
tree1a9bb839e591ef5cd5db028fc3d71c9c6630f2cd
parenta149eeb8a3c297936b01635aef3b2c25ebd4a853 (diff)
downloadcdo-66de880f109fdf3d07c41f1b757fc5da42dde3c8.zip
cdo-66de880f109fdf3d07c41f1b757fc5da42dde3c8.tar.gz
cdo-66de880f109fdf3d07c41f1b757fc5da42dde3c8.tar.bz2
[322739] [DB] DBStoreAccessor.rollback does not remove new IDBTables
https://bugs.eclipse.org/bugs/show_bug.cgi?id=322739
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java14
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java54
-rw-r--r--plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF18
4 files changed, 69 insertions, 22 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 82b29a8..534917f 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
@@ -18,7 +18,12 @@ import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
import org.eclipse.net4j.db.ddl.IDBTable;
+import org.eclipse.net4j.internal.db.ddl.DBTable;
import org.eclipse.net4j.spi.db.DBSchema;
+import org.eclipse.net4j.util.ReflectUtil;
+
+import java.lang.reflect.Field;
+import java.util.Map;
/**
* @author Eike Stepper
@@ -254,4 +259,13 @@ public class CDODBSchema extends DBSchema
{
INSTANCE.lock();
}
+
+ public void removeTable(String name)
+ {
+ Field tablesField = ReflectUtil.getField(DBSchema.class, "tables");
+
+ @SuppressWarnings("unchecked")
+ Map<String, DBTable> tables = (Map<String, DBTable>)ReflectUtil.getValue(tablesField, this);
+ tables.remove(name);
+ }
}
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 9394794..b8005fa 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
@@ -44,6 +44,7 @@ import org.eclipse.emf.cdo.server.db.mapping.IClassMappingAuditSupport;
import org.eclipse.emf.cdo.server.db.mapping.IClassMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
+import org.eclipse.emf.cdo.server.internal.db.mapping.AbstractMappingStrategy;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
import org.eclipse.emf.cdo.spi.common.commit.CDOChangeSetSegment;
@@ -493,6 +494,10 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
try
{
getConnection().rollback();
+
+ // Bugzilla 298632: Must rollback DBSchema to its prior state and drop the tables
+ IMappingStrategy strategy = getStore().getMappingStrategy();
+ ((AbstractMappingStrategy)strategy).removeMapping(getConnection(), commitContext.getNewPackageUnits());
}
catch (SQLException ex)
{
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
index 3b1b2b5..74fe8a1 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
@@ -28,6 +28,7 @@ import org.eclipse.emf.cdo.server.db.mapping.IClassMapping;
import org.eclipse.emf.cdo.server.db.mapping.IListMapping;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
+import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.DBAnnotation;
import org.eclipse.emf.cdo.server.internal.db.ObjectIDIterator;
import org.eclipse.emf.cdo.spi.common.commit.CDOChangeSetSegment;
@@ -38,6 +39,7 @@ import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.net4j.util.StringUtil;
@@ -369,9 +371,7 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
try
{
- Set<IDBTable> modelTables = new HashSet<IDBTable>();
- mapPackageUnits(packageUnits, modelTables);
- getStore().getDBAdapter().createTables(modelTables, connection);
+ mapPackageUnits(packageUnits, connection, false);
}
finally
{
@@ -387,42 +387,55 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
}
}
- private void mapPackageUnits(InternalCDOPackageUnit[] packageUnits, Set<IDBTable> modelTables)
+ public void removeMapping(Connection connection, InternalCDOPackageUnit[] packageUnits)
+ {
+ mapPackageUnits(packageUnits, connection, true);
+ }
+
+ private void mapPackageUnits(InternalCDOPackageUnit[] packageUnits, Connection connection, boolean unmap)
{
if (packageUnits != null && packageUnits.length != 0)
{
for (InternalCDOPackageUnit packageUnit : packageUnits)
{
- mapPackageInfos(packageUnit.getPackageInfos(), modelTables);
+ mapPackageInfos(packageUnit.getPackageInfos(), connection, unmap);
}
}
}
- private void mapPackageInfos(InternalCDOPackageInfo[] packageInfos, Set<IDBTable> modelTables)
+ private void mapPackageInfos(InternalCDOPackageInfo[] packageInfos, Connection connection, boolean unmap)
{
for (InternalCDOPackageInfo packageInfo : packageInfos)
{
EPackage ePackage = packageInfo.getEPackage();
if (!CDOModelUtil.isCorePackage(ePackage))
{
- mapClasses(EMFUtil.getPersistentClasses(ePackage), modelTables);
+ mapClasses(EMFUtil.getPersistentClasses(ePackage), connection, unmap);
}
}
}
- private void mapClasses(EClass[] eClasses, Set<IDBTable> modelTables)
+ private void mapClasses(EClass[] eClasses, Connection connection, boolean unmap)
{
for (EClass eClass : eClasses)
{
if (!(eClass.isInterface() || eClass.isAbstract()))
{
- String mapping = DBAnnotation.TABLE_MAPPING.getValue(eClass);
+ if (!unmap)
+ {
+ String mapping = DBAnnotation.TABLE_MAPPING.getValue(eClass);
- // TODO Maybe we should explicitly report unknown values of the annotation
- if (mapping == null || !mapping.equalsIgnoreCase(DBAnnotation.TABLE_MAPPING_NONE))
+ // TODO Maybe we should explicitly report unknown values of the annotation
+ if (mapping == null || !mapping.equalsIgnoreCase(DBAnnotation.TABLE_MAPPING_NONE))
+ {
+ IClassMapping classMapping = createClassMapping(eClass);
+ getStore().getDBAdapter().createTables(classMapping.getDBTables(), connection);
+ }
+ }
+ else
{
- IClassMapping classMapping = createClassMapping(eClass);
- modelTables.addAll(classMapping.getDBTables());
+ IClassMapping mapping = removeClassMapping(eClass);
+ getStore().getDBAdapter().dropTables(mapping.getDBTables(), connection);
}
}
}
@@ -439,6 +452,21 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
return mapping;
}
+ private IClassMapping removeClassMapping(EClass eClass)
+ {
+ IClassMapping mapping = classMappings.get(eClass);
+ if (mapping != null)
+ {
+ IDBSchema schema = getStore().getDBSchema();
+ for (IDBTable table : mapping.getDBTables())
+ {
+ ((CDODBSchema)schema).removeTable(table.getName());
+ }
+ classMappings.remove(eClass);
+ }
+ return mapping;
+ }
+
protected abstract IClassMapping doCreateClassMapping(EClass eClass);
public final IClassMapping getClassMapping(EClass eClass)
diff --git a/plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF
index f61f80a..67f2160 100644
--- a/plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.net4j.db;singleton:=true
-Bundle-Version: 3.0.0.qualifier
+Bundle-Version: 3.0.1.qualifier
Bundle-Activator: org.eclipse.net4j.internal.db.bundle.OM$Activator
Bundle-Vendor: %providerName
Bundle-ClassPath: .
@@ -10,13 +10,13 @@ Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.net4j.util;bundle-version="[3.0.0,4.0.0)";visibility:=reexport
-Export-Package: org.eclipse.net4j.db;version="3.0.0",
- org.eclipse.net4j.db.ddl;version="3.0.0",
- org.eclipse.net4j.db.dml;version="3.0.0",
- org.eclipse.net4j.internal.db;version="3.0.0";x-internal:=true,
- org.eclipse.net4j.internal.db.bundle;version="3.0.0";x-internal:=true,
- org.eclipse.net4j.internal.db.ddl;version="3.0.0";x-internal:=true,
- org.eclipse.net4j.internal.db.dml;version="3.0.0";x-internal:=true,
- org.eclipse.net4j.spi.db;version="3.0.0"
+Export-Package: org.eclipse.net4j.db;version="3.0.1",
+ org.eclipse.net4j.db.ddl;version="3.0.1",
+ org.eclipse.net4j.db.dml;version="3.0.1",
+ org.eclipse.net4j.internal.db;version="3.0.1";x-friends:="org.eclipse.emf.cdo.server.db",
+ org.eclipse.net4j.internal.db.bundle;version="3.0.1";x-friends:="org.eclipse.emf.cdo.server.db",
+ org.eclipse.net4j.internal.db.ddl;version="3.0.1";x-friends:="org.eclipse.emf.cdo.server.db",
+ org.eclipse.net4j.internal.db.dml;version="3.0.1";x-friends:="org.eclipse.emf.cdo.server.db",
+ org.eclipse.net4j.spi.db;version="3.0.1"
Bundle-ActivationPolicy: lazy
Eclipse-BuddyPolicy: registered