public abstract class BaseConditionsObject extends Object implements ConditionsObject
Modifier and Type | Field and Description |
---|---|
(package private) static String |
COLLECTION_ID_FIELD
Field name for collection ID.
|
private Connection |
connection
The JDBC connection used for database operations.
|
(package private) static SimpleDateFormat |
DEFAULT_DATE_FORMAT
Date formatting for insert statement.
|
private FieldValues |
fieldValues
The field values which is a map of key-value pairs corresponding to column values in the database.
|
private int |
rowId
The row ID of the object in its table.
|
private TableMetaData |
tableMetaData
The information about the associated table such as the table and column names.
|
(package private) static int |
UNSET_COLLECTION_ID
Value that indicates collection ID is not set (no collection assigned).
|
(package private) static int |
UNSET_ROW_ID
Value that indicates row ID is not assigned (new record).
|
Modifier | Constructor and Description |
---|---|
protected |
BaseConditionsObject()
No argument class constructor; usable by sub-classes only.
|
|
BaseConditionsObject(Connection connection,
TableMetaData tableMetaData)
Public class constructor.
|
|
BaseConditionsObject(Connection connection,
TableMetaData tableMetaData,
FieldValues fields)
Fully qualified class constructor.
|
Modifier and Type | Method and Description |
---|---|
private String |
buildInsertStatement()
Create a SQL insert string for a prepared statement.
|
private String |
buildUpdateStatement()
Build a SQL update string for a prepared statement.
|
protected static String |
defaultToString(BaseConditionsObject object)
Perform the default to string operation on a conditions object.
|
void |
delete()
Delete the object from the database using its row ID.
|
boolean |
equals(Object object) |
Integer |
getCollectionId()
Get the collection ID of the object.
|
<T> T |
getFieldValue(Class<T> type,
String name)
Get a field value by name.
|
<T> T |
getFieldValue(String name)
Get a field value.
|
FieldValues |
getFieldValues()
Get the field values.
|
int |
getRowId()
Get the row ID.
|
TableMetaData |
getTableMetaData()
Get the table meta data for the object.
|
boolean |
hasValidCollectionId()
Return
true if collection ID is valid. |
void |
insert()
Insert the object into the conditions database.
|
boolean |
isNew()
Return
true if object is not in the database. |
boolean |
select(int id)
Select a conditions object by its row ID.
|
(package private) void |
setCollectionId(int collectionId)
Set the collection ID of the object.
|
void |
setConnection(Connection connection)
Set the JDBC database connection of the object.
|
void |
setFieldValue(String name,
Object value)
Set a field value.
|
void |
setFieldValues(FieldValues fieldValues)
Set the field values of the object.
|
(package private) void |
setRowId(int rowId)
Set the row ID of the object.
|
void |
setTableMetaData(TableMetaData tableMetaData)
Set the table meta data of the object.
|
String |
toString()
Convert this object to a string.
|
boolean |
update()
Perform an update operation to insert this object's data into the database.
|
static final String COLLECTION_ID_FIELD
static final SimpleDateFormat DEFAULT_DATE_FORMAT
static final int UNSET_COLLECTION_ID
static final int UNSET_ROW_ID
private Connection connection
private FieldValues fieldValues
private int rowId
private TableMetaData tableMetaData
protected BaseConditionsObject()
public BaseConditionsObject(Connection connection, TableMetaData tableMetaData)
This should be used when creating new objects without a list of field values. A new FieldValues
object
will be automatically created from the table information.
connection
- the database connectiontableMetaData
- the table meta datapublic BaseConditionsObject(Connection connection, TableMetaData tableMetaData, FieldValues fields)
This should be used when creating new objects from a list of field values.
connection
- the database connectiontableMetaData
- the table meta datafields
- the field valuesprotected static String defaultToString(BaseConditionsObject object)
object
- the conditions objectprivate String buildInsertStatement()
private String buildUpdateStatement()
public final void delete() throws DatabaseObjectException, SQLException
delete
in interface DatabaseObject
DatabaseObjectException
- if object is not in the databaseSQLException
- if there is an error performing the delete operationpublic final Integer getCollectionId()
getCollectionId
in interface ConditionsObject
public final <T> T getFieldValue(Class<T> type, String name)
getFieldValue
in interface ConditionsObject
type
- the return typename
- the name of the fieldpublic <T> T getFieldValue(String name)
getFieldValue
in interface ConditionsObject
T
- the implicit return typename
- the field namepublic FieldValues getFieldValues()
getFieldValues
in interface ConditionsObject
public final int getRowId()
getRowId
in interface ConditionsObject
public final TableMetaData getTableMetaData()
getTableMetaData
in interface DatabaseObject
null
if not setpublic boolean hasValidCollectionId()
true
if collection ID is valid.hasValidCollectionId
in interface ConditionsObject
true
if collection ID is validpublic final void insert() throws DatabaseObjectException, SQLException
insert
in interface DatabaseObject
SQLException
DatabaseObjectException
public final boolean isNew()
true
if object is not in the database.
This returns true
if the object has a valid row ID.
isNew
in interface DatabaseObject
true
if object is not in the databasepublic final boolean select(int id) throws DatabaseObjectException, SQLException
select
in interface DatabaseObject
id
- the row IDtrue
is selection was performedDatabaseObjectException
- if there was an error selecting information into this objectSQLException
- if there was a query errorvoid setCollectionId(int collectionId) throws ConditionsObjectException
collectionId
- the collection ID of the objectConditionsObjectException
public final void setConnection(Connection connection)
setConnection
in interface DatabaseObject
connection
- the database connection of the objectpublic final void setFieldValue(String name, Object value)
Calling this method will flag the object as "dirty" meaning it needs to be updated in the database.
setFieldValue
in interface ConditionsObject
name
- the name of the fieldvalue
- the new value of the fieldpublic void setFieldValues(FieldValues fieldValues)
setFieldValues
in interface ConditionsObject
fieldValues
- the field values of the objectvoid setRowId(int rowId)
rowId
- the new row IDpublic final void setTableMetaData(TableMetaData tableMetaData)
This sets which table is associated with the object for database operations.
setTableMetaData
in interface DatabaseObject
tableMetaData
- the table meta dataTableMetaData
public String toString()
public final boolean update() throws DatabaseObjectException, SQLException
update
in interface DatabaseObject
true
if an update occurredSQLException
- if there is a SQL query errorDatabaseObjectException
Copyright © 2019. All rights reserved.