ca.sqlpower.wabit.dao
Class WabitSessionPersister

java.lang.Object
  extended by ca.sqlpower.wabit.dao.WabitSessionPersister
All Implemented Interfaces:
ca.sqlpower.dao.SPPersister

public class WabitSessionPersister
extends java.lang.Object
implements ca.sqlpower.dao.SPPersister

This class represents a Data Access Object for WabitSessions.

Special Case: If this persister receives a new WabitWorkspace the workspace in the session this persister is attached to must be cleaned up or removed. A new workspace event signals that an entire new set of objects that make up the workspace as a whole is about to be sent to the session. If the objects still exist in the workspace when the persister tries to create new objects exceptions will be thrown as an object with the same UUID will exist in the workspace.


Nested Class Summary
 
Nested classes/interfaces inherited from interface ca.sqlpower.dao.SPPersister
ca.sqlpower.dao.SPPersister.DataType, ca.sqlpower.dao.SPPersister.SPPersistMethod
 
Field Summary
protected  java.util.Map<java.lang.String,java.lang.String> objectsToRemove
          WabitObject removal buffer, mapping of WabitObject UUIDs to their parents
protected  java.util.Comparator<PersistedWabitObject> persistedObjectComparator
           
protected  java.util.List<PersistedWabitObject> persistedObjects
          Persisted WabitObject buffer, contains all the data that was passed into the persistedObject call in the order of insertion
protected  java.util.Comparator<java.lang.String> removedObjectComparator
          This comparator sorts buffered removeObject calls by each SPObject UUID.
 
Constructor Summary
WabitSessionPersister(java.lang.String name, WabitSession session)
          Creates a session persister that can update any object at or a descendant of the given session's workspace object.
WabitSessionPersister(java.lang.String name, WabitSession session, WabitObject root)
          Creates a session persister that can update an object at or a descendant of the given root now.
 
Method Summary
 void begin()
          Begins a transaction
 void commit()
          Commits the persisted WabitObjects, its properties and removals
 void enforeThreadSafety()
           
 boolean isHeadingToWisconsin()
           
 boolean isUpdatingWabitWorkspace()
          This is part of the 'echo-cancellation' system to notify any WorkspacePersisterListener listening to the same session to ignore modifications to that session.
 void persistObject(java.lang.String parentUUID, java.lang.String type, java.lang.String uuid, int index)
          Persists a WabitObject given by its UUID, class name, and parent UUID
 void persistProperty(java.lang.String uuid, java.lang.String propertyName, ca.sqlpower.dao.SPPersister.DataType propertyType, java.lang.Object newValue)
          Persists a WabitObject property unconditionally given by its object UUID, property name, property type, and new value
 void persistProperty(java.lang.String uuid, java.lang.String propertyName, ca.sqlpower.dao.SPPersister.DataType propertyType, java.lang.Object oldValue, java.lang.Object newValue)
          Persists a WabitObject property conditionally given by its object UUID, property name, property type, expected old value, and new value
 void removeObject(java.lang.String parentUUID, java.lang.String uuid)
          Removes WabitObjects from persistent storage.
 void rollback()
           
 void rollback(boolean force)
          Rollback all changes to persistent storage to the beginning of the transaction
 void setGodMode(boolean godMode)
          Turns this persister as a preacher of the truth and always the truth.
 java.lang.String toString()
           
static void undoForSession(WabitSession session, java.util.List<PersistedObjectEntry> creations, java.util.List<PersistedPropertiesEntry> properties, java.util.List<RemovedObjectEntry> removals)
          This static accessible method allows
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

persistedObjects

protected java.util.List<PersistedWabitObject> persistedObjects
Persisted WabitObject buffer, contains all the data that was passed into the persistedObject call in the order of insertion


removedObjectComparator

protected final java.util.Comparator<java.lang.String> removedObjectComparator
This comparator sorts buffered removeObject calls by each SPObject UUID. The UUIDs being compared must matchup with an existing SPObject in the root. If it does not exist, it means that the SPObject has just been removed and this comparator is reshuffling the map. TODO We need a generic way of comparing SPObjects. Instead of using the WabitObjectOrder enums which currently exist in WabitWorkspace, QueryCache, WabitOlapDimension and Page, we need to somehow make use of the WabitObjectComparator instead.


objectsToRemove

protected java.util.Map<java.lang.String,java.lang.String> objectsToRemove
WabitObject removal buffer, mapping of WabitObject UUIDs to their parents


persistedObjectComparator

protected final java.util.Comparator<PersistedWabitObject> persistedObjectComparator
Constructor Detail

WabitSessionPersister

public WabitSessionPersister(java.lang.String name,
                             WabitSession session)
Creates a session persister that can update any object at or a descendant of the given session's workspace object. If the persist call to this persister is involving an object that is not the workspace or descendant of the workspace in the given session an exception will be thrown depending on the call. See the specific method being called for more information about the exceptions that will be thrown.


