polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [1/4] zest-qi4j git commit: Reporting usecase() in NoSuchEntityException.
Date Sat, 11 Jul 2015 12:19:20 GMT
Repository: zest-qi4j
Updated Branches:
  refs/heads/develop f2cbcb9f1 -> 72c2eae1e


Reporting usecase() in NoSuchEntityException.


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

Branch: refs/heads/develop
Commit: d6dadb2ac305b70b0d3685f67fc545b5b1b14b80
Parents: f2cbcb9
Author: Niclas Hedhman <niclas@hedhman.org>
Authored: Sat Jul 11 14:23:14 2015 +0300
Committer: Niclas Hedhman <niclas@hedhman.org>
Committed: Sat Jul 11 14:23:14 2015 +0300

----------------------------------------------------------------------
 .../api/unitofwork/NoSuchEntityException.java   | 21 ++++++++++++++------
 .../unitofwork/concern/UnitOfWorkConcern.java   |  1 +
 .../AbstractAssociationInstance.java            |  2 +-
 .../org/qi4j/runtime/entity/EntityInstance.java |  4 +---
 .../runtime/structure/ModuleUnitOfWork.java     |  3 +--
 .../runtime/unitofwork/UnitOfWorkInstance.java  |  4 ++--
 .../prefs/PreferencesEntityStoreMixin.java      |  2 +-
 .../infrastructure/model/EntityModel.java       |  4 +++-
 .../infrastructure/model/EntityModel.java       |  4 +++-
 9 files changed, 28 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d6dadb2a/core/api/src/main/java/org/qi4j/api/unitofwork/NoSuchEntityException.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/qi4j/api/unitofwork/NoSuchEntityException.java b/core/api/src/main/java/org/qi4j/api/unitofwork/NoSuchEntityException.java
index aff3bfa..cbffe9d 100644
--- a/core/api/src/main/java/org/qi4j/api/unitofwork/NoSuchEntityException.java
+++ b/core/api/src/main/java/org/qi4j/api/unitofwork/NoSuchEntityException.java
@@ -14,6 +14,7 @@
 package org.qi4j.api.unitofwork;
 
 import org.qi4j.api.entity.EntityReference;
+import org.qi4j.api.usecase.Usecase;
 import org.qi4j.functional.Function;
 import org.qi4j.functional.Iterables;
 
@@ -25,25 +26,28 @@ public class NoSuchEntityException
     extends UnitOfWorkException
 {
     private final EntityReference identity;
+    private final Usecase usecase;
     private final Class<?>[] mixinTypes;
 
-    public NoSuchEntityException( EntityReference identity, Class<?> mixinType )
+    public NoSuchEntityException( EntityReference identity, Class<?> mixinType, Usecase
usecase )
     {
-        super( "Could not find entity (" + identity + ") of type " + mixinType.getName()
);
+        super( "Could not find entity (" + identity + ") of type " + mixinType.getName()
+ " in usecase '" + usecase.name() + "'" );
         this.identity = identity;
+        this.usecase = usecase;
         this.mixinTypes = new Class<?>[]{ mixinType };
     }
 
-    public NoSuchEntityException( EntityReference identity, Class<?>[] mixinTypes )
+    public NoSuchEntityException( EntityReference identity, Class<?>[] mixinTypes,
Usecase usecase )
     {
-        super( "Could not find entity (" + identity + ") of type " + toString( mixinTypes
) );
+        super( "Could not find entity (" + identity + ") of type " + toString( mixinTypes
) + " in usecase '" + usecase.name() + "'" );
         this.identity = identity;
         this.mixinTypes = mixinTypes;
+        this.usecase = usecase;
     }
 
-    public NoSuchEntityException( EntityReference identity, Iterable<Class<?>>
types )
+    public NoSuchEntityException( EntityReference identity, Iterable<Class<?>>
types, Usecase usecase )
     {
-        this( identity, castToArray( types ) );
+        this( identity, castToArray( types ), usecase );
     }
 
     public EntityReference identity()
@@ -56,6 +60,11 @@ public class NoSuchEntityException
         return mixinTypes;
     }
 
