public abstract class JDBCObjectController<DBOBJ extends JDBCObject<DBOBJ>> extends MappedAttributesObject
Modifier and Type | Field and Description |
---|---|
protected java.lang.Class<DBOBJ> |
ivDBObjCls
The class of the JDBC object associated with the controller.
|
protected int |
ivFieldCount
The number of fields in the table associated with the controller.
|
protected java.lang.String |
ivFieldKeyAlt
The alternate key definition resource key for the table associated with
the controller.
|
protected java.lang.String |
ivFieldKeyPri
The primary key definition resource key for the table associated with
the controller.
|
protected java.lang.String |
ivFieldResPfx
The field definition resource key prefix for the table associated with
the controller.
|
protected int |
ivSyncLast
The zero-based index of the last sync field for the table associated
with the controller.
|
protected java.lang.String |
ivSyncType
The sync record type for the table associated with the controller.
|
protected java.lang.String |
ivTableName
The name of the database table associated with the controller.
|
private static long |
serialVersionUID
The class' serialization version id.
|
ivHashCode, ivHashFlds, ivObjAttrs
Modifier | Constructor and Description |
---|---|
protected |
JDBCObjectController(java.lang.Class<DBOBJ> objcls)
A special constructor for the abstract object controller.
|
protected |
JDBCObjectController(java.lang.Class<DBOBJ> objcls,
java.lang.String tblname)
The recommended constructor for the abstract object controller.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(DBOBJ obj)
Adds a new record to the table associated with the controller.
|
int |
add(DBOBJ obj,
boolean logdup)
Adds a new record to the table associated with the controller.
|
int |
add(java.lang.String[] data)
Adds a new record to the table associated with the controller using the
given string array of field values.
|
protected java.util.HashMap<java.lang.String,java.lang.Object> |
arrayToMap(java.lang.String[] data)
Returns a map of field names and values using the given string array of
field values.
|
protected java.util.HashMap<java.lang.String,java.lang.Object> |
arrayToMap(java.lang.String[] data,
java.util.HashMap<java.lang.String,java.lang.Object> attrs)
Returns a map of field names and values using the given string array of
field values.
|
private java.util.HashMap<java.lang.String,java.lang.Object> |
arrayToMap(java.lang.String[] data,
java.util.HashMap<java.lang.String,java.lang.Object> attrs,
boolean forupdate)
Returns a map of field names and values using the given string array of
field values.
|
int |
countAll()
Returns the number of records in the table associated with the controller.
|
boolean |
delete(DBOBJ obj)
Deletes an existing record from the table associated with the controller.
|
int |
delete(java.lang.String[] data)
Deletes one or more existing records from the table associated with the
controller.
|
boolean |
deleteAll()
Deletes all records in the table associated with the controller.
|
void |
dispose()
Disposes of the controller and its owned objects.
|
boolean |
equals(java.lang.Object obj)
Compares the given object to this object and determines if the two are
equal.
|
java.util.ArrayList<DBOBJ> |
getAll()
Returns a collection of all records in the table associated with the
controller.
|
java.sql.Connection |
getConnection()
Returns the JDBC connection associated with the controller.
|
JDBCConnectionInfo |
getConnectionInfo()
Returns the JDBC connection information object that owns this controller.
|
<DBOBJCTLR extends JDBCObjectController<? extends JDBCObject<?>>> |
getController(java.lang.Class<DBOBJCTLR> ctlrcls)
Returns the JDBC object controller for the given controller class.
|
java.lang.String[] |
getFieldNames()
Returns an array of field names for the table associated with the
controller.
|
protected java.lang.String[] |
getFieldNamesForKey()
Returns an array of primary key field names for the table associated with
the controller.
|
protected java.lang.String[] |
getFieldNamesForUpdate()
Returns an array of update field names for the table associated with the
controller.
|
protected boolean[] |
getFieldNulls()
Returns an array of field nullable flags for the table associated with
the controller.
|
protected boolean[] |
getFieldNullsForKey()
Returns an array of primary key field nullable flags for the table
associated with the controller.
|
protected boolean[] |
getFieldNullsForUpdate()
Returns an array of update field nullable flags for the table associated
with the controller.
|
protected java.lang.String |
getFieldsForOrderBy()
Returns the SQL 'order by' clause field string for the table associated
with the controller.
|
protected java.lang.String |
getFieldsForWhere()
Returns the SQL 'where' clause field string for the table associated with
the controller.
|
protected double |
getFieldSize(java.lang.String fldname)
Returns the size of a field (metadata column size and decimal digits).
|
protected int[] |
getFieldTypes()
Returns an array of field types (java.sql.Types) for the table associated
with the controller.
|
protected int[] |
getFieldTypesForKey()
Returns an array of primary key field types (java.sql.Types) for the
table associated with the controller.
|
protected int[] |
getFieldTypesForUpdate()
Returns an array of update field types (java.sql.Types) for the table
associated with the controller.
|
protected java.lang.String |
getStatementForDelete()
Returns the SQL delete statement string for the table associated with
the controller.
|
protected java.lang.String |
getStatementForGet()
Returns the SQL get statement string for the table associated with
the controller.
|
protected java.lang.String |
getStatementForGetAll()
Returns the SQL get all statement string for the table associated with
the controller.
|
protected java.lang.String |
getStatementForInsert()
Returns the SQL insert statement string for the table associated with
the controller.
|
protected java.lang.String |
getStatementForUpdate()
Returns the SQL update statement string for the table associated with
the controller.
|
protected java.lang.String |
getStatementKey(java.lang.String stmtsfx)
Returns the full SQL statement resource key for a given statement resource
key suffix.
|
protected java.lang.String |
getStatementString(java.lang.String stmtsfx)
Returns an SQL statement string for a given statement resource key suffix.
|
java.lang.String |
getTableName()
Returns the name of the database table associated with the controller.
|
protected boolean |
hasFieldNamesForKey()
Answers if the table associated with the controller has key field names.
|
protected boolean |
hasFieldNamesForUpdate()
Answers if the table associated with the controller has update field names.
|
protected boolean |
isDuplicate(java.lang.Exception e)
Answers if the given exception is a SQL duplicate record exception.
|
protected java.lang.String[] |
resultSetToArray(java.sql.ResultSet rs)
Returns a string array of sync field values from the given SQL result set.
|
protected java.util.HashMap<java.lang.String,java.lang.Object> |
resultSetToMap(java.sql.ResultSet rs)
Returns a map of field names and values from the given SQL result set.
|
protected java.util.HashMap<java.lang.String,java.lang.Object> |
resultSetToMap(java.sql.ResultSet rs,
java.lang.String tblname)
Returns a map of field names and values from the given SQL result set.
|
DBOBJ |
resultSetToObject(java.sql.ResultSet rs)
Returns a database object from the given SQL result set.
|
void |
setConnectionInfo(JDBCConnectionInfo cninf)
Sets the JDBC connection information object that owns this controller.
|
protected boolean |
setPSDeleteValues(java.sql.PreparedStatement ps,
DBOBJ obj)
Sets the parameter values for the SQL prepared statement that will be
used to delete the given object.
|
protected boolean |
setPSExistsValues(java.sql.PreparedStatement ps,
DBOBJ obj)
Sets the parameter values for the SQL prepared statement that will be
used to determine the existence of the given object.
|
protected boolean |
setPSInsertValues(java.sql.PreparedStatement ps,
DBOBJ obj)
Sets the parameter values for the SQL prepared statement that will be
used to insert the given object.
|
protected boolean |
setPSUpdateValues(java.sql.PreparedStatement ps,
DBOBJ obj)
Sets the parameter values for the SQL prepared statement that will be
used to update the given object.
|
protected void |
setPSValue(java.sql.PreparedStatement ps,
DBOBJ obj,
java.lang.String fldname,
int fldtype,
boolean fldnull,
int parmidx)
Sets a parameter value for an SQL prepared statement using the supplied
values.
|
boolean |
update(DBOBJ obj)
Updates an existing record in the table associated with the controller.
|
int |
update(java.lang.String[] data)
Updates an existing record in the table associated with the controller
using the given string array of field values.
|
DBOBJ |
valuesToObject(java.util.HashMap<java.lang.String,java.lang.Object> attrs)
Returns a database object from the given set of attributes.
|
cloneMapAttributes, formatValue, formatValue, getHashFields, getMapArrayList, getMapAttributes, getMapBigDecimal, getMapBoolean, getMapDate, getMapDouble, getMapInteger, getMapLong, getMapMapped, getMapObject, getMapShort, getMapString, getMapString, getMapStringBuffer, getMapStringBuilder, getMapTime, getMapTimestamp, getMapVector, hashCode, setHashFields, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMap, setMapAttributes, setMapObject, setMapTime, setMapTimestamp, toStringArray
private static final long serialVersionUID
protected java.lang.Class<DBOBJ extends JDBCObject<DBOBJ>> ivDBObjCls
protected java.lang.String ivTableName
protected java.lang.String ivFieldResPfx
protected java.lang.String ivFieldKeyPri
protected java.lang.String ivFieldKeyAlt
protected int ivFieldCount
protected java.lang.String ivSyncType
protected int ivSyncLast
protected JDBCObjectController(java.lang.Class<DBOBJ> objcls)
objcls
- (Class) The class of the JDBC object associated with
the controller.protected JDBCObjectController(java.lang.Class<DBOBJ> objcls, java.lang.String tblname)
objcls
- (Class) The class of the JDBC object associated with
the controller.tblname
- (String) The name of the database table associated
with the controller.public boolean equals(java.lang.Object obj)
equals
in class MappedAttributesObject
obj
- (Object) The object to compare with this object.true
if the specified object is equal to
this object, otherwise false
.public boolean add(DBOBJ obj)
obj
- (JDBCObject) The object for the record to be added.true
if the record added successfully,
otherwise false
.public int add(DBOBJ obj, boolean logdup)
obj
- (JDBCObject) The object for the record to be added.logdup
- (boolean) true
if duplicate errors are to
be logged as an exception, otherwise false
. When
duplicates are logged, the return value of 1 is never returned.public int add(java.lang.String[] data)
data
- (String[]) A string array of field values.protected java.util.HashMap<java.lang.String,java.lang.Object> arrayToMap(java.lang.String[] data) throws java.lang.Exception
Types.OTHER
values.
data
- (String[]) A string array of field values.java.lang.Exception
- - if an error occurs while processing the array of
field values.protected java.util.HashMap<java.lang.String,java.lang.Object> arrayToMap(java.lang.String[] data, java.util.HashMap<java.lang.String,java.lang.Object> attrs) throws java.lang.Exception
Types.OTHER
values.
data
- (String[]) A string array of field values.attrs
- (HashMap) A pre-existing collection of field names and
values.java.lang.Exception
- - if an error occurs while processing the array of
field values.private java.util.HashMap<java.lang.String,java.lang.Object> arrayToMap(java.lang.String[] data, java.util.HashMap<java.lang.String,java.lang.Object> attrs, boolean forupdate) throws java.lang.Exception
Types.OTHER
values.
data
- (String[]) A string array of field values.attrs
- (HashMap) A pre-existing collection of field names and
values.forupdate
- (boolean) true
if the string array of
field values is going to be used to update an existing object,
otherwise false
. When true
, fields
in the string array that contain an empty string are ignored
(a map value is not set); plus, for CHAR and VARCHAR fields,
a double quoted empty string (\"\") in the string array denotes
that the map field value should be set to an empty string.java.lang.Exception
- - if an error occurs while processing the array of
field values.public int countAll()
public boolean delete(DBOBJ obj)
obj
- (JDBCObject) The object for the record to be deleted.true
if the record deleted successfully,
otherwise false
.public int delete(java.lang.String[] data)
NOTE: This method provides no actual logic and always returns success. Subclasses must provide their own implementation of what's needed here.
data
- (String[]) A string array of field values.public boolean deleteAll()
true
if the deletes are successful,
otherwise false
.public void dispose()
public java.util.ArrayList<DBOBJ> getAll()
public java.sql.Connection getConnection()
getConnectionInfo().getConnection()
.public JDBCConnectionInfo getConnectionInfo()
public <DBOBJCTLR extends JDBCObjectController<? extends JDBCObject<?>>> DBOBJCTLR getController(java.lang.Class<DBOBJCTLR> ctlrcls)
getConnectionInfo().getController()
.ctlrcls
- (Class) The class for the desired controller.public java.lang.String[] getFieldNames()
protected java.lang.String[] getFieldNamesForKey()
protected java.lang.String[] getFieldNamesForUpdate()
protected boolean[] getFieldNulls()
protected boolean[] getFieldNullsForKey()
protected boolean[] getFieldNullsForUpdate()
protected double getFieldSize(java.lang.String fldname)
fldname
- (String) The name of a field in the table associated
with this controller.protected int[] getFieldTypes()
Types.OTHER
values.
protected int[] getFieldTypesForKey()
Types.OTHER
values.
protected int[] getFieldTypesForUpdate()
Types.OTHER
values.
protected java.lang.String getFieldsForOrderBy()
protected java.lang.String getFieldsForWhere()
protected java.lang.String getStatementForDelete()
protected java.lang.String getStatementForGet()
protected java.lang.String getStatementForGetAll()
protected java.lang.String getStatementForInsert()
protected java.lang.String getStatementForUpdate()
protected java.lang.String getStatementKey(java.lang.String stmtsfx)
stmtsfx
- (String) The resource key suffix for the desired SQL
statement. "SQL.protected java.lang.String getStatementString(java.lang.String stmtsfx)
stmtsfx
- (String) The resource key suffix for the desired SQL
statement. "SQL.public java.lang.String getTableName()
protected boolean hasFieldNamesForKey()
true
if the table has key field names,
otherwise false
.protected boolean hasFieldNamesForUpdate()
true
if the table has update field names,
otherwise false
.protected boolean isDuplicate(java.lang.Exception e)
e
- (Exception) The exception to check.true
if the exception is a SQL duplicate
record exception, otherwise false
.protected java.lang.String[] resultSetToArray(java.sql.ResultSet rs) throws java.sql.SQLException
Types.OTHER
values.
rs
- (ResultSet) The result set containing the database record
from which the field values are to be obtained.java.sql.SQLException
- - if an error occurs while processing the result
set.protected java.util.HashMap<java.lang.String,java.lang.Object> resultSetToMap(java.sql.ResultSet rs) throws java.sql.SQLException
Types.OTHER
values.
rs
- (ResultSet) The result set containing the database record
from which the names and values are to be obtained.java.sql.SQLException
- - if an error occurs while processing the result
set.protected java.util.HashMap<java.lang.String,java.lang.Object> resultSetToMap(java.sql.ResultSet rs, java.lang.String tblname) throws java.sql.SQLException
Types.OTHER
values.
rs
- (ResultSet) The result set containing the database record
from which the names and values are to be obtained.tblname
- (String) The name of a table. Only store column values
from this table in the map.java.sql.SQLException
- - if an error occurs while processing the result
set.public DBOBJ resultSetToObject(java.sql.ResultSet rs) throws java.sql.SQLException
rs
- (ResultSet) The result set containing the database record
from which the new object is to be created.java.sql.SQLException
- - if an error occurs while processing the result
set.public void setConnectionInfo(JDBCConnectionInfo cninf)
cninf
- (JDBCConnectionInfo) The controller's JDBC connection
information object.protected boolean setPSDeleteValues(java.sql.PreparedStatement ps, DBOBJ obj)
Types.OTHER
values.
ps
- (PreparedStatement) The SQL prepared statement that is to
have its values set.obj
- (JDBCObject) The object that is to be deleted.true
if setting the SQL parameters is
successful, otherwise false
.protected boolean setPSExistsValues(java.sql.PreparedStatement ps, DBOBJ obj)
Types.OTHER
values.
ps
- (PreparedStatement) The SQL prepared statement that is to
have its values set.obj
- (JDBCObject) The object that is to be checked.true
if setting the SQL parameters is
successful, otherwise false
.protected boolean setPSInsertValues(java.sql.PreparedStatement ps, DBOBJ obj)
Types.OTHER
values.
ps
- (PreparedStatement) The SQL prepared statement that is to
have its values set.obj
- (JDBCObject) The object that is to be inserted.true
if setting the SQL parameters is
successful, otherwise false
.protected boolean setPSUpdateValues(java.sql.PreparedStatement ps, DBOBJ obj)
Types.OTHER
values.
ps
- (PreparedStatement) The SQL prepared statement that is to
have its values set.obj
- (JDBCObject) The object that is to be updated.true
if setting the SQL parameters is
successful, otherwise false
.protected void setPSValue(java.sql.PreparedStatement ps, DBOBJ obj, java.lang.String fldname, int fldtype, boolean fldnull, int parmidx) throws java.lang.Exception
Types.OTHER
values.
ps
- (PreparedStatement) The SQL prepared statement that is to
have a value set.obj
- (JDBCObject) The object that contains the value to set.fldname
- (String) The name of the field for the value to set.fldtype
- (int) The type of field for the value to set.fldnull
- (boolean) The nullable flag of field for the value to
set.parmidx
- (int) The index of the parameter to set.java.lang.Exception
- - if an error occurs while setting the parameter
value.public boolean update(DBOBJ obj)
obj
- (JDBCObject) The object for the record to be updated.true
if the record updated successfully,
otherwise false
.public int update(java.lang.String[] data)
NOTE: This method provides no actual logic and always returns success. Subclasses must provide their own implementation of what's needed here.
data
- (String[]) A string array of field values.public DBOBJ valuesToObject(java.util.HashMap<java.lang.String,java.lang.Object> attrs)
attrs
- (HashMap) The attributes to assign to the new object.