|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.tentackle.db.DbObject
public abstract class DbObject
Database object.
All database objects must extend DbObject, which provides the generic
functionality of persistent objects. Every DbObject is associated
to a logical Db connection, which can be either local or remote.
The application-specific configuration is achieved by implementing and/or
overriding methods (pure OO-approach). These methods are generated
by wurblets (see http://www.wurbelizer.org) which are already provided by Tentackle.
DbObjects have the following predefined attributes:
ObjectId as their common IdSource.
However, that can be changed on a per-class basis by providing a property file.
| Nested Class Summary | |
|---|---|
static interface |
DbObject.CopyAllToDbLogger
The logger for copyAllToDb(org.tentackle.db.Db, boolean, org.tentackle.db.DbObject.CopyAllToDbLogger). |
static class |
DbObject.IdComparator<T extends DbObject>
Compares the IDs. |
static class |
DbObject.NameComparator<T extends DbObject>
Compares the string representation (toString()). |
static class |
DbObject.NameIdComparator<T extends DbObject>
Compares the names + IDs. |
| Field Summary | |
|---|---|
static char |
BEGIN
modification type: begin transaction |
static char |
COMMIT
modification type: commit transaction |
static char |
DELETE
modification type: object deleted |
static char |
DELETEALL
modification type: all objects of given type deleted |
static String |
FIELD_ID
name of ID column |
static String |
FIELD_SERIAL
name of serial column |
static String |
FIELD_TABLESERIAL
name of tableserial column |
static DbObject.IdComparator<DbObject> |
idComparator
ID comparator |
static char |
INSERT
modification type: object inserted |
static long |
lazyMethodInterval
Interval in [ms] to avoid invocation bursts of some methods due to swing's event model. |
static DbObject.NameComparator<DbObject> |
nameComparator
name comparator |
static DbObject.NameIdComparator<DbObject> |
nameIdComparator
name + ID comparator |
static String |
TX_DELETE_LIST
transaction name: delete list |
static String |
TX_DELETE_MISSING_IN_LIST
transaction name: delete missing in list |
static String |
TX_DELETE_OBJECT
transaction name: delete object |
static String |
TX_DUMMY_UPDATE
transaction name: dummy update |
static String |
TX_INSERT_OBJECT
transaction name: insert object |
static String |
TX_INSERT_PLAIN
transaction name: insert plain |
static String |
TX_SAVE
transaction name: save |
static String |
TX_SAVE_LIST
transaction name: save list |
static String |
TX_UPDATE_OBJECT
transaction name: update object |
static String |
TX_UPDATE_PLAIN
transaction name: update plain |
static String |
TX_UPDATE_SERIAL
transaction name: update serial |
static String |
TX_UPDATE_SERIAL_AND_TABLESERIAL
transaction name: update serial and tableserial |
static String |
TX_UPDATE_TABLESERIAL
transaction name: update tableserial |
static char |
UPDATE
modification type: object updated |
| Constructor Summary | |
|---|---|
DbObject()
Creates a database object not associated to a logical Db-connection. |
|
DbObject(Db db)
Creates a database object. |
|
| Method Summary | ||
|---|---|---|
void |
_delete()
Wrapper for delete(). |
|
void |
_save()
Wrapper for save(). |
|
boolean |
alwaysPrepare()
Determines whether prepared statements of this class should always be prepared each time when the statement used. |
|
protected void |
assertLazyNotWithinTX()
Asserts that lazy method is not used within a transaction. |
|
boolean |
attributesModified()
Determines whether this object got some of its attributes modified. It does not check whether some of its composites are modified! This method can also be used for non-tracked objects. |
|
protected boolean |
beginTx(String txName)
Begins a transaction. Also sets the txObject if a transaction is started or isTxObject() returns true. |
|
DbObject |
clone()
Clones an object. |
|
int |
compareTo(DbObject obj)
Compare two objects. We are using the ID to compare objects. |
|
int |
copyAllToDb(Db destDb,
boolean plain,
DbObject.CopyAllToDbLogger logger)
Copies all objects of this class to another db. |
|
void |
copyLazyValues(DbObject obj)
Copies the lazy values from one object to another. |
|
boolean |
copyToDb(Db destDb,
boolean plain)
Copies an object from one db connection to another. |
|
long |
countModification()
Counts a modification for the class of this object with optimization. |
|
long |
countModification(boolean optimize)
Counts a modification for the class of this object. |
|
ModificationLog |
createModificationLog(char modType)
Creates a ModificationLog. |
|
boolean |
delete()
Removes this object from the database (with linked objects, i.e. |
|
boolean |
deleteLinkedObjects()
Deletes all linked objects |
|
static int |
deleteList(List<? extends DbObject> list)
Deletes a List of objects. |
|
static int |
deleteMissingInList(List<? extends DbObject> oldList,
List<? extends DbObject> newList)
Deletes all objects in oldList that are not in newList. |
|
boolean |
deleteObject(boolean withLinkedObjects)
Removes this object from the database. Note: this method should be used by the application with great care! Use delete() instead! |
|
boolean |
deletePlain()
Deletes this object from the database without any further processing (i.e. |
|
boolean |
dummyUpdate()
Performs a dummy update. The method is provided as an alternative to reloadLocked() or selectLocked(long, boolean)
to lock the object during a transaction by updating the ID without changing it. |
|
boolean |
equals(Object object)
Objects are identical if their IDs and classes are identical. |
|
boolean |
finishModification(char modType)
Does any postprocessing after delete, insert or update. |
|
boolean |
finishNotUpdated()
Does any update postprocessing for objects not being updated (because not modified for some reason, e.g. |
|
String |
getClassBaseName()
Gets the basename of the class of this object. The basename is the class name without the package name. |
|
String |
getClassName()
Gets the class name of this object. This is equivalent to getClass().getName() except for PartialDbObjects! |
|
Db |
getDb()
Get the logical db connection for this object. |
|
abstract DbObjectClassVariables |
getDbObjectClassVariables()
Gets the some attributes and variables common to all objects of the same class. |
|
protected int |
getDeleteStatementId()
Gets the prepared statement id for delete(). |
|
protected int |
getDummyUpdateStatementId()
Gets the prepared statement id for dummyUpdate(). |
|
long[] |
getExpirationBacklog(long minSerial,
long maxSerial)
Gets the expiration backlog for a given range of tableserials. |
|
long[] |
getExpiredTableSerials(long oldSerial,
long maxSerial)
Combines selectExpiredTableSerials(long) and getExpirationBacklog(long, long).A physical database query is only done if the requested range is not in the backlog. |
|
int |
getFieldCount()
Gets the number of columns (fields) in the table corresponding to the class of this object. The method does 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. |
|
ImageIcon |
getIcon()
Gets the icon of this object. |
|
long |
getId()
Gets the object ID. |
|
IdSource |
getIdSource()
Get the IdSource. |
|
protected int |
getInsertStatementId()
Gets the prepared statement id for insert(). |
|
String |
getMultiName()
Gets the human readable name for multiple (> 1) objects of this class. |
|
DbObjectRemoteDelegate |
getRemoteDelegate()
Gets the delegate for remote connections. Each class has its own delegate. |
|
protected int |
getRemoteDelegateId()
Returns the ID of the delegate for the class of this object. |
|
protected int |
getSelectAllStatementId()
Gets the prepared statement id for selectAll(boolean). |
|
protected int |
getSelectExpiredTableSerials1StatementId()
Gets the prepared statement id for selectExpiredTableSerials(long). |
|
protected int |
getSelectExpiredTableSerials2StatementId()
Gets the prepared statement id for selectExpiredTableSerials(long). |
|
protected int |
getSelectLockedStatementId()
Gets the prepared statement id for selectLocked(long, boolean). |
|
protected int |
getSelectSerialStatementId()
Gets the prepared statement id for selectSerial(long). |
|
protected int |
getSelectStatementId()
Gets the prepared statement id for select(long, boolean). |
|
long |
getSerial()
Gets the serial number. |
|
String |
getSingleName()
Gets the human readable name for one (1) object of this class. |
|
String |
getSqlAllFields()
Gets the sql text to select all fields (and all objects). |
|
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()
Get the SQL-string to select all columns of this class (may be across multiple tables) |
|
String |
getTableName()
Gets the database table name for the class of this object. |
|
long |
getTableSerial()
Gets the table serial. |
|
protected int |
getUpdateSerialAndTableSerialStatementId()
Gets the prepared statement id for updateSerialAndTableSerial(). |
|
protected int |
getUpdateSerialStatementId()
Gets the prepared statement id for updateSerial(). |
|
protected int |
getUpdateStatementId()
Gets the prepared statement id for update(). |
|
protected int |
getUpdateTableSerialStatementId()
Gets the prepared statement id for updateTableSerial(). |
|
int |
hashCode()
The hashcode for a Db-object is simply the ID. |
|
boolean |
initModification(char modType)
Does any preprocessing before delete, insert or update. |
|
boolean |
insert()
Inserts this (new) object into the database with linked objects. |
|
boolean |
insertObject(boolean withLinkedObjects)
Inserts this (new) object into the database. |
|
boolean |
insertPlain()
Insert this object into the database without any further processing (i.e. |
|
void |
invalidateLazyValues()
Clears the lazy values. Makes it safe to invoke the lazy method and being sure to invoke the non-lazy too. |
|
boolean |
isCountingModification(int modType)
Determines whether modifications of this object are counted in the modification table. |
|
boolean |
isDeleted()
Checks whether object is deleted (or got a reserved ID). |
|
boolean |
isEditable()
Checks whether this object can be edited by the user. |
|
boolean |
isEditableLazy()
Gets the editable state which has been valid for at least the last lazyMethodInterval milliseconds. |
|
boolean |
isEntity()
Returns whether instances of this class exist as database entities. |
|
boolean |
isGettingFieldCount()
As getFieldCount() is invoked from getFields(org.tentackle.db.ResultSetWrapper) this prevents
a heap overflow. |
|
boolean |
isIdValid()
Checks whether the object has a valid ID, i.e. |
|
boolean |
isLazyElapsed()
For the GUI a lazy method is provided to reduce the invocations. |
|
static boolean |
isListModified(List<? extends DbObject> list)
Checks whether some of the objects in the list are modified. |
|
boolean |
isLoggingModification(int modType)
Determines whether each modification of this object (with respect to the database) should be logged. |
|
boolean |
isModified()
Determines whether the object should be written to persistant storage because it has been modified. |
|
boolean |
isNew()
Checks whether this object is already persistant in the db or only residing in memory. |
|
boolean |
isPartial()
Returns true if object is only a partial implementation. |
|
boolean |
isReferenced()
Checks whether this object is referenced by other objects. |
|
boolean |
isReferencedLazy()
Gets the referenced state which has been valid for at least the last lazyMethodInterval milliseconds. |
|
boolean |
isRemovable()
Checks whether this object can be removed. |
|
boolean |
isRemovableLazy()
Gets the removeable state which has been valid for at least the last lazyMethodInterval milliseconds. |
|
boolean |
isSaveable()
Determines whether this object is allowed to be stored in DB. The default is true. |
|
boolean |
isTableSerialValid()
By default objects don't need to include the tableSerial in the database table. |
|
boolean |
isTracked()
Checks if modification of this object are tracked, i.e. |
|
boolean |
isTxObject()
Determines whether this object becomes the txObject (see Db.setTxObject(org.tentackle.db.DbObject)) within a transaction. |
|
boolean |
isUpdatingSerialEvenIfNotModified()
Determines whether in updates of composite objects unmodified objects in the update path get at least the serial updated or are not touched at all. |
|
boolean |
isVirgin()
Checks whether this object ever was stored in the database. |
|
boolean |
loadLinkedObjects()
Loads all linked objects. |
|
boolean |
logModification(char modType)
Logs a modification for this object to the modlog (not to be mixed up with the modification-counter!) |
|
void |
markDeleted()
Marks an object to be deleted. This is done by negating its id. |
|
static int |
markListDeleted(List<? extends DbObject> list)
Marks all objects in a list to be deleted. Use this method if a list-SQL-delete removed a set of objects and you have to reflect that in the list of objects. |
|
static
|
newByClass(Class<T> clazz)
Instantiates a new object for a given class (without db-context). |
|
static
|
newByClass(Db db,
Class<T> clazz)
Instantiates a new object for a given class and db. |
|
static
|
newByClassWrapped(Class<T> clazz)
Instantiates a new object for a given class transforming exceptions to DbRuntimeException. |
|
void |
newId()
Obtains a new ID for this object. |
|
DbObject |
newObject()
Creates a new object with the same class and same logical db connection as this object. |
|
int |
prepareDeleteStatement()
Prepares the delete statement (usually the same for all objects) |
|
int |
prepareDummyUpdateStatement()
Prepares the dummy update. |
|
abstract int |
prepareInsertStatement()
Prepares the insert statement. |
|
int |
prepareSelectLockedStatement()
Prepares the select statement with lock (usually the same for all objects) |
|
int |
prepareSelectSerialStatement()
Prepares the selectSerial statement (usually the same for all objects) |
|
int |
prepareSelectStatement()
Prepares the select statement (usually the same for all objects) |
|
boolean |
prepareSetFields()
Prepares the object's attributes before the object is saved to the database. |
|
int |
prepareUpdateSerialAndTableSerialStatement()
Prepares the serial + tableSerial update. |
|
int |
prepareUpdateSerialStatement()
Prepares the serial update. |
|
abstract int |
prepareUpdateStatement()
Prepare the update statement. |
|
int |
prepareUpdateTableSerialStatement()
Prepares the tableSerial update. |
|
boolean |
readFromResultSetWrapper(ResultSetWrapper rs)
Reads the values from a result-set into this object. |
|
boolean |
readFromResultSetWrapper(ResultSetWrapper rs,
boolean withLinkedObjects)
Reads the values from a result-set into this object. |
|
DbObject |
reload()
Reloads the object. |
|
DbObject |
reloadLocked()
Reloads the object with a write lock. |
|
void |
reserveId()
Reserves an ID. |
|
boolean |
save()
Saves this object. This is the standard method applications should use to insert or update objects. |
|
boolean |
saveLinkedObjects()
Saves all linked objects. |
|
static int |
saveList(List<? extends DbObject> list)
Saves a list of objects. The linked objects are saved as well. |
|
static int |
saveList(List<? extends DbObject> list,
boolean modifiedOnly)
Saves a list of DbObjects. All objects with isSaveable() == true will be saved. |
|
static
|
select(Db db,
Class<T> clazz,
long id)
Selects an object for a given class and db by its unique id. |
|
static
|
select(Db db,
String className,
long id)
Selects an object for a given class name and db by its unique id. |
|
DbObject |
select(long id)
Loads an object from the database by its unique ID. |
|
DbObject |
select(long id,
boolean withLinkedObjects)
Loads an object from the database by its unique ID. |
|
List<? extends DbObject> |
selectAll()
Selects all objects of this class as a List. |
|
List<? extends DbObject> |
selectAll(boolean withLinkedObjects)
Selects all objects of this class as a List. |
|
static
|
selectAll(Db db,
Class<T> clazz)
Selects all objects of this class. |
|
DbCursor<? extends DbObject> |
selectAllCursor()
Selects all objects of this class as a DbCursor. |
|
DbCursor<? extends DbObject> |
selectAllCursor(boolean withLinkedObjects)
Selects all objects of this class as a DbCursor. |
|
ResultSetWrapper |
selectAllResultSet()
Selects all objects of this class and returns the ResultSetWrapper. |
|
long[] |
selectExpiredTableSerials(long oldSerial)
Determines the objects with a tableSerial starting at a given serial. |
|
long[] |
selectExpiredTableSerials(long oldSerial,
long maxSerial)
Determines the objects with their tableSerial within a given range. |
|
DbObject |
selectInValidContext(long id,
boolean withLinkedObjects)
Same as select(long, boolean) but makes sure that the object is selected
in a valid context, i.e. |
|
DbObject |
selectLocked(long id)
Load the object from the database with exclusive lock (aka write lock). |
|
DbObject |
selectLocked(long id,
boolean withLinkedObjects)
Load the object from the database with exclusive lock (aka write lock). |
|
long |
selectModification()
Selects the current modification counter for the class of this object. |
|
DbObject |
selectNext(ResultSetWrapper rs,
boolean withLinkedObjects)
Selects the next object from a resultset. |
|
long |
selectSerial()
Selects the serial-number for this object. |
|
long |
selectSerial(long id)
Selects the serial-number for a given object id. |
|
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 |
setDummyUpdateStatementId(int id)
Sets the prepared statement id for dummyUpdate(). |
|
abstract 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. |
|
void |
setId(long id)
Sets the unique ID of this object. |
|
protected void |
setInsertStatementId(int id)
Sets the prepared statement id for insert(). |
|
void |
setModified(boolean modified)
Sets the modified flag. |
|
protected void |
setSelectAllStatementId(int id)
Sets the prepared statement id for selectAll(boolean). |
|
protected void |
setSelectExpiredTableSerials1StatementId(int id)
Sets the prepared statement id for selectExpiredTableSerials(long). |
|
protected void |
setSelectExpiredTableSerials2StatementId(int id)
Sets the prepared statement id for selectExpiredTableSerials(long). |
|
protected void |
setSelectLockedStatementId(int id)
Sets the prepared statement id for selectLocked(long, boolean). |
|
protected void |
setSelectSerialStatementId(int id)
Sets the prepared statement id for selectSerial(long). |
|
protected void |
setSelectStatementId(int id)
Sets the prepared statement id for select(long, boolean). |
|
void |
setSerial(long serial)
Sets the serial number (modification count). |
|
void |
setTableSerial(long tableSerial)
Sets the table serial number (table modification count). |
|
protected void |
setUpdateSerialAndTableSerialStatementId(int id)
Sets the prepared statement id for updateSerialAndTableSerial(). |
|
protected void |
setUpdateSerialStatementId(int id)
Sets the prepared statement id for updateSerial(). |
|
protected void |
setUpdateStatementId(int id)
Sets the prepared statement id for update(). |
|
protected void |
setUpdateTableSerialStatementId(int id)
Sets the prepared statement id for updateTableSerial(). |
|
boolean |
sync()
Try to update an object first and if that failes, try to insert. This method is used for transferring an Object from one DB to another as it is the case in RMI-connections, where the ID is transmitted, but the object may or may not exist in the other database. |
|
boolean |
syncObject(boolean withLinkedObjects)
Try to update an object first and if that failes, try to insert. This method is used for transferring an Object from one DB to another as it is the case in RMI-connections, where the ID is transmitted, but the object may or may not exist in the other database. |
|
String |
toGenericString()
Gets the string value: " getSingleName()[id/serial]".Example: "Product[344/2]" |
|
String |
toString()
Gets the default string value. The default implementation invokes toGenericString(). |
|
boolean |
update()
Updates this object to the database. The modified attribute gets cleared if insert was successful. |
|
protected void |
updateFieldCount(int columnIndex)
Updates the fieldCount in the class variables if the given columnIndex is greater than current fieldcount. |
|
int |
updateFields(ResultSetWrapper rs)
Updates the fields in the result-set. Because it is only used in updateable cursors and by far most apps don't use that feature, the method is not abstract and by default throws the exception for "not implemented". |
|
boolean |
updateObject(boolean withLinkedObjects)
Updates this object to the database. The modified attribute gets cleared if insert was successful. |
|
boolean |
updatePlain()
Updates this object to the database without any further processing (i.e. |
|
boolean |
updateSerial()
Updates and increments the serial number of this object. The method is provided to update an object with isModified() == true and 'modified' == false, i.e. |
|
boolean |
updateSerialAndTableSerial()
Same as updateSerial() but updates tableSerial as well. |
|
boolean |
updateTableSerial()
Updates the tableSerial only. The method is provided to explicitly force this object to expire in caches. |
|
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static long lazyMethodInterval
isEditableLazy(), for example.
public static DbObject.IdComparator<DbObject> idComparator
public static DbObject.NameComparator<DbObject> nameComparator
public static DbObject.NameIdComparator<DbObject> nameIdComparator
public static String FIELD_ID
public static String FIELD_SERIAL
public static String FIELD_TABLESERIAL
public static final char BEGIN
public static final char COMMIT
public static final char INSERT
public static final char UPDATE
public static final char DELETE
public static final char DELETEALL
public static final String TX_INSERT_PLAIN
public static final String TX_INSERT_OBJECT
public static final String TX_UPDATE_PLAIN
public static final String TX_DUMMY_UPDATE
public static final String TX_UPDATE_SERIAL
public static final String TX_UPDATE_SERIAL_AND_TABLESERIAL
public static final String TX_UPDATE_TABLESERIAL
public static final String TX_UPDATE_OBJECT
public static final String TX_SAVE
public static final String TX_DELETE_OBJECT
public static final String TX_SAVE_LIST
public static final String TX_DELETE_LIST
public static final String TX_DELETE_MISSING_IN_LIST
| Constructor Detail |
|---|
public DbObject(Db db)
db - the logical Db-connectionpublic DbObject()
Db-connection.
The connection must be set via setDb(org.tentackle.db.Db) in order to use it.
| Method Detail |
|---|
public String toString()
toGenericString().
toString in class Objectpublic String toGenericString()
getSingleName()[id/serial]".
public abstract DbObjectClassVariables getDbObjectClassVariables()
DbObjectClassVariables.
public String getClassBaseName()
public String getClassName()
public DbObject clone()
Cloning an object yields a copy with id=0 and serial=0.
Needs to be overridden if object references, etc... have to be cloned too.
Subclasses should throw a DbRuntimeException if they should not be cloned
depending on the application logic (not CloneNotSupportedException).
clone in class ObjectCloneablepublic boolean isPartial()
public boolean isEntity()
public DbObject newObject()
public void setDb(Db db)
db - the db connectionpublic Db getDb()
public void setId(long id)
isModified().
id - the object idpublic long getId()
public void setSerial(long serial)
isModified().
serial - the serial numberpublic long getSerial()
public final void setTableSerial(long tableSerial)
isModified().
tableSerial - the new table serialpublic long getTableSerial()
public void newId()
If the object already has an ID or is deleted (negative ID) the ID will _not_ change.
public void reserveId()
Reserved IDs are negative.
A new object with a reserved ID can be distinguished from
a deleted object by its serial. See also isVirgin().
If the object already has an ID or is deleted (negative ID)
the ID will _not_ change.
public boolean isNew()
public boolean isIdValid()
public boolean isDeleted()
isVirgin().
public boolean isVirgin()
public void setModified(boolean modified)
For optimizations it is possible to skip objects that have not been modified. The modified-attribute is cleared whenever the object is saved (inserted or updated -- NOT insertPlain and updatePlain!). The application is responsible to set the modified flag! This is usually done in the setter-methods of the db-attributes. The wurblet 'DbMethods' does this for you with option '--tracked'
modified - is true if object is flagged modified, false if not.public boolean isTracked()
public boolean isModified()
By definition, an object is 'modified' if the object OR ANY of its composites are modified. See DbRelations.wrbl on how and when to override isModified().
New objects are modified by definition! Furthermore, isModified() will invoke the errorhandler if isTracked() != true. DbMethods automatically override this method if option --tracked is given.
public boolean attributesModified()
public boolean isSaveable()
public boolean loadLinkedObjects()
Note: Linked objects are not to be mixed up with composites. See the wurblet AppDbRelations for how this method is used.
public boolean saveLinkedObjects()
Note: Linked objects are not to be mixed up with composites. See the wurblet AppDbRelations for how this method is used.
public boolean deleteLinkedObjects()
Note: Linked objects are not to be mixed up with composites. See the wurblet AppDbRelations for how this method is used.
public ImageIcon getIcon()
PlafGlobal.getIcon(java.lang.String, java.lang.String)("unknown").
public boolean isReferenced()
It is invoked before operations that may have an impact on the referential integrity. The default implementation returns false.
The application can assume a lazy context (invoked from is...Lazy) if invoked outside a transaction. This is just an optimization hint.
public boolean isRemovable()
It is invoked before operations that may have an impact on the referential integrity. The default implementation returns true if !isNew and !isReferenced. Does not refer to the SecurityManager!
The application can assume a lazy context (invoked from is...Lazy) if invoked outside a transaction. This is just an optimization hint.
Notice that isRemovable() for performance reasons is not covered by its own delegate method in remote connections. Hence, if classes in your application require a different implementation (!isNew && !isReferenced) you must provide such a remote method.
public boolean isEditable()
The default implementation returns true. Does not refer to the SecurityManager!
The application can assume a lazy context (invoked from is...Lazy) if invoked outside a transaction. This is just an optimization hint.
Notice that isEditable() for performance reasons is not covered by its own delegate method in remote connections. Hence, if classes in your application require a different implementation you must provide such a remote method.
public boolean isLazyElapsed()
public void copyLazyValues(DbObject obj)
obj - the object to copy the values frompublic void invalidateLazyValues()
protected void assertLazyNotWithinTX()
public boolean isReferencedLazy()
public boolean isRemovableLazy()
public boolean isEditableLazy()
public boolean isCountingModification(int modType)
modType - is one of the modtypes INSERT, UPDATE, DELETE, ...
ModificationCounterpublic boolean isTableSerialValid()
public boolean isLoggingModification(int modType)
modType - is one of the modtypes INSERT, UPDATE, DELETE, ...
ModificationLogpublic boolean equals(Object object)
equals in class Objectobject - the object to test for equality
true if this object is the same as the obj
argument; false otherwise.Object.hashCode(),
Hashtablepublic int compareTo(DbObject obj)
compareTo in interface Comparable<DbObject>obj - the object to compare this object with
public int hashCode()
hashCode in class ObjectObject.equals(java.lang.Object),
Hashtablepublic IdSource getIdSource()
public String getSqlPrefix()
public String getSqlPrefixWithDot()
public boolean readFromResultSetWrapper(ResultSetWrapper rs,
boolean withLinkedObjects)
rs - is the result set (wrapper)withLinkedObjects - is true if load linked objects too
public final boolean readFromResultSetWrapper(ResultSetWrapper rs)
rs - is the result set (wrapper)
public DbObject select(long id,
boolean withLinkedObjects)
For local db connections the current object's attributes will be replaced by the database values (i.e. this object is returned). For remote connections, a copy of the object in the server is returned. Hence, applications should always create a new object and invoke select and don't make any further assumptions. This applies to all select methods returning an object! Example:
Customer customer = new Customer(db).select(customerId);
Since Java 1.5 covariance is supported and you should consider
overriding the method and cast the return value to the appropriate class.
id - is the object idwithLinkedObjects - is true if load linked objects too
public DbObject select(long id)
For local db connections the current object's attributes will be replaced by the database values (i.e. this object is returned). For remote connections, a copy of the object in the server is returned. Hence, applications should always create a new object and invoke select and don't make any further assumptions. This applies to all select methods returning an object! Example:
Customer customer = new Customer(db).select(customerId);
Since Java 1.5 covariance is supported and you should consider
overriding the method and cast the return value to the appropriate class.
id - is the object id
public DbObject selectLocked(long id,
boolean withLinkedObjects)
id - is the object idwithLinkedObjects - is true if load linked objects too
public DbObject selectLocked(long id)
id - is the object id
public DbObject selectInValidContext(long id,
boolean withLinkedObjects)
select(long, boolean) but makes sure that the object is selected
in a valid context, i.e. performs optional class specific
initialization that are beyond a normal DbObject.
This method primarily is provided for being overridden by
AppDbObject.selectInValidContext(long, boolean).
The default implementation simply invokes select().
id - is the object idwithLinkedObjects - is true if load linked objects too
public DbObject reload()
Note: to make sure that any lazy inits are cleared, the returned object is always a new object.
public DbObject reloadLocked()
public ResultSetWrapper selectAllResultSet()
public DbObject selectNext(ResultSetWrapper rs,
boolean withLinkedObjects)
rs - the result setwithLinkedObjects - is true if load linked objects too
public List<? extends DbObject> selectAll(boolean withLinkedObjects)
List.
withLinkedObjects - is true if load linked objects too
public List<? extends DbObject> selectAll()
List.
The linked objects are loaded as well.
public DbCursor<? extends DbObject> selectAllCursor(boolean withLinkedObjects)
DbCursor.
Will prompt the user if too much data received.
withLinkedObjects - is true if load linked objects too
public DbCursor<? extends DbObject> selectAllCursor()
DbCursor.
Will prompt the user if too much data received.
The linked objects are loaded as well.
public long selectSerial(long id)
id - the object id
public long selectSerial()
public boolean copyToDb(Db destDb,
boolean plain)
destDb - the destination dbplain - is true to use insertPlain (recommended), else insert
public int copyAllToDb(Db destDb,
boolean plain,
DbObject.CopyAllToDbLogger logger)
destDb - is the destination DBplain - is true to use insertPlain (recommended),
else use insert (if superclass is abstract for example)logger - is an optional logger (null = none)
public boolean insertPlain()
public boolean deletePlain()
public boolean updatePlain()
public boolean dummyUpdate()
reloadLocked() or selectLocked(long, boolean)
to lock the object during a transaction by updating the ID without changing it.
public boolean updateSerial()
isUpdatingSerialEvenIfNotModified()public boolean updateSerialAndTableSerial()
updateSerial() but updates tableSerial as well.
Notice: the tableSerial is NOT modified in the current object,
but only in the database!
public boolean updateTableSerial()
public boolean isUpdatingSerialEvenIfNotModified()
The default implementation returns false. Override this method to change to 'true'.
updateObject(boolean)public boolean isTxObject()
txObject (see Db.setTxObject(org.tentackle.db.DbObject)) within a transaction.
By default, only objects initiating a transaction are txObjects.
However, for composites the top-level object usually is also the txObject, even if the
transaction involves different txobjects. As a consequence, the current txObject can
change during a transaction.
public boolean initModification(char modType)
modType - is the modification type: DELETE, INSERT or UPDATE
public boolean finishModification(char modType)
modType - is the modification type: DELETE, INSERT or UPDATE
public boolean finishNotUpdated()
AppDbObject.
protected boolean beginTx(String txName)
isTxObject() returns true.
txName - the transaction name
public boolean insertObject(boolean withLinkedObjects)
Note: this method does *NOT* set the ID and should be used
by the application with great care! Use save() instead!
withLinkedObjects - true if insert also linked objects
public boolean insert()
The modified attribute gets cleared if insert was successful.
It is also verified that the object isSaveable().
Note: this method does *NOT* set the ID and should be used
by the application with great care! Use save() instead!
public boolean updateObject(boolean withLinkedObjects)
save() instead!
withLinkedObjects - true if update also linked objects
public boolean update()
isSaveable().
Note: this method should be used by the application with great care!
Use save() instead!
public boolean save()
If the ID is 0, a new ID is obtained and this object inserted. Otherwise this object is updated. The modified attribute gets cleared if save() was successful.
public void _save()
throws DbRuntimeException
save().
Unique violations and optimistic locking failures don't throw exceptions, because if these operations fail, the application can and must deal with it. However, in some situations (bulk operations) it is sufficient to just throw an exception instead.
DbRuntimeException - thrown if save returned false
public void _delete()
throws DbRuntimeException
delete().
Optimistic locking or delete failures don't throw exceptions, because if these operations fail, the application can and must deal with it. However, in some situations (bulk operations) it is sufficient to just throw an exception instead.
DbRuntimeException - thrown if delete returned falsepublic boolean syncObject(boolean withLinkedObjects)
withLinkedObjects - true if insert/update also linked objects
public boolean sync()
isSaveable().Notice that the modified-attribute remains unchanged!
public boolean deleteObject(boolean withLinkedObjects)
delete() instead!
withLinkedObjects - true if remove linked objects too.
public boolean delete()
isNew() again.
It is also verified that the object isSaveable().
public void markDeleted()
isModified().
public long countModification(boolean optimize)
optimize - is true if optimize modcounting within transaction
ModificationCounterpublic long countModification()
ModificationCounterpublic long selectModification()
ModificationCounterpublic long[] selectExpiredTableSerials(long oldSerial)
oldSerial - non-inclusive lower bound for tableSerial (>oldSerial)
public long[] selectExpiredTableSerials(long oldSerial,
long maxSerial)
oldSerial - non-inclusive lower bound for tableSerial (> oldSerial)maxSerial - inclusive upper bound for tableSerial (≤ maxSerial)
public long[] getExpirationBacklog(long minSerial,
long maxSerial)
minSerial - the lower serial bound of the query (minSerial < tableSerial)maxSerial - the upper serial bound of the query (tableSerial ≤ maxSerial)
public long[] getExpiredTableSerials(long oldSerial,
long maxSerial)
selectExpiredTableSerials(long) and getExpirationBacklog(long, long).
oldSerial - non-inclusive lower bound for tableSerial (> oldSerial)maxSerial - inclusive upper bound for tableSerial (≤ maxSerial)
public ModificationLog createModificationLog(char modType)
ModificationLog.
modType - is the modification type
public boolean logModification(char modType)
modType - is the modification type (INSERT, DELETE or UPDATE)
public DbObjectRemoteDelegate getRemoteDelegate()
protected int getRemoteDelegateId()
DbObjectRemoteDelegateImplpublic int getFieldCount()
public boolean isGettingFieldCount()
getFieldCount() is invoked from getFields(org.tentackle.db.ResultSetWrapper) this prevents
a heap overflow.
protected void updateFieldCount(int columnIndex)
columnIndex - is the result-set column index (>=1)public boolean alwaysPrepare()
public void setAlwaysPrepare(boolean alwaysPrepare)
alwaysPrepare - true if always prepareprotected int getSelectStatementId()
select(long, boolean).
protected void setSelectStatementId(int id)
select(long, boolean).
id - the statement idprotected int getSelectAllStatementId()
selectAll(boolean).
protected void setSelectAllStatementId(int id)
selectAll(boolean).
id - the statement idprotected int getSelectLockedStatementId()
selectLocked(long, boolean).
protected void setSelectLockedStatementId(int id)
selectLocked(long, boolean).
id - the statement idprotected int getSelectSerialStatementId()
selectSerial(long).
protected void setSelectSerialStatementId(int id)
selectSerial(long).
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 getDummyUpdateStatementId()
dummyUpdate().
protected void setDummyUpdateStatementId(int id)
dummyUpdate().
id - the statement idprotected int getUpdateSerialStatementId()
updateSerial().
protected void setUpdateSerialStatementId(int id)
updateSerial().
id - the statement idprotected int getUpdateTableSerialStatementId()
updateTableSerial().
protected void setUpdateTableSerialStatementId(int id)
updateTableSerial().
id - the statement idprotected int getUpdateSerialAndTableSerialStatementId()
updateSerialAndTableSerial().
protected void setUpdateSerialAndTableSerialStatementId(int id)
updateSerialAndTableSerial().
id - the statement idprotected int getSelectExpiredTableSerials1StatementId()
selectExpiredTableSerials(long).
protected void setSelectExpiredTableSerials1StatementId(int id)
selectExpiredTableSerials(long).
id - the statement idprotected int getSelectExpiredTableSerials2StatementId()
selectExpiredTableSerials(long).
protected void setSelectExpiredTableSerials2StatementId(int id)
selectExpiredTableSerials(long).
id - the statement idpublic String getTableName()
public String getSingleName()
public String getMultiName()
public abstract boolean getFields(ResultSetWrapper rs)
ResultSetWrapper and stores them in the object's attributes.
rs - the result set
public boolean prepareSetFields()
public abstract int setFields(PreparedStatementWrapper st)
PreparedStatementWrapper from the object's attributes.
st - the statement
public int updateFields(ResultSetWrapper rs)
rs - the result set
public String getSqlAllFields()
public String getSqlSelectAllFields()
public abstract int prepareInsertStatement()
public abstract int prepareUpdateStatement()
public int prepareSelectStatement()
public int prepareSelectLockedStatement()
public int prepareSelectSerialStatement()
public int prepareDeleteStatement()
public int prepareDummyUpdateStatement()
public int prepareUpdateSerialStatement()
public int prepareUpdateTableSerialStatement()
public int prepareUpdateSerialAndTableSerialStatement()
public static <T extends DbObject> T newByClass(Class<T> clazz)
throws InstantiationException,
IllegalAccessException
T - the class typeclazz - the class
InstantiationException
IllegalAccessExceptionpublic static <T extends DbObject> T newByClassWrapped(Class<T> clazz)
T - the class typeclazz - the class
public static <T extends DbObject> T newByClass(Db db,
Class<T> clazz)
throws InstantiationException,
IllegalAccessException
T - the class typedb - the db connectionclazz - the class
InstantiationException
IllegalAccessException
public static <T extends DbObject> T select(Db db,
Class<T> clazz,
long id)
throws InstantiationException,
IllegalAccessException
T - the class typedb - the db connectionclazz - the classid - the object ID
InstantiationException
IllegalAccessException
public static <T extends DbObject> T select(Db db,
String className,
long id)
throws ClassNotFoundException,
InstantiationException,
IllegalAccessException
T - the class typedb - the db connectionclassName - the class nameid - the object ID
ClassNotFoundException
InstantiationException
IllegalAccessException
public static <T extends DbObject> List<T> selectAll(Db db,
Class<T> clazz)
throws InstantiationException,
IllegalAccessException
T - the database object classdb - the logical db connectionclazz - the database object class
InstantiationException
IllegalAccessExceptionpublic static int deleteList(List<? extends DbObject> list)
list - the list of object to delete
public static int markListDeleted(List<? extends DbObject> list)
list - the objects to delete
public static int deleteMissingInList(List<? extends DbObject> oldList,
List<? extends DbObject> newList)
oldList - the list of objects stored in dbnewList - the new list of objects
public static boolean isListModified(List<? extends DbObject> list)
list - the objects
public static int saveList(List<? extends DbObject> list,
boolean modifiedOnly)
TrackedArrayList must *NOT* contain untracked objects.
The errorhandler will be invoked if such an object
is detected. This is a quality measure to ensure code consistency.
The wurblet DbRelations automatically takes care of that.
list - the list to savemodifiedOnly - is true if only modified objects are saved
public static int saveList(List<? extends DbObject> list)
TrackedArrayList must *NOT* contain untracked objects.
The errorhandler will be invoked if such an object
is detected. This is a quality measure to ensure code consistency.
The wurblet DbRelations automatically takes care of that.
list - the list to save
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||