Class JdbcCpoAdapter

All Implemented Interfaces:
Serializable, CpoAdapter
Direct Known Subclasses:
JdbcCpoTrxAdapter

public class JdbcCpoAdapter extends CpoBaseAdapter<DataSource>
JdbcCpoAdapter is the JDBC implementation of CpoAdapter, a set of routines that are responsible for managing value beans from a jdbc datasource.
Author:
david berry
See Also:
  • Method Details

    • getInstance

      public static JdbcCpoAdapter getInstance(JdbcCpoMetaDescriptor metaDescriptor, DataSourceInfo<DataSource> jdsiTrx) throws CpoException
      Finds or Creates a JdbcCpoAdapter.
      Parameters:
      metaDescriptor - - The meta descriptor for the datasource
      jdsiTrx - - The datasurce info
      Returns:
      A JdbcCpoAdapter
      Throws:
      CpoException - - An error occurred finding of creating the datasource adapter
    • getInstance

      public static JdbcCpoAdapter getInstance(JdbcCpoMetaDescriptor metaDescriptor, DataSourceInfo<DataSource> jdsiWrite, DataSourceInfo<DataSource> jdsiRead) throws CpoException
      Creates a JdbcCpoAdapter.
      Parameters:
      metaDescriptor - This datasource that identifies the cpo metadata datasource
      jdsiWrite - The datasource that identifies the transaction database for write transactions.
      jdsiRead - The datasource that identifies the transaction database for read-only transactions.
      Returns:
      - A JdbcCpoAdapter
      Throws:
      CpoException - exception
    • existsBean

      public <T> long existsBean(CpoQuery query, T bean) throws CpoException
      Description copied from class: CpoBaseAdapter
      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:
      existsBean in interface CpoAdapter
      Specified by:
      existsBean in class CpoBaseAdapter<DataSource>
      Type Parameters:
      T - The type of the JavaBean
      Parameters:
      query - The function group and clauses to apply
      bean - 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
    • newWhere

      public CpoWhere newWhere()
      Description copied from interface: CpoAdapter
      Creates an empty CpoWhere.
      
       CpoWhere where = cpo.newWhere();
       
      Specified by:
      newWhere in interface CpoAdapter
      Overrides:
      newWhere in class CpoBaseAdapter<DataSource>
      Returns:
      A CpoWhere
    • newWhere

      public <T> CpoWhere newWhere(Logical logical, String attr, Comparison comp, T value)
      Description copied from interface: CpoAdapter
      Creates a CpoWhere comparing the attribute to the value.
      
       CpoWhere where = cpo.newWhere(Logical.NONE, "id", Comparison.EQ, 42);
       
      Specified by:
      newWhere in interface CpoAdapter
      Overrides:
      newWhere in class CpoBaseAdapter<DataSource>
      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 constrain
      comp - The comparison operator
      value - The value to compare against
      Returns:
      A CpoWhere
    • newWhere

      public <T> CpoWhere newWhere(Logical logical, String attr, Comparison comp, T value, boolean not)
      Description copied from interface: CpoAdapter
      Creates a CpoWhere comparing the attribute to the value, optionally negated.
      Specified by:
      newWhere in interface CpoAdapter
      Overrides:
      newWhere in class CpoBaseAdapter<DataSource>
      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 constrain
      comp - The comparison operator
      value - The value to compare against
      not - true to negate the comparison
      Returns:
      A CpoWhere
    • getCpoMetaDescriptor

      public CpoMetaDescriptor getCpoMetaDescriptor()
      Description copied from interface: CpoAdapter
      Get the CpoMetaDescriptor
      Returns:
      The CpoMetaDescriptor
    • getCpoAttributes

      public List<CpoAttribute> getCpoAttributes(String expression) throws CpoException
      Description copied from interface: CpoAdapter
      Gets the CpoAttribute definitions matching a comma-separated expression of attribute names, as declared in the meta data for this bean's class.
      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