ca.sqlpower.wabit.dao.json
Class WabitJSONPersister

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

public class WabitJSONPersister
extends java.lang.Object
implements WabitPersister

A WabitPersister implementation that serializes WabitPersister method calls as JSONObjects and transmits them to a destination using a MessageSender. This allows these method calls to be transmitted to other systems, typically (but not necessarily) over a network connection.


Nested Class Summary
 
Nested classes/interfaces inherited from interface ca.sqlpower.wabit.dao.WabitPersister
WabitPersister.DataType, WabitPersister.WabitPersistMethod
 
Constructor Summary
WabitJSONPersister(MessageSender<JSONObject> messageSender)
          Create a WabitJSONPersister that uses the given MessageSender to transmit the JSON content
 
Method Summary
 void begin()
          Indicates the start of an atomic transaction of persisting multiple WabitObjects.
 void commit()
          Causes a current WabitObject persistence transaction to commit its results.
 MessageSender<JSONObject> getMessageSender()
           
 void persistObject(java.lang.String parentUUID, java.lang.String type, java.lang.String uuid, int index)
          Adds a WabitObject into the persistent storage.
 void persistProperty(java.lang.String uuid, java.lang.String propertyName, WabitPersister.DataType type, java.lang.Object newValue)
          Modifies the named property of the specified WabitObject in this persister's workspace.
 void persistProperty(java.lang.String uuid, java.lang.String propertyName, WabitPersister.DataType type, java.lang.Object oldValue, java.lang.Object newValue)
          Modifies the named property of the specified WabitObject in this persister's workspace.
 void removeObject(java.lang.String parentUUID, java.lang.String uuid)
          Removes a WabitObject from persistent storage
 void rollback()
          Restores the persisted WabitObject back to the state it was in before the transaction began (i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WabitJSONPersister

public WabitJSONPersister(MessageSender<JSONObject> messageSender)
Create a WabitJSONPersister that uses the given MessageSender to transmit the JSON content

Method Detail

begin

public void begin()
           throws WabitPersistenceException
Description copied from interface: WabitPersister
Indicates the start of an atomic transaction of persisting multiple WabitObjects. To be used with a paired call to WabitPersister.commit()

Specified by:
begin in interface WabitPersister
Throws:
WabitPersistenceException - A general Exception that is thrown if any Exception occurs while persisting the WabitObject. It can be used to wrap the specific cause Exception and provide other details like the WabitObject UUID.

commit

public void commit()
            throws WabitPersistenceException
Description copied from interface: WabitPersister
Causes a current WabitObject persistence transaction to commit its results.

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
Description copied from interface: WabitPersister
Adds a WabitObject into the persistent storage. If the WabitObject already exists in persistent storage, then it will throw an exception Note that this will not persist its properties or any child objects.

Specified by:
persistObject in interface WabitPersister
Parameters:
parentUUID - The UUID of the parent WabitObject of the object to persist. If the WabitObject has no parent (as is the case for WabitWorkspace), then it can be set to null.
type - A String of the class name of the WabitObject to be persisted (ex. WabitWorkspace)
uuid - The UUID of the WabitObject to actually persist
index - The index of the WabitObject in its parents' list of children
Throws:
WabitPersistenceException - A general Exception that is thrown if any Exception occurs while persisting the WabitObject. It can be used to wrap the specific cause Exception and provide other details like the WabitObject UUID. Some potential exceptional situations include:
  • A WabitObject with the given UUID already exists in the persistent storage
  • A WabitObject with the given parent UUID does not exist

persistProperty

public void persistProperty(java.lang.String uuid,
                            java.lang.String propertyName,
                            WabitPersister.DataType type,
                            java.lang.Object oldValue,
                            java.lang.Object newValue)
                     throws WabitPersistenceException
Description copied from interface: WabitPersister
Modifies the named property of the specified WabitObject in this persister's workspace. It may throw an Exception if the actual previous value in persistent storage does not match the expected previous value as an indication to the object using this WabitPersister that their cached copy of the WabitObject may be out of sync with the persistent storage.

Specified by:
persistProperty in interface WabitPersister
Parameters:
uuid - The UUID of the WabitObject in which to set the property
propertyName - The JavaBeans property name of the property that changed, as it would be discovered by the java.beans.Introspector class
type - The type, and Java representation, of this property
oldValue - The expected previous value of the property
newValue - The new value to set for the property
Throws:
WabitPersistenceException - A general Exception that is thrown if any Exception occurs while persisting the property. It can be used to wrap the specific cause Exception and provide other details like the WabitObject UUID. Some potential exceptional situations include:
  • The WabitObject UUID is unknown to this persister
  • The given property name does not exist
  • The given property is not writable
  • The property type of the given old/new values do not match each other or the actual property in the object
  • The existing persistent value doesn't match expected oldValue

persistProperty

public void persistProperty(java.lang.String uuid,
                            java.lang.String propertyName,
                            WabitPersister.DataType type,
                            java.lang.Object newValue)
                     throws WabitPersistenceException
Description copied from interface: WabitPersister
Modifies the named property of the specified WabitObject in this persister's workspace. This version is an unconditional call, and does not check the previous state of the property. To ensure the WabitObjects stay in synch, this method should only be called by the Persister representing the master copy of the WabitObject.

Specified by:
persistProperty in interface WabitPersister
Parameters:
uuid - The UUID of the WabitObject in which to set the property
propertyName - The JavaBeans property name of the property that changed, as it would be discovered by the java.beans.Introspector class
type - The type, and Java representation, of this property
newValue - The new value to set for the property
Throws:
WabitPersistenceException - A general Exception that is thrown if any Exception occurs while persisting the property. It can be used to wrap the specific cause Exception and provide other details like the WabitObject UUID. Some potential exceptional situations include:
  • The WabitObject UUID is unknown to this persister
  • The given property name does not exist
  • The given property is not writable
  • The property type of the given value does not match the actual property in the object

removeObject

public void removeObject(java.lang.String parentUUID,
                         java.lang.String uuid)
                  throws WabitPersistenceException
Description copied from interface: WabitPersister
Removes a WabitObject from persistent storage

Specified by:
removeObject in interface WabitPersister
Parameters:
parentUUID - The UUID of the parent WabitObject of the object to remove
uuid - The UUID of the WabitObject to remove
Throws:
WabitPersistenceException - A general Exception that is thrown if any Exception occurs while persisting the WabitObject. It can be used to wrap the specific cause Exception and provide other details like the WabitObject UUID.

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

getMessageSender

public MessageSender<JSONObject> getMessageSender()


Copyright © 2009. All Rights Reserved.