Package org.apache.cayenne.reflect

Examples of org.apache.cayenne.reflect.LifecycleCallbackRegistry$AnnotationReader


        assertEquals(0, serverContext.getQueryCache().size());
    }

    public void testPostAddCallback() throws Exception {

        LifecycleCallbackRegistry callbackRegistry = clientServerChannel
                .getEntityResolver()
                .getCallbackRegistry();

        final boolean[] flag = new boolean[1];

        try {
            callbackRegistry.addListener(MtTable1.class, new LifecycleListener() {

                public void postLoad(Object entity) {
                }

                public void postPersist(Object entity) {
                }

                public void postRemove(Object entity) {
                }

                public void postUpdate(Object entity) {
                }

                public void postAdd(Object entity) {
                    flag[0] = true;
                }

                public void preRemove(Object entity) {
                }

                public void preUpdate(Object entity) {
                }

                public void prePersist(Object entity) {
                }
            });

            clientContext.newObject(ClientMtTable1.class);

            assertFalse(flag[0]);
            clientContext.commitChanges();
            assertTrue(flag[0]);
        }
        finally {
            callbackRegistry.clear();
        }
    }
View Full Code Here


    public void testPostAddOnObjectCallback() throws Exception {

        DataContext serverContext = (DataContext) clientServerChannel.getParentChannel();

        LifecycleCallbackRegistry callbackRegistry = serverContext
                .getEntityResolver()
                .getCallbackRegistry();

        try {
            callbackRegistry.addListener(
                    LifecycleEvent.POST_ADD,
                    MtTable1.class,
                    "prePersistMethod");

            Persistent clientObject = clientContext.newObject(ClientMtTable1.class);
            clientContext.commitChanges();

            // find peer
            MtTable1 peer = (MtTable1) serverContext.getGraphManager().getNode(
                    clientObject.getObjectId());

            assertNotNull(peer);
            assertTrue(peer.isPrePersisted());
        }
        finally {
            callbackRegistry.clear();
        }
    }
View Full Code Here

    }

    public void testPreRemoveCallback() throws Exception {

        // an exception was triggered within POST_LOAD callback
        LifecycleCallbackRegistry callbackRegistry = clientServerChannel
                .getEntityResolver()
                .getCallbackRegistry();

        final boolean[] flag = new boolean[1];

        try {
            callbackRegistry.addListener(MtTable1.class, new LifecycleListener() {

                public void postLoad(Object entity) {
                }

                public void postPersist(Object entity) {
                }

                public void postRemove(Object entity) {
                }

                public void postUpdate(Object entity) {
                }

                public void postAdd(Object entity) {
                }

                public void preRemove(Object entity) {
                    flag[0] = true;
                }

                public void preUpdate(Object entity) {
                }

                public void prePersist(Object entity) {
                }
            });

            ClientMtTable1 object = clientContext.newObject(ClientMtTable1.class);

            assertFalse(flag[0]);
            clientContext.commitChanges();
            assertFalse(flag[0]);

            clientContext.deleteObject(object);
            clientContext.commitChanges();
            assertTrue(flag[0]);
        }
        finally {
            callbackRegistry.clear();
        }
    }
View Full Code Here

    }

    public void testCAY830() throws Exception {

        // an exception was triggered within POST_LOAD callback
        LifecycleCallbackRegistry callbackRegistry = clientServerChannel
                .getEntityResolver()
                .getCallbackRegistry();

        try {
            callbackRegistry.addListener(MtReflexive.class, new LifecycleListener() {

                public void postLoad(Object entity) {
                }

                public void postPersist(Object entity) {
                }

                public void postRemove(Object entity) {
                }

                public void postUpdate(Object entity) {
                }

                public void postAdd(Object entity) {
                }

                public void preRemove(Object entity) {
                }

                public void preUpdate(Object entity) {
                }

                public void prePersist(Object entity) {
                }
            });

            ClientMtReflexive o1 = clientContext.newObject(ClientMtReflexive.class);
            o1.setName("parent");

            ClientMtReflexive o2 = clientContext.newObject(ClientMtReflexive.class);
            o2.setName("child");
            o2.setToParent(o1);
            clientContext.commitChanges();

            clientContext.deleteObject(o1);
            clientContext.deleteObject(o2);
            clientContext.commitChanges();
            // per CAY-830 an exception is thrown here
        }
        finally {
            callbackRegistry.clear();
        }
    }
