org.tentackle.db
Class ObjectId

java.lang.Object
  extended by org.tentackle.db.DbObject
      extended by org.tentackle.db.ObjectId
All Implemented Interfaces:
Serializable, Cloneable, Comparable<DbObject>, CommitTxRunnable, IdSource

public class ObjectId
extends DbObject
implements IdSource, CommitTxRunnable

A DbObject implementing IdSource used to create unique object IDs.

As the object-id is stored in a separate table, an instance of an object is used to retrieve a new (unique) ID for a DbObject.

Author:
harald
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.tentackle.db.DbObject
DbObject.CopyAllToDbLogger, DbObject.IdComparator<T extends DbObject>, DbObject.NameComparator<T extends DbObject>, DbObject.NameIdComparator<T extends DbObject>
 
Field Summary
static String TABLENAME
          the table name
 
Fields inherited from class org.tentackle.db.DbObject
BEGIN, COMMIT, DELETE, DELETEALL, FIELD_ID, FIELD_SERIAL, FIELD_TABLESERIAL, idComparator, INSERT, lazyMethodInterval, nameComparator, nameIdComparator, TX_DELETE_LIST, TX_DELETE_MISSING_IN_LIST, TX_DELETE_OBJECT, TX_DUMMY_UPDATE, TX_INSERT_OBJECT, TX_INSERT_PLAIN, TX_SAVE, TX_SAVE_LIST, TX_UPDATE_OBJECT, TX_UPDATE_PLAIN, TX_UPDATE_SERIAL, TX_UPDATE_SERIAL_AND_TABLESERIAL, TX_UPDATE_TABLESERIAL, UPDATE
 
Constructor Summary
ObjectId()
           
ObjectId(Db db)
          Creates a new unique object ID.
 
Method Summary
 void commit()
          Performs any processing necessary before commit.
 DbObjectClassVariables getDbObjectClassVariables()
          Gets the some attributes and variables common to all objects of the same class.
 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.
 boolean insert()
          Inserts this (new) object into the database with linked objects.
 DbObject newObject()
          Creates a new object with the same class and same logical db connection as this object.
 long nextId()
          Retrieves the next ID and updates the table.
 int prepareDeleteStatement()
          Prepares the delete statement (usually the same for all objects)
 int prepareInsertStatement()
          Prepares the insert statement.
 int prepareUpdateStatement()
          Prepare the update statement.
 void returnId(long id)
          Return an ID back to the pool
 DbObject select(long id)
          Loads an object from the database by its unique ID.
 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.
 boolean update()
          Updates this object to the database.
The modified attribute gets cleared if insert was successful.
 
Methods inherited from class org.tentackle.db.DbObject
_delete, _save, alwaysPrepare, assertLazyNotWithinTX, attributesModified, beginTx, clone, compareTo, copyAllToDb, copyLazyValues, copyToDb, countModification, countModification, createModificationLog, delete, deleteLinkedObjects, deleteList, deleteMissingInList, deleteObject, deletePlain, dummyUpdate, equals, finishModification, finishNotUpdated, getClassBaseName, getClassName, getDb, getDeleteStatementId, getDummyUpdateStatementId, getExpirationBacklog, getExpiredTableSerials, getFieldCount, getIcon, getId, getIdSource, getInsertStatementId, getMultiName, getRemoteDelegate, getRemoteDelegateId, getSelectAllStatementId, getSelectExpiredTableSerials1StatementId, getSelectExpiredTableSerials2StatementId, getSelectLockedStatementId, getSelectSerialStatementId, getSelectStatementId, getSerial, getSingleName, getSqlAllFields, getSqlPrefix, getSqlPrefixWithDot, getSqlSelectAllFields, getTableName, getTableSerial, getUpdateSerialAndTableSerialStatementId, getUpdateSerialStatementId, getUpdateStatementId, getUpdateTableSerialStatementId, hashCode, initModification, insertObject, insertPlain, invalidateLazyValues, isCountingModification, isDeleted, isEditable, isEditableLazy, isEntity, isGettingFieldCount, isIdValid, isLazyElapsed, isListModified, isLoggingModification, isModified, isNew, isPartial, isReferenced, isReferencedLazy, isRemovable, isRemovableLazy, isSaveable, isTableSerialValid, isTracked, isTxObject, isUpdatingSerialEvenIfNotModified, isVirgin, loadLinkedObjects, logModification, markDeleted, markListDeleted, newByClass, newByClass, newByClassWrapped, newId, prepareDummyUpdateStatement, prepareSelectLockedStatement, prepareSelectSerialStatement, prepareSelectStatement, prepareSetFields, prepareUpdateSerialAndTableSerialStatement, prepareUpdateSerialStatement, prepareUpdateTableSerialStatement, readFromResultSetWrapper, readFromResultSetWrapper, reload, reloadLocked, reserveId, save, saveLinkedObjects, saveList, saveList, select, select, select, selectAll, selectAll, selectAll, selectAllCursor, selectAllCursor, selectAllResultSet, selectExpiredTableSerials, selectExpiredTableSerials, selectInValidContext, selectLocked, selectLocked, selectModification, selectNext, selectSerial, selectSerial, setAlwaysPrepare, setDb, setDeleteStatementId, setDummyUpdateStatementId, setId, setInsertStatementId, setModified, setSelectAllStatementId, setSelectExpiredTableSerials1StatementId, setSelectExpiredTableSerials2StatementId, setSelectLockedStatementId, setSelectSerialStatementId, setSelectStatementId, setSerial, setTableSerial, setUpdateSerialAndTableSerialStatementId, setUpdateSerialStatementId, setUpdateStatementId, setUpdateTableSerialStatementId, sync, syncObject, toGenericString, toString, updateFieldCount, updateFields, updateObject, updatePlain, updateSerial, updateSerialAndTableSerial, updateTableSerial
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TABLENAME