WabitSessionPersister

public WabitSessionPersister(java.lang.String name,
                             WabitSession session,
                             WabitObject root)
Creates a session persister that can update an object at or a descendant of the given root now. If the persist call involves an object that is outside of the scope of the root node and its descendant tree an exception will be thrown depending on the method called as the object will not be found.

Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

begin

public void begin()
Begins a transaction

Specified by:
begin in interface ca.sqlpower.dao.SPPersister

commit

public void commit()
            throws ca.sqlpower.dao.SPPersistenceException
Commits the persisted WabitObjects, its properties and removals

Specified by:
commit in interface ca.sqlpower.dao.SPPersister
Throws:
ca.sqlpower.dao.SPPersistenceException

persistObject

public void persistObject(java.lang.String parentUUID,
                          java.lang.String type,
                          java.lang.String uuid,
                          int index)
                   throws ca.sqlpower.dao.SPPersistenceException
Persists a WabitObject given by its UUID, class name, and parent UUID

A new WabitWorkspace object signals that there is a new workspace being persisted and the current one attached to this listener must either go away or clean up. See the class level documentation for more on this special case.

Specified by:
persistObject in interface ca.sqlpower.dao.SPPersister
Parameters:
parentUUID - The parent UUID of the WabitObject to persist
type - The class name of the WabitObject to persist
uuid - The UUID of the WabitObject to persist
index - The index of the WabitObject within its parents' list of children
Throws:
ca.sqlpower.dao.SPPersistenceException - Thrown if the property name is not known in this method.

persistProperty

public void persistProperty(java.lang.String uuid,
                            java.lang.String propertyName,
                            ca.sqlpower.dao.SPPersister.DataType propertyType,
                            java.lang.Object oldValue,
                            java.lang.Object newValue)
                     throws ca.sqlpower.dao.SPPersistenceException
Persists a WabitObject property conditionally given by its object UUID, property name, property type, expected old value, and new value

Specified by:
persistProperty in interface ca.sqlpower.dao.SPPersister
Parameters:
uuid - The UUID of the WabitObject to persist the property upon
propertyName - The property name
propertyType - The property type
oldValue - The expected old property value
newValue - The new property value to persist
Throws:
ca.sqlpower.dao.SPPersistenceException - Thrown if the property name is not known in this method.

persistProperty

public void persistProperty(java.lang.String uuid,
                            java.lang.String propertyName,
                            ca.sqlpower.dao.SPPersister.DataType propertyType,
                            java.lang.Object newValue)
                     throws ca.sqlpower.dao.SPPersistenceException
Persists a WabitObject property unconditionally given by its object UUID, property name, property type, and new value

Specified by:
persistProperty in interface ca.sqlpower.dao.SPPersister
Parameters:
uuid - The UUID of the WabitObject to persist the property upon
propertyName - The property name
propertyType - The property type
newValue - The new property value to persist
Throws:
ca.sqlpower.dao.SPPersistenceException - Thrown if the property name is not known in this method.

removeObject

public void removeObject(java.lang.String parentUUID,
                         java.lang.String uuid)
                  throws ca.sqlpower.dao.SPPersistenceException
Removes WabitObjects from persistent storage.

Specified by:
removeObject in interface ca.sqlpower.dao.SPPersister
Parameters:
parentUUID - The parent UUID of the WabitObject to remove
uuid - The UUID of the WabitObject to remove
Throws:
ca.sqlpower.dao.SPPersistenceException

rollback

public void rollback()
Specified by:
rollback in interface ca.sqlpower.dao.SPPersister

rollback

public void rollback(boolean force)
Rollback all changes to persistent storage to the beginning of the transaction

Throws:
ca.sqlpower.dao.SPPersistenceException

isHeadingToWisconsin

public boolean isHeadingToWisconsin()

isUpdatingWabitWorkspace

public boolean isUpdatingWabitWorkspace()
This is part of the 'echo-cancellation' system to notify any WorkspacePersisterListener listening to the same session to ignore modifications to that session.


enforeThreadSafety

public void enforeThreadSafety()

setGodMode

public void setGodMode(boolean godMode)
Turns this persister as a preacher of the truth and always the truth. All calls are turned into unconditionals.

Parameters:
godMode - True or False

undoForSession

public static void undoForSession(WabitSession session,
                                  java.util.List<PersistedObjectEntry> creations,
                                  java.util.List<PersistedPropertiesEntry> properties,
                                  java.util.List<RemovedObjectEntry> removals)
                           throws ca.sqlpower.dao.SPPersistenceException
This static accessible method allows

Parameters:
session -
creations -
properties -
removals -
Throws:
ca.sqlpower.dao.SPPersistenceException


Copyright © 2009. All Rights Reserved.