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

    • Constructor Detail

      • 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 Detail

      • 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>>
      • 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
      • createAttributesInSnapshot

        protected void createAttributesInSnapshot​(AbstractPersistentObject snapshot)
        Updates the attributes in snapshot object.
        The snapshot object is assumed to be a clone of this object.
        Parameters:
        snapshot - 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.
        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()
        Specified by:
        copy in interface org.tentackle.misc.Snapshotable<T extends PersistentDomainObject<T>>
      • 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>>
      • 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.
      • setPersistable

        public void setPersistable​(boolean persistable)
        Sets the local persistable flag.

        The implementation maintains an additional flag to disable persistabilty.

        Parameters:
        persistable - true if persistable, false if not persistable
      • setRootId

        public void setRootId​(long rootId)
        Sets the ID of the root entity this component belongs to.
        Parameters:
        rootId - the root id
      • setRootClassId

        public void setRootClassId​(int rootClassId)
        Sets the class ID of the root entity this component belongs to.
        Parameters:
        rootClassId - the root class id
      • assertNormTextProvided

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

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

        public StringBuilder createAttributesNormText()
        Creates the normtext of all attributes with the normtext option.
        The method is usually generated by the MethodsImpl wurblet.
        Returns:
        the builder holding the unnormalized text, null if no normtext attributes
      • createRelationsNormText

        public StringBuilder createRelationsNormText()
        Creates the normtext of all relations with the normtext option.
        The method is usually generated by the PdoRelations wurblet.
        Returns:
        the builder holding the unnormalized 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.
      • 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
      • getSqlContextCondition

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

        public String getSqlClassIdCondition()
        Gets the additional condition to be used in the WHERE clause for the classid.
         Example: return " AND " + CN_CLASSID + "=?";
         
        Returns:
        the condition, null if none necessary
      • 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 optional table alias.
        Parameters:
        name - the short name
        Returns:
        the full name
      • 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.
      • getValidClassId

        public int getValidClassId()
        Gets the classid.
        Returns:
        the classid
        Throws:
        org.tentackle.session.PersistenceException - if not valid
      • isClassIdRequiredInWhereClause

        public boolean isClassIdRequiredInWhereClause()
        Returns whether the classid needs to be inluded in the WHERE-clause.
        Applies only to leafs with SINGLE inheritance.
        Returns:
        true if include classid
      • isExplicitIdAliasRequiredInJoins

        public boolean isExplicitIdAliasRequiredInJoins()
        Returns whether an explicit id alias is necessary in joins.
        This applies to MULTI-table inherited PDOs only (abstracts and leafs).
        Returns:
        true if need 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)
      • 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 overwridden 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,
                                                                         Supplier<String> 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, Supplier).

        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
      • 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
      • 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 the to the domain's requirements.
        Parameters:
        js - the joined select
        rs - the result set
      • 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
      • setClassIdsInStatement

        protected int setClassIdsInStatement​(JoinedSelect<T> js,
                                             PreparedStatementWrapper st,
                                             int ndx)
        Sets the class-ID parameters if required for the joins.
        Notice that this method only works for joins with no subjoins and is used only for eager joins, i.e.the default selects.
        All code for non-eager joins is generated via the DbModelWurblet.
        Parameters:
        js - the join configuration
        st - the statement
        ndx - the next parameter ndx
        Returns:
        the next parameter index
      • 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
      • 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 agains the security rules.
      • 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
      • createSelectByNormTextSql

        public String createSelectByNormTextSql​(boolean not)
        Creates the SQL code for select by normtext.
        Parameters:
        not - true if find all not matching the normtext
        Returns:
        the sql code
      • createSelectAllSql

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

        public String createSelectAllWithExpiredTableSerialsSql()
        Creates SQL code for selectAllWithExpiredTableSerials(long).
        Appends context condition and order by clause if configured.
        By default, the result is sorted by tableserial + id.
        Returns:
        the sql code
      • 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
      • 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 boolean 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:
            cache.expire(maxSerial);
         
        while "cache" has been declared by the wurblet PdoCache.
        Parameters:
        maxSerial - is the new tableSerial this object will get
        Returns:
        true if cache invalidated, false if there is no cache
        See Also:
        PdoCache
      • 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
      • getContextUserId

        public long getContextUserId()
        Gets the user id from the current context, i.e. userinfo.

        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. Afterwards the flag will be cleared.

        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)
      • 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,
                                          T obj)
        Configures the remotely retrieved object.
        Parameters:
        context - the local domain context
        obj - the object
      • configureRemoteObjects

        public void configureRemoteObjects​(DomainContext context,
                                           Collection<T> 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.
      • deleteImpl

        protected void deleteImpl()
        Implementation of delete bypassing the invocation handler.
      • 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
      • 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 childs 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:
        updateObject()
      • isModified

        protected <X extends PersistentDomainObject<X>> boolean isModified​(Collection<X> pdos)
        Checks whether some of the 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.
      • createUpdateTokenLockOnlySql

        public String createUpdateTokenLockOnlySql()
        Creates the SQL code for the updateTokenLockOnly() statement.
        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
      • 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.
      • 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
      • 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.
      • 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.
      • setTokenLockObject

        public <U extends PersistentDomainObject<U>> void setTokenLockObject​(U obj)
        Sets the locking object.

        CAUTION: the method is provided for rare corner cases like administration tools. Don't use it for regular locking/unlocking!

        Type Parameters:
        U - the locking object type
        Parameters:
        obj - the locking object, null to clear.
      • isCountingModificationForTokenLock

        public boolean isCountingModificationForTokenLock()
      • 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 token lock columns in db-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 usually is 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 editing info in db-record (if feature enabled).
        Will *NOT* log modification and *NOT* update the serial-counter! Must be called from within application where appropriate. See PdoEditDialog.

        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 usually is 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 editedBy-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 cleanup.
      • 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(Object)
      • setTransientData

        public void setTransientData​(Object data)
        Sets the optional transient data object.
        Parameters:
        data - the transient data
        See Also:
        getTransientData()
      • 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
      • 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
      • 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