atg.cortex
Class Cortex

java.lang.Object
  extended by atg.cortex.PropertyList
      extended by atg.cortex.ResultSetProcessor
          extended by atg.cortex.Query
              extended by atg.cortex.Cortex

public class Cortex
extends Query

A Cortex is a subclass of Query in which some properties have been marked as "keys". These keys allow a bean to uniquely identify a set of rows in a set of tables. This allows functions such as inserting, deleting, updating, and selecting to be performed on an object-by-object basis.

Note that this implementation assumes that the columns are confined to a single table, that each property maps to at most one column, and each column maps to at most one property.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Constructor Summary
Cortex()
          Creates and returns a new Cortex
 
Method Summary
 void addKey(java.lang.String pKeyPropertyName)
          Adds the specified property as one of the primary keys.
 int delete(java.sql.Connection pConnection)
          Deletes all rows from the class' table.
 int delete(java.util.Dictionary pSelector, boolean pIsAnd, java.sql.Connection pConnection)
          Deletes all rows from the class' tables whose values match the specified selector.
 int delete(java.lang.Object[] pObjects, java.sql.Connection pConnection)
          Deletes all rows from the class' table whose primary key matches the primary key of the specified objects.
 int delete(java.lang.Object pObject, java.sql.Connection pConnection)
          Deletes all rows from the class' tables whose primary key matches the primary key of the specified object.
 ColumnProperty getColumnFromProperty(java.lang.String pPropertyName)
          Returns the ColumnProperty corresponding to the specified property, or null if not found.
 java.lang.String getColumnNameFromProperty(java.lang.String pPropertyName)
          Returns the full column name corresponding to the specified property, or null if not found.
 java.lang.String getKey(int pIndex)
          Returns the name of the property acting as the key at the specified index.
 int getKeyCount()
          Returns the number of keys
 java.util.Dictionary getPropertyToColumnMap()
          Returns the Dictionary mapping property name to ColumnProperty.
 int insert(java.util.Dictionary pInsertValues, java.sql.Connection pConnection)
          Inserts a new set row into the class' table, using only the property names and values specified in the given Dictionary.
 int insert(java.lang.Object[] pObjects, java.sql.Connection pConnection)
          Inserts a new set of rows into the class' tables.
 int insert(java.lang.Object[] pObjects, java.lang.String[] pPropertyNames, java.sql.Connection pConnection)
          Inserts a new set of rows into the class' tables.
 int insert(java.lang.Object pObject, java.sql.Connection pConnection)
          Inserts a new row into the class' tables.
 int insert(java.lang.Object pObject, java.lang.String[] pPropertyNames, java.sql.Connection pConnection)
          Inserts a new row into the class' tables.
 java.lang.Object[] select(java.sql.Connection pConnection)
          Selects all rows from this Cortex's table.
 java.lang.Object[] select(java.util.Dictionary pSelector, boolean pIsAnd, java.sql.Connection pConnection)
          Searches for the rows in the database that match the specified selector.
 java.lang.Object[] select(java.lang.Object[] pObjects, java.sql.Connection pConnection)
          Searches for the specified rows in the database, where each row is selected by the corresponding object in the specified array.
 java.lang.Object select(java.lang.Object pObject, java.sql.Connection pConnection)
          Searches for the specified row in the database.
 int update(java.util.Dictionary pSelector, boolean pIsAnd, java.util.Dictionary pUpdateValues, java.sql.Connection pConnection)
          Updates all rows from the class' tables whose values match the specified selector.
 int update(java.lang.Object[] pObjects, java.sql.Connection pConnection)
          Updates all rows in the class' tables whose primary key matches the primary key of the specified objects.
 int update(java.lang.Object[] pObjects, java.lang.String[] pPropertyNames, java.sql.Connection pConnection)
          Updates all rows in the class' tables whose primary key matches the primary key of the specified objects.
 int update(java.lang.Object pObject, java.sql.Connection pConnection)
          Updates all rows in the class' tables whose primary key matches the primary key of the specified object.
 int update(java.lang.Object pObject, java.lang.String[] pPropertyNames, java.sql.Connection pConnection)
          Updates all rows in the class' tables whose primary key matches the primary key of the specified object.
 
