You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by pa...@apache.org on 2016/12/06 17:30:12 UTC

[5/5] zest-java git commit: api: Lifecycle can throw Exception

api: Lifecycle can throw Exception


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

Branch: refs/heads/develop
Commit: 994d38913cd99c1a691611c50580c58d9fdc2940
Parents: ccb54f3
Author: Paul Merlin <pa...@apache.org>
Authored: Tue Dec 6 09:41:51 2016 +0100
Committer: Paul Merlin <pa...@apache.org>
Committed: Tue Dec 6 09:41:51 2016 +0100

----------------------------------------------------------------------
 .../org/apache/zest/api/entity/Lifecycle.java   | 11 ++++------
 .../zest/api/entity/LifecycleException.java     | 14 +++++--------
 .../zest/runtime/entity/EntityInstance.java     |  2 --
 .../zest/runtime/entity/EntityMixinsModel.java  | 21 ++++++++++++++++++--
 .../apache/zest/regression/qi382/Qi382Test.java | 11 ++++------
 .../zest/runtime/entity/EntityCreationTest.java |  5 +----
 .../zest/runtime/entity/LifecycleTest.java      |  7 ++-----
 .../uowfile/plural/HasUoWFilesLifecycle.java    |  7 +++----
 .../uowfile/singular/HasUoWFileLifecycle.java   |  7 +++----
 9 files changed, 41 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/994d3891/core/api/src/main/java/org/apache/zest/api/entity/Lifecycle.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/Lifecycle.java b/core/api/src/main/java/org/apache/zest/api/entity/Lifecycle.java
