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 2018/05/31 10:13:26 UTC
[isis] 04/05: ISIS-1954: IsisSystem: refactoring deprecated methods
out into a mixin
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
commit 3e3f21de48058ceddced23b5253e8e94ee99db16
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu May 31 11:18:59 2018 +0200
ISIS-1954: IsisSystem: refactoring deprecated methods out into a mixin
Task-Url: https://issues.apache.org/jira/browse/ISIS-1954
---
.../integtestsupport/IntegrationTestAbstract3.java | 7 +-
core/legacy/integtestsupport-legacy/pom.xml | 12 +-
.../HeadlessWithBootstrappingAbstract.java | 3 +-
.../isis/core/runtime/headless/IsisSystem.java | 187 +--------------------
.../runtime/headless/IsisSystem_Transactions.java | 178 ++++++++++++++++++++
.../headless/TransactionSupportInternal.java | 30 ++++
6 files changed, 222 insertions(+), 195 deletions(-)
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract3.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract3.java
index c48e37c..2bea7bd 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract3.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract3.java
@@ -37,8 +37,6 @@ import org.junit.rules.ExpectedException;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;
/**
@@ -46,7 +44,7 @@ import org.slf4j.event.Level;
*/
public abstract class IntegrationTestAbstract3 extends HeadlessWithBootstrappingAbstract {
- private static final Logger LOG = LoggerFactory.getLogger(IntegrationTestAbstract3.class);
+ //private static final Logger LOG = LoggerFactory.getLogger(IntegrationTestAbstract3.class);
@Rule
public ExpectedException expectedExceptions = ExpectedException.none();
@@ -71,8 +69,7 @@ public abstract class IntegrationTestAbstract3 extends HeadlessWithBootstrapping
// Instead we expect it to be bootstrapped via @Before
try {
base.evaluate();
- final IsisSystem isft = IsisSystem.get();
- isft.endTran();
+ IsisSystem.get().getTransactionSupportInternal().endTran();
} catch(final Throwable e) {
// determine if underlying cause is an applib-defined exception,
final RecoverableException recoverableException =
diff --git a/core/legacy/integtestsupport-legacy/pom.xml b/core/legacy/integtestsupport-legacy/pom.xml
index 009a12e..0b7470c 100644
--- a/core/legacy/integtestsupport-legacy/pom.xml
+++ b/core/legacy/integtestsupport-legacy/pom.xml
@@ -45,12 +45,12 @@
<artifactId>isis-core-integtestsupport</artifactId>
<scope>compile</scope>
</dependency>
- <dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-integtestsupport</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
+<!-- <dependency> -->
+<!-- <groupId>org.apache.isis.core</groupId> -->
+<!-- <artifactId>isis-core-integtestsupport</artifactId> -->
+<!-- <type>test-jar</type> -->
+<!-- <scope>test</scope> -->
+<!-- </dependency> -->
<!-- JDO API (non transient, provided by plugin) -->
<dependency>
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/HeadlessWithBootstrappingAbstract.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/HeadlessWithBootstrappingAbstract.java
index 82acb3e..903599c 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/HeadlessWithBootstrappingAbstract.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/HeadlessWithBootstrappingAbstract.java
@@ -116,8 +116,7 @@ public abstract class HeadlessWithBootstrappingAbstract extends HeadlessAbstract
}
private void beginTransaction() {
- final IsisSystem isft = IsisSystem.get();
- isft.beginTran();
+ IsisSystem.get().getTransactionSupportInternal().beginTran();
}
protected void tearDownAllModules() {
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem.java
index 8892029..0317ea6 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem.java
@@ -25,9 +25,6 @@ import java.util.Set;
import org.apache.isis.applib.AppManifest;
import org.apache.isis.applib.fixtures.FixtureClock;
-import org.apache.isis.applib.fixtures.InstallableFixture;
-import org.apache.isis.applib.services.command.Command;
-import org.apache.isis.applib.services.command.CommandContext;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.core.commons.config.IsisConfiguration;
import org.apache.isis.core.commons.config.IsisConfigurationDefault;
@@ -36,16 +33,11 @@ import org.apache.isis.core.metamodel.services.ServicesInjector;
import org.apache.isis.core.metamodel.specloader.validator.MetaModelInvalidException;
import org.apache.isis.core.runtime.authentication.AuthenticationManager;
import org.apache.isis.core.runtime.authentication.AuthenticationRequest;
-import org.apache.isis.core.runtime.fixtures.FixturesInstallerDelegate;
import org.apache.isis.core.runtime.headless.auth.AuthenticationRequestNameOnly;
import org.apache.isis.core.runtime.logging.IsisLoggingConfigurer;
import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
import org.apache.isis.core.runtime.system.session.IsisSessionFactoryBuilder;
-import org.apache.isis.core.runtime.system.transaction.IsisTransaction;
-import org.apache.isis.core.runtime.system.transaction.IsisTransaction.State;
-import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
import org.apache.isis.core.runtime.systemusinginstallers.IsisComponentProvider;
import com.google.common.base.Joiner;
@@ -261,10 +253,6 @@ public class IsisSystem {
openSession();
}
-// public DomainObjectContainer getContainer() {
-// return getService(DomainObjectContainer.class);
-// }
-
// -- isisSystem (populated during setup)
protected IsisSessionFactory isisSessionFactory;
@@ -282,8 +270,6 @@ public class IsisSystem {
return authenticationSession;
}
-
-
// -- openSession, closeSession, nextSession
@@ -306,134 +292,6 @@ public class IsisSystem {
}
}
-
-
- // -- beginTran, endTran, commitTran, abortTran
-
- /**
- * @deprecated - ought to be using regular domain services rather than reaching into the framework
- */
- @Deprecated
- public void beginTran() {
- final IsisTransactionManager transactionManager = getTransactionManager();
- final IsisTransaction transaction = transactionManager.getCurrentTransaction();
-
- if(transaction == null) {
- startTransactionForUser(transactionManager);
- return;
- }
-
- final State state = transaction.getState();
- switch(state) {
- case COMMITTED:
- case ABORTED:
- startTransactionForUser(transactionManager);
- break;
- case IN_PROGRESS:
- // nothing to do
- break;
- case MUST_ABORT:
- throw new AssertionError("Transaction is in state of '" + state + "'");
- default:
- throw new AssertionError("Unknown transaction state '" + state + "'");
- }
-
- }
-
- private void startTransactionForUser(IsisTransactionManager transactionManager) {
- transactionManager.startTransaction();
-
- // specify that this command (if any) is being executed by a 'USER'
- final CommandContext commandContext = getService(CommandContext.class);
- Command command = commandContext.getCommand();
- command.setExecutor(Command.Executor.USER);
- }
-
- /**
- * Either commits or aborts the transaction, depending on the Transaction's {@link IsisTransaction#getState()}
- *
- * @deprecated - ought to be using regular domain services rather than reaching into the framework
- */
- @Deprecated
- public void endTran() {
- final IsisTransactionManager transactionManager = getTransactionManager();
- final IsisTransaction transaction = transactionManager.getCurrentTransaction();
- if(transaction == null) {
- throw new AssertionError("No transaction exists");
- }
-
- transactionManager.endTransaction();
-
- final State state = transaction.getState();
- switch(state) {
- case COMMITTED:
- break;
- case ABORTED:
- break;
- case IN_PROGRESS:
- throw new AssertionError("Transaction is still in state of '" + state + "'");
- case MUST_ABORT:
- throw new AssertionError("Transaction is still in state of '" + state + "'");
- default:
- throw new AssertionError("Unknown transaction state '" + state + "'");
- }
- }
-
- /**
- * Commits the transaction.
- *
- * @deprecated - ought to be using regular domain services rather than reaching into the framework
- */
- @Deprecated
- public void commitTran() {
- final IsisTransactionManager transactionManager = getTransactionManager();
- final IsisTransaction transaction = transactionManager.getCurrentTransaction();
- if(transaction == null) {
- throw new AssertionError("No transaction exists");
- }
- final State state = transaction.getState();
- switch(state) {
- case COMMITTED:
- case ABORTED:
- case MUST_ABORT:
- throw new AssertionError("Transaction is in state of '" + state + "'");
- case IN_PROGRESS:
- transactionManager.endTransaction();
- break;
- default:
- throw new AssertionError("Unknown transaction state '" + state + "'");
- }
- }
-
- /**
- * Aborts the transaction.
- *
- * @deprecated - ought to be using regular domain services rather than reaching into the framework
- */
- @Deprecated
- public void abortTran() {
- final IsisTransactionManager transactionManager = getTransactionManager();
- final IsisTransaction transaction = transactionManager.getCurrentTransaction();
- if(transaction == null) {
- throw new AssertionError("No transaction exists");
- }
- final State state = transaction.getState();
- switch(state) {
- case ABORTED:
- break;
- case COMMITTED:
- throw new AssertionError("Transaction is in state of '" + state + "'");
- case MUST_ABORT:
- case IN_PROGRESS:
- transactionManager.abortTransaction();
- break;
- default:
- throw new AssertionError("Unknown transaction state '" + state + "'");
- }
- }
-
-
-
// -- getService
public <C> C getService(Class<C> serviceClass) {
@@ -441,48 +299,13 @@ public class IsisSystem {
return servicesInjector.lookupServiceElseFail(serviceClass);
}
+ // -- Mixin for deprecated TransactionSupportInternal ([ahuber] refactored out of this class to ease removal)
-
- // -- Fixture management (for each test, rather than at bootstrap)
-
- /**
- * @deprecated - use {@link org.apache.isis.applib.fixturescripts.FixtureScripts} domain service instead.
- */
- @Deprecated
- public void installFixtures(final InstallableFixture... fixtures) {
- final FixturesInstallerDelegate fid = new FixturesInstallerDelegate(isisSessionFactory);
- for (final InstallableFixture fixture : fixtures) {
- fid.addFixture(fixture);
- }
- fid.installFixtures();
-
- // ensure that tests are performed in separate xactn to any fixture setup.
- final IsisTransactionManager transactionManager = getTransactionManager();
- final IsisTransaction transaction = transactionManager.getCurrentTransaction();
- final State transactionState = transaction.getState();
- if(transactionState.canCommit()) {
- commitTran();
- try {
- nextSession();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- beginTran();
- }
- }
-
-
-
- // -- Dependencies
-
- private IsisTransactionManager getTransactionManager() {
- return getPersistenceSession().getTransactionManager();
- }
+ private final TransactionSupportInternal transactionSupportInternal = new IsisSystem_Transactions();
- private PersistenceSession getPersistenceSession() {
- return isisSessionFactory.getCurrentSession().getPersistenceSession();
- }
-
+ public TransactionSupportInternal getTransactionSupportInternal() {
+ return transactionSupportInternal;
+ }
}
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem_Transactions.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem_Transactions.java
new file mode 100644
index 0000000..cb931cd
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem_Transactions.java
@@ -0,0 +1,178 @@
+/*
+ * 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.runtime.headless;
+
+import org.apache.isis.applib.services.command.Command;
+import org.apache.isis.applib.services.command.CommandContext;
+import org.apache.isis.core.metamodel.services.ServicesInjector;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
+import org.apache.isis.core.runtime.system.transaction.IsisTransaction;
+import org.apache.isis.core.runtime.system.transaction.IsisTransaction.State;
+import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
+
+class IsisSystem_Transactions implements TransactionSupportInternal {
+
+ /**
+ * @deprecated - ought to be using regular domain services rather than reaching into the framework
+ */
+ @Deprecated @Override
+ public void beginTran() {
+ final IsisTransactionManager transactionManager = getTransactionManager();
+ final IsisTransaction transaction = transactionManager.getCurrentTransaction();
+
+ if(transaction == null) {
+ startTransactionForUser(transactionManager);
+ return;
+ }
+
+ final State state = transaction.getState();
+ switch(state) {
+ case COMMITTED:
+ case ABORTED:
+ startTransactionForUser(transactionManager);
+ break;
+ case IN_PROGRESS:
+ // nothing to do
+ break;
+ case MUST_ABORT:
+ throw new AssertionError("Transaction is in state of '" + state + "'");
+ default:
+ throw new AssertionError("Unknown transaction state '" + state + "'");
+ }
+
+ }
+
+ private void startTransactionForUser(IsisTransactionManager transactionManager) {
+ transactionManager.startTransaction();
+
+ // specify that this command (if any) is being executed by a 'USER'
+ final CommandContext commandContext = getService(CommandContext.class);
+ Command command = commandContext.getCommand();
+ command.setExecutor(Command.Executor.USER);
+ }
+
+ /**
+ * Either commits or aborts the transaction, depending on the Transaction's {@link IsisTransaction#getState()}
+ *
+ * @deprecated - ought to be using regular domain services rather than reaching into the framework
+ */
+ @Deprecated @Override
+ public void endTran() {
+ final IsisTransactionManager transactionManager = getTransactionManager();
+ final IsisTransaction transaction = transactionManager.getCurrentTransaction();
+ if(transaction == null) {
+ throw new AssertionError("No transaction exists");
+ }
+
+ transactionManager.endTransaction();
+
+ final State state = transaction.getState();
+ switch(state) {
+ case COMMITTED:
+ break;
+ case ABORTED:
+ break;
+ case IN_PROGRESS:
+ throw new AssertionError("Transaction is still in state of '" + state + "'");
+ case MUST_ABORT:
+ throw new AssertionError("Transaction is still in state of '" + state + "'");
+ default:
+ throw new AssertionError("Unknown transaction state '" + state + "'");
+ }
+ }
+
+// /**
+// * Commits the transaction.
+// *
+// * @deprecated - ought to be using regular domain services rather than reaching into the framework
+// */
+// @Deprecated
+// public void commitTran() {
+// final IsisTransactionManager transactionManager = getTransactionManager();
+// final IsisTransaction transaction = transactionManager.getCurrentTransaction();
+// if(transaction == null) {
+// throw new AssertionError("No transaction exists");
+// }
+// final State state = transaction.getState();
+// switch(state) {
+// case COMMITTED:
+// case ABORTED:
+// case MUST_ABORT:
+// throw new AssertionError("Transaction is in state of '" + state + "'");
+// case IN_PROGRESS:
+// transactionManager.endTransaction();
+// break;
+// default:
+// throw new AssertionError("Unknown transaction state '" + state + "'");
+// }
+// }
+
+// /**
+// * Aborts the transaction.
+// *
+// * @deprecated - ought to be using regular domain services rather than reaching into the framework
+// */
+// @Deprecated
+// public void abortTran() {
+// final IsisTransactionManager transactionManager = getTransactionManager();
+// final IsisTransaction transaction = transactionManager.getCurrentTransaction();
+// if(transaction == null) {
+// throw new AssertionError("No transaction exists");
+// }
+// final State state = transaction.getState();
+// switch(state) {
+// case ABORTED:
+// break;
+// case COMMITTED:
+// throw new AssertionError("Transaction is in state of '" + state + "'");
+// case MUST_ABORT:
+// case IN_PROGRESS:
+// transactionManager.abortTransaction();
+// break;
+// default:
+// throw new AssertionError("Unknown transaction state '" + state + "'");
+// }
+// }
+
+ // -- getService
+
+ private <C> C getService(Class<C> serviceClass) {
+ final ServicesInjector servicesInjector = isisSessionFactory().getServicesInjector();
+ return servicesInjector.lookupServiceElseFail(serviceClass);
+ }
+
+ // -- Dependencies
+
+ private IsisTransactionManager getTransactionManager() {
+ return getPersistenceSession().getTransactionManager();
+ }
+
+ private PersistenceSession getPersistenceSession() {
+ return isisSessionFactory().getCurrentSession().getPersistenceSession();
+ }
+
+ private IsisSessionFactory isisSessionFactory() {
+ return IsisContext.getSessionFactory();
+ }
+
+
+}
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/TransactionSupportInternal.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/TransactionSupportInternal.java
new file mode 100644
index 0000000..a14e4b7
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/headless/TransactionSupportInternal.java
@@ -0,0 +1,30 @@
+/*
+ * 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.runtime.headless;
+
+/**
+ * [ahuber] temporal interface to ease refactoring and finally removal
+ * @deprecated ought to be using regular domain services rather than reaching into the framework
+ */
+@Deprecated
+public interface TransactionSupportInternal {
+ void beginTran();
+ void endTran();
+}
--
To stop receiving notification emails like this one, please contact
ahuber@apache.org.