ca.sqlpower.wabit.dao
Class WabitSessionPersister

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

public class WabitSessionPersister
extends java.lang.Object
implements WabitPersister

This class represents a Data Access Object for WabitSessions.


Nested Class Summary
 
Nested classes/interfaces inherited from interface ca.sqlpower.wabit.dao.WabitPersister
WabitPersister.DataType, WabitPersister.WabitPersistMethod
 
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, WabitPersister.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, WabitPersister.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()
          Restores the persisted WabitObject back to the state it was in before the transaction began (i.e.
 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
 

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 WabitPersister

commit

public void commit()
            throws WabitPersistenceException
Commits the persisted WabitObjects, its properties and removals

Specified by:
commit in interface WabitPersister
Throws:
WabitPersistenceException - A general Exception that is thrown if any Exception occurs while committing the transaction. This could be caused by one being thrown by #persistObject(String, String), #persistProperty(String, String, Object, Object), or WabitPersister.removeObject(String, String). Some other exceptional situations include:
  • An update conflict with another transaction
  • Network issues
  • Insufficient permissions in the backing store

persistObject

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

Specified by:
persistObject in interface WabitPersister
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:
WabitPersistenceException - Thrown if the property name is not known in this method.

persistProperty

public void persistProperty(java.lang.String uuid,
                            java.lang.String propertyName,
                            WabitPersister.DataType propertyType,
                            java.lang.Object oldValue,
                            java.lang.Object newValue)
                     throws WabitPersistenceException
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 WabitPersister
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:
WabitPersistenceException - Thrown if the property name is not known in this method.

persistProperty

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

Specified by:
persistProperty in interface WabitPersister
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:
WabitPersistenceException - Thrown if the property name is not known in this method.

removeObject

public void removeObject(java.lang.String parentUUID,
                         java.lang.String uuid)
                  throws WabitPersistenceException
Removes WabitObjects from persistent storage.

Specified by:
removeObject in interface WabitPersister
Parameters:
parentUUID - The parent UUID of the WabitObject to remove
uuid - The UUID of the WabitObject to remove
Throws:
WabitPersistenceException

rollback

public void rollback()
Description copied from interface: WabitPersister
Restores the persisted WabitObject back to the state it was in before the transaction began (i.e. when the call to WabitPersister.begin() was made). Typically, this would be called if an exception occurs during an atomic transaction. In the event that a rollback() is called within a nested transaction (that is, a begin() call after another begin() call before commit()), then the state of the WabitObjects must be rolled back to the state they were in before the highest level transaction began.

Specified by:
rollback in interface WabitPersister

rollback

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

Throws:
WabitPersistenceException

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 WabitPersistenceException
This static accessible method allows

Parameters:
session -
creations -
properties -
removals -
Throws:
WabitPersistenceException


Copyright © 2009. All Rights Reserved.