You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2016/05/20 00:45:02 UTC
[25/30] isis git commit: ISIS-1409: removing
PersistenceSessionServiceAware.
ISIS-1409: removing PersistenceSessionServiceAware.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/fbf1770f
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/fbf1770f
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/fbf1770f
Branch: refs/heads/ISIS-1408
Commit: fbf1770f4fb5ef5ce3b068565b19105a790c0f39
Parents: a2a9f51
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri May 20 00:06:22 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri May 20 00:06:22 2016 +0100
----------------------------------------------------------------------
...sFacetFromBoundedMarkerInterfaceFactory.java | 13 +-
.../DomainObjectAnnotationFacetFactory.java | 12 +-
.../bookmarks/BookmarkServiceDefault.java | 144 ----------
.../BookmarkServiceInternalDefault.java | 129 +++++++++
.../container/DomainObjectContainerDefault.java | 15 +-
.../services/factory/FactoryServiceDefault.java | 107 --------
.../factory/FactoryServiceInternalDefault.java | 102 +++++++
.../PersistenceSessionServiceAware.java | 29 --
...rsistenceSessionServiceInternalAbstract.java | 4 -
.../repository/RepositoryServiceDefault.java | 270 -------------------
.../RepositoryServiceInternalDefault.java | 265 ++++++++++++++++++
.../xactn/TransactionServiceDefault.java | 51 ----
.../TransactionServiceInternalDefault.java | 48 ++++
...RepositoryServiceDefaultTest_allMatches.java | 4 +-
.../persistence/PersistenceSessionInternal.java | 11 +-
.../core/wrapper/WrapperFactoryDefault.java | 21 +-
16 files changed, 571 insertions(+), 654 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/choices/boundedmarkerifc/ChoicesFacetFromBoundedMarkerInterfaceFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/choices/boundedmarkerifc/ChoicesFacetFromBoundedMarkerInterfaceFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/choices/boundedmarkerifc/ChoicesFacetFromBoundedMarkerInterfaceFactory.java
index 6c8a54f..2e46eb3 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/choices/boundedmarkerifc/ChoicesFacetFromBoundedMarkerInterfaceFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/choices/boundedmarkerifc/ChoicesFacetFromBoundedMarkerInterfaceFactory.java
@@ -22,16 +22,15 @@ package org.apache.isis.core.metamodel.facets.object.choices.boundedmarkerifc;
import java.lang.reflect.Method;
import org.apache.isis.applib.marker.Bounded;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceAware;
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.FacetFactoryAbstract;
import org.apache.isis.core.metamodel.facets.objectvalue.choices.ChoicesFacet;
+import org.apache.isis.core.metamodel.services.ServicesInjector;
+import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
-public class ChoicesFacetFromBoundedMarkerInterfaceFactory extends FacetFactoryAbstract implements
- PersistenceSessionServiceAware {
+public class ChoicesFacetFromBoundedMarkerInterfaceFactory extends FacetFactoryAbstract {
private PersistenceSessionServiceInternal persistenceSessionServiceInternal;
@@ -59,7 +58,9 @@ public class ChoicesFacetFromBoundedMarkerInterfaceFactory extends FacetFactoryA
}
@Override
- public void setPersistenceSessionService(final PersistenceSessionServiceInternal persistenceSessionServiceInternal) {
- this.persistenceSessionServiceInternal = persistenceSessionServiceInternal;
+ public void setServicesInjector(final ServicesInjector servicesInjector) {
+ super.setServicesInjector(servicesInjector);
+ this.persistenceSessionServiceInternal = servicesInjector.lookupService(PersistenceSessionServiceInternal.class);
}
+
}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java
index ea97b8d..dfb8f24 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/facets/object/domainobject/DomainObjectAnnotationFacetFactory.java
@@ -81,9 +81,8 @@ import org.apache.isis.core.metamodel.facets.object.mixin.MixinFacet;
import org.apache.isis.core.metamodel.facets.object.mixin.MixinFacetForDomainObjectAnnotation;
import org.apache.isis.core.metamodel.facets.object.publishedobject.PublishedObjectFacet;
import org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceAware;
import org.apache.isis.core.metamodel.services.ServicesInjector;
+import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
import org.apache.isis.core.metamodel.spec.ObjectSpecId;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidatorComposite;
@@ -96,7 +95,7 @@ import org.apache.isis.objectstore.jdo.metamodel.facets.object.persistencecapabl
public class DomainObjectAnnotationFacetFactory extends FacetFactoryAbstract
implements AdapterManagerAware,
- MetaModelValidatorRefiner, PersistenceSessionServiceAware,
+ MetaModelValidatorRefiner,
PostConstructMethodCache {
private final MetaModelValidatorForDeprecatedAnnotation auditedValidator = new MetaModelValidatorForDeprecatedAnnotation(Audited.class);
@@ -501,6 +500,9 @@ public class DomainObjectAnnotationFacetFactory extends FacetFactoryAbstract
boundedValidator.setConfiguration(configuration);
immutableValidator.setConfiguration(configuration);
objectTypeValidator.setConfiguration(configuration);
+
+ this.persistenceSessionServiceInternal =
+ servicesInjector.lookupService(PersistenceSessionServiceInternal.class);
}
@@ -509,10 +511,6 @@ public class DomainObjectAnnotationFacetFactory extends FacetFactoryAbstract
this.adapterManager = adapterManager;
}
- @Override
- public void setPersistenceSessionService(final PersistenceSessionServiceInternal persistenceSessionServiceInternal) {
- this.persistenceSessionServiceInternal = persistenceSessionServiceInternal;
- }
// //////////////////////////////////////
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/bookmarks/BookmarkServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/bookmarks/BookmarkServiceDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/bookmarks/BookmarkServiceDefault.java
deleted file mode 100644
index 5584c57..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/bookmarks/BookmarkServiceDefault.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * 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.core.metamodel.services.bookmarks;
-
-import org.apache.isis.applib.annotation.DomainService;
-import org.apache.isis.applib.annotation.NatureOfService;
-import org.apache.isis.applib.annotation.Programmatic;
-import org.apache.isis.applib.services.bookmark.Bookmark;
-import org.apache.isis.applib.services.bookmark.BookmarkHolder;
-import org.apache.isis.applib.services.bookmark.BookmarkService2;
-import org.apache.isis.applib.services.wrapper.WrapperFactory;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceAware;
-import org.apache.isis.core.runtime.persistence.ObjectNotFoundException;
-
-/**
- * This service enables a serializable "bookmark" to be created for an entity.
- *
- * <p>
- * This implementation has no UI and there are no other implementations of the service API, and so it annotated
- * with {@link org.apache.isis.applib.annotation.DomainService}. Because this class is implemented in core, this means
- * that it is automatically registered and available for use; no further configuration is required.
- */
-@DomainService(
- nature = NatureOfService.DOMAIN
-)
-public class BookmarkServiceDefault implements BookmarkService2,
- PersistenceSessionServiceAware {
-
- private PersistenceSessionServiceInternal persistenceSessionServiceInternal;
-
- // //////////////////////////////////////
-
- @Programmatic
- @Override
- public Object lookup(
- final BookmarkHolder bookmarkHolder,
- final FieldResetPolicy fieldResetPolicy) {
- Bookmark bookmark = bookmarkHolder.bookmark();
- return bookmark != null? lookup(bookmark, fieldResetPolicy): null;
- }
-
- @Programmatic
- @Override
- public Object lookup(final BookmarkHolder bookmarkHolder) {
- return lookup(bookmarkHolder, FieldResetPolicy.RESET);
- }
-
- // //////////////////////////////////////
-
- @Programmatic
- @Override
- public Object lookup(
- final Bookmark bookmark,
- final FieldResetPolicy fieldResetPolicy) {
- if(bookmark == null) {
- return null;
- }
- try {
- return persistenceSessionServiceInternal.lookup(bookmark, fieldResetPolicy);
- } catch(ObjectNotFoundException ex) {
- return null;
- }
- }
-
- @Programmatic
- @Override
- public Object lookup(final Bookmark bookmark) {
- return lookup(bookmark, FieldResetPolicy.RESET);
- }
-
- // //////////////////////////////////////
-
- @SuppressWarnings("unchecked")
- @Programmatic
- @Override
- public <T> T lookup(
- final Bookmark bookmark,
- final FieldResetPolicy fieldResetPolicy,
- Class<T> cls) {
- return (T) lookup(bookmark, fieldResetPolicy);
- }
-
- @SuppressWarnings("unchecked")
- @Programmatic
- @Override
- public <T> T lookup(final Bookmark bookmark, Class<T> cls) {
- return (T) lookup(bookmark, FieldResetPolicy.RESET, cls);
- }
-
- // //////////////////////////////////////
-
- @Programmatic
- @Override
- public Bookmark bookmarkFor(final Object domainObject) {
- if(domainObject == null) {
- return null;
- }
- return persistenceSessionServiceInternal.bookmarkFor(unwrapped(domainObject));
- }
-
- private Object unwrapped(Object domainObject) {
- return wrapperFactory != null ? wrapperFactory.unwrap(domainObject) : domainObject;
- }
-
- // //////////////////////////////////////
-
- @Programmatic
- @Override
- public Bookmark bookmarkFor(Class<?> cls, String identifier) {
- return persistenceSessionServiceInternal.bookmarkFor(cls, identifier);
- }
-
- // //////////////////////////////////////
-
-
-
-
- @Override
- public void setPersistenceSessionService(final PersistenceSessionServiceInternal persistenceSessionServiceInternal) {
- this.persistenceSessionServiceInternal = persistenceSessionServiceInternal;
- }
-
-
- @javax.inject.Inject
- private WrapperFactory wrapperFactory;
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/bookmarks/BookmarkServiceInternalDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/bookmarks/BookmarkServiceInternalDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/bookmarks/BookmarkServiceInternalDefault.java
new file mode 100644
index 0000000..7eb86f5
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/bookmarks/BookmarkServiceInternalDefault.java
@@ -0,0 +1,129 @@
+/*
+ * 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.core.metamodel.services.bookmarks;
+
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.applib.services.bookmark.BookmarkHolder;
+import org.apache.isis.applib.services.bookmark.BookmarkService2;
+import org.apache.isis.applib.services.wrapper.WrapperFactory;
+import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
+import org.apache.isis.core.runtime.persistence.ObjectNotFoundException;
+
+/**
+ * This service enables a serializable "bookmark" to be created for an entity.
+ *
+ * <p>
+ * This implementation has no UI and there are no other implementations of the service API, and so it annotated
+ * with {@link org.apache.isis.applib.annotation.DomainService}. Because this class is implemented in core, this means
+ * that it is automatically registered and available for use; no further configuration is required.
+ */
+@DomainService(
+ nature = NatureOfService.DOMAIN
+)
+public class BookmarkServiceInternalDefault implements BookmarkService2 {
+
+
+ @Programmatic
+ @Override
+ public Object lookup(
+ final BookmarkHolder bookmarkHolder,
+ final FieldResetPolicy fieldResetPolicy) {
+ Bookmark bookmark = bookmarkHolder.bookmark();
+ return bookmark != null? lookup(bookmark, fieldResetPolicy): null;
+ }
+
+ @Programmatic
+ @Override
+ public Object lookup(final BookmarkHolder bookmarkHolder) {
+ return lookup(bookmarkHolder, FieldResetPolicy.RESET);
+ }
+
+
+ @Programmatic
+ @Override
+ public Object lookup(
+ final Bookmark bookmark,
+ final FieldResetPolicy fieldResetPolicy) {
+ if(bookmark == null) {
+ return null;
+ }
+ try {
+ return persistenceSessionServiceInternal.lookup(bookmark, fieldResetPolicy);
+ } catch(ObjectNotFoundException ex) {
+ return null;
+ }
+ }
+
+ @Programmatic
+ @Override
+ public Object lookup(final Bookmark bookmark) {
+ return lookup(bookmark, FieldResetPolicy.RESET);
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Programmatic
+ @Override
+ public <T> T lookup(
+ final Bookmark bookmark,
+ final FieldResetPolicy fieldResetPolicy,
+ Class<T> cls) {
+ return (T) lookup(bookmark, fieldResetPolicy);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Programmatic
+ @Override
+ public <T> T lookup(final Bookmark bookmark, Class<T> cls) {
+ return (T) lookup(bookmark, FieldResetPolicy.RESET, cls);
+ }
+
+
+ @Programmatic
+ @Override
+ public Bookmark bookmarkFor(final Object domainObject) {
+ if(domainObject == null) {
+ return null;
+ }
+ return persistenceSessionServiceInternal.bookmarkFor(unwrapped(domainObject));
+ }
+
+ private Object unwrapped(Object domainObject) {
+ return wrapperFactory != null ? wrapperFactory.unwrap(domainObject) : domainObject;
+ }
+
+
+ @Programmatic
+ @Override
+ public Bookmark bookmarkFor(Class<?> cls, String identifier) {
+ return persistenceSessionServiceInternal.bookmarkFor(cls, identifier);
+ }
+
+
+
+ @javax.inject.Inject
+ PersistenceSessionServiceInternal persistenceSessionServiceInternal;
+
+ @javax.inject.Inject
+ private WrapperFactory wrapperFactory;
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
index 424bd78..c00ab71 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
@@ -60,16 +60,15 @@ import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
import org.apache.isis.core.metamodel.consent.InteractionResult;
import org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceAware;
import org.apache.isis.core.metamodel.services.container.query.QueryFindByPattern;
import org.apache.isis.core.metamodel.services.container.query.QueryFindByTitle;
+import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
@DomainService(nature = NatureOfService.DOMAIN)
public class DomainObjectContainerDefault
- implements DomainObjectContainer, PersistenceSessionServiceAware, AdapterManagerAware, ExceptionRecognizer {
+ implements DomainObjectContainer, AdapterManagerAware, ExceptionRecognizer {
//region > titleOf
@@ -649,11 +648,9 @@ public class DomainObjectContainerDefault
//region > framework dependencies
- private PersistenceSessionServiceInternal persistenceSessionServiceInternal;
private AdapterManager adapterManager;
-
protected AdapterManager getAdapterManager() {
return adapterManager;
}
@@ -668,11 +665,6 @@ public class DomainObjectContainerDefault
return persistenceSessionServiceInternal;
}
- @Programmatic
- @Override
- public void setPersistenceSessionService(final PersistenceSessionServiceInternal persistenceSessionServiceInternal) {
- this.persistenceSessionServiceInternal = persistenceSessionServiceInternal;
- }
@@ -710,6 +702,9 @@ public class DomainObjectContainerDefault
@Inject
WrapperFactory wrapperFactory;
+ @javax.inject.Inject
+ PersistenceSessionServiceInternal persistenceSessionServiceInternal;
+
//endregion
}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/factory/FactoryServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/factory/FactoryServiceDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/factory/FactoryServiceDefault.java
deleted file mode 100644
index ae64445..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/factory/FactoryServiceDefault.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.core.metamodel.services.factory;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
-import javax.inject.Inject;
-
-import org.apache.isis.applib.NonRecoverableException;
-import org.apache.isis.applib.annotation.DomainService;
-import org.apache.isis.applib.annotation.NatureOfService;
-import org.apache.isis.applib.annotation.Programmatic;
-import org.apache.isis.applib.services.factory.FactoryService;
-import org.apache.isis.applib.services.registry.ServiceRegistry;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.facets.object.mixin.MixinFacet;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceAware;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
-
-@DomainService(
- nature = NatureOfService.DOMAIN
-)
-public class FactoryServiceDefault implements FactoryService, PersistenceSessionServiceAware {
-
-
- @Programmatic
- @Override
- @SuppressWarnings("unchecked")
- public <T> T instantiate(final Class<T> domainClass) {
- final ObjectSpecification spec = specificationLoader.loadSpecification(domainClass);
- final ObjectAdapter adapter = doCreateTransientInstance(spec);
- return (T) adapter.getObject();
- }
-
- /**
- * Factored out as a potential hook method for subclasses.
- */
- protected ObjectAdapter doCreateTransientInstance(final ObjectSpecification spec) {
- return persistenceSessionServiceInternal.createTransientInstance(spec);
- }
-
-
-
- @Programmatic
- @Override
- public <T> T mixin(final Class<T> mixinClass, final Object mixedIn) {
- final ObjectSpecification objectSpec = specificationLoader.loadSpecification(mixinClass);
- final MixinFacet mixinFacet = objectSpec.getFacet(MixinFacet.class);
- if(mixinFacet == null) {
- throw new NonRecoverableException("Class '" + mixinClass.getName() + " is not a mixin");
- }
- if(!mixinFacet.isMixinFor(mixedIn.getClass())) {
- throw new NonRecoverableException("Mixin class '" + mixinClass.getName() + " is not a mixin for supplied object '" + mixedIn + "'");
- }
- final Constructor<?>[] constructors = mixinClass.getConstructors();
- for (Constructor<?> constructor : constructors) {
- if(constructor.getParameterTypes().length == 1 &&
- constructor.getParameterTypes()[0].isAssignableFrom(mixedIn.getClass())) {
- final Object mixin;
- try {
- mixin = constructor.newInstance(mixedIn);
- return (T) serviceRegistry.injectServicesInto(mixin);
- } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
- throw new NonRecoverableException(e);
- }
- }
- }
- // should never get here because of previous guards
- throw new NonRecoverableException( String.format(
- "Failed to locate constructor in %s to instantiate using %s", mixinClass.getName(), mixedIn));
- }
-
- @Inject
- SpecificationLoader specificationLoader;
-
- @Inject
- ServiceRegistry serviceRegistry;
-
- private PersistenceSessionServiceInternal persistenceSessionServiceInternal;
- @Override
- public void setPersistenceSessionService(final PersistenceSessionServiceInternal persistenceSessionServiceInternal) {
-
- this.persistenceSessionServiceInternal = persistenceSessionServiceInternal;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/factory/FactoryServiceInternalDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/factory/FactoryServiceInternalDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/factory/FactoryServiceInternalDefault.java
new file mode 100644
index 0000000..9198525
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/factory/FactoryServiceInternalDefault.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.core.metamodel.services.factory;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.inject.Inject;
+
+import org.apache.isis.applib.NonRecoverableException;
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.services.factory.FactoryService;
+import org.apache.isis.applib.services.registry.ServiceRegistry;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facets.object.mixin.MixinFacet;
+import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
+
+@DomainService(
+ nature = NatureOfService.DOMAIN
+)
+public class FactoryServiceInternalDefault implements FactoryService {
+
+
+ @Programmatic
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T> T instantiate(final Class<T> domainClass) {
+ final ObjectSpecification spec = specificationLoader.loadSpecification(domainClass);
+ final ObjectAdapter adapter = doCreateTransientInstance(spec);
+ return (T) adapter.getObject();
+ }
+
+ /**
+ * Factored out as a potential hook method for subclasses.
+ */
+ protected ObjectAdapter doCreateTransientInstance(final ObjectSpecification spec) {
+ return persistenceSessionServiceInternal.createTransientInstance(spec);
+ }
+
+
+
+ @Programmatic
+ @Override
+ public <T> T mixin(final Class<T> mixinClass, final Object mixedIn) {
+ final ObjectSpecification objectSpec = specificationLoader.loadSpecification(mixinClass);
+ final MixinFacet mixinFacet = objectSpec.getFacet(MixinFacet.class);
+ if(mixinFacet == null) {
+ throw new NonRecoverableException("Class '" + mixinClass.getName() + " is not a mixin");
+ }
+ if(!mixinFacet.isMixinFor(mixedIn.getClass())) {
+ throw new NonRecoverableException("Mixin class '" + mixinClass.getName() + " is not a mixin for supplied object '" + mixedIn + "'");
+ }
+ final Constructor<?>[] constructors = mixinClass.getConstructors();
+ for (Constructor<?> constructor : constructors) {
+ if(constructor.getParameterTypes().length == 1 &&
+ constructor.getParameterTypes()[0].isAssignableFrom(mixedIn.getClass())) {
+ final Object mixin;
+ try {
+ mixin = constructor.newInstance(mixedIn);
+ return (T) serviceRegistry.injectServicesInto(mixin);
+ } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
+ throw new NonRecoverableException(e);
+ }
+ }
+ }
+ // should never get here because of previous guards
+ throw new NonRecoverableException( String.format(
+ "Failed to locate constructor in %s to instantiate using %s", mixinClass.getName(), mixedIn));
+ }
+
+ @Inject
+ SpecificationLoader specificationLoader;
+
+ @Inject
+ ServiceRegistry serviceRegistry;
+
+ @javax.inject.Inject
+ PersistenceSessionServiceInternal persistenceSessionServiceInternal;
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceAware.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceAware.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceAware.java
deleted file mode 100644
index 29d939a..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceAware.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.core.metamodel.services.persistsession;
-
-import org.apache.isis.applib.annotation.Programmatic;
-
-public interface PersistenceSessionServiceAware {
-
- @Programmatic
- public void setPersistenceSessionService(final PersistenceSessionServiceInternal persistenceSessionServiceInternal);
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceInternalAbstract.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceInternalAbstract.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceInternalAbstract.java
index 60714af..f10cc90 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceInternalAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceInternalAbstract.java
@@ -26,10 +26,6 @@ public abstract class PersistenceSessionServiceInternalAbstract implements Persi
final AdapterManagerAware cast = AdapterManagerAware.class.cast(candidate);
cast.setAdapterManager(this);
}
- if (PersistenceSessionServiceAware.class.isAssignableFrom(candidate.getClass())) {
- final PersistenceSessionServiceAware cast = PersistenceSessionServiceAware.class.cast(candidate);
- cast.setPersistenceSessionService(this);
- }
}
}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceDefault.java
deleted file mode 100644
index 966bdef..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceDefault.java
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * 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.core.metamodel.services.repository;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.PostConstruct;
-
-import com.google.common.base.Predicate;
-
-import org.apache.isis.applib.PersistFailedException;
-import org.apache.isis.applib.RepositoryException;
-import org.apache.isis.applib.annotation.DomainService;
-import org.apache.isis.applib.annotation.NatureOfService;
-import org.apache.isis.applib.annotation.Programmatic;
-import org.apache.isis.applib.query.Query;
-import org.apache.isis.applib.query.QueryFindAllInstances;
-import org.apache.isis.applib.services.factory.FactoryService;
-import org.apache.isis.applib.services.repository.RepositoryService;
-import org.apache.isis.applib.services.wrapper.WrapperFactory;
-import org.apache.isis.applib.services.xactn.TransactionService;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAware;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceAware;
-
-@DomainService(
- nature = NatureOfService.DOMAIN
-)
-public class RepositoryServiceDefault
- implements RepositoryService,
- PersistenceSessionServiceAware, AdapterManagerAware {
-
-
-
- private boolean autoFlush;
-
- @Programmatic
- @PostConstruct
- public void init(Map<String, String> properties) {
- final boolean disableAutoFlush = Boolean.parseBoolean(properties.get(KEY_DISABLE_AUTOFLUSH));
- this.autoFlush = !disableAutoFlush;
- }
-
-
- // //////////////////////////////////////
-
- @Programmatic
- @Override
- public <T> T instantiate(final Class<T> domainClass) {
- return factoryService.instantiate(domainClass);
- }
-
- // //////////////////////////////////////
-
- @Programmatic
- @Override
- public boolean isPersistent(final Object domainObject) {
- final ObjectAdapter adapter = adapterManager.adapterFor(unwrapped(domainObject));
- return adapter.representsPersistent();
- }
-
- @Programmatic
- @Override
- public void persist(final Object object) {
- if (isPersistent(object)) {
- return;
- }
- final ObjectAdapter adapter = adapterManager.adapterFor(unwrapped(object));
-
- if(adapter == null) {
- throw new PersistFailedException("Object not known to framework; instantiate using newTransientInstance(...) rather than simply new'ing up.");
- }
- if (adapter.isParentedCollection()) {
- // TODO check aggregation is supported
- return;
- }
- if (isPersistent(object)) {
- throw new PersistFailedException("Object already persistent; OID=" + adapter.getOid());
- }
- persistenceSessionServiceInternal.makePersistent(adapter);
- }
-
- @Programmatic
- @Override
- public void persistAndFlush(final Object object) {
- persist(object);
- transactionService.flushTransaction();
- }
-
- @Override
- @Programmatic
- public void remove(final Object domainObject) {
- removeIfNotAlready(domainObject);
- }
-
- private void removeIfNotAlready(final Object object) {
- if (!isPersistent(object)) {
- return;
- }
- if (object == null) {
- throw new IllegalArgumentException("Must specify a reference for disposing an object");
- }
- final ObjectAdapter adapter = adapterManager.adapterFor(unwrapped(object));
- if (!isPersistent(object)) {
- throw new RepositoryException("Object not persistent: " + adapter);
- }
-
- persistenceSessionServiceInternal.remove(adapter);
- }
-
- @Override
- @Programmatic
- public void removeAndFlush(final Object domainObject) {
- remove(domainObject);
- transactionService.flushTransaction();
- }
-
-
- // //////////////////////////////////////
-
-
- //region > allInstances, allMatches, uniqueMatch, firstMatch
-
- @Programmatic
- @Override
- public <T> List<T> allInstances(final Class<T> type, long... range) {
- return allMatches(new QueryFindAllInstances<T>(type, range));
- }
-
- // //////////////////////////////////////
-
- @Programmatic
- @Override
- public <T> List<T> allMatches(final Class<T> cls, final Predicate<? super T> predicate, long... range) {
- final List<T> allInstances = allInstances(cls, range);
- final List<T> filtered = new ArrayList<T>();
- for (final T instance : allInstances) {
- if (predicate.apply(instance)) {
- filtered.add(instance);
- }
- }
- return filtered;
- }
-
-
- @Programmatic
- @Override
- public <T> List<T> allMatches(final Query<T> query) {
- if(autoFlush) {
- transactionService.flushTransaction();
- }
- return submitQuery(query);
- }
-
- <T> List<T> submitQuery(final Query<T> query) {
- final List<ObjectAdapter> allMatching = persistenceSessionServiceInternal.allMatchingQuery(query);
- return ObjectAdapter.Util.unwrapT(allMatching);
- }
-
-
- // //////////////////////////////////////
-
-
- @Programmatic
- @Override
- public <T> T uniqueMatch(final Class<T> type, final Predicate<T> predicate) {
- final List<T> instances = allMatches(type, predicate, 0, 2); // No need to fetch more than 2.
- if (instances.size() > 1) {
- throw new RepositoryException("Found more than one instance of " + type + " matching filter " + predicate);
- }
- return firstInstanceElseNull(instances);
- }
-
-
- @Programmatic
- @Override
- public <T> T uniqueMatch(final Query<T> query) {
- final List<T> instances = allMatches(query); // No need to fetch more than 2.
- if (instances.size() > 1) {
- throw new RepositoryException("Found more that one instance for query:" + query.getDescription());
- }
- return firstInstanceElseNull(instances);
- }
-
-
- // //////////////////////////////////////
-
-
- @Programmatic
- @Override
- public <T> T firstMatch(final Class<T> cls, final Predicate<T> predicate) {
- final List<T> allInstances = allInstances(cls); // Have to fetch all, as matching is done in next loop
- for (final T instance : allInstances) {
- if (predicate.apply(instance)) {
- return instance;
- }
- }
- return null;
- }
-
-
- @Programmatic
- @Override
- @SuppressWarnings("unchecked")
- public <T> T firstMatch(final Query<T> query) {
- if(autoFlush) {
- transactionService.flushTransaction();
- }
- final ObjectAdapter firstMatching = persistenceSessionServiceInternal.firstMatchingQuery(query);
- return (T) ObjectAdapter.Util.unwrap(firstMatching);
- }
-
-
- // //////////////////////////////////////
-
-
- private static <T> T firstInstanceElseNull(final List<T> instances) {
- return instances.size() == 0 ? null : instances.get(0);
- }
-
-
- private Object unwrapped(Object domainObject) {
- return wrapperFactory != null ? wrapperFactory.unwrap(domainObject) : domainObject;
- }
-
-
- @javax.inject.Inject
- FactoryService factoryService;
-
- @javax.inject.Inject
- WrapperFactory wrapperFactory;
-
- @javax.inject.Inject
- TransactionService transactionService;
-
- private PersistenceSessionServiceInternal persistenceSessionServiceInternal;
- @Override
- public void setPersistenceSessionService(final PersistenceSessionServiceInternal persistenceSessionServiceInternal) {
-
- this.persistenceSessionServiceInternal = persistenceSessionServiceInternal;
- }
-
- private AdapterManager adapterManager;
- @Override
- public void setAdapterManager(final AdapterManager adapterManager) {
- this.adapterManager = adapterManager;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceInternalDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceInternalDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceInternalDefault.java
new file mode 100644
index 0000000..d8d6521
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceInternalDefault.java
@@ -0,0 +1,265 @@
+/*
+ * 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.core.metamodel.services.repository;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.PostConstruct;
+
+import com.google.common.base.Predicate;
+
+import org.apache.isis.applib.PersistFailedException;
+import org.apache.isis.applib.RepositoryException;
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.query.Query;
+import org.apache.isis.applib.query.QueryFindAllInstances;
+import org.apache.isis.applib.services.factory.FactoryService;
+import org.apache.isis.applib.services.repository.RepositoryService;
+import org.apache.isis.applib.services.wrapper.WrapperFactory;
+import org.apache.isis.applib.services.xactn.TransactionService;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAware;
+import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
+
+@DomainService(
+ nature = NatureOfService.DOMAIN
+)
+public class RepositoryServiceInternalDefault
+ implements RepositoryService,
+ AdapterManagerAware {
+
+
+
+ private boolean autoFlush;
+
+ @Programmatic
+ @PostConstruct
+ public void init(Map<String, String> properties) {
+ final boolean disableAutoFlush = Boolean.parseBoolean(properties.get(KEY_DISABLE_AUTOFLUSH));
+ this.autoFlush = !disableAutoFlush;
+ }
+
+
+ // //////////////////////////////////////
+
+ @Programmatic
+ @Override
+ public <T> T instantiate(final Class<T> domainClass) {
+ return factoryService.instantiate(domainClass);
+ }
+
+ // //////////////////////////////////////
+
+ @Programmatic
+ @Override
+ public boolean isPersistent(final Object domainObject) {
+ final ObjectAdapter adapter = adapterManager.adapterFor(unwrapped(domainObject));
+ return adapter.representsPersistent();
+ }
+
+ @Programmatic
+ @Override
+ public void persist(final Object object) {
+ if (isPersistent(object)) {
+ return;
+ }
+ final ObjectAdapter adapter = adapterManager.adapterFor(unwrapped(object));
+
+ if(adapter == null) {
+ throw new PersistFailedException("Object not known to framework; instantiate using newTransientInstance(...) rather than simply new'ing up.");
+ }
+ if (adapter.isParentedCollection()) {
+ // TODO check aggregation is supported
+ return;
+ }
+ if (isPersistent(object)) {
+ throw new PersistFailedException("Object already persistent; OID=" + adapter.getOid());
+ }
+ persistenceSessionServiceInternal.makePersistent(adapter);
+ }
+
+ @Programmatic
+ @Override
+ public void persistAndFlush(final Object object) {
+ persist(object);
+ transactionService.flushTransaction();
+ }
+
+ @Override
+ @Programmatic
+ public void remove(final Object domainObject) {
+ removeIfNotAlready(domainObject);
+ }
+
+ private void removeIfNotAlready(final Object object) {
+ if (!isPersistent(object)) {
+ return;
+ }
+ if (object == null) {
+ throw new IllegalArgumentException("Must specify a reference for disposing an object");
+ }
+ final ObjectAdapter adapter = adapterManager.adapterFor(unwrapped(object));
+ if (!isPersistent(object)) {
+ throw new RepositoryException("Object not persistent: " + adapter);
+ }
+
+ persistenceSessionServiceInternal.remove(adapter);
+ }
+
+ @Override
+ @Programmatic
+ public void removeAndFlush(final Object domainObject) {
+ remove(domainObject);
+ transactionService.flushTransaction();
+ }
+
+
+ // //////////////////////////////////////
+
+
+ //region > allInstances, allMatches, uniqueMatch, firstMatch
+
+ @Programmatic
+ @Override
+ public <T> List<T> allInstances(final Class<T> type, long... range) {
+ return allMatches(new QueryFindAllInstances<T>(type, range));
+ }
+
+ // //////////////////////////////////////
+
+ @Programmatic
+ @Override
+ public <T> List<T> allMatches(final Class<T> cls, final Predicate<? super T> predicate, long... range) {
+ final List<T> allInstances = allInstances(cls, range);
+ final List<T> filtered = new ArrayList<T>();
+ for (final T instance : allInstances) {
+ if (predicate.apply(instance)) {
+ filtered.add(instance);
+ }
+ }
+ return filtered;
+ }
+
+
+ @Programmatic
+ @Override
+ public <T> List<T> allMatches(final Query<T> query) {
+ if(autoFlush) {
+ transactionService.flushTransaction();
+ }
+ return submitQuery(query);
+ }
+
+ <T> List<T> submitQuery(final Query<T> query) {
+ final List<ObjectAdapter> allMatching = persistenceSessionServiceInternal.allMatchingQuery(query);
+ return ObjectAdapter.Util.unwrapT(allMatching);
+ }
+
+
+ // //////////////////////////////////////
+
+
+ @Programmatic
+ @Override
+ public <T> T uniqueMatch(final Class<T> type, final Predicate<T> predicate) {
+ final List<T> instances = allMatches(type, predicate, 0, 2); // No need to fetch more than 2.
+ if (instances.size() > 1) {
+ throw new RepositoryException("Found more than one instance of " + type + " matching filter " + predicate);
+ }
+ return firstInstanceElseNull(instances);
+ }
+
+
+ @Programmatic
+ @Override
+ public <T> T uniqueMatch(final Query<T> query) {
+ final List<T> instances = allMatches(query); // No need to fetch more than 2.
+ if (instances.size() > 1) {
+ throw new RepositoryException("Found more that one instance for query:" + query.getDescription());
+ }
+ return firstInstanceElseNull(instances);
+ }
+
+
+ // //////////////////////////////////////
+
+
+ @Programmatic
+ @Override
+ public <T> T firstMatch(final Class<T> cls, final Predicate<T> predicate) {
+ final List<T> allInstances = allInstances(cls); // Have to fetch all, as matching is done in next loop
+ for (final T instance : allInstances) {
+ if (predicate.apply(instance)) {
+ return instance;
+ }
+ }
+ return null;
+ }
+
+
+ @Programmatic
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T> T firstMatch(final Query<T> query) {
+ if(autoFlush) {
+ transactionService.flushTransaction();
+ }
+ final ObjectAdapter firstMatching = persistenceSessionServiceInternal.firstMatchingQuery(query);
+ return (T) ObjectAdapter.Util.unwrap(firstMatching);
+ }
+
+
+ // //////////////////////////////////////
+
+
+ private static <T> T firstInstanceElseNull(final List<T> instances) {
+ return instances.size() == 0 ? null : instances.get(0);
+ }
+
+
+ private Object unwrapped(Object domainObject) {
+ return wrapperFactory != null ? wrapperFactory.unwrap(domainObject) : domainObject;
+ }
+
+
+ @javax.inject.Inject
+ FactoryService factoryService;
+
+ @javax.inject.Inject
+ WrapperFactory wrapperFactory;
+
+ @javax.inject.Inject
+ TransactionService transactionService;
+
+ private AdapterManager adapterManager;
+ @Override
+ public void setAdapterManager(final AdapterManager adapterManager) {
+ this.adapterManager = adapterManager;
+ }
+
+ @javax.inject.Inject
+ PersistenceSessionServiceInternal persistenceSessionServiceInternal;
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/xactn/TransactionServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/xactn/TransactionServiceDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/xactn/TransactionServiceDefault.java
deleted file mode 100644
index 92be34f..0000000
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/xactn/TransactionServiceDefault.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.core.metamodel.services.xactn;
-
-import org.apache.isis.applib.annotation.DomainService;
-import org.apache.isis.applib.annotation.NatureOfService;
-import org.apache.isis.applib.services.xactn.TransactionService;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceAware;
-
-@DomainService(
- nature = NatureOfService.DOMAIN
-)
-public class TransactionServiceDefault implements TransactionService, PersistenceSessionServiceAware {
-
-
- @Override
- public void flushTransaction() {
- persistenceSessionServiceInternal.flush();
- }
-
- @Override
- public void nextTransaction() {
- persistenceSessionServiceInternal.commit();
- persistenceSessionServiceInternal.beginTran();
- }
-
- private PersistenceSessionServiceInternal persistenceSessionServiceInternal;
- @Override
- public void setPersistenceSessionService(final PersistenceSessionServiceInternal persistenceSessionServiceInternal) {
-
- this.persistenceSessionServiceInternal = persistenceSessionServiceInternal;
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/xactn/TransactionServiceInternalDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/xactn/TransactionServiceInternalDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/xactn/TransactionServiceInternalDefault.java
new file mode 100644
index 0000000..ceaab92
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/xactn/TransactionServiceInternalDefault.java
@@ -0,0 +1,48 @@
+/*
+ * 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.core.metamodel.services.xactn;
+
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.services.xactn.TransactionService;
+import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
+
+@DomainService(
+ nature = NatureOfService.DOMAIN
+)
+public class TransactionServiceInternalDefault implements TransactionService {
+
+
+ @Override
+ public void flushTransaction() {
+ persistenceSessionServiceInternal.flush();
+ }
+
+ @Override
+ public void nextTransaction() {
+ persistenceSessionServiceInternal.commit();
+ persistenceSessionServiceInternal.beginTran();
+ }
+
+
+ @javax.inject.Inject
+ PersistenceSessionServiceInternal persistenceSessionServiceInternal;
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceDefaultTest_allMatches.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceDefaultTest_allMatches.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceDefaultTest_allMatches.java
index c7a435e..863c23e 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceDefaultTest_allMatches.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/repository/RepositoryServiceDefaultTest_allMatches.java
@@ -39,14 +39,14 @@ public class RepositoryServiceDefaultTest_allMatches {
@Rule
public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
- private RepositoryServiceDefault repositoryService;
+ private RepositoryServiceInternalDefault repositoryService;
@Mock
private TransactionService mockTransactionService;
@Before
public void setUp() throws Exception {
- repositoryService = new RepositoryServiceDefault() {
+ repositoryService = new RepositoryServiceInternalDefault() {
@Override <T> List<T> submitQuery(final Query<T> query) {
return null;
}
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionInternal.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionInternal.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionInternal.java
index ac0f6f0..df4e535 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionInternal.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionInternal.java
@@ -89,12 +89,11 @@ import org.apache.isis.core.metamodel.facets.object.callbacks.UpdatingLifecycleE
import org.apache.isis.core.metamodel.facets.object.value.ValueFacet;
import org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet;
import org.apache.isis.core.metamodel.facets.propcoll.accessor.PropertyOrCollectionAccessorFacet;
-import org.apache.isis.core.metamodel.services.msgbroker.MessageBrokerServiceInternal;
-import org.apache.isis.core.metamodel.services.msgbroker.MessageBrokerServiceAware;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceAware;
import org.apache.isis.core.metamodel.services.ServicesInjector;
import org.apache.isis.core.metamodel.services.container.query.QueryCardinality;
+import org.apache.isis.core.metamodel.services.msgbroker.MessageBrokerServiceAware;
+import org.apache.isis.core.metamodel.services.msgbroker.MessageBrokerServiceInternal;
+import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
import org.apache.isis.core.metamodel.spec.FreeStandingList;
import org.apache.isis.core.metamodel.spec.ObjectSpecId;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
@@ -405,10 +404,6 @@ public class PersistenceSessionInternal implements
final MessageBrokerServiceAware cast = MessageBrokerServiceAware.class.cast(candidate);
cast.setMessageBrokerService(this);
}
- if (PersistenceSessionServiceAware.class.isAssignableFrom(candidate.getClass())) {
- final PersistenceSessionServiceAware cast = PersistenceSessionServiceAware.class.cast(candidate);
- cast.setPersistenceSessionService(this);
- }
}
//endregion
http://git-wip-us.apache.org/repos/asf/isis/blob/fbf1770f/core/wrapper/src/main/java/org/apache/isis/core/wrapper/WrapperFactoryDefault.java
----------------------------------------------------------------------
diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/WrapperFactoryDefault.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/WrapperFactoryDefault.java
index 4c67195..080d7be 100644
--- a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/WrapperFactoryDefault.java
+++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/WrapperFactoryDefault.java
@@ -54,7 +54,6 @@ import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider
import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAware;
import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
-import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceAware;
import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
import org.apache.isis.core.wrapper.dispatchers.InteractionEventDispatcher;
import org.apache.isis.core.wrapper.dispatchers.InteractionEventDispatcherTypeSafe;
@@ -73,8 +72,7 @@ import org.apache.isis.core.wrapper.proxy.ProxyCreator;
* configuration is required.
*/
@DomainService(nature = NatureOfService.DOMAIN)
-public class WrapperFactoryDefault implements WrapperFactory,
- AdapterManagerAware, PersistenceSessionServiceAware {
+public class WrapperFactoryDefault implements WrapperFactory, AdapterManagerAware {
private final List<InteractionListener> listeners = new ArrayList<InteractionListener>();
private final Map<Class<? extends InteractionEvent>, InteractionEventDispatcher> dispatchersByEventClass = new HashMap<Class<? extends InteractionEvent>, InteractionEventDispatcher>();
@@ -253,8 +251,7 @@ public class WrapperFactoryDefault implements WrapperFactory,
}
protected <T> T createProxy(final T domainObject, final ExecutionMode mode) {
- return proxyContextHandler.proxy(domainObject, this, mode, authenticationSessionProvider, specificationLoader,
- getAdapterManager(), getPersistenceSessionService());
+ return proxyContextHandler.proxy(domainObject, this, mode, authenticationSessionProvider, specificationLoader, getAdapterManager(), persistenceSessionServiceInternal);
}
@Override
@@ -304,7 +301,6 @@ public class WrapperFactoryDefault implements WrapperFactory,
private AdapterManager adapterManager;
- private PersistenceSessionServiceInternal persistenceSessionServiceInternal;
protected AdapterManager getAdapterManager() {
return adapterManager;
@@ -317,20 +313,13 @@ public class WrapperFactoryDefault implements WrapperFactory,
- protected PersistenceSessionServiceInternal getPersistenceSessionService() {
- return persistenceSessionServiceInternal;
- }
- @Programmatic
- @Override
- public void setPersistenceSessionService(final PersistenceSessionServiceInternal persistenceSessionServiceInternal) {
- this.persistenceSessionServiceInternal = persistenceSessionServiceInternal;
- }
-
-
@Inject
AuthenticationSessionProvider authenticationSessionProvider;
@Inject
SpecificationLoader specificationLoader;
+ @javax.inject.Inject
+ PersistenceSessionServiceInternal persistenceSessionServiceInternal;
+
}