index e7bde27..3eb933a 100644
--- a/core/api/src/main/java/org/apache/zest/api/entity/Lifecycle.java
+++ b/core/api/src/main/java/org/apache/zest/api/entity/Lifecycle.java
@@ -65,17 +65,15 @@ package org.apache.zest.api.entity;
  */
 public interface Lifecycle
 {
-
     /**
      * Creation callback method.
      * <p>
      * Called by the Zest runtime before the newInstance of the entity completes, before the constraints are checked,
      * allowing for additional initialization.
      * </p>
-     * @throws LifecycleException if the entity could not be created
+     * @throws Exception if the entity could not be created
      */
-    void create()
-        throws LifecycleException;
+    void create() throws Exception;
 
     /**
      * Removal callback method.
@@ -83,8 +81,7 @@ public interface Lifecycle
      * Called by the Zest runtime before the entity is removed from the system, allowing
      * for clean-up operations.
      * </p>
-     * @throws LifecycleException if the entity could not be removed
+     * @throws Exception if the entity could not be removed
      */
-    void remove()
-        throws LifecycleException;
+    void remove() throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/994d3891/core/api/src/main/java/org/apache/zest/api/entity/LifecycleException.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/entity/LifecycleException.java b/core/api/src/main/java/org/apache/zest/api/entity/LifecycleException.java
index 4670cf8..c4b5957 100644
--- a/core/api/src/main/java/org/apache/zest/api/entity/LifecycleException.java
+++ b/core/api/src/main/java/org/apache/zest/api/entity/LifecycleException.java
@@ -21,23 +21,19 @@
 package org.apache.zest.api.entity;
 
 /**
- * Thrown by methods of Lifecycle if invocation fails
+ * Thrown if Lifecycle invocation fails
  */
 public class LifecycleException
     extends RuntimeException
 {
-    public LifecycleException( String s )
-    {
-        super( s );
-    }
+    private static final long serialVersionUID = 1L;
 
-    public LifecycleException( String s, Throwable throwable )
+    public LifecycleException()
     {
-        super( s, throwable );
     }
 
-    public LifecycleException( Throwable throwable )
+    public LifecycleException( String message, Throwable cause )
     {
-        super( throwable );
+        super( message, cause );
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/994d3891/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java
index 86f00cc..09453f1 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java
@@ -33,7 +33,6 @@ import org.apache.zest.api.constraint.ConstraintViolationException;
 import org.apache.zest.api.entity.EntityComposite;
 import org.apache.zest.api.entity.EntityReference;
 import org.apache.zest.api.identity.HasIdentity;
-import org.apache.zest.api.entity.LifecycleException;
 import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.api.unitofwork.NoSuchEntityException;
 import org.apache.zest.api.unitofwork.UnitOfWork;
@@ -242,7 +241,6 @@ public final class EntityInstance
     }
 
     public void remove( UnitOfWork unitOfWork )
-        throws LifecycleException
     {
         invokeRemove();
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/994d3891/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityMixinsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityMixinsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityMixinsModel.java
index 52ad5a9..c0737ed 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityMixinsModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityMixinsModel.java
@@ -25,6 +25,7 @@ import java.util.ArrayList;
 import java.util.List;
 import org.apache.zest.api.composite.CompositeInstance;
 import org.apache.zest.api.entity.Lifecycle;
+import org.apache.zest.api.entity.LifecycleException;
 import org.apache.zest.api.property.StateHolder;
 import org.apache.zest.bootstrap.BindingException;
 import org.apache.zest.runtime.composite.MixinModel;
@@ -88,11 +89,27 @@ public final class EntityMixinsModel
 
                 if( create )
                 {
-                    lifecycle.create();
+                    try
+                    {
+                        lifecycle.create();
+                    }
+                    catch( Exception ex )
+                    {
+                        String message = "Unable to invoke create lifecycle on " + lifecycle;
+                        throw new LifecycleException( message, ex );
+                    }
                 }
                 else
                 {
-                    lifecycle.remove();
+                    try
+                    {
+                        lifecycle.remove();
+                    }
+                    catch( Exception ex )
+                    {
+                        String message = "Unable to invoke remove lifecycle on " + lifecycle;
+                        throw new LifecycleException( message, ex );
+                    }
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/994d3891/core/runtime/src/test/java/org/apache/zest/regression/qi382/Qi382Test.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/zest/regression/qi382/Qi382Test.java b/core/runtime/src/test/java/org/apache/zest/regression/qi382/Qi382Test.java
index 800d241..f34b55a 100644
--- a/core/runtime/src/test/java/org/apache/zest/regression/qi382/Qi382Test.java
+++ b/core/runtime/src/test/java/org/apache/zest/regression/qi382/Qi382Test.java
@@ -19,26 +19,25 @@
  */
 package org.apache.zest.regression.qi382;
 
-import org.apache.zest.api.identity.Identity;
-import org.apache.zest.api.identity.StringIdentity;
-import org.apache.zest.api.unitofwork.UnitOfWorkFactory;
-import org.junit.Test;
 import org.apache.zest.api.association.Association;
 import org.apache.zest.api.entity.EntityBuilder;
 import org.apache.zest.api.entity.EntityComposite;
 import org.apache.zest.api.entity.Lifecycle;
-import org.apache.zest.api.entity.LifecycleException;
+import org.apache.zest.api.identity.Identity;
+import org.apache.zest.api.identity.StringIdentity;
 import org.apache.zest.api.injection.scope.Structure;
 import org.apache.zest.api.injection.scope.This;
 import org.apache.zest.api.mixin.Mixins;
 import org.apache.zest.api.unitofwork.UnitOfWork;
 import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException;
+import org.apache.zest.api.unitofwork.UnitOfWorkFactory;
 import org.apache.zest.api.value.ValueSerialization;
 import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.ModuleAssembly;
 import org.apache.zest.entitystore.memory.MemoryEntityStoreService;
 import org.apache.zest.test.AbstractZestTest;
 import org.apache.zest.valueserialization.orgjson.OrgJsonValueSerializationService;
+import org.junit.Test;
 
 import static org.hamcrest.core.IsEqual.equalTo;
 import static org.hamcrest.core.IsNull.notNullValue;
@@ -92,7 +91,6 @@ public class Qi382Test extends AbstractZestTest
 
             @Override
             public void create()
-                throws LifecycleException
             {
                 UnitOfWork unitOfWork = uowf.currentUnitOfWork();
                 EntityBuilder<Person> builder = unitOfWork.newEntityBuilder( Person.class, NICLAS);
@@ -102,7 +100,6 @@ public class Qi382Test extends AbstractZestTest
 
             @Override
             public void remove()
-                throws LifecycleException
             {
 
             }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/994d3891/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCreationTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCreationTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCreationTest.java
index f9865e6..77c92c8 100644
--- a/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCreationTest.java
+++ b/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCreationTest.java
@@ -19,11 +19,9 @@
  */
 package org.apache.zest.runtime.entity;
 
-import org.junit.Test;
 import org.apache.zest.api.entity.EntityBuilder;
 import org.apache.zest.api.entity.EntityComposite;
 import org.apache.zest.api.entity.Lifecycle;
-import org.apache.zest.api.entity.LifecycleException;
 import org.apache.zest.api.injection.scope.This;
 import org.apache.zest.api.mixin.Mixins;
 import org.apache.zest.api.property.Immutable;
@@ -33,6 +31,7 @@ import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.ModuleAssembly;
 import org.apache.zest.test.AbstractZestTest;
 import org.apache.zest.test.EntityTestAssembler;
+import org.junit.Test;
 
 /**
  * Test case for http://team.ops4j.org/browse/QI-274
@@ -60,14 +59,12 @@ public class EntityCreationTest
 
         @Override
         public void create()
-                throws LifecycleException
         {
             this._me.someProperty().set( "SomeValue" );
         }
 
         @Override
         public void remove()
-                throws LifecycleException
         {
         }
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/994d3891/core/runtime/src/test/java/org/apache/zest/runtime/entity/LifecycleTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/entity/LifecycleTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/entity/LifecycleTest.java
index b9f5c2d..183d3e9 100644
--- a/core/runtime/src/test/java/org/apache/zest/runtime/entity/LifecycleTest.java
+++ b/core/runtime/src/test/java/org/apache/zest/runtime/entity/LifecycleTest.java
@@ -20,12 +20,9 @@
 
 package org.apache.zest.runtime.entity;
 
-import org.hamcrest.CoreMatchers;
-import org.junit.Test;
 import org.apache.zest.api.entity.EntityBuilder;
 import org.apache.zest.api.entity.EntityComposite;
 import org.apache.zest.api.entity.Lifecycle;
-import org.apache.zest.api.entity.LifecycleException;
 import org.apache.zest.api.mixin.Mixins;
 import org.apache.zest.api.unitofwork.UnitOfWork;
 import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException;
@@ -33,6 +30,8 @@ import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.ModuleAssembly;
 import org.apache.zest.test.AbstractZestTest;
 import org.apache.zest.test.EntityTestAssembler;
+import org.hamcrest.CoreMatchers;
+import org.junit.Test;
 
 import static org.junit.Assert.assertThat;
 
@@ -106,13 +105,11 @@ public class LifecycleTest
         implements Lifecycle, Testing
     {
         public void create()
-            throws LifecycleException
         {
             create = true;
         }
 
         public void remove()
-            throws LifecycleException
         {
             remove = true;
         }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/994d3891/libraries/uowfile/src/main/java/org/apache/zest/library/uowfile/plural/HasUoWFilesLifecycle.java
----------------------------------------------------------------------
diff --git a/libraries/uowfile/src/main/java/org/apache/zest/library/uowfile/plural/HasUoWFilesLifecycle.java b/libraries/uowfile/src/main/java/org/apache/zest/library/uowfile/plural/HasUoWFilesLifecycle.java
index 0891714..048372f 100644
--- a/libraries/uowfile/src/main/java/org/apache/zest/library/uowfile/plural/HasUoWFilesLifecycle.java
+++ b/libraries/uowfile/src/main/java/org/apache/zest/library/uowfile/plural/HasUoWFilesLifecycle.java
@@ -20,10 +20,10 @@
 package org.apache.zest.library.uowfile.plural;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import org.apache.zest.api.entity.Lifecycle;
-import org.apache.zest.api.entity.LifecycleException;
 import org.apache.zest.api.injection.scope.This;
 import org.apache.zest.api.mixin.Mixins;
 
@@ -39,14 +39,13 @@ public interface HasUoWFilesLifecycle<T extends Enum<T>>
 
         @Override
         public void create()
-            throws LifecycleException
         {
             // NOOP
         }
 
         @Override
         public void remove()
-            throws LifecycleException
+            throws IOException
         {
             // We use the managed files so that if the UoW gets discarded the files will be restored
             List<File> errors = new ArrayList<>();
@@ -62,7 +61,7 @@ public interface HasUoWFilesLifecycle<T extends Enum<T>>
             }
             if( !errors.isEmpty() )
             {
-                throw new LifecycleException( "Unable to delete existing files: " + errors );
+                throw new IOException( "Unable to delete existing files: " + errors );
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/994d3891/libraries/uowfile/src/main/java/org/apache/zest/library/uowfile/singular/HasUoWFileLifecycle.java
----------------------------------------------------------------------
diff --git a/libraries/uowfile/src/main/java/org/apache/zest/library/uowfile/singular/HasUoWFileLifecycle.java b/libraries/uowfile/src/main/java/org/apache/zest/library/uowfile/singular/HasUoWFileLifecycle.java
index 7e47525..553ab45 100644
--- a/libraries/uowfile/src/main/java/org/apache/zest/library/uowfile/singular/HasUoWFileLifecycle.java
+++ b/libraries/uowfile/src/main/java/org/apache/zest/library/uowfile/singular/HasUoWFileLifecycle.java
@@ -20,8 +20,8 @@
 package org.apache.zest.library.uowfile.singular;
 
 import java.io.File;
+import java.io.IOException;
 import org.apache.zest.api.entity.Lifecycle;
-import org.apache.zest.api.entity.LifecycleException;
 import org.apache.zest.api.injection.scope.This;
 import org.apache.zest.api.mixin.Mixins;
 
@@ -37,20 +37,19 @@ public interface HasUoWFileLifecycle
 
         @Override
         public void create()
-            throws LifecycleException
         {
             // NOOP
         }
 
         @Override
         public void remove()
-            throws LifecycleException
+            throws IOException
         {
             // We use the managed file so that if the UoW gets discarded the file will be restored
             File file = hasUoWFile.managedFile();
             if( file.exists() && !file.delete() )
             {
-                throw new LifecycleException( "Unable to delete existing file: " + file );
+                throw new IOException( "Unable to delete existing file: " + file );
             }
         }
     }