|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.tentackle.db.LegacyDbObject
public abstract class LegacyDbObject
Abstract class defining some essential basics for objects
*not* derived from DbObject.
Useful to access non-tentackle-based database tables.
| Constructor Summary | |
|---|---|
LegacyDbObject(Db db)
Creates a legacy db object. |
|
| Method Summary | |
|---|---|
boolean |
alwaysPrepare()
Determines whether prepared statements of this class should always be prepared each time when the statement used. |
boolean |
delete()
Removes this object from the database. |
boolean |
exists()
Tests if an object exists in the database. Because LegacyDbObjects have no serial and no id, there is no generic way to implement isNew(). |
String |
getClassBaseName()
Gets the basename of the class of this object. The basename is the class name without the package name. |
Db |
getDb()
Get the logical db connection for this object. |
protected int |
getDeleteStatementId()
Gets the prepared statement id for delete(). |
protected int |
getExistsStatementId()
Gets the prepared statement id for exists(). |
int |
getFieldCount()
Gets the number of db-columns. Will perform a dummy select if not known so far. |
abstract boolean |
getFields(ResultSetWrapper rs)
Retrieves the values of all fields (all columns of the database table) in the given ResultSetWrapper and stores them in the object's attributes. |
protected int |
getInsertStatementId()
Gets the prepared statement id for insert(). |
abstract LegacyDbObjectClassVariables |
getLegacyDbObjectClassVariables()
Gets the some attributes and variables common to all objects of the same class. |
String |
getMultiName()
Gets the human readable name for multiple (> 1) objects of this class. |
protected int |
getSelectAllStatementId()
Gets the prepared statement id for selectAll(). |
String |
getSingleName()
Gets the human readable name for one (1) object of this class. |
String |
getSqlPrefix()
Column names may be preceeded by a prefix. |
String |
getSqlPrefixWithDot()
Gets the prefix with a trailing dot or "" if no prefix. |
String |
getSqlSelectAllFields()
Gets the SQL-string to select all columns of this class (may be for joined multiple tables) |
String |
getTableName()
Gets the database table name for the class of this object. |
protected int |
getUpdateStatementId()
Gets the prepared statement id for update(). |
boolean |
insert()
Inserts this object into the database. |
boolean |
isGettingFieldCount()
as getFieldCount() is invoked from getFields() we must prevent loops and heap overflow. |
boolean |
isPartial()
Returns true if object is only a partial implementation. |
LegacyDbObject |
newObject()
Creates a new object with the same class and same logical db connection as this object. |
void |
prepareDeleteStatement()
Prepares the delete statement. The default implementation throws a DbRuntimeException. |
void |
prepareExistsStatement()
Prepare the exists statement. The default implementation throws a DbRuntimeException. |
void |
prepareInsertStatement()
Prepares the insert statement. The default implementation throws a DbRuntimeException. |
void |
prepareUpdateStatement()
Prepares the update statement. The default implementation throws a DbRuntimeException. |
boolean |
readFromResultSetWrapper(ResultSetWrapper rs)
Reads from a result-set into 'this' object. |
List<? extends LegacyDbObject> |
selectAll()
Selects all objects of this class. |
ResultSetWrapper |
selectAllResultSet()
Selects all objects and returns the ResultSetWrapper. |
LegacyDbObject |
selectNext(ResultSetWrapper rs)
Selects the next object from the resultset. |
void |
setAlwaysPrepare(boolean alwaysPrepare)
Sets the always prepare flag. |
void |
setDb(Db db)
Sets the logical db connection for this object. |
protected void |
setDeleteStatementId(int id)
Sets the prepared statement id for delete(). |
protected void |
setExistsStatementId(int id)
Sets the prepared statement id for exists(). |
int |
setFields(PreparedStatementWrapper st)
Sets the values of all fields (all columns of the database table) in the given PreparedStatementWrapper from the object's attributes. |
protected void |
setInsertStatementId(int id)
Sets the prepared statement id for insert(). |
int |
setKeyFields(PreparedStatementWrapper st,
int ndx)
Sets the unique keys. If update(), delete() or exists() are implemented
this method must be overridden to set the unique key-value(s). |
protected void |
setSelectAllStatementId(int id)
Sets the prepared statement id for selectAll(). |
protected void |
setUpdateStatementId(int id)
Sets the prepared statement id for update(). |
boolean |
update()
Updates this object to the database. |
protected void |
updateFieldCount(int columnIndex)
Update fieldCount if index greater than current fieldcount. |
boolean |
updateOrInsert()
Updates the object if it exists, else inserts it. Because transactions abort on unique violations or update failures and there is no generic concept for isNew(), we cannot provide a generic method save(). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public LegacyDbObject(Db db)
db - the db connection| Method Detail |
|---|
public void setDb(Db db)
db - the db connectionpublic Db getDb()
public String getClassBaseName()
public abstract LegacyDbObjectClassVariables getLegacyDbObjectClassVariables()
LegacyDbObject are kept in an
instance of LegacyDbObjectClassVariables.
public String getSqlPrefix()
public String getSqlPrefixWithDot()
public boolean isPartial()
public abstract boolean getFields(ResultSetWrapper rs)
ResultSetWrapper and stores them in the object's attributes.
rs - the result set
public int setFields(PreparedStatementWrapper st)
PreparedStatementWrapper from the object's attributes.
st - the statement
public void prepareInsertStatement()
public void prepareUpdateStatement()
public void prepareDeleteStatement()
public void prepareExistsStatement()
public boolean alwaysPrepare()
public void setAlwaysPrepare(boolean alwaysPrepare)
alwaysPrepare - true if always prepareprotected int getSelectAllStatementId()
selectAll().
protected void setSelectAllStatementId(int id)
selectAll().
id - the statement idprotected int getInsertStatementId()
insert().
protected void setInsertStatementId(int id)
insert().
id - the statement idprotected int getUpdateStatementId()
update().
protected void setUpdateStatementId(int id)
update().
id - the statement idprotected int getDeleteStatementId()
delete().
protected void setDeleteStatementId(int id)
delete().
id - the statement idprotected int getExistsStatementId()
exists().
protected void setExistsStatementId(int id)
exists().
id - the statement idpublic String getTableName()
public String getSingleName()
public String getMultiName()
public LegacyDbObject newObject()
public String getSqlSelectAllFields()
public boolean readFromResultSetWrapper(ResultSetWrapper rs)
rs - is the result set (wrapper)
public ResultSetWrapper selectAllResultSet()
public LegacyDbObject selectNext(ResultSetWrapper rs)
rs - the result set
public List<? extends LegacyDbObject> selectAll()
public boolean insert()
public int setKeyFields(PreparedStatementWrapper st,
int ndx)
update(), delete() or exists() are implemented
this method must be overridden to set the unique key-value(s).
Furthermore, the DbUpdate-wurblet must reflect these keys in a where-clause
with options --maponly --append=" WHERE ... "
st - the prepared statementndx - the starting index in st
public boolean update()
public boolean delete()
public int getFieldCount()
public boolean isGettingFieldCount()
protected void updateFieldCount(int columnIndex)
columnIndex - is the result-set column index (>=1)public boolean exists()
public boolean updateOrInsert()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||