View Full Code Here

        EntityResolver resolver = getDomain().getEntityResolver();
        resolver.getCallbackRegistry().clear();
    }

    public void testPostAddCallbacks() {
        LifecycleCallbackRegistry registry = getDomain()
                .getEntityResolver()
                .getCallbackRegistry();

        DataContext context = createDataContext();

        // no callbacks
        Artist a1 = context.newObject(Artist.class);
        assertNotNull(a1);
        assertFalse(a1.isPostAdded());

        registry.addListener(LifecycleEvent.POST_ADD, Artist.class, "postAddCallback");

        Artist a2 = context.newObject(Artist.class);
        assertNotNull(a2);
        assertTrue(a2.isPostAdded());

        MockCallingBackListener listener2 = new MockCallingBackListener();
        registry.addListener(
                LifecycleEvent.POST_ADD,
                Artist.class,
                listener2,
                "publicCallback");
View Full Code Here

        assertFalse(p3.isPostAdded());
        assertSame(a3, listener2.getPublicCalledbackEntity());
    }

    public void testPrePersistCallbacks() {
        LifecycleCallbackRegistry registry = getDomain()
                .getEntityResolver()
                .getCallbackRegistry();

        DataContext context = createDataContext();

        // no callbacks
        Artist a1 = context.newObject(Artist.class);
        a1.setArtistName("1");
        assertFalse(a1.isPrePersisted());
        context.commitChanges();
        assertFalse(a1.isPrePersisted());

        registry.addListener(
                LifecycleEvent.PRE_PERSIST,
                Artist.class,
                "prePersistCallback");

        Artist a2 = context.newObject(Artist.class);
        a2.setArtistName("2");
        assertFalse(a2.isPrePersisted());
        context.commitChanges();
        assertTrue(a2.isPrePersisted());

        MockCallingBackListener listener2 = new MockCallingBackListener();
        registry.addListener(
                LifecycleEvent.PRE_PERSIST,
                Artist.class,
                listener2,
                "publicCallback");
View Full Code Here

        context.commitChanges();
        assertSame(a3, listener2.getPublicCalledbackEntity());
    }

    public void testPreRemoveCallbacks() {
        LifecycleCallbackRegistry registry = getDomain()
                .getEntityResolver()
                .getCallbackRegistry();

        DataContext context = createDataContext();

        // no callbacks
        Artist a1 = context.newObject(Artist.class);
        a1.setArtistName("XX");
        context.commitChanges();
        context.deleteObject(a1);
        assertFalse(a1.isPostAdded());
        assertFalse(a1.isPreRemoved());

        registry
                .addListener(LifecycleEvent.PRE_REMOVE, Artist.class, "preRemoveCallback");

        Artist a2 = context.newObject(Artist.class);
        a2.setArtistName("XX");
        context.commitChanges();
        context.deleteObject(a2);
        assertFalse(a2.isPostAdded());
        assertTrue(a2.isPreRemoved());

        MockCallingBackListener listener2 = new MockCallingBackListener();
        registry.addListener(
                LifecycleEvent.PRE_REMOVE,
                Artist.class,
                listener2,
                "publicCallback");
View Full Code Here

        return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
    }

    public void testReturnDiffInPrePersist() {

        LifecycleCallbackRegistry registry = getDomain()
                .getEntityResolver()
                .getCallbackRegistry();

        try {

            registry.addListener(
                    LifecycleEvent.POST_ADD,
                    MtTable1.class,
                    new ClientChannelServerDiffsListener1(),
                    "prePersist");

            ClientServerChannel csChannel = new ClientServerChannel(getDomain());
            ClientChannel channel = new ClientChannel(new LocalConnection(csChannel));
            CayenneContext context = new CayenneContext(channel);
            ClientMtTable1 o = context.newObject(ClientMtTable1.class);
            o.setServerAttribute1("YY");
            context.commitChanges();

            assertFalse(o.getObjectId().isTemporary());
            assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
            assertEquals("XXX", o.getGlobalAttribute1());
        }
        finally {
            registry.clear();
        }
    }
View Full Code Here

        }
    }

    public void testReturnDiffInPreUpdate() {

        LifecycleCallbackRegistry registry = getDomain()
                .getEntityResolver()
                .getCallbackRegistry();

        try {

            registry.addListener(
                    LifecycleEvent.PRE_UPDATE,
                    MtTable1.class,
                    new ClientChannelServerDiffsListener1(),
                    "preUpdate");

            ClientServerChannel csChannel = new ClientServerChannel(getDomain());
            ClientChannel channel = new ClientChannel(new LocalConnection(csChannel));
            CayenneContext context = new CayenneContext(channel);
            ClientMtTable1 o = context.newObject(ClientMtTable1.class);
            o.setServerAttribute1("YY");
            context.commitChanges();

            assertNull(o.getGlobalAttribute1());

            o.setServerAttribute1("XX");
            context.commitChanges();

            assertFalse(o.getObjectId().isTemporary());
            assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
            assertEquals("111", o.getGlobalAttribute1());
        }
        finally {
            registry.clear();
        }
    }
View Full Code Here

        }
    }

    public void testReturnDiffClientArcChanges() {

        LifecycleCallbackRegistry registry = getDomain()
                .getEntityResolver()
                .getCallbackRegistry();

        try {
            registry.addListener(
                    LifecycleEvent.POST_ADD,
                    MtTable1.class,
                    new ClientChannelServerDiffsListener1(),
                    "prePersist");

            ClientServerChannel csChannel = new ClientServerChannel(getDomain());
            ClientChannel channel = new ClientChannel(new LocalConnection(csChannel));
            CayenneContext context = new CayenneContext(channel);
            ClientMtTable1 o = context.newObject(ClientMtTable1.class);
            ClientMtTable2 o1 = context.newObject(ClientMtTable2.class);
            o.addToTable2Array(o1);
            context.commitChanges();

            assertFalse(o.getObjectId().isTemporary());
            assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
            assertEquals("XXX", o.getGlobalAttribute1());
        }
        finally {
            registry.clear();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.reflect.LifecycleCallbackRegistry$AnnotationReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.