Class AbstractPersistentObject<T extends PersistentDomainObject<T>,P extends AbstractPersistentObject<T,P>>
- Type Parameters:
T- the PDO class (interface)P- the persistence implementation class
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<P>,ModificationLoggable,org.tentackle.misc.Identifiable,org.tentackle.misc.Immutable,org.tentackle.misc.Modifiable,org.tentackle.misc.SerialNumbered,org.tentackle.misc.Snapshotable<T>,DomainContextDependable,DomainContextProvider,PdoMethodCacheProvider<T>,PdoProvider<T>,PersistenceDelegate<T>,PersistentObject<T>,ProxyDelegate<T>,org.tentackle.reflect.EffectiveClassProvider<T>,org.tentackle.reflect.Interceptable,org.tentackle.session.SessionDependable,org.tentackle.session.SessionProvider,org.tentackle.validate.ScopeConfigurator,org.tentackle.validate.Validateable
- Direct Known Subclasses:
NumberPoolPersistenceImpl,NumberRangePersistenceImpl,SecurityPersistenceImpl
- Author:
- harald
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringname of the editedBy attribute.static final Stringname of the editedExpiry attribute.static final Stringname of the editedSince attribute.static final Stringname of the normText attribute.static final Stringname of rootclass-ID attribute.static final Stringname of root-ID attribute.static final Stringname of the editedBy column.static final Stringname of the editedExpiry column.static final Stringname of the editedSince column.static final Stringname of the normText column.static final Stringname of rootclass-ID column.static final Stringname of root-ID column.static final Stringdelete all in contextstatic final StringsaveImpl copy in contextstatic final Stringtransfer edited bystatic final Stringupdate tokenlockstatic final Stringupdate tokenlock onlyFields inherited from class org.tentackle.dbms.AbstractDbObject
AN_CLASSID, AN_ID, AN_SERIAL, AN_TABLESERIAL, CN_CLASSID, CN_ID, CN_SERIAL, CN_TABLESERIAL, 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_SYNC, TX_UPDATE_OBJECT, TX_UPDATE_PLAIN, TX_UPDATE_SERIAL, TX_UPDATE_SERIAL_AND_TABLESERIAL, TX_UPDATE_TABLESERIAL -
Constructor Summary
ConstructorsConstructorDescriptionCreates an application database object without a database context.Creates an application database object without a database context.AbstractPersistentObject(T pdo, DomainContext context) Creates an application database object.AbstractPersistentObject(T pdo, org.tentackle.session.Session session) Creates an application database object without a domain context for a given connection. -
Method Summary
Modifier and TypeMethodDescriptionintaddComponents(org.tentackle.misc.IdentifiableMap<PersistentDomainObject<?>> components, boolean onlyLoaded) Adds the components of this object to a map.intaddComponents(org.tentackle.misc.IdentifiableMap<PersistentDomainObject<?>> components, Collection<? extends PersistentDomainObject<?>> objects, boolean onlyLoaded) Adds the components of a collection to a map.<R extends PersistentDomainObject<R>>
booleanaddReferencingClass(Class<R> clazz, String methodPath) Adds a PDO class that is referencing this PDO clazz.protected voidaddSnapshot(T snapshot) Adds a snapshot to the list of snapshots.voidapplyTokenLockInfo(TokenLockInfo tokenLockInfo) Applies the given token lock info.protected voidAsserts that the domain context is mutable.protected voidAsserts that this is an embedded PDO.protected voidprotected voidAsserts that entity provides a normtext.voidAsserts that this is not an abstract entity class.protected voidAsserts that the PDO is not cached.protected voidprotected voidChecks read permission for this object.protected voidAsserts that the po's context is a root context.voidChecks the root context against the security rules.voidChecks if the po is a root entity.protected voidAsserts that entity provides a normtext.protected voidassertValidSnapshot(T snapshot) Asserts that given snapshot is valid for this object.protected voidChecks write permission for this object.booleanClears or renews the token lock.protected final Pclone()Clones this persistent object.
The method is final to prevent applications from overriding it and spoiling the contract withcreateSnapshot().voidConfigures the columns of an embedded PDO.voidconfigureRemoteObject(DomainContext context, PersistentDomainObject<?> obj) Configures the remotely retrieved object.voidconfigureRemoteObjects(DomainContext context, Collection<? extends PersistentDomainObject<?>> objects) Configures the remotely retrieved objects.booleancontainsPattern(String pattern) Searches for a "pattern" in this object.
The default implementation looks for the pattern in the normtext.copy()Creates a deep copy of this PDO.
The copied PDO and its components, if any, are new (id=0).longCreates the normalized text of all attributes with the NORMTEXT-option.
The method is usually generated by the MethodsImpl wurblet.protected voidUpdates the components in snapshot object.
The snapshot object is assumed to be a clone of this object.Creates the SQL code for the dummy update statement.
Useful get an exclusive lock within a transaction.protected org.tentackle.misc.PropertySupportCreates aQueryto retrieve a list of this entity type.createQuery(JoinedSelect<T> js) Creates aQueryto retrieve a list of this entity type.Creates the normalized text of all relations with the NORMTEXT-option.
The method is usually generated by the PdoRelations wurblet.createSelectAllByIdInnerSql(org.tentackle.sql.Backend backend) createSelectAllInnerSql(org.tentackle.sql.Backend backend) createSelectAllSql(org.tentackle.sql.Backend backend) Creates SQL-code for select all.
Appends context condition and order by clause if configured.createSelectAllWithExpiredTableSerialsSql(org.tentackle.sql.Backend backend) Creates SQL-code forselectAllWithExpiredTableSerials(long).
Appends context condition and order by clause if configured.
By default, the result is sorted by tableserial + id.createSelectByNormTextSql(org.tentackle.sql.Backend backend, boolean not) Creates the SQL code for select by normtext.Creates the SQL code for the first statement to select expired table serials.Creates the SQL code for the second statement to select expired table serials.createSelectIdInnerSql(boolean withAlias) Creates the inner sql text to select the ID field.createSelectIdInnerSql(PersistentObjectClassVariables<? super T, ? super P> classVariables, boolean withAlias) Creates the inner sql text to select the ID field.Creates the SQL code for the selectMaxId statement.Creates the SQL code for the selectMaxTableSerial statement.Creates the SQL code for the selectSerial statement.Creates the SQL code for the select inupdateTokenLock(org.tentackle.common.Timestamp, long, org.tentackle.common.Timestamp)statement.Creates a snapshot of this object.protected StatementKeycreateStatementKey(StatementId stmtId) Creates the SQL code for thetransferTokenLock(long)statement without tableserial.Creates the SQL code for thetransferTokenLock(long)statement with tableserial.Creates the SQL code for the serial + tableSerial update statement.Creates the SQL code for the serial update statement.Creates the SQL code for theupdateTokenLockOnly()statement.Creates the SQL code for theupdateTokenLock(org.tentackle.common.Timestamp, long, org.tentackle.common.Timestamp)statement.Creates the SQL code for theupdateTokenLock(org.tentackle.common.Timestamp, long, org.tentackle.common.Timestamp)statement with mod counting.voiddelete()protected <X extends PersistentDomainObject<X>>
voiddelete(Collection<X> pdos) Deletes a List of objects.
This method is provided to mark components in PDOs only.protected voiddelete(PersistentDomainObject<?> pdo) Deletes a PDO.
This method is provided to save components in PDOs only.protected voidImplementation of delete bypassing the invocation handler.protected voiddeleteImpl(DbObjectClassVariables<P> classVariables, SqlSupplier sqlSupplier) protected <X extends PersistentDomainObject<X>>
voiddeleteMissingInCollection(Collection<X> oldCollection, Collection<X> newCollection) Deletes all objects in oldList that are not in newList.
This method is provided to save components in PDOs only.voidvoidDeletes this object and all its components without any further processing.
Same asAbstractDbObject.deletePlain()but with components.intdeletePlainWithComponents(Collection<? extends PersistentDomainObject<?>> objects) Deletes plain with components all objects of a collection.derivePdoFromPo(T pdo, P po) Derive the concrete PDO from a given PO.voidvoiddiscardSnapshot(T snapshot) voidExecutes a query for a prepared statement and returns the first PDO.Executes a query for a prepared statement and returns the first PDO.Executes the query for a prepared statement and returns the results in a list.Executes the query for a prepared statement and returns the results in a list.org.tentackle.misc.TrackedList<T>executeQuery(Query query) Executes aQuerywhich was built to return a tracked list of this entity type.org.tentackle.misc.TrackedList<T>executeQuery(Query query, JoinedSelect<T> js) Executes aQuerywhich was built to return a tracked list of this entity type.voidexecuteQueryToList(PreparedStatementWrapper st, JoinedSelect<T> js, List<T> list) Executes the query for a prepared statement and adds the results to a list.voidexecuteQueryToList(ResultSetWrapper rs, JoinedSelect<T> js, List<T> list) Executes the query for a prepared statement and adds the results to a list.executeScrollableQuery(Query query) Executes aQuerywhich was built to return a tracked list of this entity type.executeScrollableQuery(Query query, JoinedSelect<T> js) Executes aQuerywhich was built to return a tracked list of this entity type.org.tentackle.misc.TrackedList<T>Executes the query for a prepared statement and returns the results in a tracked list.org.tentackle.misc.TrackedList<T>Executes the query for a prepared statement and returns the results in a tracked list.voidexpireCache(long maxSerial) Expires the cache according to the serial numbers.
If objects of this class are cached, the cache must be expired on updates, etc...Checks whether this object (if saved) would violate any unique constraints.protected voidfinishModification(ModificationType modType) protected voidfinishNotUpdated(ModificationType modType) protected PreparedStatementWrappergetBatchablePreparedStatement(ModificationType modType, StatementId stmtId, SqlSupplier sqlSupplier) Gets a prepared statement and marks it as batchable.
If there is a transaction running in batched mode, the statement will be executed via JDBC batching.getCache()Gets the cache.longGets the cache access count.longGets the last cache access time.Gets the application oriented class variables for this object.
Class variables for classes derived from AbstractPersistentObject are kept in an instance ofPersistentObjectClassVariables.getColumnName(String name) Gets the full column name with table alias.getColumnNames(Supplier<List<String>> columnNamesSupplier) Gets the comma-separated list of column names with table alias.getColumnNames(List<String> columnNames) Gets the comma-separated list of column names with table alias.Gets the column prefix for this embedded PDO.longlongGets the user id from the current domain context.
The ID is derived from the session info of the session associated with the domain context.Class<? extends org.tentackle.validate.ValidationScope>[]Adds the eager joins to the created SQL.Returns the eager joins for this PDO.longGets the id of the user currently editing this object.org.tentackle.common.TimestampGets the time since when this object is being edited.org.tentackle.common.TimestampGets the time since when this object is being edited.<E extends PersistentDomainObject<E>>
EGets the normtext.getPdo()Gets the pdo-class.<R extends PersistentDomainObject<R>>
Class<? extends AbstractPersistentObject<R,?>> getPersistenceClass(Class<R> clazz) Gets the persistence class from a pdo class.intlonggetSecurityResult(Permission permission) Gets the SQL string used in WHERE-clauses for single table inheritance entities.Gets the SQL code for the context condition.Gets the table alias.longGets the expiration in milliseconds of a token lock.
If isTokenLockProvided, the default is 1 hour, else 0.Gets the alias for the topmost super class.Gets the tablename for the topmost super class.Gets the optional transient data object.
When objects need to be reloaded from storage, all non-persistent data attached to the object would be lost.Gets the valid class-IDs for the concrete types of this type.
Applies only to entities of single- or multi-table inheritance hierarchies, except the topmost entity.protected voidinitModification(ModificationType modType) protected voidinsertImpl(DbObjectClassVariables<P> classVariables, SqlSupplier sqlSupplier) voidvoidInserts this object and all its components without any further processing.
Same asAbstractDbObject.insertPlain()but with components.intinsertPlainWithComponents(Collection<? extends PersistentDomainObject<?>> objects) Inserts plain with components all objects of a collection.booleanReturns whether this an abstract PDO.
Abstract PDOs are real objects but cannot be persisted.booleanDetermines whether object is cacheable or not.booleanisCached()booleanTells whether this object is composite (i.e.booleanisCopy()booleanReturns whether the domain context is immutable.booleanbooleanbooleanChecks whether object has been marked expired.booleanReturns whether an explicit id alias is necessary in joins.
This applies to MULTI-table inherited PDOs only (abstracts and leaves).protected <X extends PersistentDomainObject<X>>
booleanisModified(Collection<X> pdos) Checks whether some objects in the list are modified.
This method is provided to save components in PDOs only.booleanbooleanisPermissionAccepted(Permission permission) booleanbooleanDetermines whether the application is allowed to read this PDO.
Makes no sense to publish in PersistentObject because PDOs without read permissions are not read from the database at all.booleanbooleanDetermines whether to renew the token lock on saveImpl or update.booleanboolean<C extends PersistentDomainObject<C>>
booleanisRootEntityOf(C component) booleanbooleanbooleanbooleanChecks whether this object is token locked (editedBy != 0) and the lock is not expired.booleanisTokenLockedBy(long userId) Checks whether this object is edited locked by given user.booleanChecks whether this object is edited locked by the current user.booleanBy default, objects don't need to include the editedBy/Since/Expiry columns in the database table.protected booleanbooleanDetermines whether in updates of composite objects unmodified objects in the update path get at least the serial updated or are not touched at all.booleanbooleanbooleanorg.tentackle.misc.IdentifiableMap<? extends PersistentDomainObject<?>>loadComponents(boolean onlyLoaded) voidmark cache access (count and set current system-time)protected <X extends PersistentDomainObject<X>>
voidmarkDeleted(Collection<X> pdos) Marks all objects in a list to be deleted.
This method is provided to mark components in PDOs only.protected voidmarkDeleted(PersistentDomainObject<?> pdo) Marks an object to be deleted.
This method is provided to mark components in PDOs only.me()voidnewId()orderBy()Gets the natural ordering to be added in WHERE-clauses following "ORDER BY ".persist()protected TImplementation of persist bypassing the invocation handler.protected voidPresets the attributes with initial values, if the PDO is persisted the first time.
The method is invoked before the PDO is validated.voidreadJoinedRow(ResultSetWrapper rs, JoinedSelect<T> js) Reads the next row from a result set within a joined select.
The results may come in any order.voidReleases an edited by lock.
Use this method if a PDO needs to be unlocked without being persisted.reload()Reloads the object.Reloads the object with a write-lock.
Restores transient data, if present.<R extends PersistentDomainObject<R>>
booleanremoveReferencingClass(Class<R> clazz, String methodPath) Removes a PDO class that is referencing this PDO clazz.voidRequests an edited by lock.resultAll(JoinedSelect<T> js) Gets the result set for all objects in the current context for use in lists.resultAllCursor(JoinedSelect<T> js) Gets the result set for all objects in the current context for use in cursors.
Cursors differ from lists because they needResultSet.TYPE_SCROLL_INSENSITIVEset.resultAllWithExpiredTableSerials(JoinedSelect<T> js, long oldSerial) Gets the result set for all objects in the current context with a given expired tableserial.resultByNormText(String text, JoinedSelect<T> js) Gets the result set for the normtext query.resultByNormTextCursor(String text, JoinedSelect<T> js) Gets the result set for the normtext query as a cursor.protected voidCopies all attributes from a snapshot object back to this object.protected voidReverts all components of this object to a given snapshot.voidrevertToSnapshot(T snapshot) Reverts the state of this object to given snapshot.voidsave()static <X extends PersistentDomainObject<X>>
voidsave(Collection<X> pdos, boolean modifiedOnly) Saves a list of PDOs.
This method is provided to save components in PDOs only.static voidsave(PersistentDomainObject<?> pdo) Saves a PDO.
This method is provided to save components in PDOs only.protected voidsaveImpl()Implementation of save bypassing the invocation handler.select(long id) Loads a PDO from the database by its unique ID.select(long id, boolean forUpdate) Loads a PDO from the database by its unique ID.Selects all records in current context as a list.org.tentackle.misc.ScrollableResource<T>Selects all records in current context as a cursorGets all objects in context via cache.selectAllWithExpiredTableSerials(long oldSerial) selectByNormText(String text) Selects all objects with a given normtext as a list.org.tentackle.misc.ScrollableResource<T>Selects all objects with a given normtext as a cursor.selectByTemplate(AbstractPersistentObject<T, P> template) Selects an object according to a template object.selectCached(long id) Gets the object via cache.
If there is no cache (i.e.selectCachedOnly(long id) Gets the object via cache only.
If there is no cache (i.e.selectForCache(long id) selectForUpdate(long id) Loads and write-locks a PDO from the database by its unique ID.selectLatest(long greaterId, int limit) voidsetCopy(boolean copy) voidsetDomainContext(DomainContext context) voidsetDomainContextImmutable(boolean contextImmutable) Sets the immutable flag of the domain context.voidsetEditedBy(long editedBy) Sets the user editing this object.
Does *NOT* alter isModified() and does not require the object to be mutable.voidsetEditedExpiry(org.tentackle.common.Timestamp editedExpiry) Sets the time when the token should expire.
Does *NOT* alter isModified() and does not require the object to be mutable.voidsetEditedSince(org.tentackle.common.Timestamp editedSince) Sets the time since when this object is being edited.
Does *NOT* alter isModified() and does not require the object to be mutable.intsetEmbeddedFields(int ndx, PreparedStatementWrapper st) Sets the fields of an embedded PDO.voidsetEmbeddingPersistentObject(AbstractPersistentObject<?, ?> embeddingParent, String columnPrefix) Sets the embedding PO for this embedded PDO.
Throws aPersistenceExceptionif this is not an embedded PDO.voidsetExpired(boolean expired) Sets this object's expiration flag.voidsetModified(boolean modified) Sets the modified flag.voidsetNormText(String normText) Sets the normtext.voidSets the PDO.voidsetPersistable(boolean persistable) Sets the local persistable flag.voidsetRenewTokenLockRequested(boolean renewTokenLock) Sets whether to apply or renew the token lock on insert or update.voidsetRootClassId(int rootClassId) Sets the class ID of the root entity this component belongs to.voidsetRootId(long rootId) Sets the ID of the root entity this component belongs to.voidsetTransientData(Object data) Sets the optional transient data object.final StringtransferTokenLock(long userId) protected voidupdateImpl(DbObjectClassVariables<P> classVariables, SqlSupplier sqlSupplier) voidUpdates the normtext attribute if normtext is provided by this PDO.voidbooleanUpdates the root context.
Method is used after deserialization.voidupdateTokenLock(org.tentackle.common.Timestamp tokenExpiry) Updates the token lock columns in the database record.
Will *NOT* log modification and *NOT* update the serial-counter! Must be called from within application where appropriate.voidupdateTokenLock(org.tentackle.common.Timestamp tokenExpiry, long userId, org.tentackle.common.Timestamp curTime) Updates the token lock columns in the database record.
Will *NOT* log modification and *NOT* update the serial-counter! Must be called from within application where appropriate.voidUpdate the token-lock attributes to persistent storage.
No check is done whether locked or not and there is no serial update and no modlog.voidvalidate()List<org.tentackle.validate.ValidationResult>Methods inherited from class org.tentackle.dbms.AbstractDbObject
acceptPersistenceVisitor, addPropertyListener, addPropertyListener, alignComponents, applyDbObjectResult, assertNew, assertNotNew, assertNotOverloaded, assertNotRemote, assertNumberOfRowsAffected, assertRemote, assertThisRowAffected, attributesModified, clearOnRemoteSave, compareTo, createDeleteAllSql, createDeleteSql, createInsertSql, createPreparedStatement, createPreparedStatement, createSelectObjectsWithExpiredTableSerialsSql, createSelectSql, createSqlUpdate, createUpdateAndSetSerialSql, createUpdateSql, deletePlain, deleteReferencedRelations, deleteReferencingRelations, differsPersisted, dummyUpdate, equals, firePropertyChange, getBackend, getClassBaseName, getClassId, getColumnCount, getExpirationBacklog, getExpiredTableSerials, getFields, getId, getIdSource, getImmutableLoggingLevel, getModificationCount, getModificationLog, getPreparedStatement, getPreparedStatement, getPropertySupport, getSerial, getSession, getSessionHolder, getTableSerial, hashCode, insertPlain, isCountingModification, isDeleted, isEntity, isFinallyImmutable, isForcedModified, isFromThisJVM, isIdValid, isImmutable, isLoggingModification, isModified, isNew, isOverloadable, isRemovable, isReplayedLeniently, isSessionImmutable, isStatementAlwaysPrepared, isTableSerialProvided, isTracked, isVirgin, loadLazyReferences, logModification, markDeleted, newInstance, newInstance, newInstance, persistObject, prepareDelete, prepareSave, prepareSetFields, reloadObject, reloadObjectForUpdate, removeAllPropertyListeners, removePropertyListener, removePropertyListener, reserveId, reserveId, resultAllIdSerial, resultAllObjects, resultObjectsWithExpiredTableSerials, revertAttributesToSnapshot, saveObject, saveReferencedRelations, saveReferencingRelations, selectAllIdSerial, selectAllObjects, selectExpiredTableSerials, selectExpiredTableSerials, selectMaxId, selectMaxTableSerial, selectNextObject, selectObject, selectObjectForUpdate, selectObjectsWithExpiredTableSerials, selectSerial, setClassId, setFields, setFinallyImmutable, setId, setImmutable, setImmutableLoggingLevel, setModificationLog, setOverloadable, setSerial, setSession, setSessionHolder, setSessionImmutable, setStatementAlwaysPrepared, setTableSerial, toIdString, toString, unmarkDeleted, updatePlain, updateSerial, updateSerial, updateSerialAndTableSerialMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.tentackle.pdo.DomainContextProvider
on, on, op, opMethods inherited from interface org.tentackle.misc.Immutable
getImmutableLoggingLevel, isFinallyImmutable, isImmutable, setFinallyImmutable, setImmutable, setImmutableLoggingLevelMethods inherited from interface org.tentackle.misc.Modifiable
isModifiedMethods inherited from interface org.tentackle.dbms.ModificationLoggable
createModificationLogMethods inherited from interface org.tentackle.pdo.PdoProvider
on, onMethods inherited from interface org.tentackle.pdo.PersistentObject
attributesModified, differsPersisted, getClassBaseName, getClassId, getExpiredTableSerials, getId, getModificationCount, getSerial, getTableSerial, isDeleted, isNew, isRemovable, isTableSerialProvided, isTracked, reserveId, reserveId, selectAllIdSerial, selectExpiredTableSerials, selectExpiredTableSerials, selectMaxId, selectMaxTableSerial, selectSerial, toIdStringMethods inherited from interface org.tentackle.misc.SerialNumbered
isVirginMethods inherited from interface org.tentackle.session.SessionDependable
isSessionImmutable, setSession, setSessionImmutableMethods inherited from interface org.tentackle.session.SessionProvider
getSession
-
Field Details
-
CN_EDITEDBY
name of the editedBy column.- See Also:
-
AN_EDITEDBY
name of the editedBy attribute.- See Also:
-
CN_EDITEDEXPIRY
name of the editedExpiry column.- See Also:
-
AN_EDITEDEXPIRY
name of the editedExpiry attribute.- See Also:
-
CN_EDITEDSINCE
name of the editedSince column.- See Also:
-
AN_EDITEDSINCE
name of the editedSince attribute.- See Also:
-
CN_NORMTEXT
name of the normText column.- See Also:
-
AN_NORMTEXT
name of the normText attribute.- See Also:
-
CN_ROOTID
name of root-ID column.- See Also:
-
AN_ROOTID
name of root-ID attribute.- See Also:
-
CN_ROOTCLASSID
name of rootclass-ID column.- See Also:
-
AN_ROOTCLASSID
name of rootclass-ID attribute.- See Also:
-
TX_SAVE_COPY_IN_CONTEXT
saveImpl copy in context- See Also:
-
TX_DELETE_ALL_IN_CONTEXT
delete all in context- See Also:
-
TX_TRANSFER_TOKENLOCK
transfer edited by- See Also:
-
TX_UPDATE_TOKENLOCK
update tokenlock- See Also:
-
TX_UPDATE_TOKENLOCK_ONLY
update tokenlock only- See Also:
-
-
Constructor Details
-
AbstractPersistentObject
Creates an application database object.- Parameters:
pdo- the persistent domain object this is a delegate forcontext- the database context
-
AbstractPersistentObject
Creates an application database object without a domain context for a given connection.Note: the application must set the context.
- Parameters:
pdo- the persistent domain object this is a delegate forsession- the session (must be an instance ofSession).
-
AbstractPersistentObject
Creates an application database object without a database context.Note: the application must set the context.
- Parameters:
pdo- the persistent domain object this is a delegate for
-
AbstractPersistentObject
public AbstractPersistentObject()Creates an application database object without a database context.
-
-
Method Details
-
getDomainDelegate
- Specified by:
getDomainDelegatein interfacePersistenceDelegate<T extends PersistentDomainObject<T>>
-
getPdo
- Specified by:
getPdoin interfacePdoProvider<T extends PersistentDomainObject<T>>
-
me
- Specified by:
mein interfaceProxyDelegate<T extends PersistentDomainObject<T>>
-
toGenericString
- Specified by:
toGenericStringin interfaceorg.tentackle.misc.Identifiable- Overrides:
toGenericStringin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
setPdo
Sets the PDO.- Parameters:
pdo- the pdo
-
getEffectiveClass
- Specified by:
getEffectiveClassin interfaceorg.tentackle.reflect.EffectiveClassProvider<T extends PersistentDomainObject<T>>
-
getEffectiveSuperClasses
- Specified by:
getEffectiveSuperClassesin interfaceorg.tentackle.reflect.EffectiveClassProvider<T extends PersistentDomainObject<T>>
-
getPdoMethodCache
- Specified by:
getPdoMethodCachein interfacePdoMethodCacheProvider<T extends PersistentDomainObject<T>>
-
clone
Clones this persistent object.
The method is final to prevent applications from overriding it and spoiling the contract withcreateSnapshot().Notice that the proxy pdo is cleared to null in the cloned PO.
-
createSnapshot
Creates a snapshot of this object.The method must be implemented. The default implementation just throws PersistenceException.
- Specified by:
createSnapshotin interfaceorg.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>- Returns:
- the snapshot
-
createComponentsInSnapshot
Updates the components in snapshot object.
The snapshot object is assumed to be a clone of this object.There is no createAttributesInSnapshot, since the snapshot is cloned and all attributes are either immutable or frozen.
- Parameters:
snapshot- the snapshot
-
revertToSnapshot
Reverts the state of this object to given snapshot.The method must be implemented. The default implementation just throws PersistenceException.
- Specified by:
revertToSnapshotin interfaceorg.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>- Parameters:
snapshot- the snapshot to revert to
-
copy
Creates a deep copy of this PDO.
The copied PDO and its components, if any, are new (id=0).Since only loaded components are copied (i.e. the object as is, which is the contract for
Snapshotable), consider to invokeloadComponents(boolean)beforecopy()to get a logically complete copy of the aggregate.- Specified by:
copyin interfaceorg.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>- Returns:
- the new copied object
-
revertAttributesToSnapshot
Copies all attributes from a snapshot object back to this object.- Parameters:
snapshot- the snapshot object
-
revertComponentsToSnapshot
Reverts all components of this object to a given snapshot.- Parameters:
snapshot- the snapshot object
-
isSnapshot
public boolean isSnapshot()- Specified by:
isSnapshotin interfaceorg.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
-
isCopy
public boolean isCopy()- Specified by:
isCopyin interfaceorg.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>- Overrides:
isCopyin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
setCopy
public void setCopy(boolean copy) - Specified by:
setCopyin interfaceorg.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
-
getSnapshots
- Specified by:
getSnapshotsin interfaceorg.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
-
discardSnapshot
- Specified by:
discardSnapshotin interfaceorg.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
-
discardSnapshots
public void discardSnapshots()- Specified by:
discardSnapshotsin interfaceorg.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
-
addSnapshot
Adds a snapshot to the list of snapshots.- Parameters:
snapshot- the snapshot to add
-
assertValidSnapshot
Asserts that given snapshot is valid for this object.- Parameters:
snapshot- the snapshot
-
assertNotCached
protected void assertNotCached()Asserts that the PDO is not cached. -
assertMutable
protected void assertMutable()Overridden due to snapshots are immutable.
- Overrides:
assertMutablein classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
isPersistable
public boolean isPersistable()- Specified by:
isPersistablein interfacePersistentObject<T extends PersistentDomainObject<T>>- Overrides:
isPersistablein classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
setPersistable
public void setPersistable(boolean persistable) Sets the local persistable flag.The implementation maintains an additional flag to disable persistability.
- Parameters:
persistable- true if persistable, false if not persistable
-
assertPersistable
protected void assertPersistable()Overridden to provide detailed exception message.
- Overrides:
assertPersistablein classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
createPropertySupport
protected org.tentackle.misc.PropertySupport createPropertySupport()- Overrides:
createPropertySupportin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
isRootEntity
public boolean isRootEntity()The default is false. Override if this is a root-entity.
- Specified by:
isRootEntityin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
isEmbedded
public boolean isEmbedded()- Specified by:
isEmbeddedin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
assertEmbedded
protected void assertEmbedded()Asserts that this is an embedded PDO. -
getEmbeddingParent
- Specified by:
getEmbeddingParentin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
setEmbeddingPersistentObject
public void setEmbeddingPersistentObject(AbstractPersistentObject<?, ?> embeddingParent, String columnPrefix) Sets the embedding PO for this embedded PDO.
Throws aPersistenceExceptionif this is not an embedded PDO.Notice that the parent is set through its persistence object, not the PDO proxy! This is necessary because the proxy may be unknown while reading from the database result set.
- Parameters:
embeddingParent- the parent PO, never nullcolumnPrefix- the column prefix, empty string if none, never null
-
getColumnPrefix
Gets the column prefix for this embedded PDO.- Returns:
- the column prefix
-
configureEmbeddedColumns
Configures the columns of an embedded PDO.- Parameters:
rs- the result set
-
setEmbeddedFields
Sets the fields of an embedded PDO.- Parameters:
ndx- the last used column index of the prepared statementst- the prepared statement- Returns:
- the last used column index
-
isRootIdProvided
public boolean isRootIdProvided()- Specified by:
isRootIdProvidedin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
getRootId
public long getRootId()- Specified by:
getRootIdin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
setRootId
public void setRootId(long rootId) Sets the ID of the root entity this component belongs to.- Parameters:
rootId- the root id
-
isRootClassIdProvided
public boolean isRootClassIdProvided()- Specified by:
isRootClassIdProvidedin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
getRootClassId
public int getRootClassId()- Specified by:
getRootClassIdin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
setRootClassId
public void setRootClassId(int rootClassId) Sets the class ID of the root entity this component belongs to.- Parameters:
rootClassId- the root class id
-
isRootEntityOf
- Specified by:
isRootEntityOfin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
presetVirgin
protected void presetVirgin()Presets the attributes with initial values, if the PDO is persisted the first time.
The method is invoked before the PDO is validated. -
isNormTextProvided
public boolean isNormTextProvided()- Specified by:
isNormTextProvidedin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
assertNormTextProvided
protected void assertNormTextProvided()Asserts that entity provides a normtext. -
setNormText
Sets the normtext.- Parameters:
normText- the normtext
-
getNormText
Gets the normtext.- Specified by:
getNormTextin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the normtext
-
createAttributesNormText
Creates the normalized text of all attributes with the NORMTEXT-option.
The method is usually generated by the MethodsImpl wurblet.- Returns:
- the builder holding the normalized text, null if no normtext attributes
-
createRelationsNormText
Creates the normalized text of all relations with the NORMTEXT-option.
The method is usually generated by the PdoRelations wurblet.- Returns:
- the builder holding the normalized text, null if no normtext relations
-
updateNormText
public void updateNormText()Updates the normtext attribute if normtext is provided by this PDO. -
isDomainContextImmutable
public boolean isDomainContextImmutable()Returns whether the domain context is immutable.- Specified by:
isDomainContextImmutablein interfaceDomainContextDependable- Returns:
- true if context cannot be changed
-
setDomainContextImmutable
public void setDomainContextImmutable(boolean contextImmutable) Sets the immutable flag of the domain context.- Specified by:
setDomainContextImmutablein interfaceDomainContextDependable- Parameters:
contextImmutable- true if context cannot be changed
-
assertDomainContextMutable
protected void assertDomainContextMutable()Asserts that the domain context is mutable. -
setDomainContext
Setting the context will also set the session and context id.
- Specified by:
setDomainContextin interfaceDomainContextDependable
-
getDomainContext
The default implementation just returns the context. Subclasses may override this with a covariant method.
- Specified by:
getDomainContextin interfaceDomainContextProvider
-
determineContextId
public void determineContextId()The default implementation does nothing (object living in a context not depending on another object).
- Specified by:
determineContextIdin interfaceDomainContextDependable
-
getContextId
public long getContextId()The default implementation returns -1.
- Specified by:
getContextIdin interfaceDomainContextDependable
-
getSqlContextCondition
Gets the SQL code for the context condition.- Returns:
- empty if no condition (default)
-
getBaseContext
The default implementation returns the PDO's DomainContext.
- Specified by:
getBaseContextin interfaceDomainContextDependable
-
createValidContext
The default implementation just returns a new
DomainContext.- Specified by:
createValidContextin interfaceDomainContextDependable
-
getClassVariables
Gets the application oriented class variables for this object.
Class variables for classes derived from AbstractPersistentObject are kept in an instance ofPersistentObjectClassVariables.- Overrides:
getClassVariablesin classAbstractDbObject<P extends AbstractPersistentObject<T,P>> - Returns:
- the class variables
- See Also:
-
createStatementKey
- Overrides:
createStatementKeyin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
getTableName
- Specified by:
getTableNamein interfacePersistentObject<T extends PersistentDomainObject<T>>- Overrides:
getTableNamein classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
getTableAlias
Gets the table alias.- Returns:
- the alias, null if class does not map to a database table
-
getColumnName
Gets the full column name with table alias.- Parameters:
name- the short name- Returns:
- the full name
-
getColumnNames
Gets the comma-separated list of column names with table alias.- Parameters:
columnNamesSupplier- the supplier for the list of column names- Returns:
- the partial SQL string
-
getColumnNames
Gets the comma-separated list of column names with table alias.- Parameters:
columnNames- the list of column names- Returns:
- the partial SQL string
-
getValidClassIds
Gets the valid class-IDs for the concrete types of this type.
Applies only to entities of single- or multi-table inheritance hierarchies, except the topmost entity.- Returns:
- the class IDs, null if no restrictions
-
getSqlClassIdCondition
Gets the SQL string used in WHERE-clauses for single table inheritance entities.- Returns:
- the SQL string, empty if no such condition necessary
-
getTopSuperTableAlias
Gets the alias for the topmost super class.- Returns:
- the alias
-
getTopSuperTableName
Gets the tablename for the topmost super class.- Returns:
- the alias
-
getPdoClass
Gets the pdo-class.- Returns:
- the class of the associated PDO
-
isAbstract
public boolean isAbstract()Returns whether this an abstract PDO.
Abstract PDOs are real objects but cannot be persisted. They may be used to retrieve data for the concrete implementations, however.- Specified by:
isAbstractin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- true if abstract PDO
-
assertNotAbstract
public void assertNotAbstract()Asserts that this is not an abstract entity class. -
isExplicitIdAliasRequiredInJoins
public boolean isExplicitIdAliasRequiredInJoins()Returns whether an explicit id alias is necessary in joins.
This applies to MULTI-table inherited PDOs only (abstracts and leaves).- Returns:
- true if we need an explicit id alias
-
isComposite
public boolean isComposite()Tells whether this object is composite (i.e. has composite relations).
The method is overridden by the PdoRelations-wurblet if at least one relation is flagged as "composite". The default implementation returns false.- Specified by:
isCompositein interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- true if object is composite, false if not.
-
loadComponents
public org.tentackle.misc.IdentifiableMap<? extends PersistentDomainObject<?>> loadComponents(boolean onlyLoaded) By default the method throws a PersistenceException telling that it is not implemented if isComposite() returns true.
- Specified by:
loadComponentsin interfacePersistentObject<T extends PersistentDomainObject<T>>- Parameters:
onlyLoaded- true if return only already loaded components (lazy composite relations)- Returns:
- the map of all components, including this object.
-
addComponents
public int addComponents(org.tentackle.misc.IdentifiableMap<PersistentDomainObject<?>> components, boolean onlyLoaded) Adds the components of this object to a map.- Parameters:
components- the component maponlyLoaded- true if return only already loaded component (lazy composite relations)- Returns:
- the number of components added
-
addComponents
public int addComponents(org.tentackle.misc.IdentifiableMap<PersistentDomainObject<?>> components, Collection<? extends PersistentDomainObject<?>> objects, boolean onlyLoaded) Adds the components of a collection to a map.- Parameters:
components- the components mapobjects- the collection of objects to add along with their componentsonlyLoaded- true if return only already loaded components (lazy composite relations)- Returns:
- the number of components added
-
deletePlainWithComponents
public void deletePlainWithComponents()Deletes this object and all its components without any further processing.
Same asAbstractDbObject.deletePlain()but with components. -
deletePlainWithComponents
Deletes plain with components all objects of a collection.- Parameters:
objects- the collection of PDOs- Returns:
- the number of objects processed, < 0 if failed (number*(-1)-1)
-
insertPlainWithComponents
public void insertPlainWithComponents()Inserts this object and all its components without any further processing.
Same asAbstractDbObject.insertPlain()but with components. -
insertPlainWithComponents
Inserts plain with components all objects of a collection.- Parameters:
objects- the collection of PDOs- Returns:
- the number of objects processed
-
findDuplicate
Checks whether this object (if saved) would violate any unique constraints.The method is usually used by the presentation layer to check for duplicates. The default implementation invokes findByUniqueDomainKey(getUniqueDomainKey()) and throws
UnsupportedOperationExceptionif one of those methods are not implemented (which is the default).- Specified by:
findDuplicatein interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the duplicate object, null if no duplicate
-
isCacheable
public boolean isCacheable()Determines whether object is cacheable or not. The default implementation always returns true, but apps can use this as a filter.- Specified by:
isCacheablein interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- true if object is cacheable
-
isExpired
public boolean isExpired()Checks whether object has been marked expired. Expired objects will be reloaded from the database by the cache when the object is retrieved again.- Specified by:
isExpiredin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- true if object is expired (in cache)
-
setExpired
public void setExpired(boolean expired) Sets this object's expiration flag.- Specified by:
setExpiredin interfacePersistentObject<T extends PersistentDomainObject<T>>- Parameters:
expired- true if object is expired
-
getCacheAccessTime
public long getCacheAccessTime()Gets the last cache access time.- Specified by:
getCacheAccessTimein interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the last cache access time
-
getCacheAccessCount
public long getCacheAccessCount()Gets the cache access count.- Specified by:
getCacheAccessCountin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the access count
-
markCacheAccess
public void markCacheAccess()mark cache access (count and set current system-time)- Specified by:
markCacheAccessin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
isCached
public boolean isCached()- Specified by:
isCachedin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- true if object is cached
-
getSecurityResult
- Specified by:
getSecurityResultin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
isPermissionAccepted
- Specified by:
isPermissionAcceptedin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
selectByTemplate
Selects an object according to a template object. Useful to find corresponding objects in another context. The default implementation loads the same object by its ID. Should be overridden to select by some other unique key.- Parameters:
template- the template object- Returns:
- the object if found, else null.
-
getEagerJoinedSelect
Adds the eager joins to the created SQL.- Returns:
- the processed code
-
getBatchablePreparedStatement
protected PreparedStatementWrapper getBatchablePreparedStatement(ModificationType modType, StatementId stmtId, SqlSupplier sqlSupplier) Gets a prepared statement and marks it as batchable.
If there is a transaction running in batched mode, the statement will be executed via JDBC batching. Otherwise, the method is equivalent toAbstractDbObject.getPreparedStatement(StatementId, SqlSupplier).The method must only be used for inserts, updates and delete of a single row!
- Parameters:
modType- the modification typestmtId- the statement IDsqlSupplier- the SQL code supplier- Returns:
- the statement
-
insertImpl
- Overrides:
insertImplin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
updateImpl
- Overrides:
updateImplin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
deleteImpl
- Overrides:
deleteImplin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
readFromResultSetWrapper
Overridden to implement inheritance and adjust the domain context.
- Overrides:
readFromResultSetWrapperin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
executeQueryToList
Executes the query for a prepared statement and adds the results to a list.- Parameters:
st- the query statementjs- the joined select configuration, null if no joinslist- the list
-
executeQueryToList
Executes the query for a prepared statement and adds the results to a list.- Parameters:
rs- the result set wrapperjs- the joined select configuration, null if no joinslist- the list
-
executeListQuery
Executes the query for a prepared statement and returns the results in a list.- Parameters:
st- the query statementjs- the joined select configuration, null if no joins- Returns:
- the list
-
executeListQuery
Executes the query for a prepared statement and returns the results in a list.- Parameters:
st- the query statement- Returns:
- the list
-
executeTrackedListQuery
public org.tentackle.misc.TrackedList<T> executeTrackedListQuery(PreparedStatementWrapper st, JoinedSelect<T> js) Executes the query for a prepared statement and returns the results in a tracked list.- Parameters:
st- the query statementjs- the joined select configuration, null if no joins- Returns:
- the tracked list
-
executeTrackedListQuery
Executes the query for a prepared statement and returns the results in a tracked list.- Parameters:
st- the query statement- Returns:
- the tracked list
-
createQuery
Creates aQueryto retrieve a list of this entity type.- Parameters:
js- the joined select configuration, null if no joins- Returns:
- the initialized query
-
createQuery
Creates aQueryto retrieve a list of this entity type.- Returns:
- the initialized query
-
executeQuery
Executes aQuerywhich was built to return a tracked list of this entity type.- Parameters:
query- the query objectjs- the joined select configuration, null if no joins- Returns:
- the tracked list
-
executeQuery
Executes aQuerywhich was built to return a tracked list of this entity type.- Parameters:
query- the query object- Returns:
- the tracked list
-
executeScrollableQuery
Executes aQuerywhich was built to return a tracked list of this entity type.- Parameters:
query- the query objectjs- the joined select configuration, null if no joins- Returns:
- the scrollable cursor
-
executeScrollableQuery
Executes aQuerywhich was built to return a tracked list of this entity type.- Parameters:
query- the query object- Returns:
- the scrollable cursor
-
getEagerJoins
Returns the eager joins for this PDO.- Returns:
- the list of eager joins, null if none
-
readJoinedRow
Reads the next row from a result set within a joined select.
The results may come in any order. Thus, it is possible to sort the results according to the domain's requirements.- Parameters:
js- the joined selectrs- the result set
-
executeFirstPdoQuery
Executes a query for a prepared statement and returns the first PDO.- Parameters:
st- the query statementjs- the joined select configuration, null if no joins- Returns:
- the PDO
-
executeFirstPdoQuery
Executes a query for a prepared statement and returns the first PDO.- Parameters:
st- the query statement- Returns:
- the PDO
-
select
Loads a PDO from the database by its unique ID.- Parameters:
id- is the object idforUpdate- true if select FOR UPDATE- Returns:
- object if loaded, null if no such object
-
select
Loads a PDO from the database by its unique ID.- Specified by:
selectin interfacePersistentObject<T extends PersistentDomainObject<T>>- Parameters:
id- is the object id- Returns:
- object if loaded, null if no such object
-
reload
Reloads the object.Restores transient data, if present.
- Specified by:
reloadin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the object if reloaded, else null (never this)
-
reloadForUpdate
Reloads the object with a write-lock.
Restores transient data, if present.- Specified by:
reloadForUpdatein interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the object if reloaded, else null (never this)
-
selectForUpdate
Loads and write-locks a PDO from the database by its unique ID.- Specified by:
selectForUpdatein interfacePersistentObject<T extends PersistentDomainObject<T>>- Parameters:
id- is the object id- Returns:
- object if loaded, null if no such object
-
derivePdoFromPo
Derive the concrete PDO from a given PO.- Parameters:
pdo- the original persistent domain objectpo- the effective persistent object from readFromResultSetWrapper- Returns:
- the persistent domain object, null if no read permission
-
assertRootContextIsAccepted
public void assertRootContextIsAccepted()Checks the root context against the security rules. -
createSelectAllInnerSql
- Overrides:
createSelectAllInnerSqlin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
createSelectAllIdSerialInnerSql
- Overrides:
createSelectAllIdSerialInnerSqlin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
createSelectAllByIdInnerSql
- Overrides:
createSelectAllByIdInnerSqlin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
createSelectIdInnerSql
public StringBuilder createSelectIdInnerSql(PersistentObjectClassVariables<? super T, ? super P> classVariables, boolean withAlias) Creates the inner sql text to select the ID field.Returns something like:
"id FROM xytable WHERE 1=1"
- Parameters:
classVariables- the classvariableswithAlias- true if column name with table alias, else without- Returns:
- the sql text
-
createSelectIdInnerSql
Creates the inner sql text to select the ID field.Returns something like:
"id FROM xytable WHERE 1=1"
- Parameters:
withAlias- true if column name with table alias, else without- Returns:
- the sql text
-
createSelectIdInnerSql
- Overrides:
createSelectIdInnerSqlin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
createSelectByNormTextSql
Creates the SQL code for select by normtext.- Parameters:
backend- the backendnot- true to find all not matching the normtext- Returns:
- the sql code
-
createSelectSerialSql
Creates the SQL code for the selectSerial statement.- Overrides:
createSelectSerialSqlin classAbstractDbObject<P extends AbstractPersistentObject<T,P>> - Returns:
- the sql code
-
createSelectMaxIdSql
Creates the SQL code for the selectMaxId statement.- Overrides:
createSelectMaxIdSqlin classAbstractDbObject<P extends AbstractPersistentObject<T,P>> - Returns:
- the sql code
-
createSelectMaxTableSerialSql
Creates the SQL code for the selectMaxTableSerial statement.- Overrides:
createSelectMaxTableSerialSqlin classAbstractDbObject<P extends AbstractPersistentObject<T,P>> - Returns:
- the sql code
-
createDummyUpdateSql
Creates the SQL code for the dummy update statement.
Useful get an exclusive lock within a transaction.- Overrides:
createDummyUpdateSqlin classAbstractDbObject<P extends AbstractPersistentObject<T,P>> - Returns:
- the sql code
-
createUpdateSerialSql
Creates the SQL code for the serial update statement.- Overrides:
createUpdateSerialSqlin classAbstractDbObject<P extends AbstractPersistentObject<T,P>> - Returns:
- the sql code
-
createUpdateSerialAndTableSerialSql
Creates the SQL code for the serial + tableSerial update statement.- Overrides:
createUpdateSerialAndTableSerialSqlin classAbstractDbObject<P extends AbstractPersistentObject<T,P>> - Returns:
- the sql code
-
createSelectExpiredTableSerials1Sql
Creates the SQL code for the first statement to select expired table serials.- Overrides:
createSelectExpiredTableSerials1Sqlin classAbstractDbObject<P extends AbstractPersistentObject<T,P>> - Returns:
- the sql code
-
createSelectExpiredTableSerials2Sql
Creates the SQL code for the second statement to select expired table serials.- Overrides:
createSelectExpiredTableSerials2Sqlin classAbstractDbObject<P extends AbstractPersistentObject<T,P>> - Returns:
- the sql code
-
resultByNormText
Gets the result set for the normtext query.- Parameters:
text- the text to search forjs- the optional join config, null if no joins- Returns:
- the result set
- See Also:
-
resultByNormTextCursor
Gets the result set for the normtext query as a cursor.- Parameters:
text- the text to search forjs- the optional join config, null if no joins- Returns:
- the result set
- See Also:
-
selectByNormText
Selects all objects with a given normtext as a list.- Specified by:
selectByNormTextin interfacePersistentObject<T extends PersistentDomainObject<T>>- Parameters:
text- the text to search for- Returns:
- the list of objects, never null
- See Also:
-
selectByNormTextAsCursor
Selects all objects with a given normtext as a cursor.- Specified by:
selectByNormTextAsCursorin interfacePersistentObject<T extends PersistentDomainObject<T>>- Parameters:
text- the text to search for- Returns:
- the cursor
- See Also:
-
createSelectAllSql
Creates SQL-code for select all.
Appends context condition and order by clause if configured.- Parameters:
backend- the backend- Returns:
- the sql code
-
createSelectAllWithExpiredTableSerialsSql
Creates SQL-code forselectAllWithExpiredTableSerials(long).
Appends context condition and order by clause if configured.
By default, the result is sorted by tableserial + id.- Parameters:
backend- the backend- Returns:
- the sql code
-
resultAll
Gets the result set for all objects in the current context for use in lists.- Parameters:
js- the optional join config, null if no joins- Returns:
- the result set
- See Also:
-
resultAllWithExpiredTableSerials
Gets the result set for all objects in the current context with a given expired tableserial.- Parameters:
js- the optional join config, null if no joinsoldSerial- the last known tableserial- Returns:
- the result set
-
resultAllCursor
Gets the result set for all objects in the current context for use in cursors.
Cursors differ from lists because they needResultSet.TYPE_SCROLL_INSENSITIVEset.- Parameters:
js- the optional join config, null if no joins- Returns:
- the result set
- See Also:
-
selectAll
Selects all records in current context as a list.- Specified by:
selectAllin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the list of objects, never null
- See Also:
-
selectAllWithExpiredTableSerials
- Specified by:
selectAllWithExpiredTableSerialsin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
selectAllAsCursor
Selects all records in current context as a cursor- Specified by:
selectAllAsCursorin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the cursor
- See Also:
-
selectLatest
- Specified by:
selectLatestin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
getCache
Gets the cache. The default implementation returns null. Must be overridden to enable optimization features with RMI servers.- Specified by:
getCachein interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the cache, null if uncached
-
expireCache
public void expireCache(long maxSerial) Expires the cache according to the serial numbers.
If objects of this class are cached, the cache must be expired on updates, etc... Furthermore, if there is a cache, isCountingModification() MUST return true, in order for countModification() to invalidate the cache for the local JVM. Classes with a cache must override this method! The implementation with the PdoCache should look like this:super.expireCache(maxSerial); // in case inherited cache overridden cache.expire(maxSerial);while "cache" has been declared by the wurbletPdoCache.- Parameters:
maxSerial- is the new tableSerial this object will get- See Also:
-
selectCached
Gets the object via cache.
If there is no cache (i.e. the method is not overridden), the default implementation just loads from the db.- Specified by:
selectCachedin interfacePersistentObject<T extends PersistentDomainObject<T>>- Parameters:
id- the unique object ID- Returns:
- the object, null if no such object
- See Also:
-
selectCachedOnly
Gets the object via cache only.
If there is no cache (i.e. the method is not overridden), the default implementation just loads from the db.- Specified by:
selectCachedOnlyin interfacePersistentObject<T extends PersistentDomainObject<T>>- Parameters:
id- the unique object ID- Returns:
- the object, null if no such object
- See Also:
-
selectAllCached
Gets all objects in context via cache. If there is no cache (i.e. the method is not overridden), the default implementation gets it from the db.- Specified by:
selectAllCachedin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the list, never null
- See Also:
-
selectAllForCache
- Specified by:
selectAllForCachein interfacePersistentObject<T extends PersistentDomainObject<T>>
-
selectForCache
- Specified by:
selectForCachein interfacePersistentObject<T extends PersistentDomainObject<T>>
-
countModification
public long countModification()Overridden to expire the cache if object is using the tableserial.
- Overrides:
countModificationin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
addReferencingClass
public <R extends PersistentDomainObject<R>> boolean addReferencingClass(Class<R> clazz, String methodPath) Adds a PDO class that is referencing this PDO clazz.The method name can also contain dots to denote a chain of methods that must be invoked.
- Type Parameters:
R- the PDO type- Parameters:
clazz- the class to addmethodPath- the method path name, null if default"isReferencing<ClassBaseName>"- Returns:
- true if added, false if already in map
- See Also:
-
removeReferencingClass
public <R extends PersistentDomainObject<R>> boolean removeReferencingClass(Class<R> clazz, String methodPath) Removes a PDO class that is referencing this PDO clazz.- Type Parameters:
R- the PDO type- Parameters:
clazz- the class to addmethodPath- the method path name, null if default"isReferencing<ClassBaseName>"- Returns:
- true if removed, false if not in map
- See Also:
-
getPersistenceClass
public <R extends PersistentDomainObject<R>> Class<? extends AbstractPersistentObject<R,?>> getPersistenceClass(Class<R> clazz) Gets the persistence class from a pdo class.Throws a PersistenceException if the persistence class is not an
AbstractPersistentObject.- Type Parameters:
R- the PDO type- Parameters:
clazz- the pdo class- Returns:
- the persistence class
-
isReferenced
public boolean isReferenced()Overridden because remote method requires a
DomainContextinstead of just theSession.- Specified by:
isReferencedin interfacePersistentObject<T extends PersistentDomainObject<T>>- Overrides:
isReferencedin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
containsPattern
Searches for a "pattern" in this object.
The default implementation looks for the pattern in the normtext.- Specified by:
containsPatternin interfacePersistentObject<T extends PersistentDomainObject<T>>- Parameters:
pattern- the pattern to search for- Returns:
- true if this object "contains" the pattern
-
orderBy
Gets the natural ordering to be added in WHERE-clauses following "ORDER BY ". The wurblets will use it if --sort option set. Example:return CN_ID + "," + CN_PRINTED + " DESC";
For a single field with sort ascending returning the fieldname is sufficient. The default is null, i.e. no order-by-clause will be added.- Returns:
- the order by appendix string, null if no order by
-
initModification
Overridden due to security check.
- Overrides:
initModificationin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
finishModification
Overridden to clear the renewTokenLock flag.
- Overrides:
finishModificationin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
finishNotUpdated
Overridden to get the token lock removed, if any.
- Overrides:
finishNotUpdatedin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
getContextUserId
public long getContextUserId()Gets the user id from the current domain context.
The ID is derived from the session info of the session associated with the domain context.Note: invokes the errorhandler if some exception or userId is 0.
- Returns:
- the userId
-
clearTokenLock
public boolean clearTokenLock()Clears or renews the token lock.If
isRenewTokenLockRequested()is true, the token will be renewed (prolonged if existing) or created (if not existing). The operation is only done in memory, not in persistent storage.- Returns:
- true if token lock set or updated, false if token lock cleared or PDO does not provide a token lock
-
setRenewTokenLockRequested
public void setRenewTokenLockRequested(boolean renewTokenLock) Sets whether to apply or renew the token lock on insert or update.By default, the token lock (if set) will be cleared upon insert or update. However, sometimes it is necessary to keep it, renew it respectively.
Setting this flag to true will renew the token upon the next persistence operation. The flag will be cleared afterward.
- Parameters:
renewTokenLock- true to renew the token (once)
-
isRenewTokenLockRequested
public boolean isRenewTokenLockRequested()Determines whether to renew the token lock on saveImpl or update.- Returns:
- true to renew the token (once), false to clear token (default)
-
isUpdateNecessary
protected boolean isUpdateNecessary()- Overrides:
isUpdateNecessaryin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
updateObject
public void updateObject()- Overrides:
updateObjectin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
insertObject
public void insertObject()- Overrides:
insertObjectin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
deleteObject
public void deleteObject()- Overrides:
deleteObjectin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
newId
public void newId()- Overrides:
newIdin classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
updateRootContext
public boolean updateRootContext()Updates the root context.
Method is used after deserialization.- Returns:
- true if root context set, false if this is not a root-entity
-
configureRemoteObject
Configures the remotely retrieved object.- Parameters:
context- the local domain contextobj- the object
-
configureRemoteObjects
public void configureRemoteObjects(DomainContext context, Collection<? extends PersistentDomainObject<?>> objects) Configures the remotely retrieved objects.- Parameters:
context- the local domain contextobjects- the objects to configure
-
assertRootContext
protected void assertRootContext()Asserts that the po's context is a root context. -
markDeleted
Marks all objects in a list to be deleted.
This method is provided to mark components in PDOs only. This method must not be used from within the application!- Type Parameters:
X- the pdo type- Parameters:
pdos- the objects to mark deleted
-
markDeleted
Marks an object to be deleted.
This method is provided to mark components in PDOs only. This method must not be used from within the application!- Parameters:
pdo- the pdo to mark deleted
-
delete
Deletes a List of objects.
This method is provided to mark components in PDOs only. This method must not be used from within the application!- Type Parameters:
X- the pdo type- Parameters:
pdos- the list of object to delete
-
delete
Deletes a PDO.
This method is provided to save components in PDOs only. This method must not be used from within the application!- Parameters:
pdo- the pdo to mark deleted
-
deleteMissingInCollection
protected <X extends PersistentDomainObject<X>> void deleteMissingInCollection(Collection<X> oldCollection, Collection<X> newCollection) Deletes all objects in oldList that are not in newList.
This method is provided to save components in PDOs only. This method must not be used from within the application!- Type Parameters:
X- the PDO type- Parameters:
oldCollection- the list of objects stored in dbnewCollection- the new list of objects
-
assertRootEntity
public void assertRootEntity()Checks if the po is a root entity. -
delete
public void delete()- Specified by:
deletein interfacePersistentObject<T extends PersistentDomainObject<T>>
-
deleteImpl
protected void deleteImpl()Implementation of delete bypassing the invocation handler. -
save
public void save()- Specified by:
savein interfacePersistentObject<T extends PersistentDomainObject<T>>
-
saveImpl
protected void saveImpl()Implementation of save bypassing the invocation handler. -
save
public static <X extends PersistentDomainObject<X>> void save(Collection<X> pdos, boolean modifiedOnly) Saves a list of PDOs.
This method is provided to save components in PDOs only. Assumes that a transaction is already running. This method must not be used from within the application!- Type Parameters:
X- the pdo type- Parameters:
pdos- the list to savemodifiedOnly- true if only modified objects are saved
-
save
Saves a PDO.
This method is provided to save components in PDOs only. This method must not be used from within the application!- Parameters:
pdo- the pdo to save
-
persist
- Specified by:
persistin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
persistTokenLocked
- Specified by:
persistTokenLockedin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
persistImpl
Implementation of persist bypassing the invocation handler.- Returns:
- the persisted PDO
-
isUpdatingSerialEvenIfNotModified
public 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. The default is to leave unmodified objects untouched, except root entities. However, in some applications it is necessary to update the master object if some of its children are updated (usually to trigger something, e.g. a cache-update).The default implementation returns true if this is a root entity.
- Overrides:
isUpdatingSerialEvenIfNotModifiedin classAbstractDbObject<P extends AbstractPersistentObject<T,P>> - Returns:
- true if update serial even if object is unchanged
- See Also:
-
isModified
Checks whether some objects in the list are modified.
This method is provided to save components in PDOs only. Assumes that a transaction is already running. This method must not be used from within the application!- Type Parameters:
X- the PDO type- Parameters:
pdos- the objects- Returns:
- true if modified
-
isTokenLockProvided
public boolean isTokenLockProvided()By default, objects don't need to include the editedBy/Since/Expiry columns in the database table. Override this method if object contains such columns, i.e. global model option [TOKENLOCK] set.- Specified by:
isTokenLockProvidedin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- true if object is using the edited lock columns, false if not.
-
assertTokenLockProvided
protected void assertTokenLockProvided()Asserts that entity provides a normtext. -
getTokenLockTimeout
public long getTokenLockTimeout()Gets the expiration in milliseconds of a token lock.
If isTokenLockProvided, the default is 1 hour, else 0.- Specified by:
getTokenLockTimeoutin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the timespan in ms, 0 = no token required.
-
createUpdateTokenLockSql
Creates the SQL code for theupdateTokenLock(org.tentackle.common.Timestamp, long, org.tentackle.common.Timestamp)statement.- Returns:
- the sql code
-
createUpdateTokenLockWithCountSql
Creates the SQL code for theupdateTokenLock(org.tentackle.common.Timestamp, long, org.tentackle.common.Timestamp)statement with mod counting.- Returns:
- the sql code
-
createUpdateTokenLockOnlySql
Creates the SQL code for theupdateTokenLockOnly()statement.- Returns:
- the sql code
-
createSelectTokenLockSql
Creates the SQL code for the select inupdateTokenLock(org.tentackle.common.Timestamp, long, org.tentackle.common.Timestamp)statement.- Returns:
- the sql code
-
createTransferTokenLockSql
Creates the SQL code for thetransferTokenLock(long)statement without tableserial.- Returns:
- the sql code
-
createTransferTokenLockWithTableSerialSql
Creates the SQL code for thetransferTokenLock(long)statement with tableserial.- Returns:
- the sql code
-
getEditedBy
public long getEditedBy()Gets the id of the user currently editing this object.- Specified by:
getEditedByin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the id or 0 if not being edited currently.
-
setEditedBy
public void setEditedBy(long editedBy) Sets the user editing this object.
Does *NOT* alter isModified() and does not require the object to be mutable.- Parameters:
editedBy- the id of the user, 0 to clear.
-
requestTokenLock
public void requestTokenLock()Requests an edited by lock.- Specified by:
requestTokenLockin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
releaseTokenLock
public void releaseTokenLock()Releases an edited by lock.
Use this method if a PDO needs to be unlocked without being persisted.- Specified by:
releaseTokenLockin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
isTokenLocked
public boolean isTokenLocked()Checks whether this object is token locked (editedBy != 0) and the lock is not expired.- Specified by:
isTokenLockedin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- true if locked by any user
-
isTokenLockedBy
public boolean isTokenLockedBy(long userId) Checks whether this object is edited locked by given user.- Specified by:
isTokenLockedByin interfacePersistentObject<T extends PersistentDomainObject<T>>- Parameters:
userId- the user's ID- Returns:
- true locked
-
isTokenLockedByMe
public boolean isTokenLockedByMe()Checks whether this object is edited locked by the current user.- Specified by:
isTokenLockedByMein interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- true if locked
-
isTokenLockableByMe
public boolean isTokenLockableByMe()- Specified by:
isTokenLockableByMein interfacePersistentObject<T extends PersistentDomainObject<T>>
-
getEditedSince
public org.tentackle.common.Timestamp getEditedSince()Gets the time since when this object is being edited.- Specified by:
getEditedSincein interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the time, null if not being edited.
-
setEditedSince
public void setEditedSince(org.tentackle.common.Timestamp editedSince) Sets the time since when this object is being edited.
Does *NOT* alter isModified() and does not require the object to be mutable.- Parameters:
editedSince- the time, null to clear.
-
getEditedExpiry
public org.tentackle.common.Timestamp getEditedExpiry()Gets the time since when this object is being edited.- Specified by:
getEditedExpiryin interfacePersistentObject<T extends PersistentDomainObject<T>>- Returns:
- the time, null if not being edited.
-
setEditedExpiry
public void setEditedExpiry(org.tentackle.common.Timestamp editedExpiry) Sets the time when the token should expire.
Does *NOT* alter isModified() and does not require the object to be mutable.- Parameters:
editedExpiry- the expiration time, null to clear.
-
applyTokenLockInfo
Applies the given token lock info.- Parameters:
tokenLockInfo- the editedBy info
-
updateTokenLock
public void updateTokenLock(org.tentackle.common.Timestamp tokenExpiry, long userId, org.tentackle.common.Timestamp curTime) Updates the token lock columns in the database record.
Will *NOT* log modification and *NOT* update the serial-counter! Must be called from within application where appropriate.2 cases:
If expiry == 0, the "token" is released. True is returned if operation was successful and editedBy will hold 0 while editedSince holds the current (release) time. False is returned if token could not be released and nothing is changed. This is usually the case when another user holds the token (and indicates some logic errors in the application, btw.) EditedBy and editedSince are updated in the object to reflect the current values in the database. Notice: releasing an already released token is not considered to be an error. This will simply update the release timestamp.
If expiry > 0, a new token for the current user is requested. True is returned if the token could be exclusively acquired. EditedBy and editedSince are updated accordingly. If false: the object is in use by another user and editedSince and editedId holds this user and his timestamp. Notice: requesting an already requested token will simply renew the token.
The method does not check getTokenLockTimeout()! This is due to the application. Applications should use updateTokenLock(tokenExpiry). This is an internal implementation only.
- Parameters:
tokenExpiry- holds the time the token will expire. Null to release token.userId- is the current user (unused if tokenExpiry is null)curTime- is the current system time
-
updateTokenLock
public void updateTokenLock(org.tentackle.common.Timestamp tokenExpiry) Updates the token lock columns in the database record.
Will *NOT* log modification and *NOT* update the serial-counter! Must be called from within application where appropriate.2 cases:
If expiry == 0, the "token" is released. True is returned if operation was successful and editedBy will hold 0 while editedSince holds the current (release) time. False is returned if token could not be released and nothing is changed. This is usually the case when another user holds the token (and indicates some logic errors in the application, btw.) EditedBy and editedSince are updated in the object to reflect the current values in the database. Notice: releasing an already released token is not considered to be an error. This will simply update the release timestamp.
If expiry > 0, a new token for the current user is requested. True is returned if the token could be exclusively acquired. EditedBy and editedSince are updated accordingly. If false: the object is in use by another user and editedSince and editedId holds this user and his timestamp. Notice: requesting an already requested token will simply renew the token.
The method does not check getTokenLockTimeout()! This is due to the application.
- Parameters:
tokenExpiry- holds the time the token will expire. Null to release token.
-
updateTokenLockOnly
public void updateTokenLockOnly()Update the token-lock attributes to persistent storage.
No check is done whether locked or not and there is no serial update and no modlog. Used by daemons to clean up. -
transferTokenLock
- Specified by:
transferTokenLockin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
getTransientData
Gets the optional transient data object.
When objects need to be reloaded from storage, all non-persistent data attached to the object would be lost. The methodspersist(),reload()andreloadForUpdate()preserve that data viagetTransientData()andsetTransientData(Object). Applications must override those methods.
The default implementation does nothing.- Returns:
- the transient data, null if none
- See Also:
-
setTransientData
Sets the optional transient data object.- Parameters:
data- the transient data- See Also:
-
getRemoteDelegate
Overridden due to covariance.
- Overrides:
getRemoteDelegatein classAbstractDbObject<P extends AbstractPersistentObject<T,P>>
-
getDefaultScopes
The default scopes are:
PersistenceScope,MandatoryScopeandChangeableScope.- Specified by:
getDefaultScopesin interfaceorg.tentackle.validate.ScopeConfigurator
-
validate
public List<org.tentackle.validate.ValidationResult> validate(String validationPath, org.tentackle.validate.ValidationScope scope) - Specified by:
validatein interfaceorg.tentackle.validate.Validateable
-
validate
public void validate()- Specified by:
validatein interfacePersistentObject<T extends PersistentDomainObject<T>>
-
isValidated
public boolean isValidated()- Specified by:
isValidatedin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
setModified
public void setModified(boolean modified) Sets the modified flag.For optimizations, it is possible to skip objects that have not been modified. The modified-attribute is cleared whenever the object is persisted.
- Overrides:
setModifiedin classAbstractDbObject<P extends AbstractPersistentObject<T,P>> - Parameters:
modified- is true if object is flagged modified, false if not.
-
isReadAllowed
public boolean isReadAllowed()Determines whether the application is allowed to read this PDO.
Makes no sense to publish in PersistentObject because PDOs without read permissions are not read from the database at all.- Returns:
- true if allowed
-
isWriteAllowed
public boolean isWriteAllowed()- Specified by:
isWriteAllowedin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
isViewAllowed
public boolean isViewAllowed()- Specified by:
isViewAllowedin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
isEditAllowed
public boolean isEditAllowed()- Specified by:
isEditAllowedin interfacePersistentObject<T extends PersistentDomainObject<T>>
-
assertWritePermission
protected void assertWritePermission()Checks write permission for this object.- Throws:
SecurityException- if no write permission
-
assertReadPermission
protected void assertReadPermission()Checks read permission for this object.- Throws:
SecurityException- if no read permission
-