cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1484115 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/
Date Sat, 18 May 2013 13:29:48 GMT
Author: aadamchik
Date: Sat May 18 13:29:47 2013
New Revision: 1484115

URL: http://svn.apache.org/r1484115
Log:
CAY-1820 DataDomain.addListener(Object) - a shortcut for adding annotated listeners

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=1484115&r1=1484114&r2=1484115&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Sat May 18 13:29:47 2013
@@ -47,6 +47,7 @@ CAY-1809 Remove 'final' modifier from Ca
 CAY-1813 Missing ObjEntity Attribute Validation with Duplicate DbEntity Columns
 CAY-1814 Support Property.nin 
 CAY-1819 When adding a filter, auto-register it as a listener 
+CAY-1820 DataDomain.addListener(Object) - a shortcut for adding annotated listeners 
 
 Bug Fixes:
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java?rev=1484115&r1=1484114&r2=1484115&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
Sat May 18 13:29:47 2013
@@ -804,6 +804,17 @@ public class DataDomain implements Query
         filters.remove(filter);
     }
 
+    /**
+     * Adds a listener, mapping its methods to events based on annotations. This
+     * is a shortcut for
+     * 'getEntityResolver().getCallbackRegistry().addListener(listener)'.
+     * 
+     * @since 3.2
+     */
+    public void addListener(Object listener) {
+        getEntityResolver().getCallbackRegistry().addListener(listener);
+    }
+
     abstract class DataDomainFilterChain implements DataChannelFilterChain {
 
         private int i;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java?rev=1484115&r1=1484114&r2=1484115&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java
Sat May 18 13:29:47 2013
@@ -24,12 +24,20 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.annotation.PostAdd;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.event.DefaultEventManager;
 import org.apache.cayenne.log.JdbcEventLogger;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.Exhibit;
+import org.apache.cayenne.testdo.testmap.Gallery;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.testdo.testmap.annotations.Tag1;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
@@ -70,8 +78,7 @@ public class DataDomainTest extends Serv
 
             domain.lookupDataNode(new DataMap("m3"));
             fail("must have thrown on missing Map to Node maping");
-        }
-        catch (CayenneRuntimeException e) {
+        } catch (CayenneRuntimeException e) {
             // expected
         }
     }
@@ -164,8 +171,7 @@ public class DataDomainTest extends Serv
 
     public void testInitDataDomainWithDedicatedCache() throws Exception {
         Map<Object, Object> properties = new HashMap<Object, Object>();
-        properties
-                .put(DataDomain.SHARED_CACHE_ENABLED_PROPERTY, Boolean.FALSE.toString());
+        properties.put(DataDomain.SHARED_CACHE_ENABLED_PROPERTY, Boolean.FALSE.toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertFalse(domain.isSharedCacheEnabled());
@@ -173,9 +179,7 @@ public class DataDomainTest extends Serv
 
     public void testInitDataDomainValidation() throws Exception {
         Map<Object, Object> properties = new HashMap<Object, Object>();
-        properties.put(
-                DataDomain.VALIDATING_OBJECTS_ON_COMMIT_PROPERTY,
-                Boolean.TRUE.toString());
+        properties.put(DataDomain.VALIDATING_OBJECTS_ON_COMMIT_PROPERTY, Boolean.TRUE.toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertTrue(domain.isValidatingObjectsOnCommit());
@@ -183,9 +187,7 @@ public class DataDomainTest extends Serv
 
     public void testInitDataDomainNoValidation() throws Exception {
         Map<Object, Object> properties = new HashMap<Object, Object>();
-        properties.put(
-                DataDomain.VALIDATING_OBJECTS_ON_COMMIT_PROPERTY,
-                Boolean.FALSE.toString());
+        properties.put(DataDomain.VALIDATING_OBJECTS_ON_COMMIT_PROPERTY, Boolean.FALSE.toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertFalse(domain.isValidatingObjectsOnCommit());
@@ -193,9 +195,7 @@ public class DataDomainTest extends Serv
 
     public void testDataDomainInternalTransactions() throws Exception {
         Map<Object, Object> properties = new HashMap<Object, Object>();
-        properties.put(
-                DataDomain.USING_EXTERNAL_TRANSACTIONS_PROPERTY,
-                Boolean.FALSE.toString());
+        properties.put(DataDomain.USING_EXTERNAL_TRANSACTIONS_PROPERTY, Boolean.FALSE.toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertFalse(domain.isUsingExternalTransactions());
@@ -206,9 +206,7 @@ public class DataDomainTest extends Serv
 
     public void testDataDomainExternalTransactions() throws Exception {
         Map<Object, Object> properties = new HashMap<Object, Object>();
-        properties.put(
-                DataDomain.USING_EXTERNAL_TRANSACTIONS_PROPERTY,
-                Boolean.TRUE.toString());
+        properties.put(DataDomain.USING_EXTERNAL_TRANSACTIONS_PROPERTY, Boolean.TRUE.toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertTrue(domain.isUsingExternalTransactions());
@@ -222,10 +220,7 @@ public class DataDomainTest extends Serv
 
         final boolean[] cacheShutdown = new boolean[1];
 
-        DataRowStore cache = new DataRowStore(
-                "Y",
-                Collections.EMPTY_MAP,
-                new DefaultEventManager()) {
+        DataRowStore cache = new DataRowStore("Y", Collections.EMPTY_MAP, new DefaultEventManager())
{
 
             @Override
             public void shutdown() {
@@ -238,4 +233,46 @@ public class DataDomainTest extends Serv
 
         assertTrue(cacheShutdown[0]);
     }
+
+    public void testAddListener() {
+
+        DataDomain domain = runtime.getDataDomain();
+        PostAddListener listener = new PostAddListener();
+        domain.addListener(listener);
+
+        ObjectContext context = runtime.getContext();
+
+        context.newObject(Gallery.class);
+        assertEquals("e:Gallery;", listener.getAndReset());
+
+        context.newObject(Artist.class);
+        assertEquals("a:Artist;", listener.getAndReset());
+
+        context.newObject(Exhibit.class);
+        assertEquals("", listener.getAndReset());
+
+        context.newObject(Painting.class);
+        assertEquals("e:Painting;", listener.getAndReset());
+    }
+
+    class PostAddListener {
+
+        StringBuilder callbackBuffer = new StringBuilder();
+
+        @PostAdd({ Gallery.class, Painting.class })
+        void postAddEntities(Persistent object) {
+            callbackBuffer.append("e:" + object.getObjectId().getEntityName() + ";");
+        }
+
+        @PostAdd(entityAnnotations = Tag1.class)
+        void postAddAnnotated(Persistent object) {
+            callbackBuffer.append("a:" + object.getObjectId().getEntityName() + ";");
+        }
+
+        String getAndReset() {
+            String v = callbackBuffer.toString();
+            callbackBuffer = new StringBuilder();
+            return v;
+        }
+    }
 }



Mime
View raw message