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 2015/03/20 16:46:01 UTC
[1/2] isis git commit: ISIS-1100: improving algorithm for preCommit
capture of audit pre/post values;
making the refactored algorithm for flushing persistence commands more
efficient.
Repository: isis
Updated Branches:
refs/heads/master 1f8d1356e -> c79af4e24
ISIS-1100: improving algorithm for preCommit capture of audit pre/post values; making the refactored algorithm for flushing persistence commands more efficient.
in addition:
- updating comments only in DataNucleusObjectStore
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/3183d013
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/3183d013
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/3183d013
Branch: refs/heads/master
Commit: 3183d013d3d756c098ff96ace23951336e12aad6
Parents: 1f8d135
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Mar 20 15:40:31 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Mar 20 15:40:31 2015 +0000
----------------------------------------------------------------------
.../system/transaction/IsisTransaction.java | 107 +++++++++----------
.../jdo/datanucleus/DataNucleusObjectStore.java | 17 +--
2 files changed, 51 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/3183d013/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 d98381f..52def80 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
@@ -93,7 +93,6 @@ import org.apache.isis.core.runtime.persistence.objectstore.transaction.Publishi
import org.apache.isis.core.runtime.persistence.objectstore.transaction.SaveObjectCommand;
import org.apache.isis.core.runtime.persistence.objectstore.transaction.TransactionalResource;
import org.apache.isis.core.runtime.system.context.IsisContext;
-
import static org.apache.isis.core.commons.ensure.Ensure.ensureThatArg;
import static org.apache.isis.core.commons.ensure.Ensure.ensureThatState;
import static org.hamcrest.CoreMatchers.nullValue;
@@ -231,7 +230,7 @@ public class IsisTransaction implements TransactionScopedComponent {
private static final Logger LOG = LoggerFactory.getLogger(IsisTransaction.class);
private final TransactionalResource objectStore;
- private final List<PersistenceCommand> commands = Lists.newArrayList();
+ private final List<PersistenceCommand> persistenceCommands = Lists.newArrayList();
private final IsisTransactionManager transactionManager;
private final MessageBroker messageBroker;
@@ -442,7 +441,7 @@ public class IsisTransaction implements TransactionScopedComponent {
if (LOG.isDebugEnabled()) {
LOG.debug("add command " + command);
}
- commands.add(command);
+ persistenceCommands.add(command);
}
@@ -513,28 +512,30 @@ public class IsisTransaction implements TransactionScopedComponent {
do {
// this algorithm ensures that we never execute the same command twice,
// and also allow new commands to be added to end
- PersistenceCommand command = commands.isEmpty()? null: commands.get(0);
+ final List<PersistenceCommand> persistenceCommandList = Lists.newArrayList(persistenceCommands);
- if(command != null) {
+ if(!persistenceCommandList.isEmpty()) {
// so won't be processed again if a flush is encountered subsequently
- commands.remove(command);
+ persistenceCommands.removeAll(persistenceCommandList);
try {
- objectStore.execute(Collections.singletonList(command));
- if (command instanceof DestroyObjectCommand) {
- final ObjectAdapter adapter = command.onAdapter();
- adapter.setVersion(null);
- if (!adapter.isDestroyed()) {
- adapter.changeState(ResolveState.DESTROYED);
+ objectStore.execute(persistenceCommandList);
+ for (PersistenceCommand persistenceCommand : persistenceCommandList) {
+ if (persistenceCommand instanceof DestroyObjectCommand) {
+ final ObjectAdapter adapter = persistenceCommand.onAdapter();
+ adapter.setVersion(null);
+ if (!adapter.isDestroyed()) {
+ adapter.changeState(ResolveState.DESTROYED);
+ }
}
}
} catch (final RuntimeException ex) {
// if there's an exception, we want to make sure that
// all commands are cleared and propagate
- commands.clear();
+ persistenceCommands.clear();
throw ex;
}
}
- } while(!commands.isEmpty());
+ } while(!persistenceCommands.isEmpty());
}
@@ -742,7 +743,31 @@ public class IsisTransaction implements TransactionScopedComponent {
}
try {
- final Set<Entry<AdapterAndProperty, PreAndPostValues>> changedObjectProperties = getChangedObjectProperties();
+ final Map<AdapterAndProperty, PreAndPostValues> processedObjectProperties = Maps.newLinkedHashMap();
+ while(!changedObjectProperties.isEmpty()) {
+
+ final Set<AdapterAndProperty> keys = Sets.newLinkedHashSet(changedObjectProperties.keySet());
+ for (final AdapterAndProperty aap : keys) {
+
+ final PreAndPostValues papv = changedObjectProperties.remove(aap);
+
+ final ObjectAdapter adapter = aap.getAdapter();
+ if(adapter.isDestroyed()) {
+ // don't touch the object!!!
+ // JDO, for example, will complain otherwise...
+ papv.setPost(Placeholder.DELETED);
+ } else {
+ papv.setPost(aap.getPropertyValue());
+ }
+
+ // if we encounter the same objectProperty again, this will simply overwrite it
+ processedObjectProperties.put(aap, papv);
+ }
+ }
+
+ final Set<Entry<AdapterAndProperty, PreAndPostValues>> changedObjectProperties =
+ Collections.unmodifiableSet(
+ Sets.filter(processedObjectProperties.entrySet(), PreAndPostValues.Predicates.CHANGED));
ensureCommandsPersistedIfDirtyXactnAndAnySafeSemanticsHonoured(changedObjectProperties);
preCommitServices(changedObjectProperties);
@@ -1012,7 +1037,7 @@ public class IsisTransaction implements TransactionScopedComponent {
}
private PersistenceCommand getCommand(final Class<?> commandClass, final ObjectAdapter onObject) {
- for (final PersistenceCommand command : commands) {
+ for (final PersistenceCommand command : persistenceCommands) {
if (command.onAdapter().equals(onObject)) {
if (commandClass.isAssignableFrom(command.getClass())) {
return command;
@@ -1024,7 +1049,7 @@ public class IsisTransaction implements TransactionScopedComponent {
private void removeCommand(final Class<?> commandClass, final ObjectAdapter onObject) {
final PersistenceCommand toDelete = getCommand(commandClass, onObject);
- commands.remove(toDelete);
+ persistenceCommands.remove(toDelete);
}
private void removeCreate(final ObjectAdapter onObject) {
@@ -1046,7 +1071,7 @@ public class IsisTransaction implements TransactionScopedComponent {
protected ToString appendTo(final ToString str) {
str.append("state", state);
- str.append("commands", commands.size());
+ str.append("commands", persistenceCommands.size());
return str;
}
@@ -1262,8 +1287,7 @@ public class IsisTransaction implements TransactionScopedComponent {
* capturing a dummy value <tt>'[NEW]'</tt> for the pre-modification value.
*
* <p>
- * The post-modification values are captured in as a side-effect of calling {@link #getChangedObjectProperties()},
- * which returns the pre- and post- values for each {@link ObjectAdapter} in a map.
+ * The post-modification values are captured in {@link #preCommit()}.
*
* <p>
* Supported by the JDO object store; check documentation for support in other objectstores.
@@ -1289,9 +1313,8 @@ public class IsisTransaction implements TransactionScopedComponent {
* capturing the pre-modification values of the properties of the {@link ObjectAdapter}.
*
* <p>
- * The post-modification values are captured in as a side-effect of calling {@link #getChangedObjectProperties()},
- * which returns the pre- and post- values for each {@link ObjectAdapter} in a map.
- *
+ * The post-modification values are captured in {@link #preCommit()}.
+ *
* <p>
* Supported by the JDO object store; check documentation for support in other objectstores.
*/
@@ -1316,8 +1339,8 @@ public class IsisTransaction implements TransactionScopedComponent {
* capturing the pre-deletion value of the properties of the {@link ObjectAdapter}.
*
* <p>
- * The post-modification values are captured in as a side-effect of calling {@link #getChangedObjectProperties()}.
- * In the case of deleted objects, a dummy value <tt>'[DELETED]'</tt> is used as the post-modification value.
+ * The post-modification values are captured in {@link #preCommit()}. In the case of deleted objects, a
+ * dummy value <tt>'[DELETED]'</tt> is used as the post-modification value.
*
* <p>
* Supported by the JDO object store; check documentation for support in other objectstores.
@@ -1379,42 +1402,8 @@ public class IsisTransaction implements TransactionScopedComponent {
}
return previous == null;
}
-
-
- /**
- * Returns the pre- and post-values of all {@link ObjectAdapter}s that were enlisted and dirtied
- * in this transaction.
- *
- * <p>
- * This requires that the object store called {@link #enlistUpdating(ObjectAdapter)} for each object being
- * enlisted.
- *
- * <p>
- * Supported by the JDO object store (since it calls {@link #enlistUpdating(ObjectAdapter)});
- * check documentation for support in other object stores.
- */
- private Set<Entry<AdapterAndProperty, PreAndPostValues>> getChangedObjectProperties() {
- updatePostValues(changedObjectProperties.entrySet());
-
- return Collections.unmodifiableSet(Sets.filter(changedObjectProperties.entrySet(), PreAndPostValues.Predicates.CHANGED));
- }
- private static void updatePostValues(Set<Entry<AdapterAndProperty, PreAndPostValues>> entrySet) {
- for (Entry<AdapterAndProperty, PreAndPostValues> entry : entrySet) {
- final AdapterAndProperty aap = entry.getKey();
- final PreAndPostValues papv = entry.getValue();
- ObjectAdapter adapter = aap.getAdapter();
- if(adapter.isDestroyed()) {
- // don't touch the object!!!
- // JDO, for example, will complain otherwise...
- papv.setPost(Placeholder.DELETED);
- } else {
- papv.setPost(aap.getPropertyValue());
- }
- }
- }
-
////////////////////////////////////////////////////////////////////////
// Dependencies (from context)
////////////////////////////////////////////////////////////////////////
http://git-wip-us.apache.org/repos/asf/isis/blob/3183d013/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusObjectStore.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusObjectStore.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusObjectStore.java
index d6624cb..c92bae9 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusObjectStore.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusObjectStore.java
@@ -348,20 +348,9 @@ public class DataNucleusObjectStore implements ObjectStore {
ensureOpened();
ensureInTransaction();
- // no longer check if there are no commands; it could be that
- // DataNucleus has some dirty objects anyway that don't have
- // commands wrapped around them...
-
-// if (LOG.isDebugEnabled()) {
-// LOG.debug("execute " + commands.size() + " commands");
-// }
-//
-// if (commands.size() <= 0) {
-// if (LOG.isDebugEnabled()) {
-// LOG.debug("no commands");
-// }
-// return;
-// }
+ // previously we used to check that there were some commands, and skip processing otherwise.
+ // we no longer do that; it could be (is quite likely) that DataNucleus has some dirty objects anyway that
+ // don't have commands wrapped around them...
executeCommands(commands);
}
[2/2] isis git commit: ISIS-1096: fixing bug whereby
@DomainObject(objectType=...) being ignored (trampled on by the
JdoPersistceCapableFacet processing).
Posted by da...@apache.org.
ISIS-1096: fixing bug whereby @DomainObject(objectType=...) being ignored (trampled on by the JdoPersistceCapableFacet processing).
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/c79af4e2
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/c79af4e2
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/c79af4e2
Branch: refs/heads/master
Commit: c79af4e2427c6bb51bf6257aac9790a39065e63a
Parents: 3183d01
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Mar 20 15:41:53 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Mar 20 15:41:53 2015 +0000
----------------------------------------------------------------------
.../domainobject/DomainObjectAnnotationFacetFactory.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/c79af4e2/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 8bca451..5d3c35b 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
@@ -242,9 +242,11 @@ public class DomainObjectAnnotationFacetFactory extends FacetFactoryAbstract imp
}
// else check for @PersistenceCapable(schema=...)
- final JdoPersistenceCapableFacet jdoPersistenceCapableFacet = facetHolder.getFacet(JdoPersistenceCapableFacet.class);
- if(jdoPersistenceCapableFacet != null) {
- facet = ObjectSpecIdFacetForJdoPersistenceCapableAnnotation.create(jdoPersistenceCapableFacet, facetHolder);
+ if(facet == null) {
+ final JdoPersistenceCapableFacet jdoPersistenceCapableFacet = facetHolder.getFacet(JdoPersistenceCapableFacet.class);
+ if(jdoPersistenceCapableFacet != null) {
+ facet = ObjectSpecIdFacetForJdoPersistenceCapableAnnotation.create(jdoPersistenceCapableFacet, facetHolder);
+ }
}
// then add