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/26 12:09:24 UTC
[isis] branch master updated: ISIS-2033: dn-integration: more
cleaning up
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 3c3f5f7 ISIS-2033: dn-integration: more cleaning up
3c3f5f7 is described below
commit 3c3f5f7c1711a2ecdfa1514eeb01641c9aa80e77
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat Dec 26 13:09:09 2020 +0100
ISIS-2033: dn-integration: more cleaning up
---
.../applib/fixturestate/FixturesInstalledFlag.java | 34 -----
.../fixturestate/FixturesInstalledState.java | 59 ---------
.../fixturestate/FixturesInstalledStateHolder.java | 32 -----
.../jdo/applib/fixturestate/package-info.java | 47 -------
.../persistence/JdoPersistenceSession.java | 19 ++-
.../persistence/JdoPersistenceSession5.java | 111 ++++++++++++----
.../persistence/JdoPersistenceSessionFactory5.java | 13 +-
.../persistence/_JdoPersistenceSessionBase.java | 145 ---------------------
8 files changed, 100 insertions(+), 360 deletions(-)
diff --git a/persistence/jdo/applib/src/main/java/org/apache/isis/persistence/jdo/applib/fixturestate/FixturesInstalledFlag.java b/persistence/jdo/applib/src/main/java/org/apache/isis/persistence/jdo/applib/fixturestate/FixturesInstalledFlag.java
deleted file mode 100644
index 3bdf9fc..0000000
--- a/persistence/jdo/applib/src/main/java/org/apache/isis/persistence/jdo/applib/fixturestate/FixturesInstalledFlag.java
+++ /dev/null
@@ -1,34 +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.persistence.jdo.applib.fixturestate;
-
-/**
- * For {@link org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory}
- * implementations that can cache the
- * {@link PersistenceSession#isFixturesInstalled()} so is only called once per
- * application scope.
- */
-public interface FixturesInstalledFlag {
-
- public Boolean isFixturesInstalled();
-
- public void setFixturesInstalled(Boolean fixturesInstalled);
-
-}
diff --git a/persistence/jdo/applib/src/main/java/org/apache/isis/persistence/jdo/applib/fixturestate/FixturesInstalledState.java b/persistence/jdo/applib/src/main/java/org/apache/isis/persistence/jdo/applib/fixturestate/FixturesInstalledState.java
deleted file mode 100644
index 1c6433e..0000000
--- a/persistence/jdo/applib/src/main/java/org/apache/isis/persistence/jdo/applib/fixturestate/FixturesInstalledState.java
+++ /dev/null
@@ -1,59 +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.persistence.jdo.applib.fixturestate;
-
-/**
- *
- * @since 2.0
- *
- */
-public enum FixturesInstalledState {
-
- /**
- * application scoped state indicating fixture scripts have not been run yet
- */
- not_Installed,
-
- /**
- * application scoped state indicating fixture scripts are currently in the process
- * of being installed (are running)
- */
- Installing,
-
- /**
- * application scoped state indicating fixture scripts have been installed (have run)
- */
- Installed
-
- ;
-
- public boolean isNotInstalled() {
- return this == not_Installed;
- }
-
- public boolean isInstalling() {
- return this == Installing;
- }
-
- public boolean isInstalled() {
- return this == Installed;
- }
-}
-
diff --git a/persistence/jdo/applib/src/main/java/org/apache/isis/persistence/jdo/applib/fixturestate/FixturesInstalledStateHolder.java b/persistence/jdo/applib/src/main/java/org/apache/isis/persistence/jdo/applib/fixturestate/FixturesInstalledStateHolder.java
deleted file mode 100644
index 5af18ca..0000000
--- a/persistence/jdo/applib/src/main/java/org/apache/isis/persistence/jdo/applib/fixturestate/FixturesInstalledStateHolder.java
+++ /dev/null
@@ -1,32 +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.persistence.jdo.applib.fixturestate;
-
-/**
- * Implementing classes must cache the FixturesInstalledState, so fixtures are installed (run)
- * only once per application life-cycle.
- */
-public interface FixturesInstalledStateHolder {
-
- public FixturesInstalledState getFixturesInstalledState();
-
- public void setFixturesInstalledState(FixturesInstalledState fixturesInstalledState);
-
-}
diff --git a/persistence/jdo/applib/src/main/java/org/apache/isis/persistence/jdo/applib/fixturestate/package-info.java b/persistence/jdo/applib/src/main/java/org/apache/isis/persistence/jdo/applib/fixturestate/package-info.java
deleted file mode 100644
index 91b66a1..0000000
--- a/persistence/jdo/applib/src/main/java/org/apache/isis/persistence/jdo/applib/fixturestate/package-info.java
+++ /dev/null
@@ -1,47 +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.
- */
-
-/**
- * Object Persistor API.
- *
- * <p>
- * Concrete implementations are in the <tt>persistor-xxx</tt> modules. The
- * role of the {@link PersistenceSession} is to manage the lifecycle of
- * domain objects, creating them, retrieving them, persisting them, deleting them.
- * However, this object management role applies when deployed in client/server mode
- * as well as standalone.
- *
- * <p>
- * There are therefore just two implementations:
- * <ul>
- * <li> the <tt>persistor-objectstore</tt> implementation delegates to an <tt>ObjectAdapterStore</tt>
- * API that actually persists objects to some persistent store (such as XML or RDBMS)</li>
- * <li> the <tt>persistor-proxy</tt> implementation in effect provides the client-side remoting library,
- * using the remoting protocol defined in the <tt>remoting-command</tt> module.
- * </ul>
- *
- * <p>
- * Note that the {@link PersistenceSession} both extends a number of superinterfaces as well as uses implementations of
- * various helpers (for example {@link org.apache.isis.ServicesInjector.services.ServicesInjector} and {@link org.apache.isis.core.runtime.system.persistence.runtime.persistence.oidgenerator.OidGenerator}).
- * These superinterfaces and helper interfaces are not normally implemented directly, and it is the
- * responsibility of the {@link PersistenceMechanismInstaller} to ensure that the correct helper objects
- * are passed to the {@link PersistenceSession} implementation.
- */
-package org.apache.isis.persistence.jdo.applib.fixturestate;
-
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/JdoPersistenceSession.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/JdoPersistenceSession.java
index 34b655e..762276b 100644
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/JdoPersistenceSession.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/JdoPersistenceSession.java
@@ -19,6 +19,7 @@
package org.apache.isis.persistence.jdo.integration.persistence;
import org.apache.isis.core.metamodel.context.HasMetaModelContext;
+import org.apache.isis.core.transaction.integration.IsisTransactionObject;
import org.apache.isis.persistence.jdo.integration.transaction.TransactionalProcessor;
import org.apache.isis.persistence.jdo.provider.persistence.HasPersistenceManager;
@@ -27,11 +28,21 @@ extends
HasMetaModelContext,
HasPersistenceManager {
- // -------------------------------------------------------------------------------------------------
- // -- STABLE API (DRAFT)
- // -------------------------------------------------------------------------------------------------
-
+ /**
+ * Injects components, calls open on subcomponents, and then creates service
+ * adapters.
+ */
void open();
+
+ /**
+ * Closes the subcomponents.
+ * <p>
+ * Automatically {@link _TxManagerInternal#commitTransaction(IsisTransactionObject)
+ * ends (commits)} the current (Isis) {@link _Tx}. This in turn commits the underlying
+ * JDO transaction.
+ * <p>
+ * The corresponding DataNucleus entity is then closed.
+ */
void close();
TransactionalProcessor getTransactionalProcessor();
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/JdoPersistenceSession5.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/JdoPersistenceSession5.java
index b435385..eee146a 100644
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/JdoPersistenceSession5.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/JdoPersistenceSession5.java
@@ -27,16 +27,20 @@ import org.datanucleus.enhancement.Persistable;
import org.apache.isis.core.metamodel.adapter.oid.Oid;
import org.apache.isis.core.metamodel.adapter.oid.PojoRefreshException;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
import org.apache.isis.core.metamodel.context.MetaModelContext;
import org.apache.isis.core.metamodel.spec.ManagedObject;
-import org.apache.isis.core.transaction.integration.IsisTransactionObject;
-import org.apache.isis.persistence.jdo.applib.fixturestate.FixturesInstalledStateHolder;
+import org.apache.isis.core.metamodel.spec.ManagedObjects;
+import org.apache.isis.core.transaction.changetracking.EntityChangeTracker;
import org.apache.isis.persistence.jdo.datanucleus.entities.DnEntityStateProvider;
import org.apache.isis.persistence.jdo.integration.lifecycles.FetchResultHandler;
import org.apache.isis.persistence.jdo.integration.lifecycles.IsisLifecycleListener;
import org.apache.isis.persistence.jdo.integration.lifecycles.JdoStoreLifecycleListenerForIsis;
import org.apache.isis.persistence.jdo.integration.lifecycles.LoadLifecycleListenerForIsis;
+import org.apache.isis.persistence.jdo.integration.transaction.TransactionalProcessor;
+import org.apache.isis.persistence.jdo.integration.transaction.TxManagerInternalFactory;
+import lombok.Getter;
import lombok.NonNull;
import lombok.val;
import lombok.extern.log4j.Log4j2;
@@ -45,32 +49,81 @@ import lombok.extern.log4j.Log4j2;
* A wrapper around the JDO {@link PersistenceManager}.
*/
@Vetoed @Log4j2
-public class JdoPersistenceSession5 extends _JdoPersistenceSessionBase
+public class JdoPersistenceSession5
implements
+ JdoPersistenceSession,
FetchResultHandler,
IsisLifecycleListener.EntityChangeEmitter {
+ // -- FIELDS
+
+ /**
+ * populated only when {@link #open()}ed.
+ */
+ @Getter(onMethod_ = {@Override}) private PersistenceManager persistenceManager;
+
+ @Getter(onMethod_ = {@Override}) private final TransactionalProcessor transactionalProcessor;
+ @Getter(onMethod_ = {@Override}) private final MetaModelContext metaModelContext;
+
+ /**
+ * Used to create the {@link #persistenceManager} when {@link #open()}ed.
+ */
+ private final PersistenceManagerFactory jdoPersistenceManagerFactory;
+
private Runnable unregisterLifecycleListeners;
+ // -- CONSTRUCTOR
+
/**
* Initialize the object store so that calls to this object store access
* persisted objects and persist changes to the object that are saved.
- * @param storeLifecycleListener
*/
public JdoPersistenceSession5(
final MetaModelContext metaModelContext,
- final PersistenceManagerFactory jdoPersistenceManagerFactory,
- final FixturesInstalledStateHolder stateHolder) {
+ final PersistenceManagerFactory jdoPersistenceManagerFactory) {
- super(metaModelContext, jdoPersistenceManagerFactory, stateHolder);
+ if (log.isDebugEnabled()) {
+ log.debug("creating {}", this);
+ }
+
+ this.metaModelContext = metaModelContext;
+ this.jdoPersistenceManagerFactory = jdoPersistenceManagerFactory;
+
+ // sub-components
+ this.transactionalProcessor = TxManagerInternalFactory.newCommandQueue(
+ metaModelContext,
+ this,
+ (FetchResultHandler)this);
+
+ this.state = State.NOT_INITIALIZED;
}
- // -- open
+ // -- STATE
+
+ protected enum State {
+ NOT_INITIALIZED, OPEN, CLOSED
+ ;
+ protected void ensureNotOpened() {
+ if (this != State.NOT_INITIALIZED) {
+ throw new IllegalStateException("Persistence session has already been initialized");
+ }
+ }
+ protected void ensureOpened() {
+ ensureStateIs(State.OPEN);
+ }
+ private void ensureStateIs(final State stateRequired) {
+ if (this == stateRequired) {
+ return;
+ }
+ throw new IllegalStateException("State is: " + this + "; should be: " + stateRequired);
+ }
+ }
+
+ protected State state = State.NOT_INITIALIZED;
+
+ // -- OPEN
+
- /**
- * Injects components, calls open on subcomponents, and then creates service
- * adapters.
- */
@Override
public void open() {
state.ensureNotOpened();
@@ -104,19 +157,8 @@ implements
this.state = State.OPEN;
}
- // -- close
+ // -- CLOSE
- /**
- * Closes the subcomponents.
- *
- * <p>
- * Automatically {@link _TxManagerInternal#commitTransaction(IsisTransactionObject)
- * ends (commits)} the current (Isis) {@link _Tx}. This in turn commits the underlying
- * JDO transaction.
- *
- * <p>
- * The corresponding DataNucleus entity is then closed.
- */
@Override
public void close() {
@@ -247,17 +289,30 @@ implements
getEntityChangeTracker().recognizeUpdating(entity);
}
- // -- HELPER
+ // -- DEPENDENCIES
- private void debugLogNotPersistentIgnoring(Object domainObject) {
+ public EntityChangeTracker getEntityChangeTracker() {
+ return metaModelContext.getServiceRegistry()
+ .lookupServiceElseFail(EntityChangeTracker.class);
+ }
+
+ // -- DEBUG
+
+ private RootOid oidFor(Object pojo) {
+ val spec = getSpecificationLoader().loadSpecification(pojo.getClass());
+ val adapter = ManagedObject.of(spec, pojo);
+ return ManagedObjects.identify(adapter).orElse(null);
+ }
+
+ private void debugLogNotPersistentIgnoring(@Nullable Object domainObject) {
if (log.isDebugEnabled() && domainObject!=null) {
val oid = oidFor(domainObject);
log.debug("; oid={} not persistent - ignoring", oid.enString());
}
}
- private void debugLogRefreshImmediately(Object domainObject) {
- if (log.isDebugEnabled()) {
+ private void debugLogRefreshImmediately(@Nullable Object domainObject) {
+ if (log.isDebugEnabled() && domainObject!=null) {
val oid = oidFor(domainObject);
log.debug("refresh immediately; oid={}", oid.enString());
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/JdoPersistenceSessionFactory5.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/JdoPersistenceSessionFactory5.java
index 7494e3e..a73aee3 100644
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/JdoPersistenceSessionFactory5.java
+++ b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/JdoPersistenceSessionFactory5.java
@@ -41,13 +41,9 @@ import org.apache.isis.commons.internal.collections._Maps;
import org.apache.isis.core.config.IsisConfiguration;
import org.apache.isis.core.config.beans.IsisBeanTypeRegistry;
import org.apache.isis.core.metamodel.context.MetaModelContext;
-import org.apache.isis.persistence.jdo.applib.fixturestate.FixturesInstalledState;
-import org.apache.isis.persistence.jdo.applib.fixturestate.FixturesInstalledStateHolder;
import org.apache.isis.persistence.jdo.datanucleus.config.DnSettings;
import org.apache.isis.persistence.jdo.integration.config.JdoEntityTypeRegistry;
-import lombok.Getter;
-import lombok.Setter;
import lombok.val;
import lombok.extern.log4j.Log4j2;
@@ -64,7 +60,7 @@ import lombok.extern.log4j.Log4j2;
@Singleton
@Log4j2
public class JdoPersistenceSessionFactory5
-implements JdoPersistenceSessionFactory, FixturesInstalledStateHolder {
+implements JdoPersistenceSessionFactory {
@Inject private IsisBeanTypeRegistry isisBeanTypeRegistry;
@@ -75,10 +71,6 @@ implements JdoPersistenceSessionFactory, FixturesInstalledStateHolder {
private IsisConfiguration configuration;
private final JdoEntityTypeRegistry jdoEntityTypeRegistry = new JdoEntityTypeRegistry();
- @Getter(onMethod=@__({@Override}))
- @Setter(onMethod=@__({@Override}))
- FixturesInstalledState fixturesInstalledState;
-
@Override
public void init(MetaModelContext metaModelContext) {
this.metaModelContext = metaModelContext;
@@ -200,8 +192,7 @@ implements JdoPersistenceSessionFactory, FixturesInstalledStateHolder {
return new JdoPersistenceSession5(
metaModelContext,
- persistenceManagerFactory,
- this);
+ persistenceManagerFactory);
}
diff --git a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/_JdoPersistenceSessionBase.java b/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/_JdoPersistenceSessionBase.java
deleted file mode 100644
index 4267f1c..0000000
--- a/persistence/jdo/integration/src/main/java/org/apache/isis/persistence/jdo/integration/persistence/_JdoPersistenceSessionBase.java
+++ /dev/null
@@ -1,145 +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.persistence.jdo.integration.persistence;
-
-import javax.annotation.Nullable;
-import javax.jdo.PersistenceManager;
-import javax.jdo.PersistenceManagerFactory;
-
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.context.MetaModelContext;
-import org.apache.isis.core.metamodel.spec.ManagedObject;
-import org.apache.isis.core.metamodel.spec.ManagedObjects;
-import org.apache.isis.core.transaction.changetracking.EntityChangeTracker;
-import org.apache.isis.persistence.jdo.applib.fixturestate.FixturesInstalledStateHolder;
-import org.apache.isis.persistence.jdo.integration.lifecycles.FetchResultHandler;
-import org.apache.isis.persistence.jdo.integration.transaction.TransactionalProcessor;
-import org.apache.isis.persistence.jdo.integration.transaction.TxManagerInternalFactory;
-
-import lombok.Getter;
-import lombok.val;
-import lombok.extern.log4j.Log4j2;
-
-@Log4j2
-abstract class _JdoPersistenceSessionBase
-implements JdoPersistenceSession {
-
- // -- FIELDS
-
- protected final FixturesInstalledStateHolder fixturesInstalledStateHolder;
-
- @Getter(onMethod_ = {@Override}) protected final TransactionalProcessor transactionalProcessor;
- @Getter(onMethod_ = {@Override}) protected final MetaModelContext metaModelContext;
-
- /**
- * Used to create the {@link #persistenceManager} when {@link #open()}ed.
- */
- protected final PersistenceManagerFactory jdoPersistenceManagerFactory;
-
- /**
- * populated only when {@link #open()}ed.
- */
- protected PersistenceManager persistenceManager;
-
- // -- CONSTRUCTOR
-
- /**
- * Initialize the object store so that calls to this object store access
- * persisted objects and persist changes to the object that are saved.
- */
- protected _JdoPersistenceSessionBase(
- final MetaModelContext metaModelContext,
- final PersistenceManagerFactory jdoPersistenceManagerFactory,
- final FixturesInstalledStateHolder fixturesInstalledStateHolder) {
-
- if (log.isDebugEnabled()) {
- log.debug("creating {}", this);
- }
-
- this.metaModelContext = metaModelContext;
- this.jdoPersistenceManagerFactory = jdoPersistenceManagerFactory;
- this.fixturesInstalledStateHolder = fixturesInstalledStateHolder;
-
- // sub-components
- this.transactionalProcessor = TxManagerInternalFactory.newCommandQueue(
- metaModelContext,
- this,
- (FetchResultHandler)this);
-
- this.state = State.NOT_INITIALIZED;
- }
-
- // -- GETTERS
-
- public EntityChangeTracker getEntityChangeTracker() {
- return metaModelContext.getServiceRegistry()
- .lookupServiceElseFail(EntityChangeTracker.class);
- }
-
- /**
- * Only populated once {@link #open()}'d
- */
- @Override
- public PersistenceManager getPersistenceManager() {
- return persistenceManager;
- }
-
- // -- STATE
-
- protected enum State {
- NOT_INITIALIZED, OPEN, CLOSED
- ;
-
- protected void ensureNotOpened() {
- if (this != State.NOT_INITIALIZED) {
- throw new IllegalStateException("Persistence session has already been initialized");
- }
- }
-
- protected void ensureOpened() {
- ensureStateIs(State.OPEN);
- }
-
- private void ensureStateIs(final State stateRequired) {
- if (this == stateRequired) {
- return;
- }
- throw new IllegalStateException("State is: " + this + "; should be: " + stateRequired);
- }
-
- }
-
- protected State state = State.NOT_INITIALIZED;
-
- // -- OID
-
- /**
- * @param pojo
- * @return oid for the given domain object
- */
- protected @Nullable RootOid oidFor(@Nullable Object pojo) {
- if(pojo==null) {
- return null;
- }
- val spec = getSpecificationLoader().loadSpecification(pojo.getClass());
- val adapter = ManagedObject.of(spec, pojo);
- return ManagedObjects.identify(adapter).orElse(null);
- }
-
-}