You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2015/03/13 19:53:27 UTC
[8/8] isis git commit: ISIS-1091: simpler format for bookmarks.
ISIS-1091: simpler format for bookmarks.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/0fed5e38
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/0fed5e38
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/0fed5e38
Branch: refs/heads/master
Commit: 0fed5e38ac9c1f5bc90062e91fa40443ab1e00b0
Parents: a18680a
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Mar 13 18:52:52 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Mar 13 18:52:52 2015 +0000
----------------------------------------------------------------------
.../IdentifierGeneratorForDataNucleus.java | 8 +-
.../persistence/spi/JdoObjectIdSerializer.java | 204 ++++++++++++-------
.../spi/JdoObjectIdSerializerTest.java | 21 +-
3 files changed, 139 insertions(+), 94 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/0fed5e38/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/IdentifierGeneratorForDataNucleus.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/IdentifierGeneratorForDataNucleus.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/IdentifierGeneratorForDataNucleus.java
index 80f2514..07795e9 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/IdentifierGeneratorForDataNucleus.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/IdentifierGeneratorForDataNucleus.java
@@ -26,6 +26,7 @@ import javax.jdo.spi.PersistenceCapable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.apache.isis.core.commons.config.IsisConfiguration;
import org.apache.isis.core.commons.debug.DebugBuilder;
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
import org.apache.isis.core.metamodel.adapter.oid.RootOid;
@@ -84,6 +85,7 @@ class IdentifierGeneratorForDataNucleus implements IdentifierGenerator {
return recreatableObjectFacet.memento(pojo);
}
final Object jdoOid = getJdoPersistenceManager().getObjectId(pojo);
+
return JdoObjectIdSerializer.toOidIdentifier(jdoOid);
}
@@ -119,8 +121,6 @@ class IdentifierGeneratorForDataNucleus implements IdentifierGenerator {
}
-
-
// //////////////////////////////////////////////////////////////
// Dependencies (from context)
// //////////////////////////////////////////////////////////////
@@ -131,10 +131,12 @@ class IdentifierGeneratorForDataNucleus implements IdentifierGenerator {
return objectStore.getPersistenceManager();
}
-
protected DataNucleusObjectStore getDataNucleusObjectStore() {
return (DataNucleusObjectStore) IsisContext.getPersistenceSession().getObjectStore();
}
+ protected IsisConfiguration getConfiguration() {
+ return IsisContext.getConfiguration();
+ }
protected SpecificationLoader getSpecificationLoader() {
return IsisContext.getSpecificationLoader();
}
http://git-wip-us.apache.org/repos/asf/isis/blob/0fed5e38/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java
index c16f91c..3edec1b 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializer.java
@@ -20,20 +20,18 @@ package org.apache.isis.objectstore.jdo.datanucleus.persistence.spi;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
-
import javax.jdo.annotations.IdentityType;
import javax.jdo.identity.ByteIdentity;
import javax.jdo.identity.IntIdentity;
import javax.jdo.identity.LongIdentity;
import javax.jdo.identity.ObjectIdentity;
import javax.jdo.identity.StringIdentity;
-
import org.datanucleus.identity.OID;
-
import org.apache.isis.core.metamodel.adapter.oid.RootOid;
import org.apache.isis.core.metamodel.spec.ObjectSpecId;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
@@ -50,14 +48,21 @@ public final class JdoObjectIdSerializer {
public static class Exception extends RuntimeException {
private static final long serialVersionUID = 1L;
- public Exception(java.lang.Exception ex) {
+ public Exception(final java.lang.Exception ex) {
super(ex);
}
}
- public static String toOidIdentifier(Object jdoOid) {
+ public static String toOidIdentifier(final Object jdoOid) {
+
+ //
+ // @javax.jdo.annotations.PersistenceCapable(identityType = IdentityType.APPLICATION)
+ //
+ if(jdoOid instanceof javax.jdo.identity.ByteIdentity) {
+ return "b" + SEPARATOR + jdoOid;
+ }
if(jdoOid instanceof javax.jdo.identity.IntIdentity) {
- return "i" + SEPARATOR + jdoOid;
+ return "i" + SEPARATOR + jdoOid;
}
if(jdoOid instanceof javax.jdo.identity.StringIdentity) {
return "s" + SEPARATOR + jdoOid;
@@ -66,35 +71,65 @@ public final class JdoObjectIdSerializer {
return "l" + SEPARATOR + jdoOid;
}
if(jdoOid instanceof javax.jdo.identity.ObjectIdentity) {
- javax.jdo.identity.ObjectIdentity id = (ObjectIdentity) jdoOid;
- Object keyAsObject = id.getKeyAsObject();
+ final javax.jdo.identity.ObjectIdentity id = (ObjectIdentity) jdoOid;
+ final Object keyAsObject = id.getKeyAsObject();
// UUID support
if(keyAsObject instanceof UUID) {
- UUID uuid = (UUID) keyAsObject;
+ final UUID uuid = (UUID) keyAsObject;
return "u" + SEPARATOR + uuid.toString();
}
}
+
+ //
+ // @javax.jdo.annotations.PersistenceCapable(identityType = IdentityType.DATASTORE)
+ //
if(jdoOid instanceof OID) {
- OID dnOid = (OID) jdoOid;
- Object keyValue = dnOid.getKeyValue();
-
- // prettier handling of these common cases
- if(keyValue instanceof String) {
- return "S" + SEPARATOR + keyValue;
- }
- if(keyValue instanceof Long) {
- return "L" + SEPARATOR + keyValue;
- }
+ //
+ // prettier handling of common datatypes if possible
+ //
- if(keyValue instanceof BigInteger) {
- return "B" + SEPARATOR + keyValue;
- }
+ final OID dnOid = (OID) jdoOid;
+ final Object keyValue = dnOid.getKeyValue();
- if(keyValue instanceof Integer) {
- return "I" + SEPARATOR + keyValue;
- }
+ if(false) {
+
+ //
+ // 1.8.0 original handling, appending a prefix "L_" or whatever
+ //
+ // if required by user community, we could add a property in isis.properties to enable if requested.
+ //
+ if(keyValue instanceof String) {
+ return "S" + SEPARATOR + keyValue;
+ }
+
+ if(keyValue instanceof Long) {
+ return "L" + SEPARATOR + keyValue;
+ }
+
+ // 1.8.0 did not support BigDecimal
+
+ if(keyValue instanceof BigInteger) {
+ return "B" + SEPARATOR + keyValue;
+ }
+
+ if(keyValue instanceof Integer) {
+ return "I" + SEPARATOR + keyValue;
+ }
+
+ } else {
+
+ if( keyValue instanceof String ||
+ keyValue instanceof Long ||
+ keyValue instanceof BigDecimal || // 1.8.0 did not support BigDecimal
+ keyValue instanceof BigInteger ||
+ keyValue instanceof Integer) {
+
+ // no separator
+ return "" + keyValue;
+ }
+ }
}
// the JDO spec (5.4.3) requires that OIDs are serializable toString and
@@ -102,69 +137,80 @@ public final class JdoObjectIdSerializer {
return jdoOid.getClass().getName().toString() + SEPARATOR + jdoOid.toString();
}
- private static List<String> dnPrefixes = Arrays.asList("S", "I", "L", "B");
+ private static final List<String> dnPrefixes = Arrays.asList("S", "I", "L", "M", "B");
- public static Object toJdoObjectId(RootOid oid) {
+ public static Object toJdoObjectId(final RootOid oid) {
- String idStr = oid.getIdentifier();
+ final String idStr = oid.getIdentifier();
final int separatorIdx = idStr.indexOf(SEPARATOR);
-
- final String distinguisher = idStr.substring(0, separatorIdx);
- final String keyStr = idStr.substring(separatorIdx+1);
final ObjectSpecification spec = getSpecificationLoader().lookupBySpecId(oid.getObjectSpecId());
final JdoPersistenceCapableFacet jdoPcFacet = spec.getFacet(JdoPersistenceCapableFacet.class);
- if(isApplicationIdentity(jdoPcFacet)) {
+
+ if(separatorIdx != -1) {
+
+ // behaviour for OIDs as of 1.8.0 and previously
+
+ final String distinguisher = idStr.substring(0, separatorIdx);
+ final String keyStr = idStr.substring(separatorIdx + 1);
+
+ final boolean isApplicationIdentity = isApplicationIdentity(jdoPcFacet);
if("s".equals(distinguisher)) {
- return keyStr;
+ if (isApplicationIdentity) {
+ return keyStr;
+ } else {
+ return new StringIdentity(objectTypeClassFor(oid), keyStr);
+ }
+ } else if("i".equals(distinguisher)) {
+ if(isApplicationIdentity) {
+ return Integer.parseInt(keyStr);
+ } else {
+ return new IntIdentity(objectTypeClassFor(oid), keyStr);
+ }
+ } else if("l".equals(distinguisher)) {
+ if(isApplicationIdentity) {
+ return Long.parseLong(keyStr);
+ } else {
+ return new LongIdentity(objectTypeClassFor(oid), keyStr);
+ }
+ } else if("b".equals(distinguisher)) {
+ if(isApplicationIdentity) {
+ return Byte.parseByte(keyStr);
+ } else {
+ return new ByteIdentity(objectTypeClassFor(oid), keyStr);
+ }
+ } else if("u".equals(distinguisher)) {
+ if(isApplicationIdentity) {
+ return UUID.fromString(keyStr);
+ } else {
+ return new ObjectIdentity(objectTypeClassFor(oid), UUID.fromString(keyStr));
+ }
}
- else if("i".equals(distinguisher)) {
- return Integer.parseInt(keyStr);
- }
- else if("l".equals(distinguisher)) {
- return Long.parseLong(keyStr);
- }
- else if("b".equals(distinguisher)) {
- return Byte.parseByte(keyStr);
+
+ if(dnPrefixes.contains(distinguisher)) {
+ return keyStr + "[OID]" + spec.getFullIdentifier();
}
- else if("u".equals(distinguisher)) {
- return UUID.fromString(keyStr);
+
+ final String clsName = distinguisher;
+ try {
+ final Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass(clsName);
+ final Constructor<?> cons = cls.getConstructor(String.class);
+ final Object dnOid = cons.newInstance(keyStr);
+ return dnOid.toString();
+ } catch (ClassNotFoundException | IllegalArgumentException | InstantiationException | IllegalAccessException | SecurityException | InvocationTargetException | NoSuchMethodException e) {
+ throw new JdoObjectIdSerializer.Exception(e);
}
-
+
} else {
- if("s".equals(distinguisher)) {
- return new StringIdentity(objectTypeClassFor(oid), keyStr);
- }
- else if("i".equals(distinguisher)) {
- return new IntIdentity(objectTypeClassFor(oid), keyStr);
- }
- else if("l".equals(distinguisher)) {
- return new LongIdentity(objectTypeClassFor(oid), keyStr);
- }
- else if("b".equals(distinguisher)) {
- return new ByteIdentity(objectTypeClassFor(oid), keyStr);
- }
- else if("u".equals(distinguisher)) {
- return new ObjectIdentity(objectTypeClassFor(oid), UUID.fromString(keyStr));
- }
- }
-
+ // there was no separator, so this identifier must have been for
+ // @javax.jdo.annotations.PersistenceCapable(identityType = IdentityType.DATASTORE)
+ // for one of the common types (prettier handling)
+
+ return idStr + "[OID]" + spec.getFullIdentifier();
- if(dnPrefixes.contains(distinguisher)) {
- return keyStr + "[OID]" + spec.getFullIdentifier();
- }
-
- final String clsName = distinguisher;
- try {
- final Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass(clsName);
- final Constructor<?> cons = cls.getConstructor(String.class);
- final Object dnOid = cons.newInstance(keyStr);
- return dnOid.toString();
- } catch (ClassNotFoundException | IllegalArgumentException | InstantiationException | IllegalAccessException | SecurityException | InvocationTargetException | NoSuchMethodException e) {
- throw new JdoObjectIdSerializer.Exception(e);
}
}
@@ -172,12 +218,12 @@ public final class JdoObjectIdSerializer {
return jdoPcFacet != null && jdoPcFacet.getIdentityType() == IdentityType.APPLICATION;
}
- private static Class<?> objectTypeClassFor(RootOid oid) {
- final ObjectSpecId objectSpecId = oid.getObjectSpecId();
- final ObjectSpecification spec = getSpecificationLoader().lookupBySpecId(objectSpecId);
- final Class<?> correspondingClass = spec.getCorrespondingClass();
- return correspondingClass;
- }
+ private static Class<?> objectTypeClassFor(final RootOid oid) {
+ final ObjectSpecId objectSpecId = oid.getObjectSpecId();
+ final ObjectSpecification spec = getSpecificationLoader().lookupBySpecId(objectSpecId);
+ final Class<?> correspondingClass = spec.getCorrespondingClass();
+ return correspondingClass;
+ }
private static SpecificationLoaderSpi getSpecificationLoader() {
return IsisContext.getSpecificationLoader();
http://git-wip-us.apache.org/repos/asf/isis/blob/0fed5e38/tck/tck-integtests/src/test/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializerTest.java
----------------------------------------------------------------------
diff --git a/tck/tck-integtests/src/test/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializerTest.java b/tck/tck-integtests/src/test/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializerTest.java
index 012f9a6..f73adc8 100644
--- a/tck/tck-integtests/src/test/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializerTest.java
+++ b/tck/tck-integtests/src/test/java/org/apache/isis/objectstore/jdo/datanucleus/persistence/spi/JdoObjectIdSerializerTest.java
@@ -18,31 +18,28 @@
*/
package org.apache.isis.objectstore.jdo.datanucleus.persistence.spi;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
import java.math.BigInteger;
import java.util.Date;
-
import org.datanucleus.identity.OIDImpl;
import org.junit.Rule;
import org.junit.Test;
-
import org.apache.isis.applib.annotation.ObjectType;
import org.apache.isis.core.commons.matchers.IsisMatchers;
import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
public class JdoObjectIdSerializerTest {
- @ObjectType("CUS")
- public static class Customer {}
-
- public static class CustomerRepository {
- public void foo(Customer x) {}
- }
-
+ @ObjectType("CUS")
+ public static class Customer {}
+ public static class CustomerRepository {
+ public void foo(Customer x) {}
+ }
+
@Rule
public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder()
.withServices(new CustomerRepository())