Class JdbcCpoXaAdapter
- All Implemented Interfaces:
Serializable,AutoCloseable,XAResource,CpoAdapter,CpoTrxAdapter,CpoXaResource
It manages a local and global CpoTrxAdapter and manages the association of XIDs to transactions
The XAResource interface is a Java mapping of the industry standard XA interface based on the X/Open CAE Specification (Distributed Transaction Processing: The XA Specification).
The XA interface defines the contract between a Resource Manager and a Transaction Manager in a distributed transaction processing (DTP) environment. A JDBC driver or a JMS provider implements this interface to support the association between a global transaction and a database or message service connection.
The XAResource interface can be supported by any transactional resource that is intended to be used by application programs in an environment where transactions are controlled by an external transaction manager. An example of such a resource is a database management system. An application may access data through multiple database connections. Each database connection is enlisted with the transaction manager as a transactional resource. The transaction manager obtains an XAResource for each connection participating in a global transaction. The transaction manager uses the start method to associate the global transaction with the resource, and it uses the end method to disassociate the transaction from the resource. The resource manager is responsible for associating the global transaction to all work performed on its data between the start and end method invocations.
At transaction commit time, the resource managers are informed by the transaction manager to prepare, commit, or rollback a transaction according to the two-phase commit protocol.
- See Also:
-
Field Summary
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY -
Constructor Summary
ConstructorsConstructorDescriptionJdbcCpoXaAdapter(JdbcCpoAdapterFactory jdbcCpoAdapterFactory) Construct a JdbcCpoXaAdapter -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the current transaction behind the CpoTrxAdapter.voidcloseResource(JdbcCpoAdapter jdbcCpoAdapter) voidcommit()Commits the current transaction behind the CpoTrxAdaptervoidcommitResource(JdbcCpoAdapter jdbcCpoAdapter) <T> longdeleteBean(CpoQuery query, T bean) Removes the bean from the datasource using the query's DELETE function group.<T> longdeleteBeans(CpoQuery query, List<T> beans) Removes the beans from the datasource using the query's DELETE function group, batching where the datasource supports it.<T,C> T executeBean(CpoQuery query, C criteria, T result) Executes the EXECUTE function group identified by the query — typically a stored procedure — using the criteria bean to populate the IN arguments and the result bean type for the OUT arguments.<T> longexistsBean(CpoQuery query, T bean) Checks whether beans matching the given bean exist in the datasource, using the query's EXIST function group and where constraints.intGet the batch size for updating the datasourcegetCpoAttributes(String expression) Gets theCpoAttributedefinitions matching a comma-separated expression of attribute names, as declared in the meta data for this bean's class.Get the CpoMetaDescriptorGet the name of the datasourceintGet the fetch size for the datasource<T> longinsertBean(CpoQuery query, T bean) Creates the bean in the datasource using the query's CREATE function group.<T> longinsertBeans(CpoQuery query, List<T> beans) Creates the beans in the datasource using the query's CREATE function group, batching where the datasource supports it.booleanisClosed()Returns true if the TrxAdapter has been closed, false if it is still activebooleanisSameRM(XAResource xaResource) newOrderBy(String attribute, boolean ascending) Creates a CpoOrderBy for the attribute and direction.newOrderBy(String attribute, boolean ascending, String function) Creates a CpoOrderBy applying a datasource function to the attribute.newOrderBy(String marker, String attribute, boolean ascending) Creates a CpoOrderBy bound to a marker within the expression.newOrderBy(String marker, String attribute, boolean ascending, String function) Creates a CpoOrderBy bound to a marker, applying a datasource function to the attribute.newWhere()Creates an empty CpoWhere.<T> CpoWherenewWhere(Logical logical, String attr, Comparison comp, T value) Creates a CpoWhere comparing the attribute to the value.<T> CpoWherenewWhere(Logical logical, String attr, Comparison comp, T value, boolean not) Creates a CpoWhere comparing the attribute to the value, optionally negated.<T,C> T retrieveBean(CpoQuery query, C criteria, T result) Retrieves the first bean produced by the query's RETRIEVE function group, using separate criteria and result beans.<T> TretrieveBean(CpoQuery query, T bean) Retrieves a single bean from the datasource using the query's RETRIEVE function group, with the given bean supplying the search criteria and receiving the result.<T,C> Stream <T> retrieveBeans(CpoQuery query, C criteria, T result) Retrieves beans from the datasource using the query's LIST function group, with separate criteria and result beans.voidrollback()Rollback the current transaction behind the CpoTrxAdaptervoidrollbackResource(JdbcCpoAdapter jdbcCpoAdapter) voidsetBatchSize(int batchSize) set the batch size for updating the datasourcevoidsetFetchSize(int fetchSize) set the fetch size for the datasource<T> longupdateBean(CpoQuery query, T bean) Updates the bean in the datasource using the query's UPDATE function group.<T> longupdateBeans(CpoQuery query, List<T> beans) Updates the beans in the datasource using the query's UPDATE function group, batching where the datasource supports it.<T> longupsertBean(CpoQuery query, T bean) Inserts or updates the bean using the query's UPSERT function group: the EXIST function decides whether the CREATE or UPDATE function is executed.<T> longupsertBeans(CpoQuery query, List<T> beans) Inserts or updates the beans using the query's UPSERT function group: for each bean the EXIST function decides whether the CREATE or UPDATE function is executed.Methods inherited from class org.synchronoss.cpo.core.jta.CpoBaseXaResource
accept, apply, close, closeAssociated, commit, end, forget, getTransactionTimeout, prepare, recover, rollback, setTransactionTimeout, startMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.synchronoss.cpo.core.CpoAdapter
deleteBean, deleteBean, deleteBeans, deleteBeans, executeBean, executeBean, existsBean, existsBean, insertBean, insertBean, insertBeans, insertBeans, retrieveBean, retrieveBean, retrieveBeans, retrieveBeans, retrieveBeans, updateBean, updateBean, updateBeans, updateBeans, upsertBean, upsertBean, upsertBeans, upsertBeans
-
Constructor Details
-
JdbcCpoXaAdapter
Construct a JdbcCpoXaAdapter- Parameters:
jdbcCpoAdapterFactory- - The adapter factory to use to create the JdbcCpoXaAdapter- Throws:
CpoException- - An error getting the JdbcCpoXaAdapter
-
-
Method Details
-
commit
Commits the current transaction behind the CpoTrxAdapter- Specified by:
commitin interfaceCpoTrxAdapter- Throws:
CpoException- An error occurred
-
rollback
Rollback the current transaction behind the CpoTrxAdapter- Specified by:
rollbackin interfaceCpoTrxAdapter- Throws:
CpoException- An error occurred
-
close
Closes the current transaction behind the CpoTrxAdapter. All subsequent calls to the CpoTrxAdapter will throw an exception.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCpoTrxAdapter- Throws:
CpoException
-
isClosed
Returns true if the TrxAdapter has been closed, false if it is still active- Specified by:
isClosedin interfaceCpoTrxAdapter- Returns:
- true if it is closed
- Throws:
CpoException- An error occurred
-
insertBean
Description copied from interface:CpoAdapterCreates the bean in the datasource using the query's CREATE function group. The assumption is that the bean does not exist in the datasource.SomeBean bean = new SomeBean(); bean.setId(1); bean.setName("SomeName"); cpo.insertBean(CpoQuery.group("createBean"), bean);- Specified by:
insertBeanin interfaceCpoAdapter- Type Parameters:
T- The type of the JavaBean- Parameters:
query- The function group and clauses to applybean- A bean defined within the metadata of the datasource- Returns:
- The number of beans created in the datasource
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-
insertBeans
Description copied from interface:CpoAdapterCreates the beans in the datasource using the query's CREATE function group, batching where the datasource supports it. This is an all-or-nothing transaction: if one bean fails, no beans are created.List<SomeBean> beans = List.of(bean1, bean2); long created = cpo.insertBeans(CpoQuery.group("createBean"), beans);- Specified by:
insertBeansin interfaceCpoAdapter- Type Parameters:
T- The type of the JavaBean- Parameters:
query- The function group and clauses to applybeans- The beans to create- Returns:
- The number of beans created in the datasource
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-
deleteBean
Description copied from interface:CpoAdapterRemoves the bean from the datasource using the query's DELETE function group. The assumption is that the bean exists in the datasource.SomeBean bean = new SomeBean(); bean.setId(1); cpo.deleteBean(CpoQuery.group("deleteBean"), bean);- Specified by:
deleteBeanin interfaceCpoAdapter- Type Parameters:
T- The type of the JavaBean- Parameters:
query- The function group and clauses to applybean- A bean defined within the metadata of the datasource- Returns:
- The number of beans deleted from the datasource
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-
deleteBeans
Description copied from interface:CpoAdapterRemoves the beans from the datasource using the query's DELETE function group, batching where the datasource supports it. This is an all-or-nothing transaction: if one bean fails, no beans are deleted.long deleted = cpo.deleteBeans(CpoQuery.group("deleteBean"), beans);- Specified by:
deleteBeansin interfaceCpoAdapter- Type Parameters:
T- The type of the JavaBean- Parameters:
query- The function group and clauses to applybeans- The beans to delete- Returns:
- The number of beans deleted from the datasource
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-
updateBean
Description copied from interface:CpoAdapterUpdates the bean in the datasource using the query's UPDATE function group. The assumption is that the bean exists in the datasource.SomeBean bean = new SomeBean(); bean.setId(1); bean.setName("NewName"); cpo.updateBean(CpoQuery.group("updateBean"), bean);- Specified by:
updateBeanin interfaceCpoAdapter- Type Parameters:
T- The type of the JavaBean- Parameters:
query- The function group and clauses to applybean- A bean defined within the metadata of the datasource- Returns:
- The number of beans updated in the datasource
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-
updateBeans
Description copied from interface:CpoAdapterUpdates the beans in the datasource using the query's UPDATE function group, batching where the datasource supports it. This is an all-or-nothing transaction: if one bean fails, no beans are updated.long updated = cpo.updateBeans(CpoQuery.group("updateBean"), beans);- Specified by:
updateBeansin interfaceCpoAdapter- Type Parameters:
T- The type of the JavaBean- Parameters:
query- The function group and clauses to applybeans- The beans to update- Returns:
- The number of beans updated in the datasource
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-
upsertBean
Description copied from interface:CpoAdapterInserts or updates the bean using the query's UPSERT function group: the EXIST function decides whether the CREATE or UPDATE function is executed.SomeBean bean = new SomeBean(); bean.setId(1); bean.setName("SomeName"); cpo.upsertBean(CpoQuery.group("upsertBean"), bean); // inserts or updates as needed- Specified by:
upsertBeanin interfaceCpoAdapter- Type Parameters:
T- The type of the JavaBean- Parameters:
query- The function group and clauses to applybean- A bean defined within the metadata of the datasource- Returns:
- The number of beans upserted in the datasource
- Throws:
CpoException- Thrown if there are errors accessing the datasource, or if the EXIST function matches more than one record
-
upsertBeans
Description copied from interface:CpoAdapterInserts or updates the beans using the query's UPSERT function group: for each bean the EXIST function decides whether the CREATE or UPDATE function is executed.long upserted = cpo.upsertBeans(CpoQuery.group("upsertBean"), beans);- Specified by:
upsertBeansin interfaceCpoAdapter- Type Parameters:
T- The type of the JavaBean- Parameters:
query- The function group and clauses to applybeans- The beans to upsert- Returns:
- The number of beans upserted in the datasource
- Throws:
CpoException- Thrown if there are errors accessing the datasource, or if the EXIST function matches more than one record
-
existsBean
Description copied from interface:CpoAdapterChecks whether beans matching the given bean exist in the datasource, using the query's EXIST function group and where constraints.CpoWhere where = cpo.newWhere(Logical.NONE, "id", Comparison.EQ, 1); long count = cpo.existsBean(CpoQuery.group("existsBean").where(where), bean); if (count > 0) { // the bean exists }- Specified by:
existsBeanin interfaceCpoAdapter- Type Parameters:
T- The type of the JavaBean- Parameters:
query- The function group and clauses to applybean- The bean to search for in the datasource- Returns:
- The number of beans that exist in the datasource that match the specified bean. An EXIST function must either return a count as a single row with a single numeric column (count(*) style) or return one row per matching bean; a single-row result with one numeric column is always interpreted as a count
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-
executeBean
Description copied from interface:CpoAdapterExecutes the EXECUTE function group identified by the query — typically a stored procedure — using the criteria bean to populate the IN arguments and the result bean type for the OUT arguments.SomeResult result = cpo.executeBean(CpoQuery.group("calculateTotals"), criteria, new SomeResult());- Specified by:
executeBeanin interfaceCpoAdapter- Type Parameters:
T- The type of the result JavaBeanC- The type of the criteria JavaBean- Parameters:
query- The function group to executecriteria- A bean defined within the metadata of the datasource used to populate the IN argumentsresult- A bean defined within the metadata of the datasource that defines the bean type populated with the OUT arguments- Returns:
- A result bean populated with the OUT arguments
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-
retrieveBean
Description copied from interface:CpoAdapterRetrieves a single bean from the datasource using the query's RETRIEVE function group, with the given bean supplying the search criteria and receiving the result. If the function returns more than one row, an exception is thrown.SomeBean criteria = new SomeBean(); criteria.setId(1); SomeBean bean = cpo.retrieveBean(CpoQuery.group("retrieveBean"), criteria);- Specified by:
retrieveBeanin interfaceCpoAdapter- Type Parameters:
T- The type of the JavaBean- Parameters:
query- The function group and clauses to applybean- A bean defined within the metadata of the datasource whose attributes supply the search criteria- Returns:
- A populated bean of the same type as the bean passed in, or null if no beans match
- Throws:
CpoException- Thrown if there are errors accessing the datasource or more than one row is returned
-
retrieveBean
Description copied from interface:CpoAdapterRetrieves the first bean produced by the query's RETRIEVE function group, using separate criteria and result beans.SomeResult result = cpo.retrieveBean(CpoQuery.group("retrieveResult"), criteria, new SomeResult());- Specified by:
retrieveBeanin interfaceCpoAdapter- Type Parameters:
T- The type of the result JavaBeanC- The type of the criteria JavaBean- Parameters:
query- The function group and clauses to applycriteria- A bean defined within the metadata of the datasource that supplies the retrieval parametersresult- A bean defined within the metadata of the datasource that specifies the returned bean type- Returns:
- A bean of the same type as the result parameter, or null if no beans match
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-
retrieveBeans
Description copied from interface:CpoAdapterRetrieves beans from the datasource using the query's LIST function group, with separate criteria and result beans.CpoWhere where = cpo.newWhere(Logical.NONE, "dept", Comparison.EQ, "sales"); CpoOrderBy orderBy = cpo.newOrderBy("name", true); try (Stream<SomeResult> beans = cpo.retrieveBeans( CpoQuery.group("listResults").where(where).orderBy(orderBy), criteria, new SomeResult())) { beans.forEach(...); }- Specified by:
retrieveBeansin interfaceCpoAdapter- Type Parameters:
T- The type of the result JavaBeanC- The type of the criteria JavaBean- Parameters:
query- The function group and clauses to applycriteria- A bean defined within the metadata of the datasource that supplies the retrieval parametersresult- A bean defined within the metadata of the datasource that specifies the returned bean type- Returns:
- A stream of beans that meet the criteria; empty if none match. The stream is backed by open datastore resources (statement, result set, and connection) that are released only when the stream is closed; terminal operations do not close it. Always close the returned stream, preferably with try-with-resources.
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-
newOrderBy
Description copied from interface:CpoAdapterCreates a CpoOrderBy for the attribute and direction.CpoOrderBy byNameAscending = cpo.newOrderBy("name", true);- Specified by:
newOrderByin interfaceCpoAdapter- Parameters:
attribute- The metadata attribute name to order byascending- true for ascending, false for descending- Returns:
- A CpoOrderBy
- Throws:
CpoException- An error occurred creating the CpoOrderBy
-
newOrderBy
public CpoOrderBy newOrderBy(String marker, String attribute, boolean ascending) throws CpoException Description copied from interface:CpoAdapterCreates a CpoOrderBy bound to a marker within the expression.- Specified by:
newOrderByin interfaceCpoAdapter- Parameters:
marker- The marker in the expression that this order-by replacesattribute- The metadata attribute name to order byascending- true for ascending, false for descending- Returns:
- A CpoOrderBy
- Throws:
CpoException- An error occurred creating the CpoOrderBy
-
newOrderBy
public CpoOrderBy newOrderBy(String attribute, boolean ascending, String function) throws CpoException Description copied from interface:CpoAdapterCreates a CpoOrderBy applying a datasource function to the attribute.- Specified by:
newOrderByin interfaceCpoAdapter- Parameters:
attribute- The metadata attribute name to order byascending- true for ascending, false for descendingfunction- A datasource function to apply to the attribute- Returns:
- A CpoOrderBy
- Throws:
CpoException- An error occurred creating the CpoOrderBy
-
newOrderBy
public CpoOrderBy newOrderBy(String marker, String attribute, boolean ascending, String function) throws CpoException Description copied from interface:CpoAdapterCreates a CpoOrderBy bound to a marker, applying a datasource function to the attribute.- Specified by:
newOrderByin interfaceCpoAdapter- Parameters:
marker- The marker in the expression that this order-by replacesattribute- The metadata attribute name to order byascending- true for ascending, false for descendingfunction- A datasource function to apply to the attribute- Returns:
- A CpoOrderBy
- Throws:
CpoException- An error occurred creating the CpoOrderBy
-
newWhere
Description copied from interface:CpoAdapterCreates an empty CpoWhere.CpoWhere where = cpo.newWhere();- Specified by:
newWherein interfaceCpoAdapter- Returns:
- A CpoWhere
- Throws:
CpoException- An error occurred creating the CpoWhere
-
newWhere
public <T> CpoWhere newWhere(Logical logical, String attr, Comparison comp, T value) throws CpoException Description copied from interface:CpoAdapterCreates a CpoWhere comparing the attribute to the value.CpoWhere where = cpo.newWhere(Logical.NONE, "id", Comparison.EQ, 42);- Specified by:
newWherein interfaceCpoAdapter- Type Parameters:
T- The type of the value- Parameters:
logical- How this where combines with the preceding where (AND, OR, NONE)attr- The metadata attribute name to constraincomp- The comparison operatorvalue- The value to compare against- Returns:
- A CpoWhere
- Throws:
CpoException- An error occurred creating the CpoWhere
-
newWhere
public <T> CpoWhere newWhere(Logical logical, String attr, Comparison comp, T value, boolean not) throws CpoException Description copied from interface:CpoAdapterCreates a CpoWhere comparing the attribute to the value, optionally negated.- Specified by:
newWherein interfaceCpoAdapter- Type Parameters:
T- The type of the value- Parameters:
logical- How this where combines with the preceding where (AND, OR, NONE)attr- The metadata attribute name to constraincomp- The comparison operatorvalue- The value to compare againstnot- true to negate the comparison- Returns:
- A CpoWhere
- Throws:
CpoException- An error occurred creating the CpoWhere
-
getCpoMetaDescriptor
Description copied from interface:CpoAdapterGet the CpoMetaDescriptor- Specified by:
getCpoMetaDescriptorin interfaceCpoAdapter- Returns:
- The CpoMetaDescriptor
-
getDataSourceName
Description copied from interface:CpoAdapterGet the name of the datasource- Specified by:
getDataSourceNamein interfaceCpoAdapter- Returns:
- The name of the datasource
-
getFetchSize
public int getFetchSize()Description copied from interface:CpoAdapterGet the fetch size for the datasource- Specified by:
getFetchSizein interfaceCpoAdapter- Returns:
- The fetchsize
-
setFetchSize
public void setFetchSize(int fetchSize) Description copied from interface:CpoAdapterset the fetch size for the datasource- Specified by:
setFetchSizein interfaceCpoAdapter- Parameters:
fetchSize- The fetchsize to set for retrieving data
-
getBatchSize
public int getBatchSize()Description copied from interface:CpoAdapterGet the batch size for updating the datasource- Specified by:
getBatchSizein interfaceCpoAdapter- Returns:
- The batchsize
-
setBatchSize
public void setBatchSize(int batchSize) Description copied from interface:CpoAdapterset the batch size for updating the datasource- Specified by:
setBatchSizein interfaceCpoAdapter- Parameters:
batchSize- The batchsize for updating the datasource
-
getCpoAttributes
Description copied from interface:CpoAdapterGets theCpoAttributedefinitions matching a comma-separated expression of attribute names, as declared in the meta data for this bean's class.- Specified by:
getCpoAttributesin interfaceCpoAdapter- Parameters:
expression- An expression defining the CpoAttributes that you want- Returns:
- A list of CpoAttributes
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-
isSameRM
- Specified by:
isSameRMin interfaceXAResource- Throws:
XAException
-
commitResource
- Throws:
XAException
-
rollbackResource
- Throws:
XAException
-
createNewResource
- Throws:
XAException
-
closeResource
- Throws:
XAException
-