Package org.apache.cayenne.reflect

Examples of org.apache.cayenne.reflect.LifecycleCallbackRegistry


        assertSame(a1, listener2.getPublicCalledbackEntity());
    }

    public void testPostRemove() {

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

        ObjectContext context = createDataContext();

        Artist a1 = context.newObject(Artist.class);
        a1.setArtistName("XX");
        context.commitChanges();

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


        assertSame(a1, listener2.getPublicCalledbackEntity());
    }
   
    public void testPostRemove_UpdatedDeleted() {

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

        ObjectContext context = createDataContext();

        Artist a1 = context.newObject(Artist.class);
        a1.setArtistName("XX");
        context.commitChanges();

        MockCallingBackListener listener1 = new MockCallingBackListener();
        registry.addListener(
                LifecycleEvent.POST_REMOVE,
                Artist.class,
                listener1,
                "publicCallback");

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

        assertSame(a1, listener1.getPublicCalledbackEntity());
    }
   
    public void testPostRemove_InsertedUpdatedDeleted() {

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

        ObjectContext context = createDataContext();

        MockCallingBackListener listener0 = new MockCallingBackListener();
        registry.addListener(
                LifecycleEvent.POST_PERSIST,
                Artist.class,
                listener0,
                "publicCallback");
       
        MockCallingBackListener listener1 = new MockCallingBackListener();
        registry.addListener(
                LifecycleEvent.POST_REMOVE,
                Artist.class,
                listener1,
                "publicCallback");

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

        assertNull(listener2.getPublicCalledbackEntity());
    }

    public void testPostPersist() {

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

        ObjectContext context = createDataContext();
        Artist a1 = context.newObject(Artist.class);
        a1.setArtistName("XX");
        context.commitChanges();
        assertFalse(a1.isPostPersisted());

        registry.addListener(
                LifecycleEvent.POST_PERSIST,
                Artist.class,
                "postPersistCallback");
        MockCallingBackListener listener2 = new MockCallingBackListener() {

            @Override
            public void publicCallback(Object entity) {
                super.publicCallback(entity);
                assertFalse(((Persistent) entity).getObjectId().isTemporary());
            }
        };
        registry.addListener(
                LifecycleEvent.POST_PERSIST,
                Artist.class,
                listener2,
                "publicCallback");
View Full Code Here

    /**
     * Compiles internal callback registry.
     */
    synchronized void initCallbacks() {
        if (callbackRegistry == null) {
            LifecycleCallbackRegistry callbackRegistry = new LifecycleCallbackRegistry(
                    this);

            // load default callbacks
            Iterator maps = this.maps.iterator();
            while (maps.hasNext()) {
                DataMap map = (DataMap) maps.next();
                Iterator listeners = map.getDefaultEntityListeners().iterator();
                while (listeners.hasNext()) {
                    EntityListener listener = (EntityListener) listeners.next();
                    Object listenerInstance = createListener(listener);

                    CallbackDescriptor[] callbacks = listener
                            .getCallbackMap()
                            .getCallbacks();
                    for (int i = 0; i < callbacks.length; i++) {

                        Iterator callbackMethods = callbacks[i]
                                .getCallbackMethods()
                                .iterator();
                        while (callbackMethods.hasNext()) {
                            String method = (String) callbackMethods.next();

                            // note that callbacks[i].getCallbackType() == i
                            callbackRegistry.addDefaultListener(
                                    i,
                                    listenerInstance,
                                    method);
                        }
                    }
                }
            }

            // load entity callbacks
            Iterator entities = getObjEntities().iterator();
            while (entities.hasNext()) {
                ObjEntity entity = (ObjEntity) entities.next();
                Class entityClass = entity.getJavaClass();

                // external listeners go first, entity's own callbacks go next
                Iterator entityListeners = entity.getEntityListeners().iterator();
                while (entityListeners.hasNext()) {
                    EntityListener listener = (EntityListener) entityListeners.next();
                    Object listenerInstance = createListener(listener);

                    CallbackDescriptor[] callbacks = listener
                            .getCallbackMap()
                            .getCallbacks();
                    for (int i = 0; i < callbacks.length; i++) {

                        Iterator callbackMethods = callbacks[i]
                                .getCallbackMethods()
                                .iterator();
                        while (callbackMethods.hasNext()) {
                            String method = (String) callbackMethods.next();

                            // note that callbacks[i].getCallbackType() == i
                            callbackRegistry.addListener(
                                    i,
                                    entityClass,
                                    listenerInstance,
                                    method);
                        }
                    }
                }

                CallbackDescriptor[] callbacks = entity.getCallbackMap().getCallbacks();
                for (int i = 0; i < callbacks.length; i++) {
                    Iterator callbackMethods = callbacks[i]
                            .getCallbackMethods()
                            .iterator();
                    while (callbackMethods.hasNext()) {
                        String method = (String) callbackMethods.next();

                        // note that callbacks[i].getCallbackType() == i
                        callbackRegistry.addListener(i, entityClass, method);
                    }
                }
            }

            this.callbackRegistry = callbackRegistry;
View Full Code Here

    private void invokePostLoad() {
        // TODO: andrus, 9/21/2006 - this method incorrectly calls "postLoad" when query
        // refresh flag is set to false and object is already there.

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

        if (!callbackRegistry.isEmpty(LifecycleListener.POST_LOAD)) {

            List list = response.firstList();
            if (list != null
                    && !list.isEmpty()
                    && !(query.getMetaData(domain.getEntityResolver()))
                            .isFetchingDataRows()) {
                callbackRegistry.performCallbacks(LifecycleListener.POST_LOAD, list);
            }
        }
    }
View Full Code Here

                    throw new IllegalStateException("Unknown response object: "
                            + this.response);
                }

                // apply POST_LOAD callback
                LifecycleCallbackRegistry callbackRegistry = context
                        .getEntityResolver()
                        .getCallbackRegistry();

                if (!callbackRegistry.isEmpty(LifecycleListener.POST_LOAD)) {
                    callbackRegistry.performCallbacks(
                            LifecycleListener.POST_LOAD,
                            objects);
                }
            }
        }