+    public Usecase usecase()
+    {
+        return usecase;
+    }
+
     private static Class<?>[] castToArray( Iterable<Class<?>> iterableClasses
)
     {
         Iterable<Class> types = Iterables.cast( iterableClasses );

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d6dadb2a/core/api/src/main/java/org/qi4j/api/unitofwork/concern/UnitOfWorkConcern.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/qi4j/api/unitofwork/concern/UnitOfWorkConcern.java
b/core/api/src/main/java/org/qi4j/api/unitofwork/concern/UnitOfWorkConcern.java
index 3c80b1d..c684385 100644
--- a/core/api/src/main/java/org/qi4j/api/unitofwork/concern/UnitOfWorkConcern.java
+++ b/core/api/src/main/java/org/qi4j/api/unitofwork/concern/UnitOfWorkConcern.java
@@ -22,6 +22,7 @@ import org.qi4j.api.common.AppliesTo;
 import org.qi4j.api.concern.GenericConcern;
 import org.qi4j.api.injection.scope.Invocation;
 import org.qi4j.api.injection.scope.Structure;
+import org.qi4j.api.injection.scope.Uses;
 import org.qi4j.api.structure.Module;
 import org.qi4j.api.unitofwork.ConcurrentEntityModificationException;
 import org.qi4j.api.unitofwork.UnitOfWork;

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d6dadb2a/core/runtime/src/main/java/org/qi4j/runtime/association/AbstractAssociationInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/association/AbstractAssociationInstance.java
b/core/runtime/src/main/java/org/qi4j/runtime/association/AbstractAssociationInstance.java
index a517405..21d696a 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/association/AbstractAssociationInstance.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/association/AbstractAssociationInstance.java
@@ -79,7 +79,7 @@ public abstract class AbstractAssociationInstance<T>
         {
             return;
         }
-        throw new IllegalArgumentException( "Object must be a subtype of org.qi4j.api.identity.Identity"
);
+        throw new IllegalArgumentException( "Object must be a subtype of org.qi4j.api.identity.Identity:
" + instance.getClass() );
     }
 
     protected void checkImmutable()

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d6dadb2a/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityInstance.java b/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityInstance.java
index 86affb7..7228c41 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityInstance.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/entity/EntityInstance.java
@@ -31,13 +31,11 @@ import org.qi4j.api.entity.EntityComposite;
 import org.qi4j.api.entity.EntityReference;
 import org.qi4j.api.entity.Identity;
 import org.qi4j.api.entity.LifecycleException;
-import org.qi4j.api.structure.Module;
 import org.qi4j.api.unitofwork.NoSuchEntityException;
 import org.qi4j.api.unitofwork.UnitOfWork;
 import org.qi4j.api.unitofwork.UnitOfWorkException;
 import org.qi4j.runtime.composite.CompositeMethodInstance;
 import org.qi4j.runtime.composite.MixinsInstance;
-import org.qi4j.runtime.structure.ModuleInstance;
 import org.qi4j.runtime.structure.ModuleUnitOfWork;
 import org.qi4j.spi.entity.EntityState;
 import org.qi4j.spi.entity.EntityStatus;
@@ -202,7 +200,7 @@ public final class EntityInstance
 
         if( status() == EntityStatus.REMOVED )
         {
-            throw new NoSuchEntityException( identity, entityModel.types() );
+            throw new NoSuchEntityException( identity, entityModel.types(), unitOfWork().usecase()
);
         }
 
         mixins = entityModel.newMixinHolder();

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d6dadb2a/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleUnitOfWork.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleUnitOfWork.java b/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleUnitOfWork.java
index f964991..9989f65 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleUnitOfWork.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/structure/ModuleUnitOfWork.java
@@ -61,7 +61,6 @@ import org.qi4j.runtime.property.PropertyModel;
 import org.qi4j.runtime.unitofwork.EntityBuilderInstance;
 import org.qi4j.runtime.unitofwork.UnitOfWorkInstance;
 import org.qi4j.runtime.value.ValueInstance;
-import org.qi4j.spi.Qi4jSPI;
 import org.qi4j.spi.entity.EntityState;
 import org.qi4j.spi.entity.EntityStatus;
 import org.qi4j.spi.entity.NamedAssociationState;
@@ -335,7 +334,7 @@ public class ModuleUnitOfWork
         }
         else
         {
-            throw new NoSuchEntityException( compositeInstance.identity(), compositeInstance.types()
);
+            throw new NoSuchEntityException( compositeInstance.identity(), compositeInstance.types(),
usecase() );
         }
     }
 

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d6dadb2a/core/runtime/src/main/java/org/qi4j/runtime/unitofwork/UnitOfWorkInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/qi4j/runtime/unitofwork/UnitOfWorkInstance.java
b/core/runtime/src/main/java/org/qi4j/runtime/unitofwork/UnitOfWorkInstance.java
index ec33e08..67abf3a 100644
--- a/core/runtime/src/main/java/org/qi4j/runtime/unitofwork/UnitOfWorkInstance.java
+++ b/core/runtime/src/main/java/org/qi4j/runtime/unitofwork/UnitOfWorkInstance.java
@@ -162,7 +162,7 @@ public final class UnitOfWorkInstance
                 // Check if state was found
                 if( entityState == null )
                 {
-                    throw new NoSuchEntityException( identity, mixinType );
+                    throw new NoSuchEntityException( identity, mixinType, usecase );
                 }
                 else
                 {
@@ -184,7 +184,7 @@ public final class UnitOfWorkInstance
             // Check if it has been removed
             if( entityInstance.status() == EntityStatus.REMOVED )
             {
-                throw new NoSuchEntityException( identity, mixinType );
+                throw new NoSuchEntityException( identity, mixinType, usecase );
             }
         }
 

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d6dadb2a/extensions/entitystore-preferences/src/main/java/org/qi4j/entitystore/prefs/PreferencesEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-preferences/src/main/java/org/qi4j/entitystore/prefs/PreferencesEntityStoreMixin.java
b/extensions/entitystore-preferences/src/main/java/org/qi4j/entitystore/prefs/PreferencesEntityStoreMixin.java
index b078d8d..b47b376 100644
--- a/extensions/entitystore-preferences/src/main/java/org/qi4j/entitystore/prefs/PreferencesEntityStoreMixin.java
+++ b/extensions/entitystore-preferences/src/main/java/org/qi4j/entitystore/prefs/PreferencesEntityStoreMixin.java
@@ -238,7 +238,7 @@ public class PreferencesEntityStoreMixin
         {
             if( !root.nodeExists( identity.identity() ) )
             {
-                throw new NoSuchEntityException( identity, UnknownType.class );
+                throw new NoSuchEntityException( identity, UnknownType.class, unitOfWork.usecase()
);
             }
 
             Preferences entityPrefs = root.node( identity.identity() );

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d6dadb2a/samples/dci-cargo/dcisample_a/src/main/java/org/qi4j/sample/dcicargo/sample_a/infrastructure/model/EntityModel.java
----------------------------------------------------------------------
diff --git a/samples/dci-cargo/dcisample_a/src/main/java/org/qi4j/sample/dcicargo/sample_a/infrastructure/model/EntityModel.java
b/samples/dci-cargo/dcisample_a/src/main/java/org/qi4j/sample/dcicargo/sample_a/infrastructure/model/EntityModel.java
index 0b84428..0a9f138 100644
--- a/samples/dci-cargo/dcisample_a/src/main/java/org/qi4j/sample/dcicargo/sample_a/infrastructure/model/EntityModel.java
+++ b/samples/dci-cargo/dcisample_a/src/main/java/org/qi4j/sample/dcicargo/sample_a/infrastructure/model/EntityModel.java
@@ -22,6 +22,7 @@ import org.apache.wicket.model.IModel;
 import org.qi4j.api.entity.EntityComposite;
 import org.qi4j.api.entity.EntityReference;
 import org.qi4j.api.unitofwork.NoSuchEntityException;
+import org.qi4j.api.usecase.Usecase;
 import org.qi4j.sample.dcicargo.sample_a.infrastructure.conversion.DTO;
 
 /**
@@ -69,7 +70,8 @@ public class EntityModel<T extends DTO, U extends EntityComposite>
         U entity = module.currentUnitOfWork().get( entityClass, identity );
         if( entity == null )
         {
-            throw new NoSuchEntityException( EntityReference.parseEntityReference( identity
), entityClass );
+            Usecase usecase = module.currentUnitOfWork().usecase();
+            throw new NoSuchEntityException( EntityReference.parseEntityReference( identity
), entityClass, usecase );
         }
         return entity;
     }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/d6dadb2a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/infrastructure/model/EntityModel.java
----------------------------------------------------------------------
diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/infrastructure/model/EntityModel.java
b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/infrastructure/model/EntityModel.java
index a653103..fc303e0 100644
--- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/infrastructure/model/EntityModel.java
+++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/infrastructure/model/EntityModel.java
@@ -22,6 +22,7 @@ import org.apache.wicket.model.IModel;
 import org.qi4j.api.entity.EntityComposite;
 import org.qi4j.api.entity.EntityReference;
 import org.qi4j.api.unitofwork.NoSuchEntityException;
+import org.qi4j.api.usecase.Usecase;
 import org.qi4j.sample.dcicargo.sample_b.infrastructure.conversion.DTO;
 
 /**
@@ -75,7 +76,8 @@ public class EntityModel<T extends DTO, U extends EntityComposite>
         U entity = module.currentUnitOfWork().get( entityClass, identity );
         if( entity == null )
         {
-            throw new NoSuchEntityException( EntityReference.parseEntityReference( identity
), entityClass );
+            Usecase usecase = module.currentUnitOfWork().usecase();
+            throw new NoSuchEntityException( EntityReference.parseEntityReference( identity
), entityClass, usecase );
         }
         return entity;
     }


Mime
View raw message