Methods inherited from class atg.cortex.Query
addColumnProperties, addColumnProperty, getColumnProperties, getColumnProperty, getColumnPropertyCount, getSelectStatement, getTableName, getTableNames
 
Methods inherited from class atg.cortex.ResultSetProcessor
processResultSet, processResultSet, processResultSetRow, processResultSetRow, processResultSetRow
 
Methods inherited from class atg.cortex.PropertyList
addProperties, addProperty, getBeanClass, getBeanClasses, getClassProperties, getProperties, getProperty, getPropertyCount, getPropertyToClassTable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

Cortex

public Cortex()
Creates and returns a new Cortex

Method Detail

addKey

public void addKey(java.lang.String pKeyPropertyName)
Adds the specified property as one of the primary keys.


getKeyCount

public int getKeyCount()
Returns the number of keys


getKey

public java.lang.String getKey(int pIndex)
Returns the name of the property acting as the key at the specified index.


getPropertyToColumnMap

public java.util.Dictionary getPropertyToColumnMap()
Returns the Dictionary mapping property name to ColumnProperty.


getColumnFromProperty

public ColumnProperty getColumnFromProperty(java.lang.String pPropertyName)
Returns the ColumnProperty corresponding to the specified property, or null if not found. If more than one column corresponds to the property, then only one of the columns will be returned.


getColumnNameFromProperty

public java.lang.String getColumnNameFromProperty(java.lang.String pPropertyName)
Returns the full column name corresponding to the specified property, or null if not found. If more than one column corresponds to the property, then only one of the column names will be returned.


insert

