/** * Returns the persistent instance involved in the event. * * @return The persistent instance involved in the event, or null if there * was none. * * @see "Section 12.15, Java Data Objects 2.0 Specification" */ public Object getPersistentInstance() { switch (getEventType()) { case DETACH: return target == null ? getSource() // preDetach: source is persistent instance : getTarget(); // postDetach: target is persistent instance case ATTACH: return target == null ? null // preAttach: no persistent instance yet : getSource(); // postAttach: source is persistent instance } // for all other events, source is persistent instance return getSource(); }
public void postStore(Object pc) { Iterator iter = listeners.iterator(); while (iter.hasNext()) { LifecycleListenerForClass listener = (LifecycleListenerForClass) iter.next(); if (listener.forClass(pc.getClass()) && listener.getListener() instanceof StoreLifecycleListener) { ((StoreLifecycleListener)listener.getListener()).postStore(new InstanceLifecycleEvent(pc, InstanceLifecycleEvent.STORE, null)); } } }
@Override public void preDetach(InstanceLifecycleEvent arg0) { assertEquals(InstanceLifecycleEvent.DETACH, arg0.getEventType()); instances.add((TestClass) arg0.getDetachedInstance()); preDetach++; } @Override
private void checkCall(ZooInstanceEvent expected, Object pc) { assertTrue(calls.size() > 0); Pair p = calls.get(0); //System.out.println("calls:" + calls.size() + " " + p.e.getPersistentInstance()); //System.out.println("calls:" + p.type + " " + p.e.getPersistentInstance().getClass()); assertEquals(expected, p.type); assertEquals(TestClass.class, p.e.getSource().getClass()); assertTrue(pc == p.e.getPersistentInstance()); calls.remove(0); }
static Persistable persistenceCapableFor(InstanceLifecycleEvent event) { return (Persistable)event.getSource(); }
private String logString(Phase phase, LoggingLocation location, InstanceLifecycleEvent event) { final Persistable pojo = Utils.persistenceCapableFor(event); final ObjectAdapter adapter = persistenceSession.getAdapterFor(pojo); return phase + " " + location.prefix + " " + LifecycleEventType.lookup(event.getEventType()) + ": oid=" + (adapter !=null? adapter.getOid(): "(null)") + " ,pojo " + pojo; }
@Programmatic public void preStore (InstanceLifecycleEvent event) { final Object pi = event.getPersistentInstance(); if(pi instanceof org.datanucleus.enhancement.Persistable) { if(pi instanceof HoldsUpdatedBy) { ((HoldsUpdatedBy)pi).setUpdatedBy(userService.getUser().getName()); } if(pi instanceof HoldsUpdatedAt) { ((HoldsUpdatedAt)pi).setUpdatedAt(clockService.nowAsJavaSqlTimestamp()); } } }
public void postStore( InstanceLifecycleEvent evt ) { PersistenceCapable obj = ( (PersistenceCapable) evt.getSource() ); if ( obj instanceof Role ) { listener.rbacRoleSaved( (Role) obj ); } else if ( obj instanceof Permission ) { listener.rbacPermissionSaved( (Permission) obj ); } }
/** * Returns the detached instance involved in the event. * * @return The detached instance involved in the event, or null if there was none. * * @see "Section 12.15, Java Data Objects 2.0 Specification" */ public Object getDetachedInstance() { switch (getEventType()) { case DETACH: return target == null ? null // preDetach: no detached instance yet : getSource(); // postDetach: source is detached instance case ATTACH: return target == null ? getSource() // preAttach: source is detached instance : getTarget(); // postAttach: target is detached instance } // for all other events, there is no detached instance return null; }
public void postClear(Object pc) { Iterator iter = listeners.iterator(); while (iter.hasNext()) { LifecycleListenerForClass listener = (LifecycleListenerForClass) iter.next(); if (listener.forClass(pc.getClass()) && listener.getListener() instanceof ClearLifecycleListener) { ((ClearLifecycleListener)listener.getListener()).postClear(new InstanceLifecycleEvent(pc, InstanceLifecycleEvent.CLEAR, null)); } } }
public void postDelete( InstanceLifecycleEvent evt ) { PersistenceCapable obj = ( (PersistenceCapable) evt.getSource() ); if ( obj == null ) { // Do not track null objects. // These events are typically a product of an internal lifecycle event. return; } if ( obj instanceof Role ) { listener.rbacRoleRemoved( (Role) obj ); } else if ( obj instanceof Permission ) { listener.rbacPermissionRemoved( (Permission) obj ); } }
@Override public void postDetach(InstanceLifecycleEvent arg0) { assertEquals(InstanceLifecycleEvent.DETACH, arg0.getEventType()); instances.add((TestClass) arg0.getDetachedInstance()); postDetach++; } }
/** * Returns the persistent instance involved in the event. * * @return The persistent instance involved in the event, or null if there * was none. * * @see "Section 12.15, Java Data Objects 2.0 Specification" */ public Object getPersistentInstance() { switch (getEventType()) { case DETACH: return target == null ? getSource() // preDetach: source is persistent instance : getTarget(); // postDetach: target is persistent instance case ATTACH: return target == null ? null // preAttach: no persistent instance yet : getSource(); // postAttach: source is persistent instance } // for all other events, source is persistent instance return getSource(); }
public void postDelete(Object pc) { Iterator iter = listeners.iterator(); while (iter.hasNext()) { LifecycleListenerForClass listener = (LifecycleListenerForClass) iter.next(); if (listener.forClass(pc.getClass()) && listener.getListener() instanceof DeleteLifecycleListener) { ((DeleteLifecycleListener)listener.getListener()).postDelete(new InstanceLifecycleEvent(pc, InstanceLifecycleEvent.DELETE, null)); } } }
/** * Returns the detached instance involved in the event. * * @return The detached instance involved in the event, or null if there was none. * * @see "Section 12.15, Java Data Objects 2.0 Specification" */ public Object getDetachedInstance() { switch (getEventType()) { case DETACH: return target == null ? null // preDetach: no detached instance yet : getSource(); // postDetach: source is detached instance case ATTACH: return target == null ? getSource() // preAttach: source is detached instance : getTarget(); // postAttach: target is detached instance } // for all other events, there is no detached instance return null; }
public void preDirty(Object pc) { Iterator iter = listeners.iterator(); while (iter.hasNext()) { LifecycleListenerForClass listener = (LifecycleListenerForClass) iter.next(); if (listener.forClass(pc.getClass()) && listener.getListener() instanceof DirtyLifecycleListener) { ((DirtyLifecycleListener)listener.getListener()).preDirty(new InstanceLifecycleEvent(pc, InstanceLifecycleEvent.DIRTY, null)); } } }
public void postCreate(Object pc) { Iterator iter = listeners.iterator(); while (iter.hasNext()) { LifecycleListenerForClass listener = (LifecycleListenerForClass) iter.next(); if (listener.forClass(pc.getClass()) && listener.getListener() instanceof CreateLifecycleListener) { ((CreateLifecycleListener)listener.getListener()).postCreate(new InstanceLifecycleEvent(pc, InstanceLifecycleEvent.CREATE, null)); } } }
public void postDirty(Object pc) { Iterator iter = listeners.iterator(); while (iter.hasNext()) { LifecycleListenerForClass listener = (LifecycleListenerForClass) iter.next(); if (listener.forClass(pc.getClass()) && listener.getListener() instanceof DirtyLifecycleListener) { ((DirtyLifecycleListener)listener.getListener()).postDirty(new InstanceLifecycleEvent(pc, InstanceLifecycleEvent.DIRTY, null)); } } }
public void preAttach(Object pc) { Iterator iter = listeners.iterator(); while (iter.hasNext()) { LifecycleListenerForClass listener = (LifecycleListenerForClass) iter.next(); if (listener.forClass(pc.getClass()) && listener.getListener() instanceof AttachLifecycleListener) { ((AttachLifecycleListener)listener.getListener()).preAttach(new InstanceLifecycleEvent(pc, InstanceLifecycleEvent.ATTACH, null)); } } if (pc instanceof AttachCallback) { ((AttachCallback) pc).jdoPreAttach(); } }
public void preDetach(Object pc) { Iterator iter = listeners.iterator(); while (iter.hasNext()) { LifecycleListenerForClass listener = (LifecycleListenerForClass) iter.next(); if (listener.forClass(pc.getClass()) && listener.getListener() instanceof DetachLifecycleListener) { ((DetachLifecycleListener)listener.getListener()).preDetach(new InstanceLifecycleEvent(pc, InstanceLifecycleEvent.DETACH, null)); } } if (pc instanceof DetachCallback) { ((DetachCallback) pc).jdoPreDetach(); } }