You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/12/21 20:46:51 UTC
[isis] branch master updated: ISIS-2033: reinstate JDO facets in
new jdo-integration module
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 75d688c ISIS-2033: reinstate JDO facets in new jdo-integration module
75d688c is described below
commit 75d688c89dcda03bc30639650cd3658d53b1be37
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Dec 21 21:39:00 2020 +0100
ISIS-2033: reinstate JDO facets in new jdo-integration module
---
.../entities/DnEntityStateProvider.java | 45 ++++-
.../jdo/integration/IsisModuleJdoIntegration.java | 5 +-
.../integration/metamodel/JdoProgrammingModel.java | 115 +++++++++++-
.../{ => facets/entity}/JdoEntityFacetFactory.java | 8 +-
...JdoDatastoreIdentityAnnotationFacetFactory.java | 61 ++++++
.../JdoDatastoreIdentityFacet.java} | 18 +-
.../JdoDatastoreIdentityFacetAbstract.java | 54 ++++++
.../JdoDatastoreIdentityFacetAnnotation.java} | 16 +-
.../JdoDatastoreIdentityFacetImpl.java} | 16 +-
.../object/datastoreidentity/package-info.java | 17 ++
.../JdoDiscriminatorAnnotationFacetFactory.java | 104 +++++++++++
.../discriminator/JdoDiscriminatorFacet.java} | 9 +-
.../JdoDiscriminatorFacetDefault.java} | 14 +-
...ferredFromJdoDiscriminatorValueAnnotation.java} | 19 +-
.../facets/object/discriminator/package-info.java | 17 ++
...cIdFacetForJdoPersistenceCapableAnnotation.java | 51 +++++
...doPersistenceCapableAnnotationFacetFactory.java | 98 ++++++++++
.../JdoPersistenceCapableFacet.java} | 29 ++-
.../JdoPersistenceCapableFacetAbstract.java | 79 ++++++++
.../JdoPersistenceCapableFacetAnnotation.java} | 19 +-
.../JdoPersistenceCapableFacetImpl.java} | 20 +-
.../object/persistencecapable/package-info.java | 22 +++
.../facets/object/query/JdoNamedQuery.java | 112 +++++++++++
.../object/query/JdoQueriesFacetAnnotation.java} | 20 +-
.../query/JdoQueryAnnotationFacetFactory.java | 102 ++++++++++
.../facets/object/query/JdoQueryFacet.java | 59 ++++++
.../facets/object/query/JdoQueryFacetAbstract.java | 64 +++++++
.../object/query/JdoQueryFacetAnnotation.java} | 20 +-
.../object/query/VisitorForClauseAbstract.java | 109 +++++++++++
.../facets/object/query/VisitorForFromClause.java | 67 +++++++
.../object/query/VisitorForVariablesClause.java | 68 +++++++
.../version/JdoVersionAnnotationFacetFactory.java | 107 +++++++++++
.../facets/object/version/JdoVersionFacet.java} | 9 +-
.../version/JdoVersionFacetFromAnnotation.java} | 14 +-
.../facets/object/version/package-info.java | 17 ++
...DerivedFromJdoColumnAnnotationFacetFactory.java | 180 ++++++++++++++++++
.../BigDecimalFacetDerivedFromJdoColumn.java | 59 ++++++
.../prop/column/BigDecimalFacetFallback.java | 47 +++++
.../MandatoryFacetDerivedFromJdoColumn.java} | 20 +-
...datoryFacetInferredFromAbsenceOfJdoColumn.java} | 19 +-
...ndatoryFromJdoColumnAnnotationFacetFactory.java | 207 +++++++++++++++++++++
...DerivedFromJdoColumnAnnotationFacetFactory.java | 159 ++++++++++++++++
.../MaxLengthFacetDerivedFromJdoColumn.java} | 15 +-
.../JdoNotPersistentAnnotationFacetFactory.java | 58 ++++++
.../prop/notpersistent/JdoNotPersistentFacet.java} | 19 +-
.../JdoNotPersistentFacetAbstract.java} | 21 ++-
.../JdoNotPersistentFacetAnnotation.java} | 14 +-
.../notpersistent/JdoNotPersistentFacetImpl.java} | 14 +-
...edFacetDerivedFromJdoPrimaryKeyAnnotation.java} | 19 +-
.../JdoPrimaryKeyAnnotationFacetFactory.java | 64 +++++++
.../prop/primarykey/JdoPrimaryKeyFacet.java} | 19 +-
.../primarykey/JdoPrimaryKeyFacetAbstract.java} | 21 ++-
.../primarykey/JdoPrimaryKeyFacetAnnotation.java} | 14 +-
.../prop/primarykey/JdoPrimaryKeyFacetImpl.java} | 14 +-
...nalFacetDerivedFromJdoPrimaryKeyAnnotation.java | 43 +++++
.../facets/prop/primarykey/package-info.java | 22 +++
.../jdo/integration/services/DnJdoSupport.java | 190 +++++++++++++++++++
...tityStateProvider.java => JdoFacetContext.java} | 9 +-
persistence/jdo/spring/pom.xml | 2 +-
59 files changed, 2689 insertions(+), 164 deletions(-)
diff --git a/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/entities/DnEntityStateProvider.java b/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/entities/DnEntityStateProvider.java
index 67fcaca..9c012b3 100644
--- a/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/entities/DnEntityStateProvider.java
+++ b/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/entities/DnEntityStateProvider.java
@@ -18,16 +18,23 @@
*/
package org.apache.isis.persistence.jdo.datanucleus.entities;
+import java.lang.reflect.Method;
+import java.util.Set;
+
+import javax.annotation.Nullable;
+
import org.datanucleus.enhancement.Persistable;
import org.springframework.stereotype.Component;
import org.apache.isis.applib.services.repository.EntityState;
-import org.apache.isis.persistence.jdo.provider.entities.JdoEntityStateProvider;
+import org.apache.isis.commons.internal.base._NullSafe;
+import org.apache.isis.commons.internal.collections._Sets;
+import org.apache.isis.persistence.jdo.provider.entities.JdoFacetContext;
import lombok.val;
@Component
-public class DnEntityStateProvider implements JdoEntityStateProvider {
+public class DnEntityStateProvider implements JdoFacetContext {
@Override
public EntityState getEntityState(Object pojo) {
@@ -51,4 +58,38 @@ public class DnEntityStateProvider implements JdoEntityStateProvider {
return EntityState.NOT_PERSISTABLE;
}
+ @Override
+ public boolean isPersistenceEnhanced(@Nullable Class<?> cls) {
+ if(cls==null) {
+ return false;
+ }
+ return org.datanucleus.enhancement.Persistable.class.isAssignableFrom(cls);
+ }
+
+ @Override
+ public boolean isMethodProvidedByEnhancement(@Nullable Method method) {
+ if(method==null) {
+ return false;
+ }
+ ensureInit();
+ return /*methodStartsWith(method, "jdo") || */
+ jdoMethodsProvidedByEnhancement.contains(method.toString());
+ }
+
+ // -- HELPER
+
+ private static final Set<String> jdoMethodsProvidedByEnhancement = _Sets.newHashSet();
+
+ private static Method[] getMethodsProvidedByEnhancement() {
+ return org.datanucleus.enhancement.Persistable.class.getDeclaredMethods();
+ }
+
+ private static void ensureInit() {
+ if(jdoMethodsProvidedByEnhancement.isEmpty()) {
+ _NullSafe.stream(getMethodsProvidedByEnhancement())
+ .map(Method::toString)
+ .forEach(jdoMethodsProvidedByEnhancement::add);
+ }
+ }
+
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/IsisModuleJdoIntegration.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/IsisModuleJdoIntegration.java
index 9d6ecd0..719c4de 100644
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/IsisModuleJdoIntegration.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/IsisModuleJdoIntegration.java
@@ -24,6 +24,7 @@ import org.springframework.context.annotation.Import;
import org.apache.isis.core.runtime.IsisModuleCoreRuntime;
import org.apache.isis.persistence.jdo.applib.IsisModulePersistenceJdoApplib;
import org.apache.isis.persistence.jdo.integration.metamodel.JdoProgrammingModel;
+import org.apache.isis.persistence.jdo.integration.services.DnJdoSupport;
@Configuration
@Import({
@@ -34,7 +35,9 @@ import org.apache.isis.persistence.jdo.integration.metamodel.JdoProgrammingModel
// @Component's
JdoProgrammingModel.class,
-// // @Service's
+ // @Service's
+ DnJdoSupport.class
+
// DataNucleusSettings.class,
// ExceptionRecognizerForSQLIntegrityConstraintViolationUniqueOrIndexException.class,
// ExceptionRecognizerForJDODataStoreExceptionIntegrityConstraintViolationForeignKeyNoActionException.class,
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/JdoProgrammingModel.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/JdoProgrammingModel.java
index e36ed8e..119a404 100644
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/JdoProgrammingModel.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/JdoProgrammingModel.java
@@ -18,29 +18,134 @@
*/
package org.apache.isis.persistence.jdo.integration.metamodel;
-import javax.inject.Inject;
+import javax.jdo.annotations.IdentityType;
import org.springframework.stereotype.Component;
-import org.apache.isis.core.config.IsisConfiguration;
import org.apache.isis.core.metamodel.facetapi.MetaModelRefiner;
+import org.apache.isis.core.metamodel.facets.collections.CollectionFacet;
+import org.apache.isis.core.metamodel.facets.object.ignore.datanucleus.RemoveDatanucleusPersistableTypesFacetFactory;
+import org.apache.isis.core.metamodel.facets.object.ignore.datanucleus.RemoveDnPrefixedMethodsFacetFactory;
+import org.apache.isis.core.metamodel.facets.object.ignore.jdo.RemoveJdoEnhancementTypesFacetFactory;
+import org.apache.isis.core.metamodel.facets.object.ignore.jdo.RemoveJdoPrefixedMethodsFacetFactory;
+import org.apache.isis.core.metamodel.facets.object.parented.ParentedCollectionFacet;
import org.apache.isis.core.metamodel.progmodel.ProgrammingModel;
import org.apache.isis.core.metamodel.progmodel.ProgrammingModel.Marker;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.entity.JdoEntityFacetFactory;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.object.datastoreidentity.JdoDatastoreIdentityAnnotationFacetFactory;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.object.discriminator.JdoDiscriminatorAnnotationFacetFactory;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable.JdoPersistenceCapableAnnotationFacetFactory;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable.JdoPersistenceCapableFacet;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.object.query.JdoQueryAnnotationFacetFactory;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.object.version.JdoVersionAnnotationFacetFactory;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.column.BigDecimalDerivedFromJdoColumnAnnotationFacetFactory;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.column.MandatoryFromJdoColumnAnnotationFacetFactory;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.column.MaxLengthDerivedFromJdoColumnAnnotationFacetFactory;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.notpersistent.JdoNotPersistentAnnotationFacetFactory;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.primarykey.JdoPrimaryKeyAnnotationFacetFactory;
import lombok.val;
@Component
public class JdoProgrammingModel implements MetaModelRefiner {
- @Inject private IsisConfiguration config;
+ //@Inject private IsisConfiguration config;
@Override
public void refineProgrammingModel(ProgrammingModel pm) {
- val step1 = ProgrammingModel.FacetProcessingOrder.A2_AFTER_FALLBACK_DEFAULTS;
+ val step0 = ProgrammingModel.FacetProcessingOrder.A2_AFTER_FALLBACK_DEFAULTS;
+
+ pm.addFactory(step0, JdoEntityFacetFactory.class, Marker.JDO);
+
+
+ val step1 = ProgrammingModel.FacetProcessingOrder.C2_AFTER_METHOD_REMOVING;
+
+ // come what may, we have to ignore the PersistenceCapable supertype.
+ pm.addFactory(step1, RemoveJdoEnhancementTypesFacetFactory.class, Marker.JDO);
+ // so we may as well also just ignore any 'jdo' prefixed methods here also.
+ pm.addFactory(step1, RemoveJdoPrefixedMethodsFacetFactory.class, Marker.JDO);
+ // Datanucleus
+ pm.addFactory(step1, RemoveDatanucleusPersistableTypesFacetFactory.class, Marker.JDO);
+ pm.addFactory(step1, RemoveDnPrefixedMethodsFacetFactory.class, Marker.JDO);
+
+
+ val step2 = ProgrammingModel.FacetProcessingOrder.A2_AFTER_FALLBACK_DEFAULTS;
+
+ pm.addFactory(step2, JdoPersistenceCapableAnnotationFacetFactory.class, Marker.JDO);
+ pm.addFactory(step2, JdoDatastoreIdentityAnnotationFacetFactory.class, Marker.JDO);
+
+ pm.addFactory(step2, JdoPrimaryKeyAnnotationFacetFactory.class, Marker.JDO);
+ pm.addFactory(step2, JdoNotPersistentAnnotationFacetFactory.class, Marker.JDO);
+ pm.addFactory(step2, JdoDiscriminatorAnnotationFacetFactory.class, Marker.JDO);
+ pm.addFactory(step2, JdoVersionAnnotationFacetFactory.class, Marker.JDO);
+
+ pm.addFactory(step2, JdoQueryAnnotationFacetFactory.class, Marker.JDO);
+
+ pm.addFactory(step2, BigDecimalDerivedFromJdoColumnAnnotationFacetFactory.class, Marker.JDO);
+ pm.addFactory(step2, MaxLengthDerivedFromJdoColumnAnnotationFacetFactory.class, Marker.JDO);
+ // must appear after JdoPrimaryKeyAnnotationFacetFactory (above)
+ // and also MandatoryFacetOnPropertyMandatoryAnnotationFactory
+ // and also PropertyAnnotationFactory
+ pm.addFactory(step2, MandatoryFromJdoColumnAnnotationFacetFactory.class, Marker.JDO);
+
+
+ // -- validators
+
+ addValidatorToEnsureIdentityType(pm);
+ addValidatorToCheckForUnsupportedAnnotations(pm);
- pm.addFactory(step1, JdoEntityFacetFactory.class, Marker.JPA);
}
+
+ // -- HELPER
+ private void addValidatorToEnsureIdentityType(ProgrammingModel pm) {
+ pm.addValidator((objSpec, validation) -> {
+
+ final JdoPersistenceCapableFacet jpcf = objSpec.getFacet(JdoPersistenceCapableFacet.class);
+ if(jpcf == null) {
+ return true;
+ }
+ final IdentityType identityType = jpcf.getIdentityType();
+ if(identityType == IdentityType.APPLICATION) {
+ // ok
+
+ } else if(identityType == IdentityType.NONDURABLE) {
+ // ok; for use with DN view objects (http://www.datanucleus.org/products/accessplatform_3_2/datastores/rdbms_views.html)
+
+ } else if(identityType == IdentityType.DATASTORE || identityType == IdentityType.UNSPECIFIED) {
+
+ // TODO: ensure that DATASTORE has recognised @DatastoreIdentity attribute
+
+ } else {
+ // in fact, at the time of writing there are no others, so this is theoretical in case there is
+ // a future change to the JDO spec
+ validation.onFailure(
+ objSpec,
+ objSpec.getIdentifier(),
+ "%s: is annotated with @PersistenceCapable but with an unrecognized identityType (%s)",
+ objSpec.getFullIdentifier(),
+ identityType);
+ }
+
+ return true;
+ }, Marker.JDO);
+
+ }
+
+ private void addValidatorToCheckForUnsupportedAnnotations(ProgrammingModel pm) {
+
+ pm.addValidator((objSpec, validation) -> {
+ if (objSpec.containsNonFallbackFacet(ParentedCollectionFacet.class) && !objSpec.containsNonFallbackFacet(CollectionFacet.class)) {
+ validation.onFailure(
+ objSpec,
+ objSpec.getIdentifier(),
+ "%s: JDO/DataNucleus object store currently does not supported Aggregated or EmbeddedOnly annotations",
+ objSpec.getFullIdentifier());
+ }
+ return true;
+ }, Marker.JDO);
+
+ }
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/JdoEntityFacetFactory.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/entity/JdoEntityFacetFactory.java
similarity index 98%
rename from persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/JdoEntityFacetFactory.java
rename to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/entity/JdoEntityFacetFactory.java
index 716f49f..b3d72e8 100644
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/JdoEntityFacetFactory.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/entity/JdoEntityFacetFactory.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.integration.metamodel;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.entity;
import java.lang.reflect.Method;
import java.math.BigInteger;
@@ -51,7 +51,7 @@ import org.apache.isis.core.metamodel.facets.object.entity.EntityFacet;
import org.apache.isis.core.metamodel.spec.ManagedObject;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.persistence.jdo.applib.integration.JdoSupportService;
-import org.apache.isis.persistence.jdo.provider.entities.JdoEntityStateProvider;
+import org.apache.isis.persistence.jdo.provider.entities.JdoFacetContext;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -292,9 +292,9 @@ public class JdoEntityFacetFactory extends FacetFactoryAbstract {
// -- DEPENDENCIES
- protected JdoEntityStateProvider getJdoEntityStateProvider() {
+ protected JdoFacetContext getJdoEntityStateProvider() {
return serviceRegistry
- .lookupServiceElseFail(JdoEntityStateProvider.class);
+ .lookupServiceElseFail(JdoFacetContext.class);
}
protected PersistenceManager getPersistenceManager() {
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityAnnotationFacetFactory.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityAnnotationFacetFactory.java
new file mode 100644
index 0000000..dc413e9
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityAnnotationFacetFactory.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.datastoreidentity;
+
+
+import javax.inject.Inject;
+import javax.jdo.annotations.DatastoreIdentity;
+import javax.jdo.annotations.IdGeneratorStrategy;
+
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.Annotations;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.persistence.jdo.provider.entities.JdoFacetContext;
+
+public class JdoDatastoreIdentityAnnotationFacetFactory extends FacetFactoryAbstract {
+
+ @Inject private JdoFacetContext jdoFacetContext;
+
+ public JdoDatastoreIdentityAnnotationFacetFactory() {
+ super(FeatureType.OBJECTS_ONLY);
+ }
+
+ @Override
+ public void process(ProcessClassContext processClassContext) {
+ final Class<?> cls = processClassContext.getCls();
+
+ // only applies to JDO entities; ignore any view models
+ if(!jdoFacetContext.isPersistenceEnhanced(cls)) {
+ return;
+ }
+
+ final DatastoreIdentity annotation = Annotations.getAnnotation(cls, DatastoreIdentity.class);
+ if (annotation == null) {
+ return;
+ }
+ IdGeneratorStrategy strategyAttribute = annotation.strategy();
+
+ FacetUtil.addFacet(new JdoDatastoreIdentityFacetAnnotation(
+ strategyAttribute, processClassContext.getFacetHolder()));
+ return;
+ }
+
+
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityFacet.java
similarity index 65%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityFacet.java
index 791698c..2bb246e 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityFacet.java
@@ -16,13 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.datastoreidentity;
-import org.apache.isis.applib.services.repository.EntityState;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
+import javax.jdo.annotations.DatastoreIdentity;
+import javax.jdo.annotations.IdGeneratorStrategy;
- EntityState getEntityState(Object pojo);
-
+import org.apache.isis.core.metamodel.facetapi.Facet;
+
+
+/**
+ * Corresponds to annotating the class with the {@link DatastoreIdentity} annotation.
+ */
+public interface JdoDatastoreIdentityFacet extends Facet {
+
+ IdGeneratorStrategy getStrategy();
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityFacetAbstract.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityFacetAbstract.java
new file mode 100644
index 0000000..9afbbf9
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityFacetAbstract.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.datastoreidentity;
+
+import java.util.Map;
+
+import javax.jdo.annotations.IdGeneratorStrategy;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+
+public abstract class JdoDatastoreIdentityFacetAbstract extends FacetAbstract implements
+JdoDatastoreIdentityFacet {
+
+
+ public static Class<? extends Facet> type() {
+ return JdoDatastoreIdentityFacet.class;
+ }
+
+ private final IdGeneratorStrategy strategy;
+
+ public JdoDatastoreIdentityFacetAbstract(IdGeneratorStrategy strategy, FacetHolder facetHolder) {
+ super(JdoDatastoreIdentityFacetAbstract.type(), facetHolder, Derivation.NOT_DERIVED);
+ this.strategy = strategy;
+ }
+
+ @Override
+ public IdGeneratorStrategy getStrategy() {
+ return strategy;
+ }
+
+ @Override public void appendAttributesTo(final Map<String, Object> attributeMap) {
+ super.appendAttributesTo(attributeMap);
+ attributeMap.put("strategy", strategy);
+ }
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityFacetAnnotation.java
similarity index 65%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityFacetAnnotation.java
index 791698c..1c077d5 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityFacetAnnotation.java
@@ -16,13 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.datastoreidentity;
-import org.apache.isis.applib.services.repository.EntityState;
+import javax.jdo.annotations.IdGeneratorStrategy;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+
+public class JdoDatastoreIdentityFacetAnnotation extends JdoDatastoreIdentityFacetImpl {
+
+ public JdoDatastoreIdentityFacetAnnotation(IdGeneratorStrategy strategy, FacetHolder facetHolder) {
+ super(strategy, facetHolder);
+ }
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityFacetImpl.java
similarity index 65%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityFacetImpl.java
index 791698c..b0573f0 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/JdoDatastoreIdentityFacetImpl.java
@@ -16,13 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.datastoreidentity;
-import org.apache.isis.applib.services.repository.EntityState;
+import javax.jdo.annotations.IdGeneratorStrategy;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+
+public class JdoDatastoreIdentityFacetImpl extends JdoDatastoreIdentityFacetAbstract {
+
+ public JdoDatastoreIdentityFacetImpl(IdGeneratorStrategy strategy, FacetHolder facetHolder) {
+ super(strategy, facetHolder);
+ }
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/package-info.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/package-info.java
new file mode 100644
index 0000000..1fbe8b7
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/datastoreidentity/package-info.java
@@ -0,0 +1,17 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.datastoreidentity;
\ No newline at end of file
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/JdoDiscriminatorAnnotationFacetFactory.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/JdoDiscriminatorAnnotationFacetFactory.java
new file mode 100644
index 0000000..3c6a443
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/JdoDiscriminatorAnnotationFacetFactory.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.discriminator;
+
+import javax.inject.Inject;
+import javax.jdo.annotations.Discriminator;
+
+import org.apache.isis.commons.internal.base._Strings;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.Annotations;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.ObjectSpecIdFacetFactory;
+import org.apache.isis.core.metamodel.facets.object.objectspecid.ObjectSpecIdFacet;
+import org.apache.isis.core.metamodel.facets.object.objectspecid.classname.ObjectSpecIdFacetDerivedFromClassName;
+import org.apache.isis.core.metamodel.services.classsubstitutor.ClassSubstitutorRegistry;
+import org.apache.isis.persistence.jdo.provider.entities.JdoFacetContext;
+
+import lombok.val;
+
+public class JdoDiscriminatorAnnotationFacetFactory
+extends FacetFactoryAbstract
+implements ObjectSpecIdFacetFactory {
+
+ @Inject private ClassSubstitutorRegistry classSubstitutorRegistry;
+ @Inject private JdoFacetContext jdoFacetContext;
+
+ public JdoDiscriminatorAnnotationFacetFactory() {
+ super(FeatureType.OBJECTS_ONLY);
+ }
+
+ @Override
+ public void process(final ProcessObjectSpecIdContext processClassContext) {
+
+ // only applies to JDO entities; ignore any view models
+ final Class<?> cls = processClassContext.getCls();
+ if(!jdoFacetContext.isPersistenceEnhanced(cls)) {
+ return;
+ }
+
+ final Discriminator annotation = Annotations.getAnnotation(cls, Discriminator.class);
+ if (annotation == null) {
+ return;
+ }
+ final FacetHolder facetHolder = processClassContext.getFacetHolder();
+
+ final String annotationValue = annotation.value();
+ final ObjectSpecIdFacet facet;
+ if (!_Strings.isNullOrEmpty(annotationValue)) {
+ facet = new ObjectSpecIdFacetInferredFromJdoDiscriminatorValueAnnotation(
+ annotationValue, facetHolder);
+ } else {
+ val substitute = classSubstitutorRegistry.getSubstitution(cls);
+ if(substitute.isNeverIntrospect()) {
+ return;
+ }
+
+ val substituted = substitute.apply(cls);
+ facet = new ObjectSpecIdFacetDerivedFromClassName(
+ substituted.getCanonicalName(),
+ facetHolder);
+
+ }
+ FacetUtil.addFacet(facet);
+ }
+
+
+ @Override
+ public void process(ProcessClassContext processClassContext) {
+
+ // only applies to JDO entities; ignore any view models
+ final Class<?> cls = processClassContext.getCls();
+ if(!jdoFacetContext.isPersistenceEnhanced(cls)) {
+ return;
+ }
+
+ final Discriminator annotation = Annotations.getAnnotation(processClassContext.getCls(), Discriminator.class);
+ if (annotation == null) {
+ return;
+ }
+ String annotationValueAttribute = annotation.value();
+ final FacetHolder facetHolder = processClassContext.getFacetHolder();
+ FacetUtil.addFacet(new JdoDiscriminatorFacetDefault(annotationValueAttribute, facetHolder));
+ }
+
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/JdoDiscriminatorFacet.java
similarity index 72%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/JdoDiscriminatorFacet.java
index 791698c..9fb2851 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/JdoDiscriminatorFacet.java
@@ -16,13 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.discriminator;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.core.metamodel.facets.SingleValueFacet;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
+public interface JdoDiscriminatorFacet extends SingleValueFacet<String> {
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/JdoDiscriminatorFacetDefault.java
similarity index 63%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/JdoDiscriminatorFacetDefault.java
index 791698c..2ed6dee 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/JdoDiscriminatorFacetDefault.java
@@ -16,13 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.discriminator;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.SingleValueFacetAbstract;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
+public class JdoDiscriminatorFacetDefault extends SingleValueFacetAbstract<String> implements JdoDiscriminatorFacet {
+
+ public JdoDiscriminatorFacetDefault(String value, FacetHolder holder) {
+ super(JdoDiscriminatorFacet.class, value, holder);
+ }
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/ObjectSpecIdFacetInferredFromJdoDiscriminatorValueAnnotation.java
similarity index 59%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/ObjectSpecIdFacetInferredFromJdoDiscriminatorValueAnnotation.java
index 791698c..f10e6bd 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/ObjectSpecIdFacetInferredFromJdoDiscriminatorValueAnnotation.java
@@ -16,13 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.discriminator;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.objectspecid.ObjectSpecIdFacetAbstract;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
+public class ObjectSpecIdFacetInferredFromJdoDiscriminatorValueAnnotation extends
+ObjectSpecIdFacetAbstract {
+
+ public ObjectSpecIdFacetInferredFromJdoDiscriminatorValueAnnotation(final String value,
+ final FacetHolder holder) {
+ super(value, holder);
+ }
+
}
+
+// Copyright (c) Naked Objects Group Ltd.
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/package-info.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/package-info.java
new file mode 100644
index 0000000..35e1a41
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/discriminator/package-info.java
@@ -0,0 +1,17 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.discriminator;
\ No newline at end of file
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/domainobject/objectspecid/ObjectSpecIdFacetForJdoPersistenceCapableAnnotation.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/domainobject/objectspecid/ObjectSpecIdFacetForJdoPersistenceCapableAnnotation.java
new file mode 100644
index 0000000..7e0bd80
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/domainobject/objectspecid/ObjectSpecIdFacetForJdoPersistenceCapableAnnotation.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.domainobject.objectspecid;
+
+import java.util.Locale;
+
+import org.apache.isis.commons.internal.base._Strings;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.objectspecid.ObjectSpecIdFacet;
+import org.apache.isis.core.metamodel.facets.object.objectspecid.ObjectSpecIdFacetAbstract;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable.JdoPersistenceCapableFacet;
+
+public class ObjectSpecIdFacetForJdoPersistenceCapableAnnotation extends ObjectSpecIdFacetAbstract {
+
+ public static ObjectSpecIdFacet create(
+ final JdoPersistenceCapableFacet persistenceCapableFacet,
+ final FacetHolder holder) {
+
+ if(persistenceCapableFacet.isFallback()) {
+ return null;
+ }
+ final String schema = persistenceCapableFacet.getSchema();
+ if(_Strings.isNullOrEmpty(schema)) {
+ return null;
+ }
+ final String objectType = schema.toLowerCase(Locale.ROOT) + "." + persistenceCapableFacet.getTable();
+ return new ObjectSpecIdFacetForJdoPersistenceCapableAnnotation(objectType, holder);
+ }
+
+ private ObjectSpecIdFacetForJdoPersistenceCapableAnnotation(final String value,
+ final FacetHolder holder) {
+ super(value, holder);
+ }
+}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableAnnotationFacetFactory.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableAnnotationFacetFactory.java
new file mode 100644
index 0000000..9c5e407
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableAnnotationFacetFactory.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable;
+
+
+import javax.inject.Inject;
+import javax.jdo.annotations.EmbeddedOnly;
+import javax.jdo.annotations.IdentityType;
+import javax.jdo.annotations.PersistenceCapable;
+
+import org.apache.isis.commons.internal.base._Strings;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.Annotations;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.ObjectSpecIdFacetFactory;
+import org.apache.isis.core.metamodel.facets.object.domainobject.DomainObjectAnnotationFacetFactory;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.object.domainobject.objectspecid.ObjectSpecIdFacetForJdoPersistenceCapableAnnotation;
+import org.apache.isis.persistence.jdo.provider.entities.JdoFacetContext;
+
+import lombok.val;
+
+/**
+ * Implements {@link ObjectSpecIdFacetFactory} only because is a prereq of {@link DomainObjectAnnotationFacetFactory}.
+ */
+public class JdoPersistenceCapableAnnotationFacetFactory
+extends FacetFactoryAbstract
+implements ObjectSpecIdFacetFactory {
+
+ @Inject private JdoFacetContext jdoFacetContext;
+
+ public JdoPersistenceCapableAnnotationFacetFactory() {
+ super(FeatureType.OBJECTS_ONLY);
+ }
+
+ @Override
+ public void process(ObjectSpecIdFacetFactory.ProcessObjectSpecIdContext processClassContext) {
+ final Class<?> cls = processClassContext.getCls();
+
+ // only applies to JDO entities; ignore any view models
+ if(!jdoFacetContext.isPersistenceEnhanced(cls)) {
+ return;
+ }
+
+ final PersistenceCapable annotation = Annotations.getAnnotation(cls, PersistenceCapable.class);
+ if (annotation == null) {
+ return;
+ }
+ String annotationSchemaAttribute = annotation.schema();
+ if(_Strings.isNullOrEmpty(annotationSchemaAttribute)) {
+ annotationSchemaAttribute = null;
+ }
+ String annotationTableAttribute = annotation.table();
+ if (_Strings.isNullOrEmpty(annotationTableAttribute)) {
+ annotationTableAttribute = cls.getSimpleName();
+ }
+
+ val facetHolder = processClassContext.getFacetHolder();
+
+ val embeddedOnlyAttribute = annotation.embeddedOnly();
+ // Whether objects of this type can only be embedded,
+ // hence have no ID that binds them to the persistence layer
+ final boolean embeddedOnly = Boolean.valueOf(embeddedOnlyAttribute)
+ || Annotations.getAnnotation(cls, EmbeddedOnly.class)!=null;
+
+ if(embeddedOnly) {
+ // suppress
+ } else {
+
+ final IdentityType annotationIdentityType = annotation.identityType();
+ val jdoPersistenceCapableFacet = new JdoPersistenceCapableFacetAnnotation(
+ annotationSchemaAttribute,
+ annotationTableAttribute, annotationIdentityType, facetHolder);
+ FacetUtil.addFacet(jdoPersistenceCapableFacet);
+ FacetUtil.addFacet(ObjectSpecIdFacetForJdoPersistenceCapableAnnotation.create(jdoPersistenceCapableFacet, facetHolder));
+ }
+
+ return;
+ }
+
+
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableFacet.java
similarity index 52%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableFacet.java
index 791698c..0102409 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableFacet.java
@@ -16,13 +16,30 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable;
-import org.apache.isis.applib.services.repository.EntityState;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
+import javax.jdo.annotations.IdentityType;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+
+
+/**
+ * Corresponds to annotating the class with the {@link javax.jdo.annotations.PersistenceCapable} annotation.
+ */
+public interface JdoPersistenceCapableFacet extends Facet {
+
+ IdentityType getIdentityType();
+
+ /**
+ * Corresponds to {@link javax.jdo.annotations.PersistenceCapable#schema()}, or null if not specified.
+ */
+ String getSchema();
+
+ /**
+ * Corresponds to {@link javax.jdo.annotations.PersistenceCapable#table()}, or to the
+ * class' {@link Class#getSimpleName() simple name} if no table specified.
+ */
+ String getTable();
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableFacetAbstract.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableFacetAbstract.java
new file mode 100644
index 0000000..c9838c7
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableFacetAbstract.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable;
+
+import java.util.Map;
+
+import javax.jdo.annotations.IdentityType;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.entity.EntityFacet;
+
+public abstract class JdoPersistenceCapableFacetAbstract
+extends FacetAbstract
+implements JdoPersistenceCapableFacet {
+
+ public static Class<? extends Facet> type() {
+ return JdoPersistenceCapableFacet.class;
+ }
+
+ private final String schema;
+ private final String table;
+ private final IdentityType identityType;
+
+ public JdoPersistenceCapableFacetAbstract(
+ final String schemaName,
+ final String tableOrTypeName,
+ final IdentityType identityType,
+ final FacetHolder holder) {
+
+ super(JdoPersistenceCapableFacetAbstract.type(), holder, Derivation.NOT_DERIVED);
+ super.setFacetAliasType(EntityFacet.class);
+ this.schema = schemaName;
+ this.table = tableOrTypeName;
+ this.identityType = identityType;
+ }
+
+ @Override
+ public IdentityType getIdentityType() {
+ return identityType;
+ }
+
+ @Override
+ public String getSchema() {
+ return schema;
+ }
+
+ @Override
+ public String getTable() {
+ return table;
+ }
+
+ @Override
+ public void appendAttributesTo(final Map<String, Object> attributeMap) {
+ super.appendAttributesTo(attributeMap);
+ attributeMap.put("schema", schema);
+ attributeMap.put("table", table);
+ attributeMap.put("identityType", identityType);
+ }
+
+
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableFacetAnnotation.java
similarity index 59%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableFacetAnnotation.java
index 791698c..c4965f7 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableFacetAnnotation.java
@@ -16,13 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable;
-import org.apache.isis.applib.services.repository.EntityState;
+import javax.jdo.annotations.IdentityType;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+public class JdoPersistenceCapableFacetAnnotation extends JdoPersistenceCapableFacetImpl {
+
+ public JdoPersistenceCapableFacetAnnotation(
+ final String schemaName,
+ final String tableOrTypeName,
+ final IdentityType identityType,
+ final FacetHolder holder) {
+ super(schemaName, tableOrTypeName, identityType, holder);
+ }
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableFacetImpl.java
similarity index 59%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableFacetImpl.java
index 791698c..e7a20f9 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/JdoPersistenceCapableFacetImpl.java
@@ -16,13 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable;
-import org.apache.isis.applib.services.repository.EntityState;
+import javax.jdo.annotations.IdentityType;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+public class JdoPersistenceCapableFacetImpl extends JdoPersistenceCapableFacetAbstract {
+
+ public JdoPersistenceCapableFacetImpl(
+ final String schemaName,
+ final String tableOrTypeName,
+ final IdentityType identityType,
+ final FacetHolder holder) {
+ super(schemaName, tableOrTypeName, identityType, holder);
+ }
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/package-info.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/package-info.java
new file mode 100644
index 0000000..c9f5123
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/persistencecapable/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable;
\ No newline at end of file
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoNamedQuery.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoNamedQuery.java
new file mode 100644
index 0000000..bc7e242
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoNamedQuery.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.query;
+
+import javax.jdo.annotations.Query;
+
+import org.apache.isis.core.metamodel.services.metamodel.MetaModelExportSupport;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+/**
+ * Value object that represents the information of a
+ * {@link javax.jdo.annotations.Query}.
+ *
+ * @see {@link JdoQueryFacet}.
+ */
+public final class JdoNamedQuery implements MetaModelExportSupport {
+
+ private final String name;
+ private final String query;
+ private final String language;
+ private final ObjectSpecification objSpec;
+
+ private JdoNamedQuery(
+ final String name,
+ final String query,
+ final String language,
+ final ObjectSpecification noSpec) {
+ this.language = language;
+
+ assert name != null;
+ assert query != null;
+ assert noSpec != null;
+
+ this.name = name;
+ this.query = query;
+ this.objSpec = noSpec;
+ }
+
+ public JdoNamedQuery(
+ final Query jdoNamedQuery,
+ final ObjectSpecification objSpec) {
+ this(jdoNamedQuery.name(), jdoNamedQuery.value(), jdoNamedQuery.language(), objSpec);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public ObjectSpecification getObjectSpecification() {
+ return objSpec;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final JdoNamedQuery other = (JdoNamedQuery) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toMetamodelString() {
+ return getName();
+ }
+
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueriesFacetAnnotation.java
similarity index 65%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueriesFacetAnnotation.java
index 791698c..6daa1e8 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueriesFacetAnnotation.java
@@ -16,13 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.query;
-import org.apache.isis.applib.services.repository.EntityState;
+import javax.jdo.annotations.Query;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+
+public class JdoQueriesFacetAnnotation extends JdoQueryFacetAbstract
+implements JdoQueryFacet {
+
+ public JdoQueriesFacetAnnotation(final Query[] jdoNamedQueries,
+ final FacetHolder holder) {
+ super(holder);
+ add(jdoNamedQueries);
+ }
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueryAnnotationFacetFactory.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueryAnnotationFacetFactory.java
new file mode 100644
index 0000000..2a7d59c
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueryAnnotationFacetFactory.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.query;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.inject.Inject;
+import javax.jdo.annotations.Queries;
+import javax.jdo.annotations.Query;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facetapi.MetaModelRefiner;
+import org.apache.isis.core.metamodel.facets.Annotations;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.progmodel.ProgrammingModel;
+import org.apache.isis.persistence.jdo.provider.entities.JdoFacetContext;
+
+import lombok.val;
+
+public class JdoQueryAnnotationFacetFactory extends FacetFactoryAbstract
+implements MetaModelRefiner {
+
+ @Inject private JdoFacetContext jdoFacetContext;
+
+ public JdoQueryAnnotationFacetFactory() {
+ super(FeatureType.OBJECTS_ONLY);
+ }
+
+ @Override
+ public void process(ProcessClassContext processClassContext) {
+ final Class<?> cls = processClassContext.getCls();
+
+ // only applies to JDO entities; ignore any view models
+ if(!jdoFacetContext.isPersistenceEnhanced(cls)) {
+ return;
+ }
+
+ final Queries namedQueriesAnnotation = Annotations.getAnnotation(cls, Queries.class);
+ final FacetHolder facetHolder = processClassContext.getFacetHolder();
+
+ if (namedQueriesAnnotation != null) {
+ super.addFacet(new JdoQueriesFacetAnnotation(
+ namedQueriesAnnotation.value(), facetHolder));
+ return;
+ }
+
+ final Query namedQueryAnnotation = Annotations.getAnnotation(cls, Query.class);
+ if (namedQueryAnnotation != null) {
+ super.addFacet(new JdoQueryFacetAnnotation(
+ namedQueryAnnotation, facetHolder));
+ }
+ }
+
+ @Override
+ public void refineProgrammingModel(ProgrammingModel programmingModel) {
+ val isValidateFromClause =
+ getConfiguration().getCore().getMetaModel().getValidator().getJdoql().isFromClause();
+ if (isValidateFromClause) {
+ programmingModel.addValidator(new VisitorForFromClause(this));
+ }
+
+ val isValidateVariablesClause =
+ getConfiguration().getCore().getMetaModel().getValidator().getJdoql().isVariablesClause();
+ if (isValidateVariablesClause) {
+ programmingModel.addValidator(new VisitorForVariablesClause(this));
+ }
+ }
+
+ private static final Pattern fromPattern = Pattern.compile("SELECT.*?FROM[\\s]+([^\\s]+).*", Pattern.CASE_INSENSITIVE);
+
+ static String from(final String query) {
+ final Matcher matcher = fromPattern.matcher(query);
+ return matcher.matches() ? matcher.group(1) : null;
+ }
+
+ private static final Pattern variablesPattern = Pattern.compile(".*?VARIABLES[\\s]+([^\\s]+).*", Pattern.CASE_INSENSITIVE);
+ static String variables(final String query) {
+ final Matcher matcher = variablesPattern.matcher(query);
+ return matcher.matches() ? matcher.group(1) : null;
+ }
+
+
+
+}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueryFacet.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueryFacet.java
new file mode 100644
index 0000000..13d0323
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueryFacet.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.query;
+
+import java.util.List;
+
+import javax.jdo.annotations.Query;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+
+
+/**
+ * In the standard JDO Model, corresponds to annotating the class with either
+ * {@link javax.jdo.annotations.Query} or
+ * {@link javax.jdo.annotations.Queries}.
+ * <p>
+ * For a {@link javax.jdo.annotations.Query}, returns a singleton list of
+ * {@link JdoNamedQuery}.
+ * For a {@link javax.jdo.annotations.Queries}, returns a list of
+ * {@link JdoNamedQuery}s.
+ * <p>
+ * In both cases, mapping is as follows
+ * <ul>
+ * <li>{@link javax.jdo.annotations.Query#name()} ->
+ * {@link JdoNamedQuery#getName()
+ * getName()} property of JDO Object Store's own
+ * {@link JdoNamedQuery} value object</li>
+ * <li>{@link javax.jdo.annotations.Query#value()} ->
+ * {@link JdoNamedQuery#getQuery()}
+ * property of JDO Object Store's own
+ * {@link JdoNamedQuery} value object</li>
+ * </ul>
+ *
+ * <p>
+ * Optional attributes of the {@link Query} annotation are not currently mapped.
+ */
+public interface JdoQueryFacet extends Facet {
+
+ /**
+ * Returns an immutable {@link List}.
+ */
+ List<JdoNamedQuery> getNamedQueries();
+}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueryFacetAbstract.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueryFacetAbstract.java
new file mode 100644
index 0000000..bd3699a
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueryFacetAbstract.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.query;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.jdo.annotations.Query;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+
+
+public class JdoQueryFacetAbstract extends FacetAbstract implements
+JdoQueryFacet {
+
+ public static Class<? extends Facet> type() {
+ return JdoQueryFacet.class;
+ }
+
+ private final List<JdoNamedQuery> namedQueries = new ArrayList<JdoNamedQuery>();
+
+ public JdoQueryFacetAbstract(final FacetHolder holder) {
+ super(JdoQueryFacetAbstract.type(), holder, Derivation.NOT_DERIVED);
+ }
+
+ protected void add(final Query... jdoNamedQueries) {
+ final ObjectSpecification objSpec = (ObjectSpecification) getFacetHolder();
+ for (final Query jdoNamedQuery : jdoNamedQueries) {
+ namedQueries.add(new JdoNamedQuery(jdoNamedQuery, objSpec));
+ }
+ }
+
+ @Override
+ public List<JdoNamedQuery> getNamedQueries() {
+ return Collections.unmodifiableList(namedQueries);
+ }
+
+ @Override public void appendAttributesTo(final Map<String, Object> attributeMap) {
+ super.appendAttributesTo(attributeMap);
+ attributeMap.put("namedQueries", namedQueries);
+ }
+
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueryFacetAnnotation.java
similarity index 65%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueryFacetAnnotation.java
index 791698c..28fee72 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/JdoQueryFacetAnnotation.java
@@ -16,13 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.query;
-import org.apache.isis.applib.services.repository.EntityState;
+import javax.jdo.annotations.Query;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+
+
+public class JdoQueryFacetAnnotation extends JdoQueryFacetAbstract
+implements JdoQueryFacet {
+
+ public JdoQueryFacetAnnotation(final Query jdoNamedQuery,
+ final FacetHolder holder) {
+ super(holder);
+ add(jdoNamedQuery);
+ }
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/VisitorForClauseAbstract.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/VisitorForClauseAbstract.java
new file mode 100644
index 0000000..77d0176
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/VisitorForClauseAbstract.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.query;
+
+import java.util.List;
+
+import org.apache.isis.applib.Identifier;
+import org.apache.isis.commons.internal.base._Strings;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidator;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting;
+
+import lombok.val;
+
+abstract class VisitorForClauseAbstract implements MetaModelValidatorVisiting.Visitor {
+
+ private final JdoQueryAnnotationFacetFactory facetFactory;
+ final String clause;
+
+ VisitorForClauseAbstract(
+ final JdoQueryAnnotationFacetFactory facetFactory,
+ final String clause) {
+
+ this.facetFactory = facetFactory;
+ this.clause = clause;
+ }
+
+ @Override
+ public boolean visit(
+ final ObjectSpecification objectSpec,
+ final MetaModelValidator validator) {
+
+ validate(objectSpec, validator);
+ return true;
+ }
+
+ private void validate(
+ final ObjectSpecification objectSpec,
+ final MetaModelValidator validator) {
+
+ final JdoQueryFacet facet = objectSpec.getFacet(JdoQueryFacet.class);
+ if(facet == null) {
+ return;
+ }
+ final List<JdoNamedQuery> namedQueries = facet.getNamedQueries();
+ for (final JdoNamedQuery namedQuery : namedQueries) {
+ if(namedQuery.getLanguage().equals("JDOQL")) {
+ final String query = namedQuery.getQuery();
+ final String fromClassName = deriveClause(query);
+ interpretJdoql(fromClassName, objectSpec, query, validator);
+ }
+ }
+ }
+
+ private void interpretJdoql(
+ final String classNameFromClause,
+ final ObjectSpecification objectSpec,
+ final String query,
+ final MetaModelValidator validator) {
+
+ if (_Strings.isNullOrEmpty(classNameFromClause)) {
+ return;
+ }
+
+ val className = objectSpec.getCorrespondingClass().getName();
+ if (getSpecificationLoader().loadSpecification(ObjectSpecId.of(classNameFromClause))==null) {
+ validator.onFailure(
+ objectSpec,
+ Identifier.classIdentifier(className),
+ "%s: error in JDOQL query, class name for '%s' clause not recognized (JDOQL : %s)",
+ className, clause, query);
+ return;
+ }
+
+ postInterpretJdoql(classNameFromClause, objectSpec, query, validator);
+ }
+
+ abstract String deriveClause(final String query);
+
+ abstract void postInterpretJdoql(
+ final String classNameFromClause,
+ final ObjectSpecification objectSpec,
+ final String query,
+ final MetaModelValidator validator);
+
+
+ SpecificationLoader getSpecificationLoader() {
+ return facetFactory.getSpecificationLoader();
+ }
+
+}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/VisitorForFromClause.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/VisitorForFromClause.java
new file mode 100644
index 0000000..5506311
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/VisitorForFromClause.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.query;
+
+import java.util.Objects;
+
+import org.apache.isis.applib.Identifier;
+import org.apache.isis.core.metamodel.spec.Hierarchical;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidator;
+
+import lombok.val;
+
+class VisitorForFromClause extends VisitorForClauseAbstract {
+
+ VisitorForFromClause(
+ final JdoQueryAnnotationFacetFactory specificationLoader) {
+ super(specificationLoader, "FROM");
+ }
+
+ @Override
+ String deriveClause(final String query) {
+ return JdoQueryAnnotationFacetFactory.from(query);
+ }
+
+ @Override
+ void postInterpretJdoql(
+ final String classNameFromClause,
+ final ObjectSpecification objectSpec,
+ final String query,
+ final MetaModelValidator validator) {
+
+ val className = objectSpec.getCorrespondingClass().getName();
+ if (Objects.equals(classNameFromClause, className)) {
+ return;
+ }
+ val fromSpec = getSpecificationLoader().loadSpecification(ObjectSpecId.of(classNameFromClause));
+ val subclasses = fromSpec.subclasses(Hierarchical.Depth.TRANSITIVE);
+ if(subclasses.contains(objectSpec)) {
+ return;
+ }
+ validator.onFailure(
+ objectSpec,
+ Identifier.classIdentifier(className),
+ "%s: error in JDOQL query, class name after '%s' clause should be same as class name on which annotated, or one of its supertypes (JDOQL : %s)",
+ className, clause, query);
+ }
+
+
+}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/VisitorForVariablesClause.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/VisitorForVariablesClause.java
new file mode 100644
index 0000000..c350271
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/query/VisitorForVariablesClause.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.query;
+
+import org.apache.isis.applib.Identifier;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.specloader.specimpl.IntrospectionState;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidator;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable.JdoPersistenceCapableFacet;
+
+import lombok.val;
+
+class VisitorForVariablesClause extends VisitorForClauseAbstract {
+
+ VisitorForVariablesClause(final JdoQueryAnnotationFacetFactory facetFactory) {
+ super(facetFactory, "VARIABLES");
+ }
+
+ @Override
+ String deriveClause(final String query) {
+ return JdoQueryAnnotationFacetFactory.variables(query);
+ }
+
+ @Override
+ void postInterpretJdoql(
+ final String classNameFromClause,
+ final ObjectSpecification objectSpec,
+ final String query,
+ final MetaModelValidator validator) {
+
+
+ val className = objectSpec.getCorrespondingClass().getName();
+ val objectSpecification = getSpecificationLoader()
+ .loadSpecification(
+ ObjectSpecId.of(classNameFromClause),
+ IntrospectionState.TYPE_INTROSPECTED);
+
+ JdoPersistenceCapableFacet persistenceCapableFacet =
+ objectSpecification.getFacet(JdoPersistenceCapableFacet.class);
+
+ if(persistenceCapableFacet == null) {
+ validator.onFailure(
+ objectSpec,
+ Identifier.classIdentifier(className),
+ "%s: error in JDOQL query, class name for '%s' clause is not annotated as @PersistenceCapable (JDOQL : %s)",
+ className, clause, query);
+ return;
+ }
+ }
+
+}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/version/JdoVersionAnnotationFacetFactory.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/version/JdoVersionAnnotationFacetFactory.java
new file mode 100644
index 0000000..226bf02
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/version/JdoVersionAnnotationFacetFactory.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.version;
+
+import javax.inject.Inject;
+import javax.jdo.annotations.Version;
+
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facetapi.MetaModelRefiner;
+import org.apache.isis.core.metamodel.facets.Annotations;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.progmodel.ProgrammingModel;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidator;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting.Visitor;
+import org.apache.isis.persistence.jdo.provider.entities.JdoFacetContext;
+
+public class JdoVersionAnnotationFacetFactory
+extends FacetFactoryAbstract
+implements MetaModelRefiner {
+
+ @Inject private JdoFacetContext jdoFacetContext;
+
+ public JdoVersionAnnotationFacetFactory() {
+ super(FeatureType.OBJECTS_ONLY);
+ }
+
+ @Override
+ public void process(ProcessClassContext processClassContext) {
+ // deliberately do NOT search superclasses/superinterfaces
+ final Class<?> cls = processClassContext.getCls();
+
+ // only applies to JDO entities; ignore any view models
+ if(!jdoFacetContext.isPersistenceEnhanced(cls)) {
+ return;
+ }
+
+ final Version annotation = Annotations.getDeclaredAnnotation(cls, Version.class);
+ if (annotation == null) {
+ return;
+ }
+ FacetUtil.addFacet(new JdoVersionFacetFromAnnotation(processClassContext.getFacetHolder()));
+ }
+
+ @Override
+ public void refineProgrammingModel(ProgrammingModel programmingModel) {
+ programmingModel.addValidator(newValidatorVisitor());
+ }
+
+ Visitor newValidatorVisitor() {
+ return new MetaModelValidatorVisiting.Visitor() {
+
+ @Override
+ public boolean visit(ObjectSpecification objectSpec, MetaModelValidator validator) {
+ validate(objectSpec, validator);
+ return true;
+ }
+
+ private void validate(ObjectSpecification objectSpec, MetaModelValidator validator) {
+ if(!declaresVersionAnnotation(objectSpec)) {
+ return;
+ }
+
+ ObjectSpecification superclassSpec = objectSpec.superclass();
+ while(superclassSpec != null) {
+ if(declaresVersionAnnotation(superclassSpec)) {
+ validator.onFailure(
+ objectSpec,
+ objectSpec.getIdentifier(),
+ "%s: cannot have @Version annotated on this subclass and any of its supertypes; superclass: %s",
+ objectSpec.getFullIdentifier(),
+ superclassSpec.getFullIdentifier() );
+ return;
+ }
+ superclassSpec = superclassSpec.superclass();
+ }
+ }
+
+ private boolean declaresVersionAnnotation(ObjectSpecification objectSpec) {
+ return Annotations.getDeclaredAnnotation(objectSpec.getCorrespondingClass(), Version.class)!=null;
+ }
+ };
+ }
+
+
+
+
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/version/JdoVersionFacet.java
similarity index 72%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/version/JdoVersionFacet.java
index 791698c..bcc75ee7 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/version/JdoVersionFacet.java
@@ -16,13 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.version;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.core.metamodel.facetapi.Facet;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
+public interface JdoVersionFacet extends Facet {
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/version/JdoVersionFacetFromAnnotation.java
similarity index 66%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/version/JdoVersionFacetFromAnnotation.java
index 791698c..9aacc53 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/version/JdoVersionFacetFromAnnotation.java
@@ -16,13 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.version;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
+public class JdoVersionFacetFromAnnotation extends FacetAbstract implements JdoVersionFacet {
+
+ public JdoVersionFacetFromAnnotation(FacetHolder holder) {
+ super(JdoVersionFacet.class, holder);
+ }
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/version/package-info.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/version/package-info.java
new file mode 100644
index 0000000..148f6ea
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/object/version/package-info.java
@@ -0,0 +1,17 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.object.version;
\ No newline at end of file
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/BigDecimalDerivedFromJdoColumnAnnotationFacetFactory.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/BigDecimalDerivedFromJdoColumnAnnotationFacetFactory.java
new file mode 100644
index 0000000..eade5ed
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/BigDecimalDerivedFromJdoColumnAnnotationFacetFactory.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.column;
+
+import java.math.BigDecimal;
+import java.util.stream.Stream;
+
+import javax.jdo.annotations.Column;
+import javax.jdo.annotations.IdentityType;
+
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facetapi.MetaModelRefiner;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+import org.apache.isis.core.metamodel.facets.properties.bigdecimal.javaxvaldigits.BigDecimalFacetOnPropertyFromJavaxValidationDigitsAnnotation;
+import org.apache.isis.core.metamodel.facets.value.bigdecimal.BigDecimalValueFacet;
+import org.apache.isis.core.metamodel.facets.value.bigdecimal.BigDecimalValueSemanticsProvider;
+import org.apache.isis.core.metamodel.progmodel.ProgrammingModel;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.MixedIn;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidator;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting.Visitor;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable.JdoPersistenceCapableFacet;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.notpersistent.JdoNotPersistentFacet;
+
+import lombok.val;
+
+
+public class BigDecimalDerivedFromJdoColumnAnnotationFacetFactory extends FacetFactoryAbstract
+implements MetaModelRefiner {
+
+ private static final int DEFAULT_LENGTH = BigDecimalValueSemanticsProvider.DEFAULT_LENGTH;
+ private static final int DEFAULT_SCALE = BigDecimalValueSemanticsProvider.DEFAULT_SCALE;
+
+ public BigDecimalDerivedFromJdoColumnAnnotationFacetFactory() {
+ super(FeatureType.PROPERTIES_ONLY);
+ }
+
+ @Override
+ public void process(final ProcessMethodContext processMethodContext) {
+
+ if(BigDecimal.class != processMethodContext.getMethod().getReturnType()) {
+ return;
+ }
+
+ final FacetedMethod holder = processMethodContext.getFacetHolder();
+
+ BigDecimalValueFacet existingFacet = holder.getFacet(BigDecimalValueFacet.class);
+
+ val jdoColumnAnnotation = processMethodContext.synthesizeOnMethod(Column.class)
+ .orElse(null);
+
+ if (jdoColumnAnnotation == null) {
+ if(existingFacet != null && !existingFacet.isFallback()) {
+ // do nothing
+ } else {
+ final BigDecimalValueFacet facet = new BigDecimalFacetFallback(holder);
+ super.addFacet(facet);
+ }
+ } else {
+
+ // obtain the existing facet's length and scale, to use as defaults if none are specified on the @Column
+ // this will mean a metamodel validation exception will only be fired later (see #refineMetaModelValidator)
+ // if there was an *explicit* value defined on the @Column annotation that is incompatible with existing.
+ Integer existingLength = null;
+ Integer existingScale = null;
+ if(existingFacet != null && !existingFacet.isFallback()) {
+ existingLength = existingFacet.getPrecision();
+ existingScale = existingFacet.getScale();
+ }
+
+ Integer length = valueElseDefaults(jdoColumnAnnotation.length(), existingLength, DEFAULT_LENGTH);
+ Integer scale = valueElseDefaults(jdoColumnAnnotation.scale(), existingScale, DEFAULT_SCALE);
+ final BigDecimalValueFacet facet = new BigDecimalFacetDerivedFromJdoColumn(holder, length, scale);
+ super.addFacet(facet);
+ }
+ }
+
+ private static final Integer valueElseDefaults(final int value, final Integer underlying, int defaultVal) {
+ return value != -1
+ ? value
+ : underlying != null
+ ? underlying
+ : defaultVal;
+ }
+
+ @Override
+ public void refineProgrammingModel(ProgrammingModel programmingModel) {
+ programmingModel.addValidator(newValidatorVisitor());
+ }
+
+ private Visitor newValidatorVisitor() {
+ return new MetaModelValidatorVisiting.Visitor() {
+
+ @Override
+ public boolean visit(ObjectSpecification objectSpec, MetaModelValidator validator) {
+ validate(objectSpec, validator);
+ return true;
+ }
+
+ private void validate(ObjectSpecification objectSpec, MetaModelValidator validator) {
+
+ // only consider persistent entities
+ final JdoPersistenceCapableFacet pcFacet = objectSpec.getFacet(JdoPersistenceCapableFacet.class);
+ if(pcFacet==null || pcFacet.getIdentityType() == IdentityType.NONDURABLE) {
+ return;
+ }
+
+ final Stream<ObjectAssociation> associations = objectSpec.streamAssociations(MixedIn.EXCLUDED)
+ .filter(ObjectAssociation.Predicates.PROPERTIES);
+
+ associations
+ // skip checks if annotated with JDO @NotPersistent
+ .filter(association->!association.containsNonFallbackFacet(JdoNotPersistentFacet.class))
+ .forEach(association->{
+ validateBigDecimalValueFacet(association, validator);
+ });
+
+ }
+
+ private void validateBigDecimalValueFacet(ObjectAssociation association, MetaModelValidator validator) {
+ BigDecimalValueFacet facet = association.getFacet(BigDecimalValueFacet.class);
+ if(facet == null) {
+ return;
+ }
+
+ BigDecimalValueFacet underlying = (BigDecimalValueFacet) facet.getUnderlyingFacet();
+ if(underlying == null) {
+ return;
+ }
+
+ if(facet instanceof BigDecimalFacetDerivedFromJdoColumn) {
+
+ if(underlying instanceof BigDecimalFacetOnPropertyFromJavaxValidationDigitsAnnotation) {
+
+ if(notNullButNotEqual(facet.getPrecision(), underlying.getPrecision())) {
+ validator.onFailure(
+ association,
+ association.getIdentifier(),
+ "%s: @javax.jdo.annotations.Column(length=...) different from @javax.validation.constraint.Digits(...); should equal the sum of its integer and fraction attributes",
+ association.getIdentifier().toClassAndNameIdentityString());
+ }
+
+ if(notNullButNotEqual(facet.getScale(), underlying.getScale())) {
+ validator.onFailure(
+ association,
+ association.getIdentifier(),
+ "%s: @javax.jdo.annotations.Column(scale=...) different from @javax.validation.constraint.Digits(fraction=...)",
+ association.getIdentifier().toClassAndNameIdentityString());
+ }
+ }
+ }
+ }
+
+ private boolean notNullButNotEqual(Integer x, Integer y) {
+ return x != null && y != null && !x.equals(y);
+ }
+ };
+ }
+
+
+}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/BigDecimalFacetDerivedFromJdoColumn.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/BigDecimalFacetDerivedFromJdoColumn.java
new file mode 100644
index 0000000..2a0936f
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/BigDecimalFacetDerivedFromJdoColumn.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.column;
+
+import java.util.Map;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.value.bigdecimal.BigDecimalValueFacet;
+import org.apache.isis.core.metamodel.facets.value.bigdecimal.BigDecimalValueFacetAbstract;
+
+
+public class BigDecimalFacetDerivedFromJdoColumn extends BigDecimalValueFacetAbstract {
+
+ private final Integer precision;
+ private final Integer scale;
+
+ public static Class<? extends Facet> type() {
+ return BigDecimalValueFacet.class;
+ }
+
+ public BigDecimalFacetDerivedFromJdoColumn(final FacetHolder holder, final Integer precision, final Integer scale) {
+ super(BigDecimalFacetDerivedFromJdoColumn.type(), holder, Derivation.NOT_DERIVED);
+ this.precision = precision;
+ this.scale = scale;
+ }
+
+ @Override
+ public Integer getPrecision() {
+ return precision;
+ }
+
+ @Override
+ public Integer getScale() {
+ return scale;
+ }
+
+ @Override public void appendAttributesTo(final Map<String, Object> attributeMap) {
+ super.appendAttributesTo(attributeMap);
+ attributeMap.put("precision", precision);
+ attributeMap.put("scale", scale);
+ }
+}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/BigDecimalFacetFallback.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/BigDecimalFacetFallback.java
new file mode 100644
index 0000000..1b757ff
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/BigDecimalFacetFallback.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.column;
+
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.value.bigdecimal.BigDecimalValueFacet;
+import org.apache.isis.core.metamodel.facets.value.bigdecimal.BigDecimalValueFacetAbstract;
+import org.apache.isis.core.metamodel.facets.value.bigdecimal.BigDecimalValueSemanticsProvider;
+
+
+public class BigDecimalFacetFallback extends BigDecimalValueFacetAbstract {
+
+ public static Class<? extends Facet> type() {
+ return BigDecimalValueFacet.class;
+ }
+
+ public BigDecimalFacetFallback(final FacetHolder holder) {
+ super(BigDecimalFacetFallback.type(), holder, Derivation.NOT_DERIVED);
+ }
+
+ @Override
+ public Integer getPrecision() {
+ return BigDecimalValueSemanticsProvider.DEFAULT_LENGTH;
+ }
+
+ @Override
+ public Integer getScale() {
+ return BigDecimalValueSemanticsProvider.DEFAULT_SCALE;
+ }
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MandatoryFacetDerivedFromJdoColumn.java
similarity index 61%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MandatoryFacetDerivedFromJdoColumn.java
index 791698c..6f70514 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MandatoryFacetDerivedFromJdoColumn.java
@@ -16,13 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
-import org.apache.isis.applib.services.repository.EntityState;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.column;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.objectvalue.mandatory.MandatoryFacetAbstract;
+
+/**
+ * Derived by presence of an <tt>@Column</tt> method.
+ */
+public class MandatoryFacetDerivedFromJdoColumn extends MandatoryFacetAbstract {
+
+
+ public MandatoryFacetDerivedFromJdoColumn(final FacetHolder holder, boolean required ) {
+ super(holder, Semantics.of(required));
+ }
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MandatoryFacetInferredFromAbsenceOfJdoColumn.java
similarity index 60%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MandatoryFacetInferredFromAbsenceOfJdoColumn.java
index 791698c..bee0f57 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MandatoryFacetInferredFromAbsenceOfJdoColumn.java
@@ -16,13 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
-import org.apache.isis.applib.services.repository.EntityState;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.column;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.objectvalue.mandatory.MandatoryFacetAbstract;
+
+/**
+ * Derived by absence of an <tt>@Column</tt> method.
+ */
+public class MandatoryFacetInferredFromAbsenceOfJdoColumn extends MandatoryFacetAbstract {
+
+ public MandatoryFacetInferredFromAbsenceOfJdoColumn(final FacetHolder holder, final boolean required) {
+ super(holder, Semantics.of(required));
+ }
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MandatoryFromJdoColumnAnnotationFacetFactory.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MandatoryFromJdoColumnAnnotationFacetFactory.java
new file mode 100644
index 0000000..5e2c86e
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MandatoryFromJdoColumnAnnotationFacetFactory.java
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.column;
+
+import java.util.stream.Stream;
+
+import javax.inject.Inject;
+import javax.jdo.annotations.Column;
+import javax.jdo.annotations.IdentityType;
+
+import org.apache.isis.commons.internal.base._Strings;
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facetapi.MetaModelRefiner;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+import org.apache.isis.core.metamodel.facets.objectvalue.mandatory.MandatoryFacet;
+import org.apache.isis.core.metamodel.facets.objectvalue.mandatory.MandatoryFacetDefault;
+import org.apache.isis.core.metamodel.facets.properties.property.mandatory.MandatoryFacetForPropertyAnnotation;
+import org.apache.isis.core.metamodel.progmodel.ProgrammingModel;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.MixedIn;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidator;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting.Visitor;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable.JdoPersistenceCapableFacet;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.notpersistent.JdoNotPersistentFacet;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.primarykey.OptionalFacetDerivedFromJdoPrimaryKeyAnnotation;
+import org.apache.isis.persistence.jdo.provider.entities.JdoFacetContext;
+
+import lombok.val;
+
+
+public class MandatoryFromJdoColumnAnnotationFacetFactory
+extends FacetFactoryAbstract
+implements MetaModelRefiner {
+
+ @Inject private JdoFacetContext jdoFacetContext;
+
+ public MandatoryFromJdoColumnAnnotationFacetFactory() {
+ super(FeatureType.PROPERTIES_ONLY);
+ }
+
+ @Override
+ public void process(final ProcessMethodContext processMethodContext) {
+
+ // only applies to JDO entities; ignore any view models
+ final Class<?> cls = processMethodContext.getCls();
+ if(!jdoFacetContext.isPersistenceEnhanced(cls)) {
+ return;
+ }
+
+ final FacetedMethod holder = processMethodContext.getFacetHolder();
+
+ final MandatoryFacet existingFacet = holder.getFacet(MandatoryFacet.class);
+ if(existingFacet != null) {
+
+ if (existingFacet instanceof OptionalFacetDerivedFromJdoPrimaryKeyAnnotation) {
+ // do not replace this facet;
+ // we must keep an optional facet here for different reasons
+ return;
+ }
+ if (existingFacet instanceof MandatoryFacetForPropertyAnnotation.Required) {
+ // do not replace this facet;
+ // an explicit @Property(optional=FALSE) annotation cannot be overridden by @Column annotation
+ return;
+ }
+ }
+
+ val jdoColumnAnnotation = processMethodContext.synthesizeOnMethod(Column.class)
+ .orElse(null);
+ boolean required = whetherRequired(processMethodContext, jdoColumnAnnotation);
+ MandatoryFacet facet = jdoColumnAnnotation != null
+ ? new MandatoryFacetDerivedFromJdoColumn(holder, required)
+ : new MandatoryFacetInferredFromAbsenceOfJdoColumn(holder, required);
+
+
+ // as a side-effect, will chain any existing facets.
+ // we'll exploit this fact for meta-model validation (see #refineMetaModelValidator(), below)
+ FacetUtil.addFacet(facet);
+
+ // however, if a @Column was explicitly provided, and the underlying facet
+ // was the simple MandatoryFacetDefault (from an absence of @Optional or @Mandatory),
+ // then don't chain, simply replace.
+ if(facet instanceof MandatoryFacetDerivedFromJdoColumn && facet.getUnderlyingFacet() instanceof MandatoryFacetDefault) {
+ facet.setUnderlyingFacet(null);
+ }
+ }
+
+ private static boolean whetherRequired(final ProcessMethodContext processMethodContext, final Column annotation) {
+
+ final String allowsNull = annotation != null ? annotation.allowsNull() : null;
+
+ if(_Strings.isNotEmpty(allowsNull)) {
+ // if miss-spelled, then DN assumes is not-nullable
+ return !"true".equalsIgnoreCase(allowsNull.trim());
+ }
+
+ final Class<?> returnType = processMethodContext.getMethod().getReturnType();
+ // per JDO spec
+ return returnType != null && returnType.isPrimitive();
+
+ }
+
+ @Override
+ public void refineProgrammingModel(ProgrammingModel programmingModel) {
+ programmingModel.addValidator(newValidatorVisitor());
+ }
+
+ private Visitor newValidatorVisitor() {
+ return new MetaModelValidatorVisiting.Visitor() {
+
+ @Override
+ public boolean visit(ObjectSpecification objectSpec, MetaModelValidator validator) {
+ validate(objectSpec, validator);
+ return true;
+ }
+
+ private void validate(ObjectSpecification objectSpec, MetaModelValidator validator) {
+
+ final JdoPersistenceCapableFacet pcFacet = objectSpec.getFacet(JdoPersistenceCapableFacet.class);
+ if(pcFacet==null || pcFacet.getIdentityType() == IdentityType.NONDURABLE) {
+ return;
+ }
+
+ final Stream<ObjectAssociation> associations = objectSpec
+ .streamAssociations(MixedIn.EXCLUDED)
+ .filter(ObjectAssociation.Predicates.PROPERTIES);
+
+ associations
+ // skip checks if annotated with JDO @NotPersistent
+ .filter(association->!association.containsNonFallbackFacet(JdoNotPersistentFacet.class))
+ .forEach(association->validateMandatoryFacet(association, validator));
+ }
+
+ private void validateMandatoryFacet(ObjectAssociation association, MetaModelValidator validator) {
+ MandatoryFacet facet = association.getFacet(MandatoryFacet.class);
+
+ MandatoryFacet underlying = (MandatoryFacet) facet.getUnderlyingFacet();
+ if(underlying == null) {
+ return;
+ }
+
+ if(facet instanceof MandatoryFacetDerivedFromJdoColumn) {
+
+ if(underlying.isInvertedSemantics() == facet.isInvertedSemantics()) {
+ return;
+ }
+
+ if(underlying.isInvertedSemantics()) {
+ // ie @Optional
+ validator.onFailure(
+ association,
+ association.getIdentifier(),
+ "%s: incompatible usage of Isis' @Optional annotation and @javax.jdo.annotations.Column; use just @javax.jdo.annotations.Column(allowsNull=\"...\")",
+ association.getIdentifier().toClassAndNameIdentityString());
+ } else {
+ validator.onFailure(
+ association,
+ association.getIdentifier(),
+ "%s: incompatible Isis' default of required/optional properties vs JDO; add @javax.jdo.annotations.Column(allowsNull=\"...\")",
+ association.getIdentifier().toClassAndNameIdentityString());
+ }
+ }
+
+ if(facet instanceof MandatoryFacetInferredFromAbsenceOfJdoColumn) {
+
+ if(underlying.isInvertedSemantics() == facet.isInvertedSemantics()) {
+ return;
+ }
+ if(underlying.isInvertedSemantics()) {
+ // ie @Optional
+ validator.onFailure(
+ association,
+ association.getIdentifier(),
+ "%s: incompatible usage of Isis' @Optional annotation and @javax.jdo.annotations.Column; use just @javax.jdo.annotations.Column(allowsNull=\"...\")",
+ association.getIdentifier().toClassAndNameIdentityString());
+ } else {
+ validator.onFailure(
+ association,
+ association.getIdentifier(),
+ "%s: incompatible default handling of required/optional properties between Isis and JDO; add @javax.jdo.annotations.Column(allowsNull=\"...\")",
+ association.getIdentifier().toClassAndNameIdentityString());
+ }
+ }
+ }
+ };
+ }
+
+}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MaxLengthDerivedFromJdoColumnAnnotationFacetFactory.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MaxLengthDerivedFromJdoColumnAnnotationFacetFactory.java
new file mode 100644
index 0000000..d55e67d
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MaxLengthDerivedFromJdoColumnAnnotationFacetFactory.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.column;
+
+import java.util.stream.Stream;
+
+import javax.inject.Inject;
+import javax.jdo.annotations.Column;
+import javax.jdo.annotations.IdentityType;
+
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facetapi.MetaModelRefiner;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+import org.apache.isis.core.metamodel.facets.objectvalue.maxlen.MaxLengthFacet;
+import org.apache.isis.core.metamodel.facets.properties.property.maxlength.MaxLengthFacetForPropertyAnnotation;
+import org.apache.isis.core.metamodel.progmodel.ProgrammingModel;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.MixedIn;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidator;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorVisiting.Visitor;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.object.persistencecapable.JdoPersistenceCapableFacet;
+import org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.notpersistent.JdoNotPersistentFacet;
+import org.apache.isis.persistence.jdo.provider.entities.JdoFacetContext;
+
+import lombok.val;
+
+
+public class MaxLengthDerivedFromJdoColumnAnnotationFacetFactory
+extends FacetFactoryAbstract
+implements MetaModelRefiner {
+
+ @Inject private JdoFacetContext jdoFacetContext;
+
+ public MaxLengthDerivedFromJdoColumnAnnotationFacetFactory() {
+ super(FeatureType.PROPERTIES_ONLY);
+ }
+
+ @Override
+ public void process(final ProcessMethodContext processMethodContext) {
+
+ // only applies to JDO entities; ignore any view models
+ final Class<?> cls = processMethodContext.getCls();
+ if(!jdoFacetContext.isPersistenceEnhanced(cls)) {
+ return;
+ }
+
+
+ if(String.class != processMethodContext.getMethod().getReturnType()) {
+ return;
+ }
+ val jdoColumnAnnotation = processMethodContext.synthesizeOnMethod(Column.class)
+ .orElse(null);
+
+ if (jdoColumnAnnotation==null) {
+ return;
+ }
+ if(jdoColumnAnnotation.length() == -1) {
+ return;
+ }
+
+ final FacetedMethod holder = processMethodContext.getFacetHolder();
+
+ MaxLengthFacet existingFacet = holder.getFacet(MaxLengthFacet.class);
+
+ final MaxLengthFacet facet = new MaxLengthFacetDerivedFromJdoColumn(jdoColumnAnnotation.length(), holder);
+
+ if(!existingFacet.isFallback()) {
+ // will raise violation later
+ facet.setUnderlyingFacet(existingFacet);
+ }
+
+ FacetUtil.addFacet(facet);
+ }
+
+ @Override
+ public void refineProgrammingModel(ProgrammingModel programmingModel) {
+ programmingModel.addValidator(newValidatorVisitor());
+ }
+
+ private Visitor newValidatorVisitor() {
+ return new MetaModelValidatorVisiting.Visitor() {
+
+ @Override
+ public boolean visit(ObjectSpecification objectSpec, MetaModelValidator validator) {
+ validate(objectSpec, validator);
+ return true;
+ }
+
+ private void validate(ObjectSpecification objectSpec, MetaModelValidator validator) {
+
+ final JdoPersistenceCapableFacet pcFacet = objectSpec.getFacet(JdoPersistenceCapableFacet.class);
+ if(pcFacet==null || pcFacet.getIdentityType() == IdentityType.NONDURABLE) {
+ return;
+ }
+
+ final Stream<ObjectAssociation> associations = objectSpec
+ .streamAssociations(MixedIn.EXCLUDED)
+ .filter(ObjectAssociation.Predicates.PROPERTIES);
+
+ associations.forEach(association->{
+ // skip checks if annotated with JDO @NotPersistent
+ if(association.containsNonFallbackFacet(JdoNotPersistentFacet.class)) {
+ return;
+ }
+
+ final MaxLengthFacet facet = association.getFacet(MaxLengthFacet.class);
+ final MaxLengthFacet underlying = (MaxLengthFacet) facet.getUnderlyingFacet();
+ if(underlying == null) {
+ return;
+ }
+
+// if(facet instanceof MaxLengthFacetDerivedFromJdoColumn && underlying instanceof MaxLengthFacetForMaxLengthAnnotationOnProperty) {
+// if(facet.value() != underlying.value()) {
+// validator.onFailure(
+// association,
+// association.getIdentifier(),
+// "%s: inconsistent lengths specified in Isis' @MaxLength(...) and @javax.jdo.annotations.Column(length=...); use just @javax.jdo.annotations.Column(length=...)",
+// association.getIdentifier().toClassAndNameIdentityString());
+// }
+// }
+ if(facet instanceof MaxLengthFacetDerivedFromJdoColumn && underlying instanceof MaxLengthFacetForPropertyAnnotation) {
+ if(facet.value() != underlying.value()) {
+ validator.onFailure(
+ association,
+ association.getIdentifier(),
+ "%s: inconsistent lengths specified in Isis' @Property(maxLength=...) and @javax.jdo.annotations.Column(length=...); use just @javax.jdo.annotations.Column(length=...)",
+ association.getIdentifier().toClassAndNameIdentityString());
+ }
+ }
+ });
+
+
+ }
+ };
+ }
+
+
+
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MaxLengthFacetDerivedFromJdoColumn.java
similarity index 65%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MaxLengthFacetDerivedFromJdoColumn.java
index 791698c..fee0cbe 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/column/MaxLengthFacetDerivedFromJdoColumn.java
@@ -16,13 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.column;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.objectvalue.maxlen.MaxLengthFacetAbstract;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
+public class MaxLengthFacetDerivedFromJdoColumn extends MaxLengthFacetAbstract {
+
+ public MaxLengthFacetDerivedFromJdoColumn(final Integer length, final FacetHolder holder) {
+ super(length, holder);
+ }
+
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentAnnotationFacetFactory.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentAnnotationFacetFactory.java
new file mode 100644
index 0000000..1942f90
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentAnnotationFacetFactory.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.notpersistent;
+
+import javax.inject.Inject;
+import javax.jdo.annotations.NotPersistent;
+
+import org.apache.isis.core.metamodel.facetapi.FacetUtil;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+import org.apache.isis.persistence.jdo.provider.entities.JdoFacetContext;
+
+public class JdoNotPersistentAnnotationFacetFactory
+extends FacetFactoryAbstract {
+
+ @Inject private JdoFacetContext jdoFacetContext;
+
+ public JdoNotPersistentAnnotationFacetFactory() {
+ super(FeatureType.PROPERTIES_ONLY);
+ }
+
+ @Override
+ public void process(ProcessMethodContext processMethodContext) {
+
+ // only applies to JDO entities; ignore any view models
+ final Class<?> cls = processMethodContext.getCls();
+ if(!jdoFacetContext.isPersistenceEnhanced(cls)) {
+ return;
+ }
+
+ final NotPersistent annotation = processMethodContext.synthesizeOnMethod(NotPersistent.class)
+ .orElse(null);
+
+ if (annotation == null) {
+ return;
+ }
+
+ final FacetedMethod holder = processMethodContext.getFacetHolder();
+ FacetUtil.addFacet(new JdoNotPersistentFacetAnnotation(holder));
+ }
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentFacet.java
similarity index 62%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentFacet.java
index 791698c..3cef048 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentFacet.java
@@ -16,13 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.notpersistent;
-import org.apache.isis.applib.services.repository.EntityState;
+import javax.jdo.annotations.PrimaryKey;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+
+
+/**
+ * Corresponds to the property with the {@link PrimaryKey} annotation.
+ * <p>
+ * The JDO {@link PrimaryKey} annotation is used internally the JDO object store to
+ * create the {@link Oid}.
+ */
+public interface JdoNotPersistentFacet extends Facet {
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentFacetAbstract.java
similarity index 57%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentFacetAbstract.java
index 791698c..0020f61 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentFacetAbstract.java
@@ -16,13 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.notpersistent;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
+public abstract class JdoNotPersistentFacetAbstract
+extends FacetAbstract
+implements JdoNotPersistentFacet {
+
+ public static Class<? extends Facet> type() {
+ return JdoNotPersistentFacet.class;
+ }
+
+ public JdoNotPersistentFacetAbstract(final FacetHolder holder) {
+ super(JdoNotPersistentFacetAbstract.type(), holder);
+ }
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentFacetAnnotation.java
similarity index 71%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentFacetAnnotation.java
index 791698c..17818e5 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentFacetAnnotation.java
@@ -16,13 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.notpersistent;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
+public class JdoNotPersistentFacetAnnotation extends JdoNotPersistentFacetImpl {
+
+ public JdoNotPersistentFacetAnnotation(final FacetHolder holder) {
+ super(holder);
+ }
+
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentFacetImpl.java
similarity index 71%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentFacetImpl.java
index 791698c..3af2a96 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/notpersistent/JdoNotPersistentFacetImpl.java
@@ -16,13 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.notpersistent;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
+public class JdoNotPersistentFacetImpl extends JdoNotPersistentFacetAbstract {
+
+ public JdoNotPersistentFacetImpl(final FacetHolder holder) {
+ super(holder);
+ }
+
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/DisabledFacetDerivedFromJdoPrimaryKeyAnnotation.java
similarity index 59%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/DisabledFacetDerivedFromJdoPrimaryKeyAnnotation.java
index 791698c..a55df39 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/DisabledFacetDerivedFromJdoPrimaryKeyAnnotation.java
@@ -16,13 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.primarykey;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.applib.annotation.Where;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.members.disabled.DisabledFacetAbstractImpl;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
+/**
+ * Derived by the presence of the primary key.
+ */
+public class DisabledFacetDerivedFromJdoPrimaryKeyAnnotation extends DisabledFacetAbstractImpl {
+
+ public DisabledFacetDerivedFromJdoPrimaryKeyAnnotation(final FacetHolder holder) {
+ super(Where.ANYWHERE, holder);
+ }
+
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyAnnotationFacetFactory.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyAnnotationFacetFactory.java
new file mode 100644
index 0000000..67d5350
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyAnnotationFacetFactory.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.primarykey;
+
+import javax.inject.Inject;
+import javax.jdo.annotations.PrimaryKey;
+
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.FacetFactoryAbstract;
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+import org.apache.isis.persistence.jdo.provider.entities.JdoFacetContext;
+
+public class JdoPrimaryKeyAnnotationFacetFactory
+extends FacetFactoryAbstract {
+
+ @Inject private JdoFacetContext jdoFacetContext;
+
+ public JdoPrimaryKeyAnnotationFacetFactory() {
+ super(FeatureType.PROPERTIES_ONLY);
+ }
+
+ @Override
+ public void process(ProcessMethodContext processMethodContext) {
+
+ // ignore any view models
+ final Class<?> cls = processMethodContext.getCls();
+ if(!jdoFacetContext.isPersistenceEnhanced(cls)) {
+ return;
+ }
+
+ //val method = processMethodContext.getMethod();
+
+ final PrimaryKey annotation = processMethodContext.synthesizeOnMethod(PrimaryKey.class)
+ .orElse(null);
+
+// _Assert.assertEquals("expected same on method=" + method , annotation,
+// Annotations.getAnnotation(method, PrimaryKey.class));
+
+ if (annotation == null) {
+ return;
+ }
+
+ final FacetedMethod holder = processMethodContext.getFacetHolder();
+ super.addFacet(new JdoPrimaryKeyFacetAnnotation(holder));
+ super.addFacet(new OptionalFacetDerivedFromJdoPrimaryKeyAnnotation(holder));
+ super.addFacet(new DisabledFacetDerivedFromJdoPrimaryKeyAnnotation(holder));
+ }
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyFacet.java
similarity index 63%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyFacet.java
index 791698c..42b4a25 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyFacet.java
@@ -16,13 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.primarykey;
-import org.apache.isis.applib.services.repository.EntityState;
+import javax.jdo.annotations.PrimaryKey;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+
+
+/**
+ * Corresponds to the property with the {@link PrimaryKey} annotation.
+ * <p>
+ * The JDO {@link PrimaryKey} annotation is used internally the JDO object store to
+ * create the {@link Oid}.
+ */
+public interface JdoPrimaryKeyFacet extends Facet {
- EntityState getEntityState(Object pojo);
-
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyFacetAbstract.java
similarity index 58%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyFacetAbstract.java
index 791698c..5ebc163 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyFacetAbstract.java
@@ -16,13 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.primarykey;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetAbstract;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
+public abstract class JdoPrimaryKeyFacetAbstract
+extends FacetAbstract
+implements JdoPrimaryKeyFacet {
+
+ public static Class<? extends Facet> type() {
+ return JdoPrimaryKeyFacet.class;
+ }
+
+ public JdoPrimaryKeyFacetAbstract(final FacetHolder holder) {
+ super(JdoPrimaryKeyFacetAbstract.type(), holder);
+ }
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyFacetAnnotation.java
similarity index 72%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyFacetAnnotation.java
index 791698c..e6c14dd 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyFacetAnnotation.java
@@ -16,13 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.primarykey;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
+public class JdoPrimaryKeyFacetAnnotation extends JdoPrimaryKeyFacetImpl {
+
+ public JdoPrimaryKeyFacetAnnotation(final FacetHolder holder) {
+ super(holder);
+ }
+
}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyFacetImpl.java
similarity index 72%
copy from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
copy to persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyFacetImpl.java
index 791698c..768f487 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/JdoPrimaryKeyFacetImpl.java
@@ -16,13 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.persistence.jdo.provider.entities;
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.primarykey;
-import org.apache.isis.applib.services.repository.EntityState;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
- EntityState getEntityState(Object pojo);
-
+public class JdoPrimaryKeyFacetImpl extends JdoPrimaryKeyFacetAbstract {
+
+ public JdoPrimaryKeyFacetImpl(final FacetHolder holder) {
+ super(holder);
+ }
+
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/OptionalFacetDerivedFromJdoPrimaryKeyAnnotation.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/OptionalFacetDerivedFromJdoPrimaryKeyAnnotation.java
new file mode 100644
index 0000000..aeea15e
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/OptionalFacetDerivedFromJdoPrimaryKeyAnnotation.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.primarykey;
+
+import javax.jdo.annotations.PrimaryKey;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.objectvalue.mandatory.MandatoryFacetAbstract;
+import org.apache.isis.core.metamodel.facets.properties.defaults.PropertyDefaultFacet;
+
+
+/**
+ * Derived by presence of {@link PrimaryKey}.
+ *
+ * <p>
+ * By default mandatory properties are initialized using the
+ * {@link PropertyDefaultFacet} facet. We don't want this, so this facet marks
+ * the property as optional, meaning that the {@link PrimaryKey} property is left
+ * untouched by Isis.
+ */
+public class OptionalFacetDerivedFromJdoPrimaryKeyAnnotation extends MandatoryFacetAbstract {
+
+ public OptionalFacetDerivedFromJdoPrimaryKeyAnnotation(final FacetHolder holder) {
+ super(holder, Semantics.OPTIONAL);
+ }
+
+}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/package-info.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/package-info.java
new file mode 100644
index 0000000..1357426
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/metamodel/facets/prop/primarykey/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+package org.apache.isis.persistence.jdo.integration.metamodel.facets.prop.primarykey;
\ No newline at end of file
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/services/DnJdoSupport.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/services/DnJdoSupport.java
new file mode 100644
index 0000000..f8b5678
--- /dev/null
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/services/DnJdoSupport.java
@@ -0,0 +1,190 @@
+package org.apache.isis.persistence.jdo.integration.services;
+
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.jdo.Extent;
+import javax.jdo.JDOQLTypedQuery;
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.datastore.JDOConnection;
+import javax.jdo.query.BooleanExpression;
+
+import org.springframework.stereotype.Service;
+
+import org.apache.isis.applib.FatalException;
+import org.apache.isis.commons.internal.collections._Lists;
+import org.apache.isis.commons.internal.collections._Maps;
+import org.apache.isis.core.metamodel.adapter.oid.ObjectPersistenceException;
+import org.apache.isis.persistence.jdo.applib.services.IsisJdoSupport_v3_2;
+
+import static org.apache.isis.commons.internal.base._NullSafe.stream;
+
+@Service
+@Named("isisJdoIntegration.DnJdoSupport")
+public class DnJdoSupport implements IsisJdoSupport_v3_2 {
+
+ @Inject @Named("transaction-aware-pmf-proxy")
+ private PersistenceManagerFactory pmf;
+
+ @Override
+ public <T> T refresh(final T domainObject) {
+ getJdoPersistenceManager().refresh(domainObject);
+ return domainObject;
+ }
+
+
+ @Override
+ public void ensureLoaded(final Collection<?> domainObjects) {
+ getJdoPersistenceManager().retrieveAll(domainObjects);
+ }
+
+ // //////////////////////////////////////
+
+
+ @Override
+ public List<Map<String, Object>> executeSql(final String sql) {
+ final JDOConnection dataStoreConnection = getJdoPersistenceManager().getDataStoreConnection();
+ try {
+ final Object connectionObj = dataStoreConnection.getNativeConnection();
+ if(!(connectionObj instanceof java.sql.Connection)) {
+ return null;
+ }
+ final java.sql.Connection connection = (java.sql.Connection) connectionObj;
+ return executeSql(connection, sql);
+ } finally {
+ dataStoreConnection.close();
+ }
+ }
+
+
+ @Override
+ public Integer executeUpdate(final String sql) {
+ final JDOConnection dataStoreConnection = getJdoPersistenceManager().getDataStoreConnection();
+ try {
+ final Object connectionObj = dataStoreConnection.getNativeConnection();
+ if(!(connectionObj instanceof java.sql.Connection)) {
+ return null;
+ }
+ final java.sql.Connection connection = (java.sql.Connection) connectionObj;
+ return executeUpdate(connection, sql);
+ } finally {
+ dataStoreConnection.close();
+ }
+ }
+
+ private static List<Map<String, Object>> executeSql(final java.sql.Connection connection, final String sql) {
+ final List<Map<String,Object>> rows = _Lists.newArrayList();
+
+ try(Statement statement = connection.createStatement()) {
+ try(final ResultSet rs = statement.executeQuery(sql)) {
+
+ final ResultSetMetaData rsmd = rs.getMetaData();
+ while(rs.next()) {
+ final Map<String,Object> row = _Maps.newLinkedHashMap();
+ final int columnCount = rsmd.getColumnCount();
+ for(int i=0; i<columnCount; i++) {
+ final Object val = rs.getObject(i+1);
+ row.put(rsmd.getColumnName(i+1), val);
+ }
+ rows.add(row);
+ }
+ }
+
+ } catch (final SQLException ex) {
+ throw new ObjectPersistenceException("Failed to executeSql: " + sql, ex);
+ }
+
+ return rows;
+ }
+
+ private static int executeUpdate(final java.sql.Connection connection, final String sql) {
+
+ try(Statement statement = connection.createStatement()){
+ return statement.executeUpdate(sql);
+
+ } catch (final SQLException ex) {
+ throw new ObjectPersistenceException("Failed to executeSql: " + sql, ex);
+ }
+ }
+
+ // //////////////////////////////////////
+
+
+ @Override
+ public void deleteAll(final Class<?>... pcClasses) {
+ for (final Class<?> pcClass : pcClasses) {
+ final Extent<?> extent = getJdoPersistenceManager().getExtent(pcClass);
+ final List<Object> instances = stream(extent).collect(Collectors.toList());
+
+ try {
+ getJdoPersistenceManager().deletePersistentAll(instances);
+ } catch (final Exception ex) {
+ throw new FatalException(ex);
+ }
+ }
+ }
+
+ // //////////////////////////////////////
+
+
+ @Override
+ public <T> List<T> executeQuery(final Class<T> cls, final BooleanExpression filter) {
+ JDOQLTypedQuery<T> query = newTypesafeQuery(cls);
+ if(filter!=null) {
+ query = query.filter(filter);
+ }
+ return executeListAndClose(query);
+ }
+
+
+ @Override
+ public <T> T executeQueryUnique(final Class<T> cls, final BooleanExpression filter) {
+ JDOQLTypedQuery<T> query = newTypesafeQuery(cls);
+ if(filter!=null) {
+ query = query.filter(filter);
+ }
+ return executeUniqueAndClose(query);
+ }
+
+
+ @Override
+ public <T> JDOQLTypedQuery<T> newTypesafeQuery(Class<T> cls) {
+ return getJdoPersistenceManager().newJDOQLTypedQuery(cls);
+ }
+
+ private static <T> List<T> executeListAndClose(final JDOQLTypedQuery<T> query) {
+ try {
+ final List<T> elements = query.executeList();
+ final List<T> list = _Lists.newArrayList(elements);
+ return list;
+ } finally {
+ query.closeAll();
+ }
+ }
+
+ private static <T> T executeUniqueAndClose(final JDOQLTypedQuery<T> query) {
+ try {
+ final T result = query.executeUnique();
+ return result;
+ } finally {
+ query.closeAll();
+ }
+ }
+
+ // //////////////////////////////////////
+
+ @Override
+ public PersistenceManager getJdoPersistenceManager() {
+ return pmf.getPersistenceManager();
+ }
+
+}
diff --git a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java b/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoFacetContext.java
similarity index 85%
rename from persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
rename to persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoFacetContext.java
index 791698c..bdde3d0 100644
--- a/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoEntityStateProvider.java
+++ b/persistence/jdo/provider/src/main/java/org/apache/isis/persistence/jdo/provider/entities/JdoFacetContext.java
@@ -18,11 +18,18 @@
*/
package org.apache.isis.persistence.jdo.provider.entities;
+import java.lang.reflect.Method;
+
import org.apache.isis.applib.services.repository.EntityState;
//XXX if there is a way to do this more directly given a PersistenceManager, we can remove this
-public interface JdoEntityStateProvider {
+public interface JdoFacetContext {
EntityState getEntityState(Object pojo);
+
+ boolean isPersistenceEnhanced(Class<?> cls);
+
+ boolean isMethodProvidedByEnhancement(Method method);
+
}
diff --git a/persistence/jdo/spring/pom.xml b/persistence/jdo/spring/pom.xml
index 2e286f9..b8466d8 100644
--- a/persistence/jdo/spring/pom.xml
+++ b/persistence/jdo/spring/pom.xml
@@ -61,7 +61,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
- <scope>provided</scope>
+<!-- <scope>provided</scope> -->
</dependency>
<dependency>