Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon McDuff2008-10-31 10:04:47 -0400
committerSimon McDuff2008-10-31 10:04:47 -0400
commitb052cd228a09572591b18b3a6f5e905088dcf84f (patch)
tree343f21423408eeca3fb4b82fe956a776b57d3dc0
parent8be552293beed11f26cbf92cfbe7369dafe499d9 (diff)
downloadcdo-b052cd228a09572591b18b3a6f5e905088dcf84f.tar.gz
cdo-b052cd228a09572591b18b3a6f5e905088dcf84f.tar.xz
cdo-b052cd228a09572591b18b3a6f5e905088dcf84f.zip
[252909] [DBStore] NPE when trying to update objects
https://bugs.eclipse.org/bugs/show_bug.cgi?id=252909
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java52
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_252909_Test.java46
3 files changed, 67 insertions, 33 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java
index 1a43de26bf..c0d07f3dfd 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java
@@ -63,8 +63,6 @@ public abstract class ClassMapping implements IClassMapping
private String selectPrefix;
- private String selectPrefixWithVersion;
-
public ClassMapping(MappingStrategy mappingStrategy, CDOClass cdoClass, CDOFeature[] features)
{
this.mappingStrategy = mappingStrategy;
@@ -106,8 +104,7 @@ public abstract class ClassMapping implements IClassMapping
// }
}
- selectPrefix = createSelectPrefix(false);
- selectPrefixWithVersion = createSelectPrefix(true);
+ selectPrefix = createSelectPrefix();
}
public MappingStrategy getMappingStrategy()
@@ -221,19 +218,15 @@ public abstract class ClassMapping implements IClassMapping
return store.getDBAdapter();
}
- protected String createSelectPrefix(boolean readVersion)
+ protected String createSelectPrefix()
{
StringBuilder builder = new StringBuilder();
builder.append("SELECT ");
if (hasFullRevisionInfo())
{
- if (readVersion)
- {
- builder.append(CDODBSchema.ATTRIBUTES_VERSION);
- builder.append(", ");
- }
-
+ builder.append(CDODBSchema.ATTRIBUTES_VERSION);
+ builder.append(", ");
builder.append(CDODBSchema.ATTRIBUTES_CREATED);
builder.append(", ");
builder.append(CDODBSchema.ATTRIBUTES_REVISED);
@@ -520,27 +513,25 @@ public abstract class ClassMapping implements IClassMapping
public void readRevision(IDBStoreAccessor accessor, CDORevision revision, int referenceChunk)
{
String where = mappingStrategy.createWhereClause(CDORevision.UNSPECIFIED_DATE);
- readRevision(accessor, (InternalCDORevision)revision, where, true, referenceChunk);
+ readRevision(accessor, (InternalCDORevision)revision, where, referenceChunk);
}
public void readRevisionByTime(IDBStoreAccessor accessor, CDORevision revision, long timeStamp, int referenceChunk)
{
String where = mappingStrategy.createWhereClause(timeStamp);
- readRevision(accessor, (InternalCDORevision)revision, where, true, referenceChunk);
+ readRevision(accessor, (InternalCDORevision)revision, where, referenceChunk);
}
public void readRevisionByVersion(IDBStoreAccessor accessor, CDORevision revision, int version, int referenceChunk)
{
String where = CDODBSchema.ATTRIBUTES_VERSION + "=" + version;
- readRevision(accessor, (InternalCDORevision)revision, where, false, referenceChunk);
- ((InternalCDORevision)revision).setVersion(version);
+ readRevision(accessor, (InternalCDORevision)revision, where, referenceChunk);
}
- protected void readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, String where,
- boolean readVersion, int referenceChunk)
+ protected void readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, String where, int referenceChunk)
{
// Read attribute table always (even without modeled attributes!)
- readAttributes(accessor, revision, where, readVersion);
+ readAttributes(accessor, revision, where);
// Read reference tables only if they exist
if (referenceMappings != null)
@@ -549,11 +540,10 @@ public abstract class ClassMapping implements IClassMapping
}
}
- protected void readAttributes(IDBStoreAccessor accessor, InternalCDORevision revision, String where,
- boolean readVersion)
+ protected void readAttributes(IDBStoreAccessor accessor, InternalCDORevision revision, String where)
{
long id = CDOIDUtil.getLong(revision.getID());
- StringBuilder builder = new StringBuilder(readVersion ? selectPrefixWithVersion : selectPrefix);
+ StringBuilder builder = new StringBuilder(selectPrefix);
builder.append(id);
builder.append(" AND (");
builder.append(where);
@@ -575,26 +565,22 @@ public abstract class ClassMapping implements IClassMapping
throw new IllegalStateException("Revision not found: " + id);
}
- int i = 1;
+ int i = 0;
if (hasFullRevisionInfo())
{
- if (readVersion)
- {
- revision.setVersion(resultSet.getInt(i++));
- }
-
- revision.setCreated(resultSet.getLong(i++));
- revision.setRevised(resultSet.getLong(i++));
- revision.setResourceID(CDOIDUtil.createLong(resultSet.getLong(i++)));
- revision.setContainerID(CDOIDUtil.createLong(resultSet.getLong(i++)));
- revision.setContainingFeatureID(resultSet.getInt(i++));
+ revision.setVersion(resultSet.getInt(++i));
+ revision.setCreated(resultSet.getLong(++i));
+ revision.setRevised(resultSet.getLong(++i));
+ revision.setResourceID(CDOIDUtil.createLong(resultSet.getLong(++i)));
+ revision.setContainerID(CDOIDUtil.createLong(resultSet.getLong(++i)));
+ revision.setContainingFeatureID(resultSet.getInt(++i));
}
if (attributeMappings != null)
{
for (IAttributeMapping attributeMapping : attributeMappings)
{
- attributeMapping.extractValue(resultSet, i++, revision);
+ attributeMapping.extractValue(resultSet, ++i, revision);
}
}
}
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 3d6ee4c3d9..75b763f68a 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
@@ -27,6 +27,7 @@ import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_251263_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_251544_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_251752_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_252214_Test;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_252909_Test;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite;
@@ -92,6 +93,7 @@ public abstract class AllTestsAllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_251544_Test.class);
testClasses.add(Bugzilla_251752_Test.class);
testClasses.add(Bugzilla_252214_Test.class);
+ testClasses.add(Bugzilla_252909_Test.class);
// TODO testClasses.add(NonCDOResourceTest.class);
// TODO testClasses.add(GeneratedEcoreTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_252909_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_252909_Test.java
new file mode 100644
index 0000000000..65391a5e31
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_252909_Test.java
@@ -0,0 +1,46 @@
+/***************************************************************************
+ * Copyright (c) 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOTransaction;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.model1.Company;
+
+/**
+ * [DBStore] NPE when trying to update objects
+ * <p>
+ * See https://bugs.eclipse.org/252909
+ *
+ * @author Simon McDuff
+ */
+public class Bugzilla_252909_Test extends AbstractCDOTest
+{
+
+ public void testBugzilla_252909() throws Exception
+ {
+ CDOSession session = openModel1Session();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource("/res1");
+ for (int i = 0; i < 10; i++)
+ {
+ Company company = getModel1Factory().createCompany();
+ company.setName("Okidoo");
+ resource.getContents().add(company);
+ transaction.commit();
+
+ clearCache(getRepository().getRevisionManager());
+ }
+ }
+
+}

Back to the top