summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2009-04-03 05:25:08 (EDT)
committerStefan Winkler2009-04-03 05:25:08 (EDT)
commit27d8e810383f54683f5ee508f7564c055b37c817 (patch)
tree9c586818c77a21f46e21367942f4d1b86c11e33c
parentd4e5d55413b12b55648e3862b417b3b8a288c146 (diff)
downloadcdo-27d8e810383f54683f5ee508f7564c055b37c817.zip
cdo-27d8e810383f54683f5ee508f7564c055b37c817.tar.gz
cdo-27d8e810383f54683f5ee508f7564c055b37c817.tar.bz2
[265447] External CDOIDs cause ImplementationError
https://bugs.eclipse.org/bugs/show_bug.cgi?id=265447
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/id/CDOIDUtil.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java23
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/AbstractJDBCDelegate.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegate.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/StatementJDBCDelegate.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AttributeMapping.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ToOneReferenceMapping.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/CDOIDTest.java93
9 files changed, 135 insertions, 10 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/id/CDOIDUtil.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/id/CDOIDUtil.java
index 546e643..287e3cf 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/id/CDOIDUtil.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/id/CDOIDUtil.java
@@ -80,8 +80,12 @@ public final class CDOIDUtil
case TEMP_OBJECT:
throw new IllegalArgumentException("id instanceof CDOIDTemp");
+ case EXTERNAL_OBJECT:
+ case EXTERNAL_TEMP_OBJECT:
+ throw new IllegalArgumentException("Can't get long id from external ID types.");
+
default:
- throw new ImplementationError();
+ throw new ImplementationError("Invalid CDOID type: " + id.getClass().getName());
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
index 5f62df0..c9dca68 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
@@ -10,6 +10,8 @@
*/
package org.eclipse.emf.cdo.server.db;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.DBStore;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
@@ -148,6 +150,27 @@ public final class CDODBUtil
return null;
}
+ /**
+ * Get the long value of a CDOID (by delegating to {@link CDOIDUtil#getLong(org.eclipse.emf.cdo.common.id.CDOID)}) In
+ * addition, provide a check for external IDs which are not supported by the DBStore
+ *
+ * @param id
+ * the ID to convert to long
+ * @return the long value of the ID
+ * @throws IllegalArgumentException
+ * if the ID is not convertibla
+ * @since 2.0
+ */
+ public static long getLong(CDOID id)
+ {
+ if (id != null && id.getType() == CDOID.Type.EXTERNAL_OBJECT)
+ {
+ throw new IllegalArgumentException("DBStore does not support external references.");
+ }
+
+ return CDOIDUtil.getLong(id);
+ }
+
// public static CDODBStoreManager getStoreManager(IDBAdapter dbAdapter,
// DataSource dataSource)
// {
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/AbstractJDBCDelegate.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/AbstractJDBCDelegate.java
index 57b414d..33acb78 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/AbstractJDBCDelegate.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/AbstractJDBCDelegate.java
@@ -16,6 +16,7 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk;
+import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
import org.eclipse.emf.cdo.server.db.IJDBCDelegate;
@@ -235,13 +236,13 @@ public abstract class AbstractJDBCDelegate extends Lifecycle implements IJDBCDel
public final void insertReference(CDOID id, int version, int index, CDOID targetId, IReferenceMapping referenceMapping)
{
doInsertReference(referenceMapping.getTable().getName(), getDBID(referenceMapping), CDOIDUtil.getLong(id), version,
- index, CDOIDUtil.getLong(targetId));
+ index, CDODBUtil.getLong(targetId));
}
public void insertReferenceRow(CDOID id, int newVersion, int index, CDOID value, IReferenceMapping referenceMapping)
{
doInsertReferenceRow(referenceMapping.getTable().getName(), getDBID(referenceMapping), CDOIDUtil.getLong(id),
- newVersion, CDOIDUtil.getLong(value), index);
+ newVersion, CDODBUtil.getLong(value), index);
}
public void moveReferenceRow(CDOID id, int newVersion, int oldPosition, int newPosition,
@@ -265,7 +266,7 @@ public abstract class AbstractJDBCDelegate extends Lifecycle implements IJDBCDel
public void updateReference(CDOID id, int version, int index, CDOID targetId, IReferenceMapping referenceMapping)
{
doUpdateReference(referenceMapping.getTable().getName(), getDBID(referenceMapping), CDOIDUtil.getLong(id), version,
- index, CDOIDUtil.getLong(targetId));
+ index, CDODBUtil.getLong(targetId));
}
public final void updateReferenceVersion(CDOID id, int newVersion, IReferenceMapping referenceMapping)
@@ -328,7 +329,7 @@ public abstract class AbstractJDBCDelegate extends Lifecycle implements IJDBCDel
public void selectRevisionReferences(InternalCDORevision revision, IReferenceMapping referenceMapping,
int referenceChunk)
{
- MoveableList<Object> list = (revision).getList(referenceMapping.getFeature());
+ MoveableList<Object> list = revision.getList(referenceMapping.getFeature());
CDOID source = revision.getID();
long sourceId = CDOIDUtil.getLong(source);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegate.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegate.java
index 86045d1..7634e77 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegate.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegate.java
@@ -14,6 +14,7 @@ package org.eclipse.emf.cdo.server.internal.db.jdbc;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.mapping.IAttributeMapping;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
@@ -334,7 +335,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
stmt.setLong(col++, revision.getCreated());
stmt.setLong(col++, revision.getRevised());
stmt.setLong(col++, CDOIDUtil.getLong(revision.getResourceID()));
- stmt.setLong(col++, CDOIDUtil.getLong((CDOID)revision.getContainerID()));
+ stmt.setLong(col++, CDODBUtil.getLong((CDOID)revision.getContainerID()));
stmt.setInt(col++, revision.getContainingFeatureID());
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/StatementJDBCDelegate.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/StatementJDBCDelegate.java
index fe05e68..11d0e0b 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/StatementJDBCDelegate.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/StatementJDBCDelegate.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionData;
+import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.mapping.IAttributeMapping;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
@@ -72,7 +73,7 @@ public class StatementJDBCDelegate extends AbstractJDBCDelegate
builder.append(", ");
builder.append(CDOIDUtil.getLong(data.getResourceID()));
builder.append(", ");
- builder.append(CDOIDUtil.getLong((CDOID)data.getContainerID()));
+ builder.append(CDODBUtil.getLong((CDOID)data.getContainerID()));
builder.append(", ");
builder.append(data.getContainingFeatureID());
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AttributeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AttributeMapping.java
index d951d28..d810b4a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AttributeMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AttributeMapping.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.cdo.server.internal.db.mapping;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.mapping.IAttributeMapping;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
@@ -178,7 +179,7 @@ public abstract class AttributeMapping extends FeatureMapping implements IAttrib
@Override
protected Object convertToDBType(Object value)
{
- return CDOIDUtil.getLong((CDOID)value);
+ return CDODBUtil.getLong((CDOID)value);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ToOneReferenceMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ToOneReferenceMapping.java
index 958509e..634698a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ToOneReferenceMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ToOneReferenceMapping.java
@@ -11,7 +11,7 @@
package org.eclipse.emf.cdo.server.internal.db.mapping;
import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -30,6 +30,6 @@ public class ToOneReferenceMapping extends AttributeMapping.AMObject
public Long getRevisionValue(InternalCDORevision revision)
{
CDOID id = (CDOID)super.getRevisionValue(revision);
- return CDOIDUtil.getLong(id);
+ return CDODBUtil.getLong(id);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
index 6afd183..0de9fca 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
@@ -59,6 +59,7 @@ public abstract class AllTestsAllConfigs extends ConfigTestSuite
{
// General
testClasses.add(InitialTest.class);
+ testClasses.add(CDOIDTest.class);
testClasses.add(ComplexTest.class);
testClasses.add(AttributeTest.class);
testClasses.add(EnumTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/CDOIDTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/CDOIDTest.java
new file mode 100644
index 0000000..0630dcf
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/CDOIDTest.java
@@ -0,0 +1,93 @@
+/**
+ * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stefan Winkler - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.internal.common.id.CDOIDExternalImpl;
+import org.eclipse.emf.cdo.internal.common.id.CDOIDExternalTempImpl;
+import org.eclipse.emf.cdo.internal.common.id.CDOIDMetaImpl;
+import org.eclipse.emf.cdo.internal.common.id.CDOIDNullImpl;
+import org.eclipse.emf.cdo.internal.common.id.CDOIDTempMetaImpl;
+import org.eclipse.emf.cdo.internal.common.id.CDOIDTempObjectImpl;
+import org.eclipse.emf.cdo.spi.common.id.AbstractCDOIDLong;
+import org.eclipse.emf.cdo.spi.common.id.CDOIDLongImpl;
+
+/**
+ * @author Stefan Winkler
+ */
+public class CDOIDTest extends AbstractCDOTest
+{
+ public void testGetLong_Null()
+ {
+ assertEquals(AbstractCDOIDLong.NULL_VALUE, CDOIDUtil.getLong(null));
+ }
+
+ public void testGetLong_NullId()
+ {
+ CDOIDNullImpl id = CDOIDNullImpl.INSTANCE;
+ assertEquals(AbstractCDOIDLong.NULL_VALUE, CDOIDUtil.getLong(id));
+ }
+
+ public void testGetLong_LongId()
+ {
+ CDOIDLongImpl id = new CDOIDLongImpl(123L);
+ assertEquals(123L, CDOIDUtil.getLong(id));
+ }
+
+ public void testGetLong_MetaId()
+ {
+ CDOIDMetaImpl id = new CDOIDMetaImpl(135L);
+ assertEquals(135, CDOIDUtil.getLong(id));
+ }
+
+ public void testGetLong_TempId()
+ {
+ CDOIDTempObjectImpl id = new CDOIDTempObjectImpl(456);
+ assertIllegalArgument(id);
+ }
+
+ public void testGetLong_TempMetaId()
+ {
+ CDOIDTempMetaImpl id = new CDOIDTempMetaImpl(789);
+ assertIllegalArgument(id);
+ }
+
+ public void testGetLong_ExtTempId()
+ {
+ CDOIDExternalTempImpl id = new CDOIDExternalTempImpl("cdo://repo123/resource456");
+ assertIllegalArgument(id);
+ }
+
+ public void testGetLong_ExtId()
+ {
+ CDOIDExternalImpl id = new CDOIDExternalImpl("cdo://repo123/resource456");
+ assertIllegalArgument(id);
+ }
+
+ private void assertIllegalArgument(CDOID id)
+ {
+ boolean thrown = false;
+ try
+ {
+ CDOIDUtil.getLong(id);
+ }
+ catch (IllegalArgumentException e)
+ {
+ thrown = true;
+ }
+ if (!thrown)
+ {
+ fail("Expected IllegalArgumentException!");
+ }
+ }
+
+}