ca.sqlpower.wabit.dao.session
Class WorkspacePersisterListener

java.lang.Object
  extended by ca.sqlpower.wabit.dao.session.WorkspacePersisterListener
All Implemented Interfaces:
ca.sqlpower.object.SPListener, java.beans.PropertyChangeListener, java.util.EventListener

public class WorkspacePersisterListener
extends java.lang.Object
implements ca.sqlpower.object.SPListener

An implementation of WabitListener used exclusively for listening to a WabitWorkspace and its children. When an event is fired from an object this listener will convert the event into persist calls. The persist calls will be made on the target persister.


Constructor Summary
WorkspacePersisterListener(WabitSession session, ca.sqlpower.dao.SPPersister targetPersister)
          This listener should be added through the static method for attaching a listener to a session.
WorkspacePersisterListener(WabitSession session, ca.sqlpower.dao.SPPersister targetPersister, WabitSessionPersister eventSource)
          This listener should be added through the static method for attaching a listener to a session.
 
Method Summary
static WorkspacePersisterListener attachListener(WabitSession session, ca.sqlpower.dao.SPPersister targetPersister, WabitSessionPersister eventSource)
          This will connect a new instance of this listener to the workspace and all of its descendants.
 void childAdded(ca.sqlpower.object.SPChildEvent e)
           
 void childRemoved(ca.sqlpower.object.SPChildEvent e)
           
protected  void persistChild(ca.sqlpower.object.SPObject parent, ca.sqlpower.object.SPObject child, java.lang.Class<? extends ca.sqlpower.object.SPObject> childClassType, int indexOfChild)
          Calls SPPersister.persistObject(String, String, String, int) for the child object and SPPersister.persistProperty(String, String, DataType, Object) for each property on the object.
 void persistObject(ca.sqlpower.object.SPObject wo)
          Persists the given object and all of its descendants to the next persister.
 void propertyChange(java.beans.PropertyChangeEvent evt)
           
 void transactionEnded(ca.sqlpower.util.TransactionEvent e)
           
 void transactionRollback(ca.sqlpower.util.TransactionEvent e)
           
 void transactionStarted(ca.sqlpower.util.TransactionEvent e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkspacePersisterListener

public WorkspacePersisterListener(WabitSession session,
                                  ca.sqlpower.dao.SPPersister targetPersister)
This listener should be added through the static method for attaching a listener to a session.

A new listener should only be created in testing. To properly add a listener to a session see #attachListener(WabitSession, SPPersister).

Parameters:
session - The session whose workspace will be listened to.
targetPersister - The persister that will have the events be forwarded to as persist calls.

WorkspacePersisterListener

public WorkspacePersisterListener(WabitSession session,
                                  ca.sqlpower.dao.SPPersister targetPersister,
                                  WabitSessionPersister eventSource)
This listener should be added through the static method for attaching a listener to a session.

A new listener should only be created in testing. To properly add a listener to a session see #attachListener(WabitSession, SPPersister).

Parameters:
session - The session whose workspace will be listened to.
targetPersister - The persister that will have the events be forwarded to as persist calls.
eventSource - A SPPersister that this listener will consult in order to perform 'echo-cancellation' of events.
Method Detail

attachListener

public static WorkspacePersisterListener attachListener(WabitSession session,
                                                        ca.sqlpower.dao.SPPersister targetPersister,
                                                        WabitSessionPersister eventSource)
This will connect a new instance of this listener to the workspace and all of its descendants. When the children of a workspace change the listener will be added to or removed from the children. When the session is being disposed of the listener will be removed from the workspace tree.

Parameters:
session - The session to listen to for lifecycle changes and its workspace will be listened to by a new persister listener.
targetPersister - This persister will have persist methods called on it when events occur in the workspace in the given session.

transactionEnded

public void transactionEnded(ca.sqlpower.util.TransactionEvent e)
Specified by:
transactionEnded in interface ca.sqlpower.object.SPListener

transactionRollback

public void transactionRollback(ca.sqlpower.util.TransactionEvent e)
Specified by:
transactionRollback in interface ca.sqlpower.object.SPListener

transactionStarted

public void transactionStarted(ca.sqlpower.util.TransactionEvent e)
Specified by:
transactionStarted in interface ca.sqlpower.object.SPListener

childAdded

public void childAdded(ca.sqlpower.object.SPChildEvent e)
Specified by:
childAdded in interface ca.sqlpower.object.SPListener

persistObject

public void persistObject(ca.sqlpower.object.SPObject wo)
Persists the given object and all of its descendants to the next persister. The root object and every descendant will be sent to the persister as a persist object and all of its properties will be sent as unconditional property persists.

Parameters:
wo - The root of the tree of objects that will be persisted. This object and all of its children will be persisted.

persistChild

protected void persistChild(ca.sqlpower.object.SPObject parent,
                            ca.sqlpower.object.SPObject child,
                            java.lang.Class<? extends ca.sqlpower.object.SPObject> childClassType,
                            int indexOfChild)
Calls SPPersister.persistObject(String, String, String, int) for the child object and SPPersister.persistProperty(String, String, DataType, Object) for each property on the object.

Parameters:
parent - The parent of the object being persisted as added to this object.
child - The child object that was added to its parent.
childClassType - The object type of the child added.
indexOfChild - The index of the child in the child list of the parent.

childRemoved

public void childRemoved(ca.sqlpower.object.SPChildEvent e)
Specified by:
childRemoved in interface ca.sqlpower.object.SPListener

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener


Copyright © 2009. All Rights Reserved.