public interface StrolchTransaction extends AutoCloseable
StrolchTransaction is the central element in Strolch. It gives the developer access to the Strolch model and
performs all the required actions to keep the model consistent etc.
A Strolch transaction is performed as follows as it is an AutoCloseable implementation
StrolchAgent strolchAgent = getStrolchAgent();
StrolchRealm realm = strolchAgent.getContainer().getRealm(StrolchConstants.DEFAULT_REALM);
try(StrolchTransaction tx = realm.openTx(certificate, getClass())){
// do work e.g. add commands
tx.commitOnClose();
}
A StrolchTransaction is always opened for a specific realm, should no specific realms be configured, then the
StrolchConstants.DEFAULT_REALM is automatically created.
A StrolchTransaction takes care of the following:
lock(StrolchRootElement) is usedAbstractTransaction| Modifier and Type | Method and Description |
|---|---|
void |
addCommand(Command command)
Adds the given
Command to the transaction. |
Audit |
auditFrom(AccessType accessType,
String elementType,
String elementSubType,
String id)
Helper method to create an
Audit with the given arguments. |
Audit |
auditFrom(AccessType accessType,
StrolchRootElement element)
Helper method to create an
Audit with the given arguments. |
void |
autoCloseableCommit()
DO NOT CALL THIS METHOD.
|
void |
autoCloseableDoNothing()
DO NOT CALL THIS METHOD.
|
void |
autoCloseableRollback()
DO NOT CALL THIS METHOD.
|
void |
close()
DO NOT CALL THIS METHOD.
|
void |
commitOnClose()
|
void |
doNothingOnClose()
|
<U> List<U> |
doQuery(ActivityQuery<U> query)
Performs the given
ActivityQuery and each returned Activity is passed through the
ActivityVisitor attached to the ActivityQuery and the return value of the visitor is added to the
return list |
<U> List<U> |
doQuery(AuditQuery<U> query)
Performs the given
AuditQuery and each returned Audit is passed through the AuditVisitor
attached to the AuditQuery and the return value of the visitor is added to the return list |
<U> List<U> |
doQuery(OrderQuery<U> query)
Performs the given
OrderQuery and each returned Order is passed through the OrderVisitor
attached to the OrderQuery and the return value of the visitor is added to the return list |
<U> List<U> |
doQuery(ResourceQuery<U> query)
Performs the given
ResourceQuery and each returned Resource is passed through the
ResourceVisitor attached to the ResourceQuery and the return value of the visitor is added to the
return list |
StrolchTransactionException |
fail(String exceptionMessage)
Sets the
TransactionCloseStrategy to TransactionCloseStrategy.ROLLBACK and returns a
StrolchTransactionException which can be thrown by the caller to stop the exception |
<T extends StrolchElement> |
findElement(Locator locator)
Used to find a
StrolchElement by a Locator. |
void |
flush()
Performs all registered commands
|
List<Activity> |
getActivitiesBy(StringListParameter refP)
Returns all
Activities which are referenced by the given StringListParameter. |
List<Activity> |
getActivitiesBy(StringListParameter refP,
boolean assertExists)
Returns all
Activities which are referenced by the given StringListParameter. |
Activity |
getActivityBy(StringParameter refP)
Returns the
Activity which is referenced by the given StringParameter. |
Activity |
getActivityBy(StringParameter refP,
boolean assertExists)
Returns the
Activity which is referenced by the given StringParameter. |
Activity |
getActivityBy(String type,
String id)
Returns the
Activity with the given type and id, or null if it does not exist |
Activity |
getActivityBy(String type,
String id,
boolean assertExists)
Returns the
Activity with the given type and id, or null if it does not exist |
ActivityMap |
getActivityMap()
Returns a reference to the
ActivityMap for the StrolchRealm for which this transaction was opened |
Activity |
getActivityTemplate(String type)
Returns a copy of the
Activity of Type StrolchConstants.TEMPLATE with the given type as id, or
null if it does not exist |
Activity |
getActivityTemplate(String type,
boolean assertExists)
Returns a copy of the
Activity of Type StrolchConstants.TEMPLATE with the given type as id. |
AuditTrail |
getAuditTrail()
Returns a reference to the
AuditTrail for the StrolchRealm for which this transaction was opened |
Certificate |
getCertificate()
Returns the
Certificate which allowed this TX to be opened |
TransactionCloseStrategy |
getCloseStrategy()
Returns the currently set
TransactionCloseStrategy |
Order |
getOrderBy(StringParameter refP)
Returns the
Order which is referenced by the given StringParameter. |
Order |
getOrderBy(StringParameter refP,
boolean assertExists)
Returns the
Order which is referenced by the given StringParameter. |
Order |
getOrderBy(String type,
String id)
Returns the
Order with the given type and id, or null if it does not exist |
Order |
getOrderBy(String type,
String id,
boolean assertExists)
Returns the
Order with the given type and id, or null if it does not exist |
OrderMap |
getOrderMap()
Returns a reference to the
OrderMap for the StrolchRealm for which this transaction was opened |
List<Order> |
getOrdersBy(StringListParameter refP)
Returns all
Orders which are referenced by the given StringListParameter. |
List<Order> |
getOrdersBy(StringListParameter refP,
boolean assertExists)
Returns all
Orders which are referenced by the given StringListParameter. |
Order |
getOrderTemplate(String type)
Returns a copy of the
Order of Type StrolchConstants.TEMPLATE with the given type as id, or null
if it does not exist |
Order |
getOrderTemplate(String type,
boolean assertExists)
Returns a copy of the
Order of Type StrolchConstants.TEMPLATE with the given type as id. |
PersistenceHandler |
getPersistenceHandler()
Returns the
PersistenceHandler. |
String |
getRealmName()
Returns the name of the
StrolchRealm for which this transaction was opened |
Resource |
getResourceBy(StringParameter refP)
Returns the
Resource which is referenced by the given StringParameter. |
Resource |
getResourceBy(StringParameter refP,
boolean assertExists)
Returns the
Resource which is referenced by the given StringParameter. |
Resource |
getResourceBy(String type,
String id)
Returns the
Resource with the given type and id, or null if it does not exist |
Resource |
getResourceBy(String type,
String id,
boolean assertExists)
Returns the
Resource with the given type and id, or null if it does not exist |
ResourceMap |
getResourceMap()
Returns a reference to the
ResourceMap for the StrolchRealm for which this transaction was opened |
List<Resource> |
getResourcesBy(StringListParameter refP)
Returns all
Resources which are referenced by the given StringListParameter. |
List<Resource> |
getResourcesBy(StringListParameter refP,
boolean assertExists)
Returns all
Resources which are referenced by the given StringListParameter. |
Resource |
getResourceTemplate(String type)
Returns a copy of the
Resource of Type StrolchConstants.TEMPLATE with the given type as id, or
null if it does not exist |
Resource |
getResourceTemplate(String type,
boolean assertExists)
Returns a copy of the
Resource of Type StrolchConstants.TEMPLATE with the given type as id. |
TransactionState |
getState() |
boolean |
isClosing() |
boolean |
isCommitting() |
boolean |
isRollingBack() |
boolean |
isSuppressAudits()
Returns true if writing
Audits is currently suppressed |
boolean |
isSuppressDoNothingLogging()
Returns true if logging of a
TransactionCloseStrategy.DO_NOTHING should be suppressed |
boolean |
isSuppressUpdates()
Returns true if the observer updates are currently suppressed
|
boolean |
isVersioningEnabled()
Returns true if versioning is enabled on the
StrolchRealm for which this transaction has been opened |
<T extends StrolchRootElement> |
lock(T element)
Locks the given element and registers it on the transaction so the lock is released when the transaction is
closed
|
<T extends StrolchRootElement> |
releaseLock(T element)
Releases the lock of the given element so that even though the transaction is still open, another
thread/transaction can lock the element
|
void |
rollbackOnClose()
|
void |
setSuppressAudits(boolean suppressAudits)
If the given argument is true, then no
Audits are written |
void |
setSuppressDoNothingLogging(boolean suppressDoNothingLogging)
If the given argument is true, then logging of a
TransactionCloseStrategy.DO_NOTHING will be suppressed |
void |
setSuppressUpdates(boolean suppressUpdates)
If the given argument is true, then no observer updates are performed
|
String getRealmName()
StrolchRealm for which this transaction was openedStrolchRealm for which this transaction was openedCertificate getCertificate()
Certificate which allowed this TX to be openedCertificate which allowed this TX to be openedAuditTrail getAuditTrail()
AuditTrail for the StrolchRealm for which this transaction was openedAuditTrailResourceMap getResourceMap()
ResourceMap for the StrolchRealm for which this transaction was openedResourceMapOrderMap getOrderMap()
OrderMap for the StrolchRealm for which this transaction was openedOrderMapActivityMap getActivityMap()
ActivityMap for the StrolchRealm for which this transaction was openedActivityMapPersistenceHandler getPersistenceHandler()
PersistenceHandler. If the StrolchRealm is not running in
DataStoreMode.TRANSIENT mode, then the PersistenceHandler will be a StrolchComponent,
otherwise it will be the internal in memory persistence handlerPersistenceHandlerTransactionCloseStrategy getCloseStrategy()
TransactionCloseStrategyTransactionCloseStrategyvoid autoCloseableDoNothing()
throws StrolchTransactionException
TransactionCloseStrategy.DO_NOTHING, then
when the transaction is closed, this method is called no changes to the model is performed but locks on objects
are released and any other resources are releasedStrolchTransactionExceptionvoid autoCloseableCommit()
throws StrolchTransactionException
TransactionCloseStrategy.COMMIT, then
when the transaction is closed, this method is called and all registered Command are performed, locks on
objects are released and any other resources are releasedStrolchTransactionExceptionvoid autoCloseableRollback()
throws StrolchTransactionException
TransactionCloseStrategy.ROLLBACK, then
when the transaction is closed, no further actions are performed and any Command which were performed
have their Command.undo() method called and any DB connections are also rolled backStrolchTransactionExceptionvoid close()
throws StrolchTransactionException
DO NOT CALL THIS METHOD. This interface implements AutoCloseable and transactions are expected to be used
in a auto closing try block:
StrolchAgent strolchAgent = getStrolchAgent();
StrolchRealm realm = strolchAgent.getContainer().getRealm("defaultRealm");
try(StrolchTransaction tx = realm.openTx(certificate, getClass())){
// do work
tx.commitOnClose();
}
After the block is closed, the transaction is automatically closed and all allocated resources are releasedclose in interface AutoCloseableStrolchTransactionExceptionvoid doNothingOnClose()
void commitOnClose()
void rollbackOnClose()
StrolchTransactionException fail(String exceptionMessage)
TransactionCloseStrategy to TransactionCloseStrategy.ROLLBACK and returns a
StrolchTransactionException which can be thrown by the caller to stop the exceptionexceptionMessage - StrolchTransactionException to be thrown by the callervoid flush()
Performs all registered commands
This method does not release any locks, nor does it notify any observers
TransactionState getState()
TransactionStateboolean isRollingBack()
StrolchTransaction is TransactionState.ROLLING_BACKboolean isCommitting()
StrolchTransaction is TransactionState.COMMITTINGboolean isClosing()
StrolchTransaction is TransactionState.CLOSINGvoid setSuppressUpdates(boolean suppressUpdates)
suppressUpdates - true to suppress the updates, false to enable themboolean isSuppressUpdates()
void setSuppressAudits(boolean suppressAudits)
Audits are writtensuppressAudits - true to suppress writing Audits, false to enable themboolean isSuppressAudits()
Audits is currently suppressedAudits is currently suppressedvoid setSuppressDoNothingLogging(boolean suppressDoNothingLogging)
TransactionCloseStrategy.DO_NOTHING will be suppressedSuppressDoNothingLogging - true to suppress logging of a TransactionCloseStrategy.DO_NOTHING, false to enable loggingboolean isSuppressDoNothingLogging()
TransactionCloseStrategy.DO_NOTHING should be suppressedTransactionCloseStrategy.DO_NOTHING should be suppressedboolean isVersioningEnabled()
StrolchRealm for which this transaction has been opened<T extends StrolchRootElement> void lock(T element) throws StrolchLockException
element - the element to lockStrolchLockException<T extends StrolchRootElement> void releaseLock(T element) throws StrolchLockException
element - the element for which the lock is to be releasedStrolchLockExceptionvoid addCommand(Command command)
Command to the transaction. Using this method guarantees that a Command is
executed properly:
and if an exception occurs:
command - Audit auditFrom(AccessType accessType, String elementType, String elementSubType, String id)
Audit with the given arguments. The audit can then be saved by calling
AuditTrail.add(StrolchTransaction, Audit)accessType - the type of accesselementType - the element type, i.e. Tags.RESOURCE, Tags.ORDERelementType - the element sub type, e.g. GroupedParameterizedElement.getType()id - the id of the element auditedAudit auditFrom(AccessType accessType, StrolchRootElement element)
Audit with the given arguments. The audit can then be saved by calling
AuditTrail.add(StrolchTransaction, Audit)accessType - the type of accesselement - the element from which to to create the audit<U> List<U> doQuery(OrderQuery<U> query)
Performs the given OrderQuery and each returned Order is passed through the OrderVisitor
attached to the OrderQuery and the return value of the visitor is added to the return list
query - the query to performOrderVisitor, never null<U> List<U> doQuery(ResourceQuery<U> query)
Performs the given ResourceQuery and each returned Resource is passed through the
ResourceVisitor attached to the ResourceQuery and the return value of the visitor is added to the
return list
query - the query to performResourceVisitor, never null<U> List<U> doQuery(ActivityQuery<U> query)
Performs the given ActivityQuery and each returned Activity is passed through the
ActivityVisitor attached to the ActivityQuery and the return value of the visitor is added to the
return list
query - the query to performActivityVisitor, never null<U> List<U> doQuery(AuditQuery<U> query)
Performs the given AuditQuery and each returned Audit is passed through the AuditVisitor
attached to the AuditQuery and the return value of the visitor is added to the return list
query - the query to performAuditVisitor, never null<T extends StrolchElement> T findElement(Locator locator) throws StrolchException, ClassCastException
Used to find a StrolchElement by a Locator.
A Locator has the form <ObjectClassType>/<Type>/<Id> - this is the least amount of path
elements to find an object. Thus to query a Resource of type "MyType" and the id "@1" use the following
path: Resourcee/MyType/@1
This method can also be used to find a deeper element, e.g. a specific Parameter on an
ParameterBag on an Order. This would be done as follows: Order/MyType/@1/myParam
locator - the locator defining the path to the element which is to be foundLocator references an element which does not exist, i.e.
an inexistant Resource or an inexistand Parameter on a Resource, then a
StrolchException is thrownStrolchException - if the element could not be foundClassCastException - if the querying code is not asking for the correct instance. Do not query a Parameter if the
variable to which the result is to be is stored is a Resource, etc.Resource getResourceTemplate(String type)
Returns a copy of the Resource of Type StrolchConstants.TEMPLATE with the given type as id, or
null if it does not exist
Templates are StrolchRootElements which have the type
StrolchConstants.TEMPLATE and their id is the type of element for which it is a template. For instance
when creating a Resource of type Person then having a template with the id
Person helps creating new Person resources; get the resource and then create a clone:
Resource.getClone()
Resource getResourceTemplate(String type, boolean assertExists) throws StrolchException
Returns a copy of the Resource of Type StrolchConstants.TEMPLATE with the given type as id. If
assertExists is true, then an exception is thrown if the template does not exist does not exist
Templates are StrolchRootElements which have the type
StrolchConstants.TEMPLATE and their id is the type of element for which it is a template. For instance
when creating a Resource of type Person then having a template with the id
Person helps creating new Person resources; get the resource and then create a clone:
Resource.getClone()
type - the id of the Resource templateResource template with the given id, or if assertExists is true,
then an exception is thrown if the resource does not existStrolchExceptionOrder getOrderTemplate(String type)
Returns a copy of the Order of Type StrolchConstants.TEMPLATE with the given type as id, or null
if it does not exist
Templates are StrolchRootElements which have the type
StrolchConstants.TEMPLATE and their id is the type of element for which it is a template. For instance
when creating an Order of type PurchaseOrder then having a template with the id
PurchaseOrder helps creating new PurchaseOrder orders; get the order and then create a clone:
Order.getClone()
Order getOrderTemplate(String type, boolean assertExists) throws StrolchException
Returns a copy of the Order of Type StrolchConstants.TEMPLATE with the given type as id. If
assertExists is true, then an exception is thrown if the template does not exist does not exist
Templates are StrolchRootElements which have the type
StrolchConstants.TEMPLATE and their id is the type of element for which it is a template. For instance
when creating an Order of type PurchaseOrder then having a template with the id
PurchaseOrder helps creating new PurchaseOrder orders; get the order and then create a clone:
Order.getClone()
type - the id of the Order templateOrder template with the given id, or if assertExists is true, then
an exception is thrown if the order does not existStrolchExceptionActivity getActivityTemplate(String type)
Returns a copy of the Activity of Type StrolchConstants.TEMPLATE with the given type as id, or
null if it does not exist
Templates are StrolchRootElements which have the type
StrolchConstants.TEMPLATE and their id is the type of element for which it is a template. For instance
when creating a Activity of type ToStock then having a template with the id
ToStock helps creating new ToStock activities; get the activity and then create a clone:
Activity.getClone()
Activity getActivityTemplate(String type, boolean assertExists) throws StrolchException
Returns a copy of the Activity of Type StrolchConstants.TEMPLATE with the given type as id. If
assertExists is true, then an exception is thrown if the template does not exist does not exist
Templates are StrolchRootElements which have the type
StrolchConstants.TEMPLATE and their id is the type of element for which it is a template. For instance
when creating a Activity of type ToStock then having a template with the id
ToStock helps creating new ToStock activities; get the activity and then create a clone:
Activity.getClone()
type - the id of the Activity templateActivity template with the given id, or if assertExists is true,
then an exception is thrown if the activity does not existStrolchExceptionResource getResourceBy(String type, String id)
Resource with the given type and id, or null if it does not existResource getResourceBy(String type, String id, boolean assertExists) throws StrolchException
Resource with the given type and id, or null if it does not existtype - the type of the Resourceid - the id of the ResourceassertExists - if true, and resource does not exist, then a StrolchException is thrownResource with the given type and id, or null if it does not existStrolchException - if the resource does not exist, and assertExists is trueResource getResourceBy(StringParameter refP) throws StrolchException
Resource which is referenced by the given StringParameter. A reference
Parameter must have its interpretation set to StrolchConstants.INTERPRETATION_RESOURCE_REF and
the UOM must be set to the resource's type and the value is the id of the resourcerefP - the StringParameter which references a ResourceStrolchException - if the StringParameter is not a properly configured as a reference parameterResource getResourceBy(StringParameter refP, boolean assertExists) throws StrolchException
Resource which is referenced by the given StringParameter. A reference
Parameter must have its interpretation set to StrolchConstants.INTERPRETATION_RESOURCE_REF and
the UOM must be set to the resource's type and the value is the id of the resourcerefP - the StringParameter which references a ResourceassertExists - if true, and resource does not exist, then a StrolchException is thrownStrolchException - if the StringParameter is not a properly configured as a reference parameter, or if the
resource does not exist, and assertExists is trueList<Resource> getResourcesBy(StringListParameter refP) throws StrolchException
Resources which are referenced by the given StringListParameter. A reference
Parameter must have its interpretation set to StrolchConstants.INTERPRETATION_RESOURCE_REF and
the UOM must be set to the resource's type and the value is the id of the resourcerefP - the StringListParameter which references a list of ResourcesStrolchException - if the StringListParameter is not a properly configured as a reference parameterList<Resource> getResourcesBy(StringListParameter refP, boolean assertExists) throws StrolchException
Resources which are referenced by the given StringListParameter. A reference
Parameter must have its interpretation set to StrolchConstants.INTERPRETATION_RESOURCE_REF and
the UOM must be set to the resource's type and the value is the id of the resourcerefP - the StringListParameter which references a list of ResourcesassertExists - if true, and resource does not exist, then a StrolchException is thrownassertExists is trueStrolchException - if the StringListParameter is not a properly configured as a reference parameterActivity getActivityBy(String type, String id)
Activity with the given type and id, or null if it does not existActivity getActivityBy(String type, String id, boolean assertExists) throws StrolchException
Activity with the given type and id, or null if it does not existtype - the type of the Activityid - the id of the ActivityassertExists - if true, and activity does not exist, then a StrolchException is thrownActivity with the given type and id, or null if it does not existStrolchException - if the activity does not exist, and assertExists is trueActivity getActivityBy(StringParameter refP) throws StrolchException
Activity which is referenced by the given StringParameter. A reference
Parameter must have its interpretation set to StrolchConstants.INTERPRETATION_ACTIVITY_REF and
the UOM must be set to the activity's type and the value is the id of the activityrefP - the StringParameter which references an ActivityStrolchException - if the StringParameter is not a properly configured as a reference parameterActivity getActivityBy(StringParameter refP, boolean assertExists) throws StrolchException
Activity which is referenced by the given StringParameter. A reference
Parameter must have its interpretation set to StrolchConstants.INTERPRETATION_ACTIVITY_REF and
the UOM must be set to the activity's type and the value is the id of the activityrefP - the StringParameter which references an ActivityassertExists - if true, and activity does not exist, then a StrolchException is thrownStrolchException - if the StringParameter is not a properly configured as a reference parameter, or if the
activity does not exist, and assertExists is trueList<Activity> getActivitiesBy(StringListParameter refP) throws StrolchException
Activities which are referenced by the given StringListParameter. A
reference Parameter must have its interpretation set to
StrolchConstants.INTERPRETATION_ACTIVITY_REF and the UOM must be set to the activity's type and the value
is the id of the activityrefP - the StringListParameter which references a list of ActivitiesStrolchException - if the StringListParameter is not a properly configured as a reference parameterList<Activity> getActivitiesBy(StringListParameter refP, boolean assertExists) throws StrolchException
Activities which are referenced by the given StringListParameter. A
reference Parameter must have its interpretation set to
StrolchConstants.INTERPRETATION_ACTIVITY_REF and the UOM must be set to the activity's type and the value
is the id of the activityrefP - the StringListParameter which references a list of ActivitiesassertExists - if true, and activity does not exist, then a StrolchException is thrownassertExists is trueStrolchException - if the StringListParameter is not a properly configured as a reference parameterOrder getOrderBy(String type, String id)
Order with the given type and id, or null if it does not existOrder getOrderBy(String type, String id, boolean assertExists) throws StrolchException
Order with the given type and id, or null if it does not existtype - the type of the Orderid - the id of the OrderassertExists - if true, and order does not exist, then a StrolchException is thrownOrder with the given type and id, or null if it does not existStrolchException - if the order does not exist, and assertExists is trueOrder getOrderBy(StringParameter refP) throws StrolchException
Order which is referenced by the given StringParameter. A reference Parameter
must have its interpretation set to StrolchConstants.INTERPRETATION_ORDER_REF and the UOM must be set to
the order's type and the value is the id of the orderrefP - the StringParameter which references an OrderStrolchException - if the StringParameter is not a properly configured as a reference parameterOrder getOrderBy(StringParameter refP, boolean assertExists) throws StrolchException
Order which is referenced by the given StringParameter. A reference Parameter
must have its interpretation set to StrolchConstants.INTERPRETATION_ORDER_REF and the UOM must be set to
the order's type and the value is the id of the orderrefP - the StringParameter which references an OrderassertExists - if true, and order does not exist, then a StrolchException is thrownStrolchException - if the StringParameter is not a properly configured as a reference parameter, or if the order
does not exist, and assertExists is trueList<Order> getOrdersBy(StringListParameter refP) throws StrolchException
Orders which are referenced by the given StringListParameter. A reference
Parameter must have its interpretation set to StrolchConstants.INTERPRETATION_ORDER_REF and the
UOM must be set to the order's type and the value is the id of the orderrefP - the StringListParameter which references a list of OrdersStrolchException - if the StringListParameter is not a properly configured as a reference parameterList<Order> getOrdersBy(StringListParameter refP, boolean assertExists) throws StrolchException
Orders which are referenced by the given StringListParameter. A reference
Parameter must have its interpretation set to StrolchConstants.INTERPRETATION_ORDER_REF and the
UOM must be set to the order's type and the value is the id of the orderrefP - the StringListParameter which references a list of OrdersassertExists - if true, and order does not exist, then a StrolchException is thrownassertExists is trueStrolchException - if the StringListParameter is not a properly configured as a reference parameterCopyright © 2011–2016 Strolch. All rights reserved.