Package org.synchronoss.cpo.core
Class CpoBaseAdapter<D>
java.lang.Object
org.synchronoss.cpo.core.cache.CpoAdapterCache
org.synchronoss.cpo.core.CpoBaseAdapter<D>
- Type Parameters:
D- The type of the Datasource
- All Implemented Interfaces:
Serializable,CpoAdapter
The CpoBaseAdapter has common functionality needed by all Adapter implementations
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCpoBaseAdapter(String dataSourceName, int fetchSize, int batchSize) Constructs the adapter with the given data source name and default fetch/batch sizes. -
Method Summary
Modifier and TypeMethodDescription<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.abstract <T> longexistsBean(CpoQuery query, T bean) The CpoAdapter will check to see if this object exists in the datasource.intGet the batch size for updating the datasourceGet 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.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.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 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, getCpoAttributes, getCpoMetaDescriptor, insertBean, insertBean, insertBeans, insertBeans, retrieveBean, retrieveBean, retrieveBeans, retrieveBeans, retrieveBeans, updateBean, updateBean, updateBeans, updateBeans, upsertBean, upsertBean, upsertBeans, upsertBeans
-
Constructor Details
-
CpoBaseAdapter
Constructs the adapter with the given data source name and default fetch/batch sizes.- Parameters:
dataSourceName- the name of the datasource this adapter is bound tofetchSize- the default fetch size to use when reading from the datasourcebatchSize- the default batch size to use when writing to the datasource
-
-
Method Details
-
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
-
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
-
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
-
existsBean
The CpoAdapter will check to see if this object exists in the datasource.Example:
class SomeObject so = new SomeObject(); long count = 0; class CpoAdapter cpo = null; try { cpo = new CpoAdapter(new JdbcDataSourceInfo(driver, url, user, password,1,1,false)); } catch (CpoException ce) { // Handle the error cpo = null; } if (cpo!=null) { so.setId(1); so.setName("SomeName"); try{ CpoWhere where = cpo.newCpoWhere(Logical.NONE, id, Comparison.EQ); count = cpo.existsObject("SomeExistCheck",so, where); if (count>0) { // object exists } else { // object does not exist } } catch (CpoException ce) { // Handle the error } }- Specified by:
existsBeanin interfaceCpoAdapter- Type Parameters:
T- The type of the JavaBean- Parameters:
query- The function group and clauses to applybean- This is an object that has been defined within the metadata of the datasource. If the class is not defined an exception will be thrown. This object will be searched for inside the datasource.- Returns:
- The number of objects that exist in the datasource that match the specified object
- Throws:
CpoException- Thrown if there are errors accessing the datasource
-