P - the persistent class typepublic abstract class AbstractDbObject<P extends AbstractDbObject<P>> extends Object implements Immutable, Identifiable, SerialNumbered, SessionDependable, Serializable, Comparable<P>, Cloneable
All persistent objects must extend AbstractDbObject, which provides the generic
functionality of persistent objects. Every AbstractDbObject is associated
to a logical Session, 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.
AbstractDbObjects have the following predefined attributes:
| Modifier and Type | Field and Description |
|---|---|
static String |
AN_CLASSID
name of class-ID attribute.
|
static String |
AN_ID
name of ID attribute.
|
static String |
AN_SERIAL
name of serial attribute.
|
static String |
AN_TABLESERIAL
name of tableserial attribute.
|
static String |
CN_CLASSID
name of class-ID column.
|
static String |
CN_ID
name of ID column.
|
static String |
CN_SERIAL
name of serial column.
|
static String |
CN_TABLESERIAL
name of tableserial column.
|
static IdComparator<AbstractDbObject<?>> |
idComparator
ID comparator
|
static NameComparator<AbstractDbObject<?>> |
nameComparator
name comparator
|
static NameIdComparator<AbstractDbObject<?>> |
nameIdComparator
name + ID comparator
|
protected boolean |
preparePending |
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: saveObject
|
static String |
TX_SAVE_LIST
transaction name: saveObject list
|
static String |
TX_SYNC
transaction name: sync
|
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
|
| Constructor and Description |
|---|
AbstractDbObject()
Creates a database object not associated to a logical
Db-connection. |
AbstractDbObject(Db db)
Creates a database object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
acceptPersistenceVisitor(PersistenceVisitor visitor,
char modType)
Accepts a persistence operation visitor.
|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list.
The listener is registered for all bound properties of this class. |
void |
addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list for a specific
property.
|
protected void |
assertMutable()
Asserts that object is mutable.
|
protected void |
assertNotNew()
Asserts that object is not new.
|
protected void |
assertNotOverloaded()
Asserts that this object is not overloaded.
|
protected void |
assertNotRemote()
asserts that this object does not belong to a remote session.
|
protected void |
assertNumberOfRowsAffected(int count,
int expected)
Checks the correct number of rows affected.
|
protected void |
assertPersistable()
Asserts that this object is saveable.
|
protected void |
assertRemote()
asserts that this object belongs to a remote session.
|
protected void |
assertThisRowAffected(int count)
Checks that exactly one row is affected.
|
boolean |
attributesModified()
Determines whether this object got some of its attributes modified.
It does not check whether some of its components are modified! This method can also be used for non-tracked entities. |
protected long |
beginTx(String txName)
Begins a transaction.
Also sets the txObject if a transaction was started. |
void |
clearOnRemoteSave()
Clears some references to reduce bandwidth.
Invoked for remote objects only. |
P |
clone()
Clones an object.
|
int |
compareTo(P obj)
Compare two objects.
We are using the ID to compare objects. |
void |
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.
|
protected void |
createAttributesInSnapshot(AbstractDbObject snapshot)
Updates the attributes in snapshot object.
The snapshot object is assumed to be a clone of this object. |
StringBuilder |
createDeleteAllSql()
Creates the sql text to delete objects.
|
String |
createDeleteSql()
Creates the SQL code for the delete statement.
|
String |
createDummyUpdateSql()
Creates the SQL code for the dummy update statement.
Useful get an exclusive lock within a transaction. |
String |
createInsertSql()
Creates the SQL code for the insert statement.
|
ModificationLog |
createModificationLog(char modType)
Creates a
ModificationLog. |
PreparedStatementWrapper |
createPreparedStatement(String sql)
Creates a one-shot prepared statement.
Uses ResultSet.TYPE_FORWARD_ONLY and ResultSet.CONCUR_READ_ONLY. |
PreparedStatementWrapper |
createPreparedStatement(String sql,
int resultSetType,
int resultSetConcurrency)
Creates a one-shot prepared statement.
|
StringBuilder |
createSelectAllByIdInnerSql()
Creates the inner sql text to select all fields by ID.
|
StringBuilder |
createSelectAllIdSerialInnerSql()
Creates the inner sql text to select the id and serial fields.
|
StringBuilder |
createSelectAllInnerSql()
Creates the inner sql text to select all fields.
|
String |
createSelectExpiredTableSerials1Sql()
Creates the SQL code for the first statement to select expired table serials.
|
String |
createSelectExpiredTableSerials2Sql()
Creates the SQL code for the second statement to select expired table serials.
|
StringBuilder |
createSelectIdInnerSql()
Creates the inner sql text to select the ID field.
|
String |
createSelectMaxIdSql()
Creates the SQL code for the selectMaxId statement.
|
String |
createSelectMaxTableSerialSql()
Creates the SQL code for the selectMaxTableSerial statement.
|
String |
createSelectSerialSql()
Creates the SQL code for the selectSerial statement.
|
String |
createSelectSql(boolean locked)
Creates the SQL code for the select by id statement.
|
StringBuilder |
createSqlUpdate()
Creates the sql intro text to update objects.
|
String |
createUpdateSerialAndTableSerialSql()
Creates the SQL code for the serial + tableSerial update statement.
|
String |
createUpdateSerialSql()
Creates the SQL code for the serial update statement.
|
String |
createUpdateSql()
Creates the SQL code for the update statement.
|
protected void |
deleteImpl(DbObjectClassVariables<P> classVariables,
Supplier<String> sqlsupplier)
Delete implementation.
|
void |
deleteObject()
Removes this object from the database (with linked objects, i.e.
|
void |
deletePlain()
Deletes this object from the database without any further processing
(i.e.
|
void |
deleteReferencedRelations()
Deletes all composite relations referenced by this object.
|
void |
deleteReferencingRelations()
Deletes all composite relations that reference this object.
|
boolean |
differsPersisted()
Returns whether any of the attributes differs from the values persisted in the database.
This method is only applicable to fulltracked entities and returns false if not fulltracked. |
void |
dummyUpdate()
Performs a dummy update.
The method is provided as an alternative to reloadLockedObject() or selectLockedObject(long)
to lock the object during a transaction by updating the ID without changing it. |
boolean |
equals(Object object)
Indicates whether some other object is "equal to" this one.
|
void |
finishModification(char modType)
Does any postprocessing after delete, insert or update.
|
void |
finishNotUpdated(char modType)
Does any update postprocessing for objects not being updated (because not modified
for some reason, e.g.
|
protected void |
firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
Support for reporting bound property changes for Object properties.
|
Backend |
getBackend()
Gets the backend.
|
String |
getClassBaseName()
Gets the basename of the class of this object.
The basename is the class name without the package name. |
int |
getClassId()
Gets the unique class id.
|
DbObjectClassVariables<P> |
getClassVariables()
Gets the some attributes and variables common to all objects of the same class.
|
int |
getColumnCount()
Gets the number of columns for this entity class.
The method does a dummy select if not known so far. |
List<IdSerialTuple> |
getExpirationBacklog(long minSerial,
long maxSerial)
Gets the expiration backlog for a given range of tableserials.
|
List<IdSerialTuple> |
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. |
void |
getFields(ResultSetWrapper rs)
Retrieves the values of all fields.
|
long |
getId()
Gets the object ID.
|
IdSource |
getIdSource()
Get the IdSource.
|
Logger.Level |
getImmutableLoggingLevel() |
long |
getModificationCount()
Selects the current modification counter for the class of this object.
|
ModificationLog |
getModificationLog()
Gets the modification log if object is being replayed.
|
PreparedStatementWrapper |
getPreparedStatement(StatementId stmtId,
int resultSetType,
int resultSetConcurrency,
Supplier<String> sqlsupplier)
Gets a prepared statement.
|
PreparedStatementWrapper |
getPreparedStatement(StatementId stmtId,
Supplier<String> sqlsupplier)
|
PropertyChangeListener[] |
getPropertyChangeListeners()
Returns an array of all the property change listeners
registered on this PDO.
|
PropertyChangeListener[] |
getPropertyChangeListeners(String propertyName)
Returns an array of all the listeners which have been associated
with the named property.
|
org.tentackle.persist.rmi.AbstractDbObjectRemoteDelegate<P> |
getRemoteDelegate()
Gets the delegate for remote connections.
Each class has its own delegate. |
long |
getSerial()
Gets the serial number.
|
Db |
getSession()
Get the logical db connection for this object.
|
SessionHolder |
getSessionHolder()
Gets the session holder.
|
String |
getTableName()
Gets the database table name for the class of this object.
|
long |
getTableSerial()
Gets the table serial.
|
int |
hashCode()
The hashcode for a Db-object is simply the ID.
It is ok -- according to the contract of hashCode() -- that objects in different tables with the same id may return the same hashcode. If the id is 0, i.e. |
void |
initModification(char modType)
Does any preprocessing before delete, insert or update.
|
protected void |
insertImpl(DbObjectClassVariables<P> classVariables,
Supplier<String> sqlsupplier)
Insert implementation.
|
void |
insertObject()
Inserts this (new) object into the database.
|
void |
insertPlain()
Insert this object into the database without any further processing
(i.e.
|
boolean |
isCountingModification(char modType)
Determines whether modifications of this object are counted in the modification table.
Counting is also turned on if the PDO provides a tableserial. |
boolean |
isDeleted()
Checks whether object is deleted.
|
boolean |
isEntity()
Returns whether instances of this class exist as database entities.
|
boolean |
isIdValid()
Checks whether the object has a valid ID, i.e.
|
boolean |
isImmutable()
Returns whether object is immutable.
|
boolean |
isLoggingModification(char 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 |
isOverloadable()
Gets the overloadable flag.
|
boolean |
isPersistable()
Determines whether this object is allowed to be stored in DB.
By default all mutable objects are allowed to be saved. |
boolean |
isReferenced()
Checks whether this object is referenced by other objects.
|
boolean |
isRemovable()
Checks whether this object can be removed.
|
boolean |
isSessionImmutable()
Returns whether the db is immutable.
|
boolean |
isStatementAlwaysPrepared()
Determines whether prepared statements of this class should always
be prepared each time when the statement used.
|
boolean |
isTableSerialProvided()
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.
|
protected boolean |
isUpdateNecessary()
Returns whether update of this object is necessary.
|
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.
|
void |
loadLazyReferences()
Loads lazy references.
|
void |
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. |
void |
newId()
Obtains a new ID for this object.
|
P |
newInstance()
Creates a new object of the same class.
The new object belongs to the same persistence connection. |
static <P extends AbstractDbObject<?>> |
newInstance(Class<P> clazz)
Instantiates a new db object for a given class without a session.
|
static <P extends AbstractDbObject<?>> |
newInstance(Session session,
Class<P> clazz)
Instantiates a new object for a given class and session.
|
P |
persistObject()
Persists this object and returns it.
|
void |
prepareDelete()
Prepares this object for delete.
The method is invoked at the client-side only, i.e. |
void |
prepareSave()
Prepares this object for saveObject.
The method is invoked at the client-side only, i.e. |
void |
prepareSetFields()
Prepares the object's attributes before the object is saved to the database.
The default implementation does nothing. |
P |
readFromResultSetWrapper(ResultSetWrapper rs)
Reads the values from a result-set into this object.
|
P |
reloadLockedObject()
Reloads the object with a write lock.
|
P |
reloadObject()
Reloads the object.
|
void |
removeAllPropertyChangeListeners()
Removes all
PropertyChangeListeners. |
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list.
|
void |
removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Removes a
PropertyChangeListener from the listener
list for a specific property. |
void |
reserveId()
Reserves an ID.
|
ResultSetWrapper |
resultAllIdSerial()
Selects all id,serial-pairs of this class and returns the ResultSetWrapper.
|
ResultSetWrapper |
resultAllObjects()
Selects all objects of this class and returns the ResultSetWrapper.
|
protected void |
revertAttributesToSnapshot(AbstractDbObject snapshot)
Copies all attributes from a snapshot object back to this object.
|
void |
saveObject()
Saves this object.
This is the standard method applications should use to insert or update objects. If the ID is 0, a new ID is obtained and this object inserted. |
void |
saveReferencedRelations(boolean update)
Saves all composite relations referenced by this object.
|
void |
saveReferencingRelations(boolean update)
Saves all composite relations that reference this object.
|
List<IdSerialTuple> |
selectAllIdSerial()
Selects all id,serial-pairs of this class as a list of
IdSerialTuple. |
List<? extends P> |
selectAllObjects()
Selects all objects of this class as a
List. |
List<IdSerialTuple> |
selectExpiredTableSerials(long oldSerial)
Determines the objects with a tableSerial starting at a given serial.
|
List<IdSerialTuple> |
selectExpiredTableSerials(long oldSerial,
long maxSerial)
Determines the objects with their tableSerial within a given range.
|
P |
selectLockedObject(long id)
Load the object from the database with exclusive lock (aka write lock).
|
long |
selectMaxId()
Selects the highest id.
|
long |
selectMaxTableSerial()
Selects the highest table serial.
|
P |
selectNextObject(ResultSetWrapper rs)
Selects the next object from a resultset.
|
P |
selectObject(long id)
Loads an object from the database by its unique ID.
|
long |
selectSerial(long id)
Selects the serial-number for a given object id.
|
void |
setClassId(int classId)
Sets the class id for this po.
|
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.
|
void |
setImmutable(boolean immutable)
Defines whether attributes of the object may be changed.
|
void |
setImmutableLoggingLevel(Logger.Level immutableLoggingLevel) |
void |
setModificationLog(ModificationLog modlog)
Sets a (transient) reference to a modification log.
Used to keep the original user and timestamp when an object gets replayed in another server instance. |
void |
setModified(boolean modified)
Sets the modified flag.
|
void |
setOverloadable(boolean overloadable)
Defines whether object may be loaded more than once from storage.
By default, overloading is not allowed. |
void |
setSerial(long serial)
Sets the serial number (modification count).
|
void |
setSession(Session session)
Sets the logical db connection for this object.
|
void |
setSessionHolder(SessionHolder sessionHolder)
Sets the session holder for this object.
|
void |
setSessionImmutable(boolean sessionImmutable)
Sets the db to immutable.
|
void |
setStatementAlwaysPrepared(boolean alwaysPrepare)
Sets the always prepare flag.
|
void |
setTableSerial(long tableSerial)
Sets the table serial number (table modification count).
|
String |
toGenericString()
Gets the string value: "<className>[id/serial]".
|
String |
toIdString()
Gets the ID string: "classId:id".
The ID string describes the PDO by its classId and object-ID. |
String |
toString()
Gets the default string value.
The default implementation invokes toGenericString(). |
void |
unmarkDeleted()
Removes the deleted mark.
|
protected void |
updateImpl(DbObjectClassVariables<P> classVariables,
Supplier<String> sqlsupplier)
Update implementation.
|
void |
updateObject()
Updates this object to the database.
The modified attribute gets cleared if insert was successful. |
void |
updatePlain()
Updates this object to the database without any further processing
(i.e.
|
void |
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. |
void |
updateSerialAndTableSerial()
Same as
updateSerial() but updates tableSerial as well. |
public static final String CN_ID
public static final String AN_ID
public static final String CN_SERIAL
public static final String AN_SERIAL
public static final String CN_TABLESERIAL
public static final String AN_TABLESERIAL
public static final String CN_CLASSID
public static final String AN_CLASSID
public static IdComparator<AbstractDbObject<?>> idComparator
public static NameComparator<AbstractDbObject<?>> nameComparator
public static NameIdComparator<AbstractDbObject<?>> nameIdComparator
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_SYNC
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
protected boolean preparePending
public AbstractDbObject(Db db)
db - the logical Db-connectionpublic AbstractDbObject()
Db-connection.
The connection must be set via setSession(org.tentackle.pdo.Session) in order to use it.public static <P extends AbstractDbObject<?>> P newInstance(Class<P> clazz)
P - the class typeclazz - the classpublic static <P extends AbstractDbObject<?>> P newInstance(Session session, Class<P> clazz)
P - the class typesession - the sessionclazz - the classpublic String toString()
toGenericString().public final String toGenericString()
Example: "de.krake.plsbl.Product[344/2]"
toGenericString in interface Identifiablepublic final String toIdString()
Example: "1022:1258474"
public DbObjectClassVariables<P> getClassVariables()
DbObjectClassVariables.public String getClassBaseName()
public int getClassId()
public void setClassId(int classId)
classId - the class id, 0 if use id from classvariablespublic P 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 PersistenceException if they should not be cloned
depending on the application logic (not CloneNotSupportedException).
protected void createAttributesInSnapshot(AbstractDbObject snapshot)
snapshot - the snapshotprotected void revertAttributesToSnapshot(AbstractDbObject snapshot)
snapshot - the snapshot objectpublic void acceptPersistenceVisitor(PersistenceVisitor visitor, char modType)
visitor - the visitormodType - the modification typepublic void addPropertyChangeListener(PropertyChangeListener listener)
Please notice that all listeners are automatically removed after setModified(false)!
listener - the property change listener to be addedremovePropertyChangeListener(java.beans.PropertyChangeListener),
getPropertyChangeListeners(),
addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener),
setModified(boolean),
removeAllPropertyChangeListeners()public void removePropertyChangeListener(PropertyChangeListener listener)
listener - the PropertyChangeListener to be removedaddPropertyChangeListener(java.beans.PropertyChangeListener),
getPropertyChangeListeners(),
removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)public PropertyChangeListener[] getPropertyChangeListeners()
PropertyChangeListeners
or an empty array if no property change
listeners are currently registeredaddPropertyChangeListener(java.beans.PropertyChangeListener),
removePropertyChangeListener(java.beans.PropertyChangeListener),
getPropertyChangeListeners(java.lang.String),
PropertyChangeSupport.getPropertyChangeListeners()public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
Note that if this pdo is inheriting a bound property, then no event will be fired in response to a change in the inherited property.
If propertyName or listener is null,
no exception is thrown and no action is taken.
Please notice that all listeners are automatically removed after setModified(false)!
propertyName - one of the property names listed abovelistener - the property change listener to be addedremovePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener),
getPropertyChangeListeners(java.lang.String),
addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener),
setModified(boolean),
removeAllPropertyChangeListeners()public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
PropertyChangeListener from the listener
list for a specific property. This method should be used to remove
PropertyChangeListeners
that were registered for a specific bound property.
If propertyName or listener is null,
no exception is thrown and no action is taken.
propertyName - a valid property namelistener - the PropertyChangeListener to be removedaddPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener),
getPropertyChangeListeners(java.lang.String),
removePropertyChangeListener(java.beans.PropertyChangeListener)public PropertyChangeListener[] getPropertyChangeListeners(String propertyName)
propertyName - a valid property namePropertyChangeListeners associated with
the named property; if no such listeners have been added or
if propertyName is null, an empty
array is returnedaddPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener),
removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener),
getPropertyChangeListeners()public void removeAllPropertyChangeListeners()
PropertyChangeListeners.
Using PropertyChangeListeners implies the risk to "forget"
about such listeners for long living objects as it is the case in
desktop client applications. This method safely removes all listeners.
It is invoked from setModified(false).
setModified(boolean)protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
propertyName - the property whose value has changedoldValue - the property's previous valuenewValue - the property's new valuepublic void setModificationLog(ModificationLog modlog)
modlog - the modification log, null to clearpublic ModificationLog getModificationLog()
public void setOverloadable(boolean overloadable)
overloadable - true if overloading is allowedpublic boolean isOverloadable()
public boolean isEntity()
public P newInstance()
public void setSessionHolder(SessionHolder sessionHolder)
If a holder is set, getSession() will return the session from the holder.
sessionHolder - the session holderpublic SessionHolder getSessionHolder()
public void setSessionImmutable(boolean sessionImmutable)
setSessionImmutable in interface SessionDependablesessionImmutable - true if db cannot be changed anymorepublic boolean isSessionImmutable()
isSessionImmutable in interface SessionDependablepublic void setSession(Session session)
setSession in interface SessionDependablesession - the db sessionpublic Db getSession()
getSession in interface SessionProviderpublic Backend getBackend()
public void setId(long id)
isModified().setId in interface Identifiableid - the object idpublic long getId()
getId in interface Identifiablepublic void setSerial(long serial)
isModified().setSerial in interface SerialNumberedserial - the serial numberpublic long getSerial()
getSerial in interface SerialNumberedpublic 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()
public boolean isVirgin()
isVirgin in interface SerialNumberedpublic 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'
If invoked with modified=false (which is the case after been loaded from storage or after successful delete/update/insert) all property change listeners will also be removed.
modified - is true if object is flagged modified, false if not.public void setImmutable(boolean immutable)
Any attempt to invoke a setter on an immutable object
results in a PersistenceException.
All generated methods check this. Note that even lazy loading of
an immutable object isn't allowed as well because the
reference to the lazily loaded object must be changed.
setImmutable in interface Immutableimmutable - true if object is immutablepublic boolean isImmutable()
By default objects are mutable.
isImmutable in interface Immutablepublic void setImmutableLoggingLevel(Logger.Level immutableLoggingLevel)
setImmutableLoggingLevel in interface Immutablepublic Logger.Level getImmutableLoggingLevel()
getImmutableLoggingLevel in interface Immutablepublic boolean isTracked()
public boolean isModified()
By definition, an object is 'modified' if the object OR ANY of its components 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 differsPersisted()
public boolean isPersistable()
public PreparedStatementWrapper getPreparedStatement(StatementId stmtId, int resultSetType, int resultSetConcurrency, Supplier<String> sqlsupplier)
stmtId - the statement idresultSetType - the result set typeresultSetConcurrency - the result set concurrencysqlsupplier - the sql code supplierpublic PreparedStatementWrapper getPreparedStatement(StatementId stmtId, Supplier<String> sqlsupplier)
stmtId - the statement idsqlsupplier - the sql code supplierpublic PreparedStatementWrapper createPreparedStatement(String sql, int resultSetType, int resultSetConcurrency)
sql - the sql coderesultSetType - the result set typeresultSetConcurrency - the result set concurrencypublic PreparedStatementWrapper createPreparedStatement(String sql)
ResultSet.TYPE_FORWARD_ONLY and ResultSet.CONCUR_READ_ONLY.sql - the sql codepublic void saveReferencingRelations(boolean update)
update - true if this is an update operation, else insertpublic void saveReferencedRelations(boolean update)
update - true if this is an update operation, else insertpublic void deleteReferencingRelations()
public void deleteReferencedRelations()
public void loadLazyReferences()
The method is used to load any lazy references (not composite) before an object
is being transferred to another tier. Some lazy references may be necessary
to persist the object on the other side (due to some weird business logic or
replicated environments such as PoolKeeper). If those referenced objects are
not available yet on the remote side (because of an inappropriately ordered stream),
they must be preloaded on the local side before Serialization.
Not to mention that those references must not be transient!
The default implementation does nothing.
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 isCountingModification(char modType)
modType - is one of the modtypes INSERT, UPDATE, DELETE, ...public boolean isTableSerialProvided()
public boolean isLoggingModification(char modType)
modType - is one of the modtypes INSERT, UPDATE, DELETE, ...ModificationLogpublic boolean equals(Object object)
DbObjects are identical if their IDs and classes are identical.
IDs are *NOT* necessarily unique among all db-tables! (see poolkeeper).
Does not throw any exception, so its safe to add null-objects
to set of DbObjects.
If this or the passed object has an Id of 0, there is no domain identity
and Object.equals(java.lang.Object)
will be invoked.
public int compareTo(P obj)
compareTo in interface Comparable<P extends AbstractDbObject<P>>obj - the object to compare this object withpublic int hashCode()
Object.hashCode() is returned.hashCode in class ObjectObject.equals(java.lang.Object),
Hashtablepublic IdSource getIdSource()
public P readFromResultSetWrapper(ResultSetWrapper rs)
rs - is the result set (wrapper)public P selectObject(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);
id - is the object idpublic P selectLockedObject(long id)
id - is the object idpublic P reloadObject()
Note: to make sure that any lazy inits are cleared, the returned object is always a new object.
public P reloadLockedObject()
public ResultSetWrapper resultAllObjects()
public ResultSetWrapper resultAllIdSerial()
public P selectNextObject(ResultSetWrapper rs)
rs - the result setpublic List<? extends P> selectAllObjects()
List.public List<IdSerialTuple> selectAllIdSerial()
IdSerialTuple.public long selectSerial(long id)
id - the object idpublic long selectMaxId()
public long selectMaxTableSerial()
public void copyToDb(Db destDb, boolean plain)
destDb - the destination dbplain - is true to use insertPlain (recommended), else insertpublic int getColumnCount()
public void insertPlain()
protected void insertImpl(DbObjectClassVariables<P> classVariables, Supplier<String> sqlsupplier)
Should not be used by applications. Will be overridden for multi-inheritance.
classVariables - the classvariablessqlsupplier - the SQL code supplierpublic void deletePlain()
protected void deleteImpl(DbObjectClassVariables<P> classVariables, Supplier<String> sqlsupplier)
Should not be used by applications. Will be overridden for multi-inheritance.
classVariables - the classvariablessqlsupplier - the SQL code supplierpublic void updatePlain()
protected void updateImpl(DbObjectClassVariables<P> classVariables, Supplier<String> sqlsupplier)
Should not be used by applications. Will be overridden for multi-inheritance.
classVariables - the classvariablessqlsupplier - the SQL code supplierpublic void dummyUpdate()
reloadLockedObject() or selectLockedObject(long)
to lock the object during a transaction by updating the ID without changing it.public void updateSerial()
isUpdatingSerialEvenIfNotModified()public void updateSerialAndTableSerial()
updateSerial() but updates tableSerial as well.
Notice: the tableSerial is NOT modified in the current object,
but only in the database!public boolean isUpdatingSerialEvenIfNotModified()
The default implementation returns false. Override this method to change to 'true'.
updateObject()public void initModification(char modType)
modType - is the modification type: DELETE, INSERT or UPDATEpublic void finishModification(char modType)
modType - is the modification type: DELETE, INSERT or UPDATEpublic void finishNotUpdated(char modType)
AbstractPersistentObject.modType - is the modification type: DELETE, INSERT or UPDATEprotected long beginTx(String txName)
txName - the transaction namepublic void insertObject()
Note: this method does *NOT* set the ID and should be used
by the application with great care! Use saveObject() instead!
protected boolean isUpdateNecessary()
public void updateObject()
saveObject() instead!public void prepareSave()
prepareSetFields() which is invoked at the server-side only).
Example:
public void prepareSave() {
// do something
...
super.prepareSave(); // IMPORTANT!!!
}
Notice that the method is invoked outside of the transaction.public void clearOnRemoteSave()
public void saveObject()
public P persistObject()
public void prepareDelete()
Example:
public void prepareDelete() {
// do something
...
super.prepareDelete(); // IMPORTANT!!!
}
Notice that the method is invoked outside of the transaction and that it
is not invoked if the object is new or not saveable.public void deleteObject()
isNew() again.
It is also verified that the object isPersistable().NotFoundException - if object is new or not saveable or not in databasepublic void markDeleted()
isModified().unmarkDeleted()public void unmarkDeleted()
markDeleted()public long countModification()
public long getModificationCount()
public List<IdSerialTuple> selectExpiredTableSerials(long oldSerial)
oldSerial - non-inclusive lower bound for tableSerial (> oldSerial)public List<IdSerialTuple> selectExpiredTableSerials(long oldSerial, long maxSerial)
oldSerial - non-inclusive lower bound for tableSerial (> oldSerial)maxSerial - inclusive upper bound for tableSerial (≤ maxSerial)public List<IdSerialTuple> 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 List<IdSerialTuple> 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 typepublic void logModification(char modType)
modType - is the modification type (INSERT, DELETE or UPDATE)public org.tentackle.persist.rmi.AbstractDbObjectRemoteDelegate<P> getRemoteDelegate()
public boolean isStatementAlwaysPrepared()
public void setStatementAlwaysPrepared(boolean alwaysPrepare)
alwaysPrepare - true if always preparepublic String getTableName()
public void getFields(ResultSetWrapper rs)
rs - the result setpublic void prepareSetFields()
public int setFields(PreparedStatementWrapper st)
PreparedStatementWrapper from the object's attributes.st - the statementpublic StringBuilder createSelectAllInnerSql()
Returns something like:
"* FROM xytable WHERE 1=1"
public StringBuilder createSelectAllIdSerialInnerSql()
Returns something like:
"id,serial FROM xytable WHERE 1=1"
public StringBuilder createSelectAllByIdInnerSql()
Returns something like:
"* FROM xytable WHERE id=?"
public StringBuilder createSelectIdInnerSql()
Returns something like:
"id FROM xytable WHERE 1=1"
public StringBuilder createDeleteAllSql()
Returns something like:
"DELETE FROM xytable WHERE 1=1"
public StringBuilder createSqlUpdate()
Returns something like:
"UPDATE xytable SET "
public String createUpdateSql()
public String createInsertSql()
public String createSelectSql(boolean locked)
locked - true if select locked (FOR UPDATE)public String createSelectSerialSql()
public String createSelectMaxIdSql()
public String createSelectMaxTableSerialSql()
public String createDeleteSql()
public String createDummyUpdateSql()
public String createUpdateSerialSql()
public String createUpdateSerialAndTableSerialSql()
public String createSelectExpiredTableSerials1Sql()
public String createSelectExpiredTableSerials2Sql()
protected void assertNotRemote()
protected void assertRemote()
protected void assertNumberOfRowsAffected(int count,
int expected)
Use whenever an executeUpdate is not related to this object.
count - the effective number of rows affectedexpected - the expected number of rows affectedNotFoundException - if count < 1protected void assertThisRowAffected(int count)
Use whenever an executeUpdate is related to this object.
count - the effective number of rows affectedprotected void assertPersistable()
protected void assertNotNew()
protected void assertNotOverloaded()
protected void assertMutable()
Copyright © 2016 Krake Softwaretechnik. All rights reserved.