summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2009-08-19 07:36:53 (EDT)
committerStefan Winkler2009-08-19 07:36:53 (EDT)
commit3457f7cac3d02a18c4b5b16b5e0b68e7f2d9e885 (patch)
treedcb5e58612be5af364c649dc927c8a9f9d863a8f
parent0b8dab31f548ed66a3057a4493c5fdbbc8383fed (diff)
downloadcdo-3457f7cac3d02a18c4b5b16b5e0b68e7f2d9e885.zip
cdo-3457f7cac3d02a18c4b5b16b5e0b68e7f2d9e885.tar.gz
cdo-3457f7cac3d02a18c4b5b16b5e0b68e7f2d9e885.tar.bz2
[284680] [DB] Provide annotation to bypass ClassMapping
https://bugs.eclipse.org/bugs/show_bug.cgi?id=284680
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBAnnotation.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java14
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBAnnotationsTest.java87
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/SQLQueryTest.java2
4 files changed, 97 insertions, 11 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBAnnotation.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBAnnotation.java
index d33942a..3b3c5f1 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBAnnotation.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBAnnotation.java
@@ -8,6 +8,8 @@
* Contributors:
* Kai Schlamp - initial API and implementation
* Eike Stepper - maintenance
+ * Kai Schlamp - Bug 284680 - [DB] Provide annotation to bypass ClassMapping
+ * Stefan Winkler - maintenance
*/
package org.eclipse.emf.cdo.server.internal.db;
@@ -19,6 +21,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
*/
public enum DBAnnotation
{
+ TABLE_MAPPING("tableMapping"), //
TABLE_NAME("tableName"), //
COLUMN_NAME("columnName"), //
COLUMN_TYPE("columnType"), //
@@ -26,6 +29,8 @@ public enum DBAnnotation
public final static String SOURCE_URI = "http://www.eclipse.org/CDO/DBStore";
+ public final static String TABLE_MAPPING_NONE = "NONE";
+
private String keyword;
private DBAnnotation(String keyword)
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 471a8fe..1d3ed71 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
@@ -8,8 +8,10 @@
* Contributors:
* Eike Stepper - initial API and implementation
* Stefan Winkler - major refactoring
- * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
- * Stefan Winkler - 282976: [DB] Influence Mappings through EAnnotations
+ * Stefan Winkler - Bug 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
+ * Stefan Winkler - Bug 282976: [DB] Influence Mappings through EAnnotations
+ * Kai Schlamp - Bug 284680 - [DB] Provide annotation to bypass ClassMapping
+ * Stefan Winkler - maintenance
*/
package org.eclipse.emf.cdo.server.internal.db.mapping;
@@ -343,7 +345,13 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
{
if (!(eClass.isInterface() || eClass.isAbstract()))
{
- createClassMapping(eClass);
+ 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))
+ {
+ createClassMapping(eClass);
+ }
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBAnnotationsTest.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBAnnotationsTest.java
index bcfbdbd..c3a1250 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBAnnotationsTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/DBAnnotationsTest.java
@@ -41,7 +41,7 @@ public class DBAnnotationsTest extends AbstractCDOTest
public void testLengthAnnotationPositive() throws Exception
{
msg("Opening session");
- EPackage model1 = (EPackage)EcoreUtil.copy(getModel1Package());
+ EPackage model1 = EcoreUtil.copy(getModel1Package());
addLengthAnnotation(model1, "8");
CDOSession session = openSession(model1);
@@ -68,7 +68,7 @@ public class DBAnnotationsTest extends AbstractCDOTest
skipConfig(AllTestsDBHsqldbNonAudit.HsqldbNonAudit.INSTANCE);
msg("Opening session");
- EPackage model1 = (EPackage)EcoreUtil.copy(getModel1Package());
+ EPackage model1 = EcoreUtil.copy(getModel1Package());
addLengthAnnotation(model1, "8");
CDOSession session = openSession(model1);
@@ -99,7 +99,7 @@ public class DBAnnotationsTest extends AbstractCDOTest
public void testLengthAnnotationByMetaData()
{
msg("Opening session");
- EPackage model1 = (EPackage)EcoreUtil.copy(getModel1Package());
+ EPackage model1 = EcoreUtil.copy(getModel1Package());
addLengthAnnotation(model1, "8");
CDOSession session = openSession(model1);
@@ -139,7 +139,7 @@ public class DBAnnotationsTest extends AbstractCDOTest
skipConfig(AllTestsDBHsqldbNonAudit.HsqldbNonAudit.INSTANCE);
msg("Opening session");
- EPackage model1 = (EPackage)EcoreUtil.copy(getModel1Package());
+ EPackage model1 = EcoreUtil.copy(getModel1Package());
addTypeAnnotation(model1, "CLOB");
CDOSession session = openSession(model1);
@@ -175,7 +175,7 @@ public class DBAnnotationsTest extends AbstractCDOTest
public void testTableNameAnnotationByMetaData()
{
msg("Opening session");
- EPackage model1 = (EPackage)EcoreUtil.copy(getModel1Package());
+ EPackage model1 = EcoreUtil.copy(getModel1Package());
addTableNameAnnotation(model1, "Subject");
CDOSession session = openSession(model1);
@@ -211,7 +211,7 @@ public class DBAnnotationsTest extends AbstractCDOTest
public void testColumnNameAnnotationByMetaData()
{
msg("Opening session");
- EPackage model1 = (EPackage)EcoreUtil.copy(getModel1Package());
+ EPackage model1 = EcoreUtil.copy(getModel1Package());
addColumnNameAnnotation(model1, "TOPIC");
CDOSession session = openSession(model1);
@@ -247,7 +247,7 @@ public class DBAnnotationsTest extends AbstractCDOTest
public void testColumnNameTypeAnnotationByMetaData()
{
msg("Opening session");
- EPackage model1 = (EPackage)EcoreUtil.copy(getModel1Package());
+ EPackage model1 = EcoreUtil.copy(getModel1Package());
addColumnNameAndTypeAnnoation(model1, "TOPIC", "CLOB");
CDOSession session = openSession(model1);
@@ -281,6 +281,66 @@ public class DBAnnotationsTest extends AbstractCDOTest
}.verify();
}
+ public void testTableMappingAnnotationByMetaData()
+ {
+ msg("Opening session");
+ EPackage model1 = EcoreUtil.copy(getModel1Package());
+ addTableMappingAnnotation(model1, "OrderDetail", "Company");
+ CDOSession session = openSession(model1);
+
+ disableConsole();
+
+ msg("Opening transaction");
+ CDOTransaction transaction = session.openTransaction();
+
+ msg("Creating resource");
+ CDOResource resource = transaction.createResource("/test1");
+
+ msg("Commit a category.");
+ EClass eClass = (EClass)model1.getEClassifier("Category");
+ EObject category = model1.getEFactoryInstance().create(eClass);
+
+ resource.getContents().add(category);
+ transaction.commit();
+ transaction.close();
+
+ msg("Check if table name was correctly set.");
+ new DBStoreVerifier(getRepository())
+ {
+ @Override
+ protected void doVerify() throws Exception
+ {
+ DatabaseMetaData metaData = getStatement().getConnection().getMetaData();
+ ResultSet rset = metaData.getTables(null, null, null, null);
+
+ boolean orderDetailTableCreated = false;
+ boolean companyTableCreated = false;
+ boolean categoryTableCreated = false;
+
+ while (rset.next())
+ {
+ String tableName = rset.getString(3);
+ if ("ORDERDETAIL".equalsIgnoreCase(tableName))
+ {
+ orderDetailTableCreated = true;
+ }
+ else if ("COMPANY".equalsIgnoreCase(tableName))
+ {
+ companyTableCreated = true;
+ }
+ else if ("CATEGORY".equalsIgnoreCase(tableName))
+ {
+ categoryTableCreated = true;
+ }
+ }
+
+ Assert.assertFalse(orderDetailTableCreated);
+ Assert.assertFalse(companyTableCreated);
+ Assert.assertTrue(categoryTableCreated);
+ }
+ }.verify();
+ }
+
private void addLengthAnnotation(EPackage model1, String value)
{
EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
@@ -335,4 +395,17 @@ public class DBAnnotationsTest extends AbstractCDOTest
EStructuralFeature element = category.getEStructuralFeature(Model1Package.CATEGORY__NAME);
element.getEAnnotations().add(annotation);
}
+
+ private void addTableMappingAnnotation(EPackage model1, String... unmappedTables)
+ {
+ for (String unmappedTable : unmappedTables)
+ {
+ EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
+ annotation.setSource("http://www.eclipse.org/CDO/DBStore");
+ annotation.getDetails().put("tableMapping", "NONE");
+
+ EClass orderDetail = (EClass)model1.getEClassifier(unmappedTable);
+ orderDetail.getEAnnotations().add(annotation);
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/SQLQueryTest.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/SQLQueryTest.java
index 758e931..927a23f 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/SQLQueryTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/SQLQueryTest.java
@@ -110,7 +110,7 @@ public class SQLQueryTest extends AbstractCDOTest
cdoQuery.setParameter(SQLQueryHandler.CDO_OBJECT_QUERY, false);
final List<Long> counts = cdoQuery.getResult(Long.class);
assertEquals(counts.size(), 1);
- assertEquals(counts.get(0).longValue(), NUM_OF_PRODUCTS);
+ assertEquals(counts.get(0).intValue(), NUM_OF_PRODUCTS);
}
transaction.commit();