com.sas.framework.expojo.mock
Class MockPersistenceProvider

java.lang.Object
  extended by com.sas.framework.expojo.PersistenceProvider
      extended by com.sas.framework.expojo.mock.MockPersistenceProvider

public class MockPersistenceProvider
extends PersistenceProvider

Provides a 'drop in' mock persistence provider that does not persist objects to a database. It's purpose is to allow expojo applications to be run/tested in a memory only environment to exercise unit tests, business rules etc., without the overhead of database persistence. It is only intended to be used as a testing mechanism. Applications running in a production environment would typically use a true persistence provider like JDO or Hibernate.


Field Summary
protected static java.lang.Object firstPersistedObject
          Stores a reference to the first persisted object - which should be the system object.
 
Fields inherited from class com.sas.framework.expojo.PersistenceProvider
depth, modelExposer
 
Constructor Summary
MockPersistenceProvider()
          Constructs the object giving it a PersistenceManager.
 
Method Summary
 void beginTx()
          Begins a transaction.
 void close()
          Closes the persistence provider.
 void commitTx()
          Commits a transaction.
 void delete(java.lang.Object object)
          Deletes the persistent object from the datastore.
 java.lang.Object getFirstPersistedObject()
          Returns firstPersistedObject
 boolean hasActiveTx()
          Returns true if the PersistenceProvider has an active transaction.
 void open()
          Opens a persistence provider.
 void persist(java.lang.Object object)
          Makes the given object persistent.
 java.lang.RuntimeException processException(java.lang.RuntimeException e)
          Processes an exception thrown while in a transaction.
 void rollbackTx()
          Rolls back a transaction.
 void setFirstPersistedObject(java.lang.Object firstPersistedObject)
          Sets firstPersistedObject
 
Methods inherited from class com.sas.framework.expojo.PersistenceProvider
setModelExposer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

firstPersistedObject

protected static transient java.lang.Object firstPersistedObject
Stores a reference to the first persisted object - which should be the system object. This can then be used by the Mock repository in getSystemEntity to return the top level system entity object. This is a static because it's shared by all threads - heh it's only the mock system ok - we're not going to have a private cache for each PersistenceProvider.

Constructor Detail

MockPersistenceProvider

public MockPersistenceProvider()
Constructs the object giving it a PersistenceManager.

Method Detail

hasActiveTx

public boolean hasActiveTx()
Returns true if the PersistenceProvider has an active transaction.

Specified by:
hasActiveTx in class PersistenceProvider

setFirstPersistedObject

public void setFirstPersistedObject(java.lang.Object firstPersistedObject)
Sets firstPersistedObject


getFirstPersistedObject

public java.lang.Object getFirstPersistedObject()
Returns firstPersistedObject


close

public void close()
Closes the persistence provider. It can no longer be used after being closed.

Specified by:
close in class PersistenceProvider

processException

public java.lang.RuntimeException processException(java.lang.RuntimeException e)
Processes an exception thrown while in a transaction. The exception could be relevent to the persistence technology or a generic RuntimeException. If it's an optimistic verification exception (optimistic locking check failed) then no exception is thrown and the persistence technology may or may not need clean. In the case of JDO a rollback as already been performed.

Specified by:
processException in class PersistenceProvider

delete

public void delete(java.lang.Object object)
Deletes the persistent object from the datastore.

Specified by:
delete in class PersistenceProvider

persist

public void persist(java.lang.Object object)
Makes the given object persistent.

Specified by:
persist in class PersistenceProvider

rollbackTx

public void rollbackTx()
Rolls back a transaction.

Specified by:
rollbackTx in class PersistenceProvider

commitTx

public void commitTx()
Commits a transaction.

Specified by:
commitTx in class PersistenceProvider

beginTx

public void beginTx()
Begins a transaction.

Specified by:
beginTx in class PersistenceProvider

open

public void open()
Opens a persistence provider.

Specified by:
open in class PersistenceProvider