summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2010-08-11 08:31:09 (EDT)
committerCaspar De Groot2010-08-11 08:31:09 (EDT)
commit04f8b941930cfdbd2b9abd419d18860428fc751a (patch)
tree0a85abfd418b4fb0c7db9b360e8088dc4e17006c
parent581807c6b158c3257ec26456a2badc530c5e5063 (diff)
downloadcdo-04f8b941930cfdbd2b9abd419d18860428fc751a.zip
cdo-04f8b941930cfdbd2b9abd419d18860428fc751a.tar.gz
cdo-04f8b941930cfdbd2b9abd419d18860428fc751a.tar.bz2
[298632] [DB] DBStoreAccessor.rollback does not remove new IDBTables
https://bugs.eclipse.org/bugs/show_bug.cgi?id=298632
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java3
-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/src/org/eclipse/net4j/db/ddl/IDBSchema.java5
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java9
5 files changed, 71 insertions, 12 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java
index 427c228..4437c0a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java
@@ -174,6 +174,18 @@ public interface IMappingStrategy
public void createMapping(Connection connection, InternalCDOPackageUnit[] packageUnits, OMMonitor monitor);
/**
+ * Remove the mapping infrastructure for the given packages. Should be called from the DBStore or the DBStoreAccessor.
+ *
+ * @param connection
+ * the connection to use.
+ * @param packageUnits
+ * the packages for which the mappings should be removed
+ * @since 4.0
+ */
+ // Bugzilla 298632
+ public void removeMapping(Connection connection, InternalCDOPackageUnit[] packageUnits);
+
+ /**
* Look up an existing class mapping for the given class. Before this method is called, the class mapping must have
* been initialized by calling {@link #createMapping(Connection, InternalCDOPackageUnit[], OMMonitor)} on its
* containing package.
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 36ae0a9..b275ae8 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
@@ -487,6 +487,9 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
try
{
getConnection().rollback();
+
+ // Bugzilla 298632: Must rollback DBSchema to its prior state and drop the tables
+ getStore().getMappingStrategy().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 4934766..f7b4cb4 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
@@ -38,6 +38,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;
@@ -377,9 +378,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
{
@@ -395,42 +394,58 @@ 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(connection, unmap, EMFUtil.getPersistentClasses(ePackage));
}
}
}
- private void mapClasses(EClass[] eClasses, Set<IDBTable> modelTables)
+ private void mapClasses(Connection connection, boolean unmap, EClass... eClasses)
{
for (EClass eClass : eClasses)
{
if (!(eClass.isInterface() || eClass.isAbstract()))
{
- String mapping = DBAnnotation.TABLE_MAPPING.getValue(eClass);
+ String mappingAnnotation = 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))
+ if (mappingAnnotation != null && mappingAnnotation.equalsIgnoreCase(DBAnnotation.TABLE_MAPPING_NONE))
{
- IClassMapping classMapping = createClassMapping(eClass);
- modelTables.addAll(classMapping.getDBTables());
+ continue;
+ }
+
+ if (!unmap)
+ {
+ // TODO Bugzilla 296087: Before we go ahead with creation, we should check if it's already there
+ IClassMapping mapping = createClassMapping(eClass);
+ getStore().getDBAdapter().createTables(mapping.getDBTables(), connection);
+ }
+ else
+ {
+ IClassMapping mapping = removeClassMapping(eClass);
+ getStore().getDBAdapter().dropTables(mapping.getDBTables(), connection);
}
}
}
@@ -447,6 +462,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())
+ {
+ 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/src/org/eclipse/net4j/db/ddl/IDBSchema.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java
index 1719f65..b422d0d 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBSchema.java
@@ -27,6 +27,11 @@ public interface IDBSchema extends IDBSchemaElement
{
public IDBTable addTable(String name) throws DBException;
+ /**
+ * @since 4.0
+ */
+ public IDBTable removeTable(String name) throws DBException;
+
public IDBTable getTable(String name);
public IDBTable[] getTables();
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java
index 499290c..44539d4 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBSchema.java
@@ -76,6 +76,15 @@ public class DBSchema extends DBSchemaElement implements IDBSchema
}
/**
+ * @since 4.0
+ */
+ public IDBTable removeTable(String name)
+ {
+ assertUnlocked();
+ return tables.remove(name);
+ }
+
+ /**
* @since 2.0
*/
public IDBTable getTable(String name)