public static final String TABLENAME
the table name

See Also:
Constant Field Values
Constructor Detail

ObjectId

public ObjectId(Db db)
Creates a new unique object ID.

use new ObjectId(db).getId() to get a new id for a DbObject.

Parameters:
db - the database connection

ObjectId

public ObjectId()
Method Detail

nextId

public long nextId()
            throws ApplicationException
Retrieves the next ID and updates the table.

Specified by:
nextId in interface IdSource
Returns:
a free ID.
Throws:
ApplicationException - if ID could not be created

newObject

public DbObject newObject()
Description copied from class: DbObject
Creates a new object with the same class and same logical db connection as this object. Must be overridden if further setup is necessary.

Overrides:
newObject in class DbObject
Returns:
the new object

returnId

public void returnId(long id)
              throws ApplicationException
Description copied from interface: IdSource
Return an ID back to the pool

Specified by:
returnId in interface IdSource
Parameters:
id - ID to be returned
Throws:
ApplicationException - if ID could not be returned

commit

public void commit()
Description copied from interface: CommitTxRunnable
Performs any processing necessary before commit. Should throw DbRuntimeException on failure.

Specified by:
commit in interface CommitTxRunnable

insert

public boolean insert()
Description copied from class: DbObject
Inserts this (new) object into the database with linked objects.

The modified attribute gets cleared if insert was successful. It is also verified that the object DbObject.isSaveable().

Note: this method does *NOT* set the ID and should be used by the application with great care! Use DbObject.save() instead!

Overrides:
insert in class DbObject
Returns:
true if inserted, false if duplicate or not saveable.

update

public boolean update()
Description copied from class: DbObject
Updates this object to the database.
The modified attribute gets cleared if insert was successful. It is also verified that the object DbObject.isSaveable().

Note: this method should be used by the application with great care! Use DbObject.save() instead!

Overrides:
update in class DbObject
Returns:
true if done, false if duplicate or object is not saveable.

select

public DbObject select(long id)
Description copied from class: DbObject
Loads an object from the database by its unique 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.

Overrides:
select in class DbObject
Parameters:
id - is the object id
Returns:
object if loaded, null if no such object

setFields

public int setFields(PreparedStatementWrapper st)
Description copied from class: DbObject
Sets the values of all fields (all columns of the database table) in the given PreparedStatementWrapper from the object's attributes.

Specified by:
setFields in class DbObject
Parameters:
st - the statement
Returns:
the number of fields set, -1 if error.

getFields

public boolean getFields(ResultSetWrapper rs)
Description copied from class: DbObject
Retrieves the values of all fields (all columns of the database table) in the given ResultSetWrapper and stores them in the object's attributes.

Specified by:
getFields in class DbObject
Parameters:
rs - the result set
Returns:
true if all fields retrieved

prepareUpdateStatement

public int prepareUpdateStatement()
Description copied from class: DbObject
Prepare the update statement.

Specified by:
prepareUpdateStatement in class DbObject
Returns:
the statememt id

prepareInsertStatement

public int prepareInsertStatement()
Description copied from class: DbObject
Prepares the insert statement.

Specified by:
prepareInsertStatement in class DbObject
Returns:
the statememt id

prepareDeleteStatement

public int prepareDeleteStatement()
Description copied from class: DbObject
Prepares the delete statement (usually the same for all objects)

Overrides:
prepareDeleteStatement in class DbObject
Returns:
the statememt id

getDbObjectClassVariables

public DbObjectClassVariables getDbObjectClassVariables()
Description copied from class: DbObject
Gets the some attributes and variables common to all objects of the same class. Class variables for classes derived from DbObject are kept in an instance of DbObjectClassVariables.

Specified by:
getDbObjectClassVariables in class DbObject
Returns:
the class variables


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de