public int insert(java.lang.Object pObject,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Inserts a new row into the class' tables. The values of the row are taken from the values of the object's properties. Any ColumnProperties marked as read-only are not included in the insert statement.

Parameters:
pObject - the object whose fields are to be to be inserted
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows inserted. Note that if the object spans multiple tables, then the number of rows will be multiplied by the number of tables.
Throws:
java.sql.SQLException - if a database access error occurs

insert

public int insert(java.lang.Object[] pObjects,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Inserts a new set of rows into the class' tables. The values of each row are taken from the values of each object's properties.

Parameters:
pObjects - the objects whose fields are to be to be inserted
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows inserted. Note that if the object spans multiple tables, then the number of rows will be multiplied by the number of tables.
Throws:
java.sql.SQLException - if a database access error occurs

insert

public int insert(java.lang.Object pObject,
                  java.lang.String[] pPropertyNames,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Inserts a new row into the class' tables. The values of the row are taken from the values of the object's properties. Only the proeprties specified in the property name list will be inserted.

Parameters:
pObject - the object whose fields are to be to be inserted
pPropertyNames - an array of the names of the properties to be updated.
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows inserted. Note that if the object spans multiple tables, then the number of rows will be multiplied by the number of tables.
Throws:
java.sql.SQLException - if a database access error occurs

insert

public int insert(java.lang.Object[] pObjects,
                  java.lang.String[] pPropertyNames,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Inserts a new set of rows into the class' tables. The values of each row are taken from the values of each object's properties. Only the properties specified in the property name list will be inserted.

Parameters:
pObjects - the objects whose fields are to be to be inserted
pPropertyNames - an array of the names of the properties to be updated.
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows inserted. Note that if the object spans multiple tables, then the number of rows will be multiplied by the number of tables.
Throws:
java.sql.SQLException - if a database access error occurs

insert

public int insert(java.util.Dictionary pInsertValues,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Inserts a new set row into the class' table, using only the property names and values specified in the given Dictionary.

Parameters:
pInsertValues - a dictionary of values to be inserted. The keys of the dictionary are the property names to be inserted, and the values are the new values to be set for the columns corresponding to those property names.
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows inserted. Note that if the object spans multiple tables, then the number of rows will be multiplied by the number of tables.
Throws:
java.sql.SQLException - if a database access error occurs

delete

public int delete(java.sql.Connection pConnection)
           throws java.sql.SQLException
Deletes all rows from the class' table.

Parameters:
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows deleted
Throws:
java.sql.SQLException - if a database access error occurs

delete

public int delete(java.lang.Object pObject,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Deletes all rows from the class' tables whose primary key matches the primary key of the specified object.

Parameters:
pObject - the object specifying the primary key value of the objects to be deleted.
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows deleted
Throws:
java.sql.SQLException - if a database access error occurs

delete

public int delete(java.lang.Object[] pObjects,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Deletes all rows from the class' table whose primary key matches the primary key of the specified objects.

Parameters:
pObjects - the object specifying the primary key value of the objects to be deleted.
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows deleted
Throws:
java.sql.SQLException - if a database access error occurs

delete

public int delete(java.util.Dictionary pSelector,
                  boolean pIsAnd,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Deletes all rows from the class' tables whose values match the specified selector. The selector is a Dictionary mapping property names to the values to be selected on those properties. Only those properties listed in the Dictionary will be considered as part of the query. A flag indicates if a selected row must match all entries in the selector, or any entry in the selector.

Parameters:
pSelector - the Dictionary mapping property name to the value to be matched for that property. Primitive values, such as "int", should be specified in object form - i.e., "Integer".
pIsAnd - flag indicating whether the entries of the selector will be placed in an AND clause or OR clause. If true, then only those rows that match all of the selector criteria will be returned. Otherwise, rows that match any of the selector criteria will be returned.
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows deleted
Throws:
java.sql.SQLException - if a database access error occurs

update

public int update(java.lang.Object pObject,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Updates all rows in the class' tables whose primary key matches the primary key of the specified object.

Parameters:
pObject - the object specifying the primary key value of the objects to be deleted, along with the new values to update into the rows.
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows updated
Throws:
java.sql.SQLException - if a database access error occurs

update

public int update(java.lang.Object[] pObjects,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Updates all rows in the class' tables whose primary key matches the primary key of the specified objects.

Parameters:
pObject - the objects specifying the primary key value of the objects to be updated, along with the new values to update into the rows.
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows updated
Throws:
java.sql.SQLException - if a database access error occurs

update

public int update(java.lang.Object pObject,
                  java.lang.String[] pPropertyNames,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Updates all rows in the class' tables whose primary key matches the primary key of the specified object. The specified object also contains the new values to be updated. Only the properties specified in the property name list will be updated.

Parameters:
pObject - the object specifying the primary key value of the objects to be deleted, along with the new values to update into the rows.
pPropertyNames - an array of the names of the properties to be updated.
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows updated
Throws:
java.sql.SQLException - if a database access error occurs

update

public int update(java.lang.Object[] pObjects,
                  java.lang.String[] pPropertyNames,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Updates all rows in the class' tables whose primary key matches the primary key of the specified objects. The specified objects also contain the new values to be updated. Only the properties specified in the property name list will be updated.

Parameters:
pObjects - the list of objects specifying the primary key value of the objects to be deleted, along with the new values to update into the rows.
pPropertyNames - an array of the names of the properties to be updated.
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows updated
Throws:
java.sql.SQLException - if a database access error occurs

update

public int update(java.util.Dictionary pSelector,
                  boolean pIsAnd,
                  java.util.Dictionary pUpdateValues,
                  java.sql.Connection pConnection)
           throws java.sql.SQLException
Updates all rows from the class' tables whose values match the specified selector. The selector is a Dictionary mapping property names to the values to be selected on those properties. Only those properties listed in the Dictionary will be considered as part of the query. A flag indicates if a selected row must match all entries in the selector, or any entry in the selector.

Parameters:
pSelector - the Dictionary mapping property name to the value to be matched for that property. Primitive values, such as "int", should be specified in object form - i.e., "Integer".
pIsAnd - flag indicating whether the entries of the selector will be placed in an AND clause or OR clause. If true, then only those rows that match all of the selector criteria will be returned. Otherwise, rows that match any of the selector criteria will be returned.
pUpdateValues - a dictionary of values to be updated. The keys of the dictionary are the property names to be updated, and the values are the new values to be set for the columns corresponding to those property names.
pConnection - the JDBC connection to use to perform the operation
Returns:
the number of rows updated
Throws:
java.sql.SQLException - if a database access error occurs

select

public java.lang.Object[] select(java.sql.Connection pConnection)
                          throws java.sql.SQLException
Selects all rows from this Cortex's table. The rows are converted to objects and returned in an array.

Parameters:
pConnection - the JDBC connection to use to perform the operation
Returns:
the table's rows converted to objects
Throws:
java.sql.SQLException - if a database access error occurs

select

public java.lang.Object select(java.lang.Object pObject,
                               java.sql.Connection pConnection)
                        throws java.sql.SQLException
Searches for the specified row in the database. The entry in the database to be retrieved is identified solely by the object's primary key, which must be set. If the row is found in the database, then a version of the object with all of the properties filled in from the database is returned. In many implementations, the argument passed to the function will be modified in place and returned. If multiple rows are found, then it is not specified which row will be returned.

Parameters:
pObject - the object specifying the primary key value of the object to be found.
pConnection - the JDBC connection to use to perform the operation
Returns:
the found object with properties filled in from the row, or null if not found.
Throws:
java.sql.SQLException - if a database access error occurs

select

public java.lang.Object[] select(java.lang.Object[] pObjects,
                                 java.sql.Connection pConnection)
                          throws java.sql.SQLException
Searches for the specified rows in the database, where each row is selected by the corresponding object in the specified array. The entry in the database to be retrieved is identified solely by the object's primary key, which must be set. If the row is found in the database, then a version of the object with all of the properties filled in from the database is put into the return array. The objects passed to the function will be modified in place and returned. If multiple rows are found for a particular object, then only one row is placed in the array (it is not specified which one).

Parameters:
pObjects - the objects specifying the primary key value of the objects to be found. Each object in the array is used to select one row from the database, which is returned as a single object in the return value.
pConnection - the JDBC connection to use to perform the operation
Returns:
the list of found objects with properties filled in from the rows. Each element of the return value is selected from the corresponding element in the object array parameter. If no row was found for one of the objects, then that element is set to null. The return value type is Object[], and should not be expected to be castable to the type of object represented by this Cortex. For example, if this Cortex represents a "Person" class, the return value is not necessarily of type Person[].
Throws:
java.sql.SQLException - if a database access error occurs

select

public java.lang.Object[] select(java.util.Dictionary pSelector,
                                 boolean pIsAnd,
                                 java.sql.Connection pConnection)
                          throws java.sql.SQLException
Searches for the rows in the database that match the specified selector. The selector is a Dictionary mapping property names to the values to be selected on those properties. Only those properties listed in the Dictionary will be considered as part of the query. A flag indicates if a selected row must match all entries in the selector, or any entry in the selector.

Parameters:
pSelector - the Dictionary mapping property name to the value to be matched for that property. Primitive values, such as "int", should be specified in object form - i.e., "Integer".
pIsAnd - flag indicating whether the entries of the selector will be placed in an AND clause or OR clause. If true, then only those rows that match all of the selector criteria will be returned. Otherwise, rows that match any of the selector criteria will be returned.
pConnection - the JDBC connection to use to perform the operation
Returns:
an array of the selected rows, converted to objects. The return value type is Object[], and should not be expected to be castable to the type of object represented by this Cortex. For example, if this Cortex represents a "Person" class, the return value is not necessarily of type Person[].
Throws:
java.sql.SQLException - if a database access error occurs