ca.sqlpower.wabit.dao.session
Class WorkspacePersisterListener

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

public class WorkspacePersisterListener
extends java.lang.Object
implements WabitListener

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, WabitPersister targetPersister)
          This listener should be added through the static method for attaching a listener to a session.
WorkspacePersisterListener(WabitSession session, WabitPersister 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, WabitPersister targetPersister, WabitSessionPersister eventSource)
          This will connect a new instance of this listener to the workspace and all of its descendants.
protected  void persistChild(WabitObject parent, WabitObject child, java.lang.Class<? extends WabitObject> childClassType, int indexOfChild)
          Calls WabitPersister.persistObject(String, String, String, int) for the child object and WabitPersister.persistProperty(String, String, DataType, Object) for each property on the object.
 void persistObject(WabitObject 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)
          Signals a transaction has finished.
 void transactionRollback(ca.sqlpower.util.TransactionEvent e)
          Signals a transaction has finished and the events that occurred during the transaction need to be reversed or not acted upon.
 void transactionStarted(ca.sqlpower.util.TransactionEvent e)
          Called when a transaction has started.
 void wabitChildAdded(WabitChildEvent e)
          Called when a child is added to an object this listener is attached to.
 void wabitChildRemoved(WabitChildEvent e)
          Called when a child is removed from an object this listener is attached to.
 
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,
                                  WabitPersister 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, WabitPersister).

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,
                                  WabitPersister 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, WabitPersister).

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 WabitPersister that this listener will consult in order to perform 'echo-cancellation' of events.
Method Detail

attachListener

public static WorkspacePersisterListener attachListener(WabitSession session,
                                                        WabitPersister 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)
Description copied from interface: WabitListener
Signals a transaction has finished. The events that occurred during the transaction should be considered one atomic operation. By the time the transaction ends in this fashion or immediately after the atomic operation should be acted upon. Some transactions may be nested inside of other transactions. In this case the transaction is finished only when the outer most transaction has completed.

Specified by:
transactionEnded in interface WabitListener
Parameters:
e - Contains the object that has finished a transaction.

transactionRollback

public void transactionRollback(ca.sqlpower.util.TransactionEvent e)
Description copied from interface: WabitListener
Signals a transaction has finished and the events that occurred during the transaction need to be reversed or not acted upon. If a transaction inside of another transaction rolls back both the inner and outer transaction will be rolled back.

Specified by:
transactionRollback in interface WabitListener
Parameters:
e - Contains the object that was rolled back and a message describing why the transaction was rolled back.

transactionStarted

public void transactionStarted(ca.sqlpower.util.TransactionEvent e)
Description copied from interface: WabitListener
Called when a transaction has started. The events fired after the transaction started until the transaction has ended or rolled back should be considered one atomic operation.

Specified by:
transactionStarted in interface WabitListener
Parameters:
e - Contains what object started a transaction and a message describing the transaction.

wabitChildAdded

public void wabitChildAdded(WabitChildEvent e)
Description copied from interface: WabitListener
Called when a child is added to an object this listener is attached to.

Specified by:
wabitChildAdded in interface WabitListener
Parameters:
e - An event describing the child added.

persistObject

public void persistObject(WabitObject 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(WabitObject parent,
                            WabitObject child,
                            java.lang.Class<? extends WabitObject> childClassType,
                            int indexOfChild)
Calls WabitPersister.persistObject(String, String, String, int) for the child object and WabitPersister.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.

wabitChildRemoved

public void wabitChildRemoved(WabitChildEvent e)
Description copied from interface: WabitListener
Called when a child is removed from an object this listener is attached to.

Specified by:
wabitChildRemoved in interface WabitListener
Parameters:
e - An event describing the child removed.

propertyChange

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


Copyright © 2009. All Rights Reserved.