Class AbstractPersistentObject<T extends PersistentDomainObject<T>,P extends AbstractPersistentObject<T,P>>

java.lang.Object
org.tentackle.dbms.AbstractDbObject<P>
org.tentackle.persist.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

public abstract class AbstractPersistentObject<T extends PersistentDomainObject<T>,P extends AbstractPersistentObject<T,P>> extends AbstractDbObject<P> implements PersistentObject<T>, org.tentackle.reflect.EffectiveClassProvider<T>, PdoMethodCacheProvider<T>, Cloneable
Base persistent implementation of a PDO.
Author:
harald
See Also:
  • Field Details

  • Constructor Details

    • AbstractPersistentObject

      public AbstractPersistentObject(T pdo, DomainContext context)
      Creates an application database object.
      Parameters:
      pdo - the persistent domain object this is a delegate for
      context - the database context
    • AbstractPersistentObject

      public AbstractPersistentObject(T pdo, org.tentackle.session.Session session)
      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 for
      session - the session (must be an instance of Session).
    • AbstractPersistentObject

      public AbstractPersistentObject(T pdo)
      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

      public DomainDelegate<T> getDomainDelegate()
      Specified by:
      getDomainDelegate in interface PersistenceDelegate<T extends PersistentDomainObject<T>>
    • getPdo

      public T getPdo()
      Specified by:
      getPdo in interface PdoProvider<T extends PersistentDomainObject<T>>
    • me

      public T me()
      Specified by:
      me in interface ProxyDelegate<T extends PersistentDomainObject<T>>
    • toGenericString

      public final String toGenericString()
      Specified by:
      toGenericString in interface org.tentackle.misc.Identifiable
      Overrides:
      toGenericString in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • setPdo

      public void setPdo(T pdo)
      Sets the PDO.
      Parameters:
      pdo - the pdo
    • getEffectiveClass

      public Class<T> getEffectiveClass()
      Specified by:
      getEffectiveClass in interface org.tentackle.reflect.EffectiveClassProvider<T extends PersistentDomainObject<T>>
    • getEffectiveSuperClasses

      public List<Class<? super T>> getEffectiveSuperClasses()
      Specified by:
      getEffectiveSuperClasses in interface org.tentackle.reflect.EffectiveClassProvider<T extends PersistentDomainObject<T>>
    • getPdoMethodCache

      public PdoMethodCache<T> getPdoMethodCache()
      Specified by:
      getPdoMethodCache in interface PdoMethodCacheProvider<T extends PersistentDomainObject<T>>
    • clone

      protected final P clone()
      Clones this persistent object.
      The method is final to prevent applications from overriding it and spoiling the contract with createSnapshot().

      Notice that the proxy pdo is cleared to null in the cloned PO.

      Overrides:
      clone in class Object
      Returns:
      the cloned persistent object
    • createSnapshot

      public T createSnapshot()
      Creates a snapshot of this object.

      The method must be implemented. The default implementation just throws PersistenceException.

      Specified by:
      createSnapshot in interface org.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
      Returns:
      the snapshot
    • createComponentsInSnapshot

      protected void createComponentsInSnapshot(AbstractPersistentObject snapshot)
      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

      public void revertToSnapshot(T snapshot)
      Reverts the state of this object to given snapshot.

      The method must be implemented. The default implementation just throws PersistenceException.

      Specified by:
      revertToSnapshot in interface org.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
      Parameters:
      snapshot - the snapshot to revert to
    • copy

      public T 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 invoke loadComponents(boolean) before copy() to get a logically complete copy of the aggregate.

      Specified by:
      copy in interface org.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
      Returns:
      the new copied object
    • revertAttributesToSnapshot

      protected void revertAttributesToSnapshot(AbstractPersistentObject snapshot)
      Copies all attributes from a snapshot object back to this object.
      Parameters:
      snapshot - the snapshot object
    • revertComponentsToSnapshot

      protected void revertComponentsToSnapshot(AbstractPersistentObject snapshot)
      Reverts all components of this object to a given snapshot.
      Parameters:
      snapshot - the snapshot object
    • isSnapshot

      public boolean isSnapshot()
      Specified by:
      isSnapshot in interface org.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
    • isCopy

      public boolean isCopy()
      Specified by:
      isCopy in interface org.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
      Overrides:
      isCopy in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • setCopy

      public void setCopy(boolean copy)
      Specified by:
      setCopy in interface org.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
    • getSnapshots

      public List<T> getSnapshots()
      Specified by:
      getSnapshots in interface org.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
    • discardSnapshot

      public void discardSnapshot(T snapshot)
      Specified by:
      discardSnapshot in interface org.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
    • discardSnapshots

      public void discardSnapshots()
      Specified by:
      discardSnapshots in interface org.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
    • addSnapshot

      protected void addSnapshot(T snapshot)
      Adds a snapshot to the list of snapshots.
      Parameters:
      snapshot - the snapshot to add
    • assertValidSnapshot

      protected void assertValidSnapshot(T snapshot)
      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:
      assertMutable in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • isPersistable

      public boolean isPersistable()
      Specified by:
      isPersistable in interface PersistentObject<T extends PersistentDomainObject<T>>
      Overrides:
      isPersistable in class AbstractDbObject<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:
      assertPersistable in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • createPropertySupport

      protected org.tentackle.misc.PropertySupport createPropertySupport()
      Overrides:
      createPropertySupport in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • isRootEntity

      public boolean isRootEntity()

      The default is false. Override if this is a root-entity.

      Specified by:
      isRootEntity in interface PersistentObject<T extends PersistentDomainObject<T>>
    • isEmbedded

      public boolean isEmbedded()
      Specified by:
      isEmbedded in interface PersistentObject<T extends PersistentDomainObject<T>>
    • assertEmbedded

      protected void assertEmbedded()
      Asserts that this is an embedded PDO.
    • getEmbeddingParent

      public <E extends PersistentDomainObject<E>> E getEmbeddingParent()
      Specified by:
      getEmbeddingParent in interface PersistentObject<T extends PersistentDomainObject<T>>
    • setEmbeddingPersistentObject

      public void setEmbeddingPersistentObject(AbstractPersistentObject<?,?> embeddingParent, String columnPrefix)
      Sets the embedding PO for this embedded PDO.
      Throws a PersistenceException if 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 null
      columnPrefix - the column prefix, empty string if none, never null
    • getColumnPrefix

      public String getColumnPrefix()
      Gets the column prefix for this embedded PDO.
      Returns:
      the column prefix
    • configureEmbeddedColumns

      public void configureEmbeddedColumns(ResultSetWrapper rs)
      Configures the columns of an embedded PDO.
      Parameters:
      rs - the result set
    • setEmbeddedFields

      public int setEmbeddedFields(int ndx, PreparedStatementWrapper st)
      Sets the fields of an embedded PDO.
      Parameters:
      ndx - the last used column index of the prepared statement
      st - the prepared statement
      Returns:
      the last used column index
    • isRootIdProvided

      public boolean isRootIdProvided()
      Specified by:
      isRootIdProvided in interface PersistentObject<T extends PersistentDomainObject<T>>
    • getRootId

      public long getRootId()
      Specified by:
      getRootId in interface PersistentObject<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:
      isRootClassIdProvided in interface PersistentObject<T extends PersistentDomainObject<T>>
    • getRootClassId

      public int getRootClassId()
      Specified by:
      getRootClassId in interface PersistentObject<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

      public <C extends PersistentDomainObject<C>> boolean isRootEntityOf(C component)
      Specified by:
      isRootEntityOf in interface PersistentObject<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:
      isNormTextProvided in interface PersistentObject<T extends PersistentDomainObject<T>>
    • assertNormTextProvided

      protected void assertNormTextProvided()
      Asserts that entity provides a normtext.
    • setNormText

      public void setNormText(String normText)
      Sets the normtext.
      Parameters:
      normText - the normtext
    • getNormText

      public String getNormText()
      Gets the normtext.
      Specified by:
      getNormText in interface PersistentObject<T extends PersistentDomainObject<T>>
      Returns:
      the normtext
    • createAttributesNormText

      public StringBuilder 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

      public StringBuilder 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:
      isDomainContextImmutable in interface DomainContextDependable
      Returns:
      true if context cannot be changed
    • setDomainContextImmutable

      public void setDomainContextImmutable(boolean contextImmutable)
      Sets the immutable flag of the domain context.
      Specified by:
      setDomainContextImmutable in interface DomainContextDependable
      Parameters:
      contextImmutable - true if context cannot be changed
    • assertDomainContextMutable

      protected void assertDomainContextMutable()
      Asserts that the domain context is mutable.
    • setDomainContext

      public void setDomainContext(DomainContext context)

      Setting the context will also set the session and context id.

      Specified by:
      setDomainContext in interface DomainContextDependable
    • getDomainContext

      public DomainContext getDomainContext()

      The default implementation just returns the context. Subclasses may override this with a covariant method.

      Specified by:
      getDomainContext in interface DomainContextProvider
    • determineContextId

      public void determineContextId()

      The default implementation does nothing (object living in a context not depending on another object).

      Specified by:
      determineContextId in interface DomainContextDependable
    • getContextId

      public long getContextId()

      The default implementation returns -1.

      Specified by:
      getContextId in interface DomainContextDependable
    • getSqlContextCondition

      public String getSqlContextCondition()
      Gets the SQL code for the context condition.
      Returns:
      empty if no condition (default)
    • getBaseContext

      public DomainContext getBaseContext()

      The default implementation returns the PDO's DomainContext.

      Specified by:
      getBaseContext in interface DomainContextDependable
    • createValidContext

      public DomainContext createValidContext()

      The default implementation just returns a new DomainContext.

      Specified by:
      createValidContext in interface DomainContextDependable
    • getClassVariables

      public PersistentObjectClassVariables<T,P> getClassVariables()
      Gets the application oriented class variables for this object.
      Class variables for classes derived from AbstractPersistentObject are kept in an instance of PersistentObjectClassVariables.

      Overrides:
      getClassVariables in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
      Returns:
      the class variables
      See Also:
    • createStatementKey

      protected StatementKey createStatementKey(StatementId stmtId)
      Overrides:
      createStatementKey in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • getTableName

      public String getTableName()
      Specified by:
      getTableName in interface PersistentObject<T extends PersistentDomainObject<T>>
      Overrides:
      getTableName in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • getTableAlias

      public String getTableAlias()
      Gets the table alias.
      Returns:
      the alias, null if class does not map to a database table
    • getColumnName

      public String getColumnName(String name)
      Gets the full column name with table alias.
      Parameters:
      name - the short name
      Returns:
      the full name
    • getColumnNames

      public String getColumnNames(Supplier<List<String>> columnNamesSupplier)
      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

      public String getColumnNames(List<String> columnNames)
      Gets the comma-separated list of column names with table alias.
      Parameters:
      columnNames - the list of column names
      Returns:
      the partial SQL string
    • getValidClassIds

      public List<Integer> 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

      public String 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

      public String getTopSuperTableAlias()
      Gets the alias for the topmost super class.
      Returns:
      the alias
    • getTopSuperTableName

      public String getTopSuperTableName()
      Gets the tablename for the topmost super class.
      Returns:
      the alias
    • getPdoClass

      public Class<T> 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:
      isAbstract in interface PersistentObject<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:
      isComposite in interface PersistentObject<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:
      loadComponents in interface PersistentObject<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 map
      onlyLoaded - 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 map
      objects - the collection of objects to add along with their components
      onlyLoaded - 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 as AbstractDbObject.deletePlain() but with components.
    • deletePlainWithComponents

      public int deletePlainWithComponents(Collection<? extends PersistentDomainObject<?>> objects)
      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 as AbstractDbObject.insertPlain() but with components.
    • insertPlainWithComponents

      public int insertPlainWithComponents(Collection<? extends PersistentDomainObject<?>> objects)
      Inserts plain with components all objects of a collection.
      Parameters:
      objects - the collection of PDOs
      Returns:
      the number of objects processed
    • findDuplicate

      public T 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 UnsupportedOperationException if one of those methods are not implemented (which is the default).

      Specified by:
      findDuplicate in interface PersistentObject<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:
      isCacheable in interface PersistentObject<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:
      isExpired in interface PersistentObject<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:
      setExpired in interface PersistentObject<T extends PersistentDomainObject<T>>
      Parameters:
      expired - true if object is expired
    • getCacheAccessTime

      public long getCacheAccessTime()
      Gets the last cache access time.
      Specified by:
      getCacheAccessTime in interface PersistentObject<T extends PersistentDomainObject<T>>
      Returns:
      the last cache access time
    • getCacheAccessCount

      public long getCacheAccessCount()
      Gets the cache access count.
      Specified by:
      getCacheAccessCount in interface PersistentObject<T extends PersistentDomainObject<T>>
      Returns:
      the access count
    • markCacheAccess

      public void markCacheAccess()
      mark cache access (count and set current system-time)
      Specified by:
      markCacheAccess in interface PersistentObject<T extends PersistentDomainObject<T>>
    • isCached

      public boolean isCached()
      Specified by:
      isCached in interface PersistentObject<T extends PersistentDomainObject<T>>
      Returns:
      true if object is cached
    • getSecurityResult

      public SecurityResult getSecurityResult(Permission permission)
      Specified by:
      getSecurityResult in interface PersistentObject<T extends PersistentDomainObject<T>>
    • isPermissionAccepted

      public boolean isPermissionAccepted(Permission permission)
      Specified by:
      isPermissionAccepted in interface PersistentObject<T extends PersistentDomainObject<T>>
    • selectByTemplate

      public T selectByTemplate(AbstractPersistentObject<T,P> template)
      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

      public JoinedSelect<T> 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 to AbstractDbObject.getPreparedStatement(StatementId, SqlSupplier).

      The method must only be used for inserts, updates and delete of a single row!

      Parameters:
      modType - the modification type
      stmtId - the statement ID
      sqlSupplier - the SQL code supplier
      Returns:
      the statement
    • insertImpl

      protected void insertImpl(DbObjectClassVariables<P> classVariables, SqlSupplier sqlSupplier)
      Overrides:
      insertImpl in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • updateImpl

      protected void updateImpl(DbObjectClassVariables<P> classVariables, SqlSupplier sqlSupplier)
      Overrides:
      updateImpl in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • deleteImpl

      protected void deleteImpl(DbObjectClassVariables<P> classVariables, SqlSupplier sqlSupplier)
      Overrides:
      deleteImpl in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • readFromResultSetWrapper

      public P readFromResultSetWrapper(ResultSetWrapper rs)

      Overridden to implement inheritance and adjust the domain context.

      Overrides:
      readFromResultSetWrapper in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • executeQueryToList

      public void executeQueryToList(PreparedStatementWrapper st, JoinedSelect<T> js, List<T> list)
      Executes the query for a prepared statement and adds the results to a list.
      Parameters:
      st - the query statement
      js - the joined select configuration, null if no joins
      list - the list
    • executeQueryToList

      public void executeQueryToList(ResultSetWrapper rs, JoinedSelect<T> js, List<T> list)
      Executes the query for a prepared statement and adds the results to a list.
      Parameters:
      rs - the result set wrapper
      js - the joined select configuration, null if no joins
      list - the list
    • executeListQuery

      public List<T> executeListQuery(PreparedStatementWrapper st, JoinedSelect<T> js)
      Executes the query for a prepared statement and returns the results in a list.
      Parameters:
      st - the query statement
      js - the joined select configuration, null if no joins
      Returns:
      the list
    • executeListQuery

      public List<T> executeListQuery(PreparedStatementWrapper st)
      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 statement
      js - the joined select configuration, null if no joins
      Returns:
      the tracked list
    • executeTrackedListQuery

      public org.tentackle.misc.TrackedList<T> executeTrackedListQuery(PreparedStatementWrapper st)
      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

      public Query createQuery(JoinedSelect<T> js)
      Creates a Query to retrieve a list of this entity type.
      Parameters:
      js - the joined select configuration, null if no joins
      Returns:
      the initialized query
    • createQuery

      public Query createQuery()
      Creates a Query to retrieve a list of this entity type.
      Returns:
      the initialized query
    • executeQuery

      public org.tentackle.misc.TrackedList<T> executeQuery(Query query, JoinedSelect<T> js)
      Executes a Query which was built to return a tracked list of this entity type.
      Parameters:
      query - the query object
      js - the joined select configuration, null if no joins
      Returns:
      the tracked list
    • executeQuery

      public org.tentackle.misc.TrackedList<T> executeQuery(Query query)
      Executes a Query which was built to return a tracked list of this entity type.
      Parameters:
      query - the query object
      Returns:
      the tracked list
    • executeScrollableQuery

      public ResultSetCursor<T> executeScrollableQuery(Query query, JoinedSelect<T> js)
      Executes a Query which was built to return a tracked list of this entity type.
      Parameters:
      query - the query object
      js - the joined select configuration, null if no joins
      Returns:
      the scrollable cursor
    • executeScrollableQuery

      public ResultSetCursor<T> executeScrollableQuery(Query query)
      Executes a Query which was built to return a tracked list of this entity type.
      Parameters:
      query - the query object
      Returns:
      the scrollable cursor
    • getEagerJoins

      public List<Join<? super T,?>> getEagerJoins()
      Returns the eager joins for this PDO.
      Returns:
      the list of eager joins, null if none
    • readJoinedRow

      public void readJoinedRow(ResultSetWrapper rs, JoinedSelect<T> js)
      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:
      rs - the result set
      js - the joined select
    • executeFirstPdoQuery

      public T executeFirstPdoQuery(PreparedStatementWrapper st, JoinedSelect<T> js)
      Executes a query for a prepared statement and returns the first PDO.
      Parameters:
      st - the query statement
      js - the joined select configuration, null if no joins
      Returns:
      the PDO
    • executeFirstPdoQuery

      public T executeFirstPdoQuery(PreparedStatementWrapper st)
      Executes a query for a prepared statement and returns the first PDO.
      Parameters:
      st - the query statement
      Returns:
      the PDO
    • select

      public T select(long id, boolean forUpdate)
      Loads a PDO from the database by its unique ID.
      Parameters:
      id - is the object id
      forUpdate - true if select FOR UPDATE
      Returns:
      object if loaded, null if no such object
    • select

      public T select(long id)
      Loads a PDO from the database by its unique ID.
      Specified by:
      select in interface PersistentObject<T extends PersistentDomainObject<T>>
      Parameters:
      id - is the object id
      Returns:
      object if loaded, null if no such object
    • reload

      public T reload()
      Reloads the object.

      Restores transient data, if present.

      Specified by:
      reload in interface PersistentObject<T extends PersistentDomainObject<T>>
      Returns:
      the object if reloaded, else null (never this)
    • reloadForUpdate

      public T reloadForUpdate()
      Reloads the object with a write-lock.
      Restores transient data, if present.
      Specified by:
      reloadForUpdate in interface PersistentObject<T extends PersistentDomainObject<T>>
      Returns:
      the object if reloaded, else null (never this)
    • selectForUpdate

      public T selectForUpdate(long id)
      Loads and write-locks a PDO from the database by its unique ID.
      Specified by:
      selectForUpdate in interface PersistentObject<T extends PersistentDomainObject<T>>
      Parameters:
      id - is the object id
      Returns:
      object if loaded, null if no such object
    • derivePdoFromPo

      public T derivePdoFromPo(T pdo, P po)
      Derive the concrete PDO from a given PO.
      Parameters:
      pdo - the original persistent domain object
      po - 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

      public StringBuilder createSelectAllInnerSql(org.tentackle.sql.Backend backend)
      Overrides:
      createSelectAllInnerSql in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • createSelectAllIdSerialInnerSql

      public StringBuilder createSelectAllIdSerialInnerSql()
      Overrides:
      createSelectAllIdSerialInnerSql in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • createSelectAllByIdInnerSql

      public StringBuilder createSelectAllByIdInnerSql(org.tentackle.sql.Backend backend)
      Overrides:
      createSelectAllByIdInnerSql in class AbstractDbObject<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 classvariables
      withAlias - true if column name with table alias, else without
      Returns:
      the sql text
    • createSelectIdInnerSql

      public StringBuilder createSelectIdInnerSql(boolean withAlias)
      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

      public StringBuilder createSelectIdInnerSql()
      Overrides:
      createSelectIdInnerSql in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • createSelectByNormTextSql

      public String createSelectByNormTextSql(org.tentackle.sql.Backend backend, boolean not)
      Creates the SQL code for select by normtext.
      Parameters:
      backend - the backend
      not - true to find all not matching the normtext
      Returns:
      the sql code
    • createSelectSerialSql

      public String createSelectSerialSql()
      Creates the SQL code for the selectSerial statement.
      Overrides:
      createSelectSerialSql in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
      Returns:
      the sql code
    • createSelectMaxIdSql

      public String createSelectMaxIdSql()
      Creates the SQL code for the selectMaxId statement.
      Overrides:
      createSelectMaxIdSql in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
      Returns:
      the sql code
    • createSelectMaxTableSerialSql

      public String createSelectMaxTableSerialSql()
      Creates the SQL code for the selectMaxTableSerial statement.
      Overrides:
      createSelectMaxTableSerialSql in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
      Returns:
      the sql code
    • createDummyUpdateSql

      public String createDummyUpdateSql()
      Creates the SQL code for the dummy update statement.
      Useful get an exclusive lock within a transaction.
      Overrides:
      createDummyUpdateSql in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
      Returns:
      the sql code
    • createUpdateSerialSql

      public String createUpdateSerialSql()
      Creates the SQL code for the serial update statement.
      Overrides:
      createUpdateSerialSql in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
      Returns:
      the sql code
    • createUpdateSerialAndTableSerialSql

      public String createUpdateSerialAndTableSerialSql()
      Creates the SQL code for the serial + tableSerial update statement.
      Overrides:
      createUpdateSerialAndTableSerialSql in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
      Returns:
      the sql code
    • createSelectExpiredTableSerials1Sql

      public String createSelectExpiredTableSerials1Sql()
      Creates the SQL code for the first statement to select expired table serials.
      Overrides:
      createSelectExpiredTableSerials1Sql in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
      Returns:
      the sql code
    • createSelectExpiredTableSerials2Sql

      public String createSelectExpiredTableSerials2Sql()
      Creates the SQL code for the second statement to select expired table serials.
      Overrides:
      createSelectExpiredTableSerials2Sql in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
      Returns:
      the sql code
    • resultByNormText

      public ResultSetWrapper resultByNormText(String text, JoinedSelect<T> js)
      Gets the result set for the normtext query.
      Parameters:
      text - the text to search for
      js - the optional join config, null if no joins
      Returns:
      the result set
      See Also:
    • resultByNormTextCursor

      public ResultSetWrapper resultByNormTextCursor(String text, JoinedSelect<T> js)
      Gets the result set for the normtext query as a cursor.
      Parameters:
      text - the text to search for
      js - the optional join config, null if no joins
      Returns:
      the result set
      See Also:
    • selectByNormText

      public List<T> selectByNormText(String text)
      Selects all objects with a given normtext as a list.
      Specified by:
      selectByNormText in interface PersistentObject<T extends PersistentDomainObject<T>>
      Parameters:
      text - the text to search for
      Returns:
      the list of objects, never null
      See Also:
    • selectByNormTextAsCursor

      public org.tentackle.misc.ScrollableResource<T> selectByNormTextAsCursor(String text)
      Selects all objects with a given normtext as a cursor.
      Specified by:
      selectByNormTextAsCursor in interface PersistentObject<T extends PersistentDomainObject<T>>
      Parameters:
      text - the text to search for
      Returns:
      the cursor
      See Also:
    • createSelectAllSql

      public String createSelectAllSql(org.tentackle.sql.Backend backend)
      Creates SQL-code for select all.
      Appends context condition and order by clause if configured.
      Parameters:
      backend - the backend
      Returns:
      the sql code
    • createSelectAllWithExpiredTableSerialsSql

      public String createSelectAllWithExpiredTableSerialsSql(org.tentackle.sql.Backend backend)
      Creates SQL-code for selectAllWithExpiredTableSerials(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

      public ResultSetWrapper resultAll(JoinedSelect<T> js)
      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

      public ResultSetWrapper resultAllWithExpiredTableSerials(JoinedSelect<T> js, long oldSerial)
      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 joins
      oldSerial - the last known tableserial
      Returns:
      the result set
    • resultAllCursor

      public ResultSetWrapper 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 need ResultSet.TYPE_SCROLL_INSENSITIVE set.
      Parameters:
      js - the optional join config, null if no joins
      Returns:
      the result set
      See Also:
    • selectAll

      public List<T> selectAll()
      Selects all records in current context as a list.
      Specified by:
      selectAll in interface PersistentObject<T extends PersistentDomainObject<T>>
      Returns:
      the list of objects, never null
      See Also:
    • selectAllWithExpiredTableSerials

      public List<T> selectAllWithExpiredTableSerials(long oldSerial)
      Specified by:
      selectAllWithExpiredTableSerials in interface PersistentObject<T extends PersistentDomainObject<T>>
    • selectAllAsCursor

      public org.tentackle.misc.ScrollableResource<T> selectAllAsCursor()
      Selects all records in current context as a cursor
      Specified by:
      selectAllAsCursor in interface PersistentObject<T extends PersistentDomainObject<T>>
      Returns:
      the cursor
      See Also:
    • selectLatest

      public List<T> selectLatest(long greaterId, int limit)
      Specified by:
      selectLatest in interface PersistentObject<T extends PersistentDomainObject<T>>
    • getCache

      public PdoCache<T> getCache()
      Gets the cache. The default implementation returns null. Must be overridden to enable optimization features with RMI servers.
      Specified by:
      getCache in interface PersistentObject<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 wurblet PdoCache.
      Parameters:
      maxSerial - is the new tableSerial this object will get
      See Also:
    • selectCached

      public T selectCached(long id)
      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:
      selectCached in interface PersistentObject<T extends PersistentDomainObject<T>>
      Parameters:
      id - the unique object ID
      Returns:
      the object, null if no such object
      See Also:
    • selectCachedOnly

      public T selectCachedOnly(long id)
      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:
      selectCachedOnly in interface PersistentObject<T extends PersistentDomainObject<T>>
      Parameters:
      id - the unique object ID
      Returns:
      the object, null if no such object
      See Also:
    • selectAllCached

      public List<T> 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:
      selectAllCached in interface PersistentObject<T extends PersistentDomainObject<T>>
      Returns:
      the list, never null
      See Also:
    • selectAllForCache

      public List<T> selectAllForCache()
      Specified by:
      selectAllForCache in interface PersistentObject<T extends PersistentDomainObject<T>>
    • selectForCache

      public T selectForCache(long id)
      Specified by:
      selectForCache in interface PersistentObject<T extends PersistentDomainObject<T>>
    • countModification

      public long countModification()

      Overridden to expire the cache if object is using the tableserial.

      Overrides:
      countModification in class AbstractDbObject<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 add
      methodPath - 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 add
      methodPath - 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 DomainContext instead of just the Session.

      Specified by:
      isReferenced in interface PersistentObject<T extends PersistentDomainObject<T>>
      Overrides:
      isReferenced in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • containsPattern

      public boolean containsPattern(String pattern)
      Searches for a "pattern" in this object.
      The default implementation looks for the pattern in the normtext.
      Specified by:
      containsPattern in interface PersistentObject<T extends PersistentDomainObject<T>>
      Parameters:
      pattern - the pattern to search for
      Returns:
      true if this object "contains" the pattern
    • orderBy

      public String 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

      protected void initModification(ModificationType modType)

      Overridden due to security check.

      Overrides:
      initModification in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • finishModification

      protected void finishModification(ModificationType modType)

      Overridden to clear the renewTokenLock flag.

      Overrides:
      finishModification in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • finishNotUpdated

      protected void finishNotUpdated(ModificationType modType)

      Overridden to get the token lock removed, if any.

      Overrides:
      finishNotUpdated in class AbstractDbObject<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:
      isUpdateNecessary in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • updateObject

      public void updateObject()
      Overrides:
      updateObject in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • insertObject

      public void insertObject()
      Overrides:
      insertObject in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • deleteObject

      public void deleteObject()
      Overrides:
      deleteObject in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • newId

      public void newId()
      Overrides:
      newId in class AbstractDbObject<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

      public void configureRemoteObject(DomainContext context, PersistentDomainObject<?> obj)
      Configures the remotely retrieved object.
      Parameters:
      context - the local domain context
      obj - the object
    • configureRemoteObjects

      public void configureRemoteObjects(DomainContext context, Collection<? extends PersistentDomainObject<?>> objects)
      Configures the remotely retrieved objects.
      Parameters:
      context - the local domain context
      objects - the objects to configure
    • assertRootContext

      protected void assertRootContext()
      Asserts that the po's context is a root context.
    • markDeleted

      protected <X extends PersistentDomainObject<X>> void markDeleted(Collection<X> pdos)
      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

      protected void markDeleted(PersistentDomainObject<?> pdo)
      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

      protected <X extends PersistentDomainObject<X>> void delete(Collection<X> pdos)
      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

      protected void delete(PersistentDomainObject<?> pdo)
      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 db
      newCollection - the new list of objects
    • assertRootEntity

      public void assertRootEntity()
      Checks if the po is a root entity.
    • delete

      public void delete()
      Specified by:
      delete in interface PersistentObject<T extends PersistentDomainObject<T>>
    • deleteImpl

      protected void deleteImpl()
      Implementation of delete bypassing the invocation handler.
    • save

      public void save()
      Specified by:
      save in interface PersistentObject<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 save
      modifiedOnly - true if only modified objects are saved
    • save

      public static void save(PersistentDomainObject<?> pdo)
      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

      public T persist()
      Specified by:
      persist in interface PersistentObject<T extends PersistentDomainObject<T>>
    • persistTokenLocked

      public T persistTokenLocked()
      Specified by:
      persistTokenLocked in interface PersistentObject<T extends PersistentDomainObject<T>>
    • persistImpl

      protected 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:
      isUpdatingSerialEvenIfNotModified in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
      Returns:
      true if update serial even if object is unchanged
      See Also:
    • isModified

      protected <X extends PersistentDomainObject<X>> boolean isModified(Collection<X> pdos)
      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:
      isTokenLockProvided in interface PersistentObject<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:
      getTokenLockTimeout in interface PersistentObject<T extends PersistentDomainObject<T>>
      Returns:
      the timespan in ms, 0 = no token required.
    • createUpdateTokenLockSql

      public String createUpdateTokenLockSql()
      Returns:
      the sql code
    • createUpdateTokenLockWithCountSql

      public String createUpdateTokenLockWithCountSql()
      Creates the SQL code for the updateTokenLock(org.tentackle.common.Timestamp, long, org.tentackle.common.Timestamp) statement with mod counting.
      Returns:
      the sql code
    • createUpdateTokenLockOnlySql

      public String createUpdateTokenLockOnlySql()
      Creates the SQL code for the updateTokenLockOnly() statement.
      Returns:
      the sql code
    • createSelectTokenLockSql

      public String createSelectTokenLockSql()
      Returns:
      the sql code
    • createTransferTokenLockSql

      public String createTransferTokenLockSql()
      Creates the SQL code for the transferTokenLock(long) statement without tableserial.
      Returns:
      the sql code
    • createTransferTokenLockWithTableSerialSql

      public String createTransferTokenLockWithTableSerialSql()
      Creates the SQL code for the transferTokenLock(long) statement with tableserial.
      Returns:
      the sql code
    • getEditedBy

      public long getEditedBy()
      Gets the id of the user currently editing this object.
      Specified by:
      getEditedBy in interface PersistentObject<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:
      requestTokenLock in interface PersistentObject<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:
      releaseTokenLock in interface PersistentObject<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:
      isTokenLocked in interface PersistentObject<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:
      isTokenLockedBy in interface PersistentObject<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:
      isTokenLockedByMe in interface PersistentObject<T extends PersistentDomainObject<T>>
      Returns:
      true if locked
    • isTokenLockableByMe

      public boolean isTokenLockableByMe()
      Specified by:
      isTokenLockableByMe in interface PersistentObject<T extends PersistentDomainObject<T>>
    • getEditedSince

      public org.tentackle.common.Timestamp getEditedSince()
      Gets the time since when this object is being edited.
      Specified by:
      getEditedSince in interface PersistentObject<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:
      getEditedExpiry in interface PersistentObject<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

      public void applyTokenLockInfo(TokenLockInfo tokenLockInfo)
      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

      public T transferTokenLock(long userId)
      Specified by:
      transferTokenLock in interface PersistentObject<T extends PersistentDomainObject<T>>
    • getTransientData

      public Object 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 methods persist(), reload() and reloadForUpdate() preserve that data via getTransientData() and setTransientData(Object). Applications must override those methods.
      The default implementation does nothing.
      Returns:
      the transient data, null if none
      See Also:
    • setTransientData

      public void setTransientData(Object data)
      Sets the optional transient data object.
      Parameters:
      data - the transient data
      See Also:
    • getRemoteDelegate

      public org.tentackle.persist.rmi.AbstractPersistentObjectRemoteDelegate<T,P> getRemoteDelegate()

      Overridden due to covariance.

      Overrides:
      getRemoteDelegate in class AbstractDbObject<P extends AbstractPersistentObject<T,P>>
    • getDefaultScopes

      public Class<? extends org.tentackle.validate.ValidationScope>[] getDefaultScopes()

      The default scopes are: PersistenceScope, MandatoryScope and ChangeableScope.

      Specified by:
      getDefaultScopes in interface org.tentackle.validate.ScopeConfigurator
    • validate

      public List<org.tentackle.validate.ValidationResult> validate(String validationPath, org.tentackle.validate.ValidationScope scope)
      Specified by:
      validate in interface org.tentackle.validate.Validateable
    • validate

      public void validate()
      Specified by:
      validate in interface PersistentObject<T extends PersistentDomainObject<T>>
    • isValidated

      public boolean isValidated()
      Specified by:
      isValidated in interface PersistentObject<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:
      setModified in class AbstractDbObject<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:
      isWriteAllowed in interface PersistentObject<T extends PersistentDomainObject<T>>
    • isViewAllowed

      public boolean isViewAllowed()
      Specified by:
      isViewAllowed in interface PersistentObject<T extends PersistentDomainObject<T>>
    • isEditAllowed

      public boolean isEditAllowed()
      Specified by:
      isEditAllowed in interface PersistentObject<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