View Full Code Here

    /**
     * Compiles internal callback registry.
     */
    synchronized void initCallbacks() {
        if (callbackRegistry == null) {
            LifecycleCallbackRegistry callbackRegistry = new LifecycleCallbackRegistry(this);

            // load default callbacks
            for (DataMap map : maps) {

                for (EntityListener listener : map.getDefaultEntityListeners()) {
                    Object listenerInstance = createListener(listener, null);
                    if (listenerInstance == null) {
                        continue;
                    }

                    CallbackDescriptor[] callbacks = listener.getCallbackMap().getCallbacks();
                    for (CallbackDescriptor callback : callbacks) {

                        for (String method : callback.getCallbackMethods()) {

                            // note that callbacks[i].getCallbackType() == i
                            callbackRegistry.addDefaultListener(callback.getCallbackType(), listenerInstance, method);
                        }
                    }
                }
            }

            // load entity callbacks
            for (ObjEntity entity : getObjEntities()) {
                Class<?> entityClass = entity.getJavaClass();

                // external listeners go first, entity's own callbacks go next
                for (EntityListener listener : entity.getEntityListeners()) {
                    Object listenerInstance = createListener(listener, entity);
                    if (listenerInstance == null) {
                        continue;
                    }

                    CallbackDescriptor[] callbacks = listener.getCallbackMap().getCallbacks();
                    for (CallbackDescriptor callback : callbacks) {

                        for (String method : callback.getCallbackMethods()) {
                            callbackRegistry.addListener(callback.getCallbackType(), entityClass, listenerInstance,
                                    method);
                        }
                    }
                }

                CallbackDescriptor[] callbacks = entity.getCallbackMap().getCallbacks();
                for (CallbackDescriptor callback : callbacks) {
                    for (String method : callback.getCallbackMethods()) {
                        callbackRegistry.addCallback(callback.getCallbackType(), entityClass, method);
                    }
                }
            }

            this.callbackRegistry = callbackRegistry;
View Full Code Here

        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
        resolver.getCallbackRegistry().clear();
    }

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

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

        registry.addCallback(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 = runtime
                .getDataDomain()
                .getEntityResolver()
                .getCallbackRegistry();

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

        registry.addCallback(
                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

TOP

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

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.