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/04/23 16:55:25 UTC
[4/5] isis git commit: ISIS-1390: minor refactorings (inlining of
methods), now easy to track usage of the CommandService
ISIS-1390: minor refactorings (inlining of methods), now easy to track usage of the CommandService
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/2f3b1072
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/2f3b1072
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/2f3b1072
Branch: refs/heads/ISIS-1291
Commit: 2f3b107282f5bb38b1bdddf1bd1af3020459aa2e
Parents: 113e4ae
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Sat Apr 23 12:58:43 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Sat Apr 23 12:58:43 2016 +0100
----------------------------------------------------------------------
.../services/command/spi/CommandService.java | 7 +-
.../system/transaction/IsisTransaction.java | 120 ++++---------------
.../transaction/IsisTransactionManager.java | 1 -
3 files changed, 25 insertions(+), 103 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/2f3b1072/core/applib/src/main/java/org/apache/isis/applib/services/command/spi/CommandService.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/command/spi/CommandService.java b/core/applib/src/main/java/org/apache/isis/applib/services/command/spi/CommandService.java
index ab33170..bce9cab 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/command/spi/CommandService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/command/spi/CommandService.java
@@ -22,12 +22,7 @@ import org.apache.isis.applib.annotation.Programmatic;
import org.apache.isis.applib.services.command.Command;
/**
- * Factory and persistence service for {@link Command}s.
- *
- * <p>
- * There is currently only one implementation, <tt>CommandServiceJdo</tt>, part of the
- * <tt>o.a.i.module:isis-module-command-jdo</tt>. To use, must both include on the classpath and also
- * register its services (eg in <tt>isis.properties</tt>).
+ * Default factory service for {@link Command}s.
*/
public interface CommandService {
http://git-wip-us.apache.org/repos/asf/isis/blob/2f3b1072/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
index 3448d46..ca35fcd 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
@@ -40,7 +40,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.isis.applib.Identifier;
-import org.apache.isis.applib.RecoverableException;
import org.apache.isis.applib.annotation.Bulk;
import org.apache.isis.applib.annotation.PublishedAction;
import org.apache.isis.applib.annotation.PublishedObject;
@@ -54,7 +53,6 @@ import org.apache.isis.applib.services.command.Command2;
import org.apache.isis.applib.services.command.Command3;
import org.apache.isis.applib.services.command.CommandContext;
import org.apache.isis.applib.services.command.spi.CommandService;
-import org.apache.isis.applib.services.eventbus.ActionDomainEvent;
import org.apache.isis.applib.services.iactn.Interaction;
import org.apache.isis.applib.services.publish.EventMetadata;
import org.apache.isis.applib.services.publish.EventPayload;
@@ -91,7 +89,6 @@ import org.apache.isis.core.metamodel.spec.feature.Contributed;
import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
import org.apache.isis.core.metamodel.transactions.TransactionState;
-import org.apache.isis.core.runtime.persistence.PersistenceConstants;
import org.apache.isis.core.runtime.persistence.objectstore.transaction.CreateObjectCommand;
import org.apache.isis.core.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
import org.apache.isis.core.runtime.persistence.objectstore.transaction.PersistenceCommand;
@@ -796,10 +793,12 @@ public class IsisTransaction implements TransactionScopedComponent {
Sets.filter(processedObjectProperties.entrySet(), PreAndPostValues.Predicates.CHANGED));
ensureCommandsPersistedIfDirtyXactnAndAnySafeSemanticsHonoured(changedObjectProperties);
+
preCommitServices(changedObjectProperties);
+
} catch (final RuntimeException ex) {
setAbortCause(new IsisTransactionManagerException(ex));
- clearCommandServiceIfConfigured();
+ completeCommandAndClearDomainEvents();
throw ex;
}
}
@@ -813,87 +812,8 @@ public class IsisTransaction implements TransactionScopedComponent {
if(!changedAdapters.isEmpty() && command.getMemberIdentifier() != null) {
command.setPersistHint(true);
}
-
- ensureSafeSemanticsHonoured(command, changedAdapters);
- }
-
- private void ensureSafeSemanticsHonoured(Command command, Set<ObjectAdapter> changedAdapters) {
-
- if(true) {
-
- // ISIS-921: disabling this functionality...
- //
- // ... the issue is that an edit (which mutates state, obviously), can cause a contributed property to
- // be evaluated, which has safe semantics.
- //
- // the solution, I think, is to set up some sort of "dummy" action to represent the edit.
- // this needs to be installed pretty early up in the stack trace. ISIS-922 raised for this.
- //
-
- return;
- }
-
- if (!(command instanceof Command2)) {
- return;
- }
-
- final List<? extends ActionDomainEvent<?>> events;
- events = flushActionDomainEvents(command);
- if (events.isEmpty()) {
- return;
- }
-
- // are all safe?
- for (ActionDomainEvent<?> event : events) {
- if(!event.getActionSemantics().isSafeInNature()) {
- // found at least one non-safe action, so all bets are off.
- return;
- }
- }
-
- // all actions invoked had safe semantics; were any objects changed?
- if (changedAdapters.isEmpty()) {
- return;
- }
-
- final String msg = "Action '" + events.get(0).getIdentifier().toFullIdentityString() + "'" +
- " (with safe semantics)" +
- " caused " + changedAdapters.size() + " object" + (changedAdapters.size() != 1 ? "s" : "") +
- " to be modified";
- LOG.error(msg);
- for (ObjectAdapter changedAdapter : changedAdapters) {
- final StringBuilder builder = new StringBuilder(" > ")
- .append(changedAdapter.getSpecification().getFullIdentifier())
- .append(": ");
- if(!changedAdapter.isDestroyed()) {
- builder.append(changedAdapter.titleString(null));
- } else {
- builder.append("(deleted object)");
- }
- LOG.error(builder.toString());
- }
-
- final boolean enforceSafeSemantics = getConfiguration().getBoolean(PersistenceConstants.ENFORCE_SAFE_SEMANTICS, PersistenceConstants.ENFORCE_SAFE_SEMANTICS_DEFAULT);
- if(enforceSafeSemantics) {
- throw new RecoverableException(msg);
- }
}
- private List<? extends ActionDomainEvent<?>> flushActionDomainEvents(
- final Command command) {
-
- if(command instanceof Command3) {
- final Command3 command3 = (Command3) command;
- return command3.flushActionDomainEvents();
- }
- // else
- if(command instanceof Command2) {
- final Command2 command2 = (Command2) command;
- return command2.flushActionInteractionEvents();
- }
- // else
- return Collections.emptyList();
- }
private static Set<ObjectAdapter> findChangedAdapters(
final Set<Entry<AdapterAndProperty, PreAndPostValues>> changedObjectProperties) {
@@ -906,7 +826,9 @@ public class IsisTransaction implements TransactionScopedComponent {
}
- private void preCommitServices(final Set<Entry<AdapterAndProperty, PreAndPostValues>> changedObjectProperties) {
+ private void preCommitServices(
+ final Set<Entry<AdapterAndProperty, PreAndPostValues>> changedObjectProperties) {
+
doAudit(changedObjectProperties);
final String currentUser = getTransactionManager().getAuthenticationSession().getUserName();
@@ -917,19 +839,12 @@ public class IsisTransaction implements TransactionScopedComponent {
publishedChangedObjectsIfRequired(currentUser, endTimestamp);
doFlush();
-
- closeServices();
- doFlush();
- }
- private void clearCommandServiceIfConfigured() {
- completeCommand();
- }
+ closeOtherApplibServicesIfConfigured();
+ completeCommandAndClearDomainEvents();
- private void closeServices() {
- closeOtherApplibServicesIfConfigured();
- completeCommand();
+ doFlush();
}
private void closeOtherApplibServicesIfConfigured() {
@@ -939,14 +854,27 @@ public class IsisTransaction implements TransactionScopedComponent {
}
}
- private void completeCommand() {
+ private void completeCommandAndClearDomainEvents() {
+
final Command command = commandContext.getCommand();
commandService.complete(command);
- flushActionDomainEvents(command);
+ if(command instanceof Command3) {
+ final Command3 command3 = (Command3) command;
+ command3.flushActionDomainEvents();
+ return;
+ }
+
+ // else
+ if(command instanceof Command2) {
+ final Command2 command2 = (Command2) command;
+ command2.flushActionInteractionEvents();
+ return;
+ }
}
+
// ////////////////////////////////////////////////////////////////
public synchronized void commit() {
http://git-wip-us.apache.org/repos/asf/isis/blob/2f3b1072/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java
index 486bedb..7896d37 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransactionManager.java
@@ -352,7 +352,6 @@ public class IsisTransactionManager implements SessionScopedComponent {
}
private Command createCommand() {
- final CommandService commandService = lookupServiceIfAny(CommandService.class);
final Command command = commandService.create();
servicesInjector.injectServicesInto(command);