polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From soelvs...@apache.org
Subject zest-java git commit: ZEST-132 DefaultUnitOfWorkAssembler now redundant, since work is done by EventBus
Date Thu, 17 Dec 2015 22:20:07 GMT
Repository: zest-java
Updated Branches:
  refs/heads/ZEST-132 4190b401d -> 86cbd80f8


ZEST-132 DefaultUnitOfWorkAssembler now redundant, since work is done by EventBus


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/86cbd80f
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/86cbd80f
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/86cbd80f

Branch: refs/heads/ZEST-132
Commit: 86cbd80f8f2f9bd8877279c56dbb12db981bb111
Parents: 4190b40
Author: Kent Sølvsten <soelvsten@apache.org>
Authored: Thu Dec 17 23:20:10 2015 +0100
Committer: Kent Sølvsten <soelvsten@apache.org>
Committed: Thu Dec 17 23:20:10 2015 +0100

----------------------------------------------------------------------
 .../unitofwork/DefaultUnitOfWorkAssembler.java    | 11 +++++------
 .../org/apache/zest/runtime/event/EventBus.java   | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/86cbd80f/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java
b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java
old mode 100644
new mode 100755
index 14171cd..3ef541d
--- a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java
+++ b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java
@@ -20,8 +20,6 @@
 
 package org.apache.zest.bootstrap.unitofwork;
 
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.api.unitofwork.UnitOfWorkFactory;
 import org.apache.zest.bootstrap.Assembler;
 import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.ModuleAssembly;
@@ -33,11 +31,12 @@ public class DefaultUnitOfWorkAssembler
     public void assemble( ModuleAssembly module )
         throws AssemblyException
     {
-        Class factoryMixin = loadMixinClass( "org.apache.zest.runtime.unitofwork.UnitOfWorkFactoryMixin"
);
-        module.services( UnitOfWorkFactory.class ).withMixins( factoryMixin );
+        // Do nothing - added automatically by EventBus
+        //Class factoryMixin = loadMixinClass( "org.apache.zest.runtime.unitofwork.UnitOfWorkFactoryMixin"
);
+        //module.services( UnitOfWorkFactory.class ).withMixins( factoryMixin );
 
-        Class uowMixin = loadMixinClass( "org.apache.zest.runtime.unitofwork.ModuleUnitOfWork"
);
-        module.transients( UnitOfWork.class ).withMixins( uowMixin );
+        //Class uowMixin = loadMixinClass( "org.apache.zest.runtime.unitofwork.ModuleUnitOfWork"
);
+        //module.transients( UnitOfWork.class ).withMixins( uowMixin );
     }
 
     private Class<?> loadMixinClass( String name )

http://git-wip-us.apache.org/repos/asf/zest-java/blob/86cbd80f/core/runtime/src/main/java/org/apache/zest/runtime/event/EventBus.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/event/EventBus.java b/core/runtime/src/main/java/org/apache/zest/runtime/event/EventBus.java
index 59b8c73..74dd346 100755
--- a/core/runtime/src/main/java/org/apache/zest/runtime/event/EventBus.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/event/EventBus.java
@@ -26,13 +26,31 @@ import java.util.ListIterator;
 import java.util.Map;
 import org.apache.zest.api.event.ZestEvent;
 import org.apache.zest.api.event.ZestEventHandler;
+import org.apache.zest.api.unitofwork.UnitOfWork;
+import org.apache.zest.api.unitofwork.UnitOfWorkFactory;
+import org.apache.zest.bootstrap.ModuleAssembly;
 import org.apache.zest.bootstrap.handler.ModuleAssembledEvent;
+import org.apache.zest.runtime.unitofwork.ModuleUnitOfWork;
+import org.apache.zest.runtime.unitofwork.UnitOfWorkFactoryMixin;
 
 public class EventBus
 {
     public EventBus() {
+        // emit ModuleAssembledEvent to interested users
         ModuleAssembledRuntimeEvent.Handler handler = event -> EventBus.this.emit( new
ModuleAssembledEvent( event.getModuleAssembly() ) );
         addHandler( ModuleAssembledRuntimeEvent.TYPE, handler );
+        // add default UnitOfWork to all modules (of not already added by user)
+        addHandler( ModuleAssembledRuntimeEvent.TYPE, new ModuleAssembledRuntimeEvent.Handler(
 ) {
+            @Override
+            public void onModuleAssembled( ModuleAssembledRuntimeEvent event )
+            {
+                ModuleAssembly moduleAssembly = event.getModuleAssembly();
+                // mixin will not be used, if user have already added a matching mixin
+                // @TODO make it possible to ask if service is already there (more robust)
+                moduleAssembly.services( UnitOfWorkFactory.class ).withMixins( UnitOfWorkFactoryMixin.class
);
+                moduleAssembly.transients( UnitOfWork.class ).withMixins( ModuleUnitOfWork.class
);
+            }
+        });
     }
 
     /**


Mime
View raw message