Class NumberPoolDomainImpl

All Implemented Interfaces:
Serializable, NumberPoolDomain, DomainContextProvider, DomainDelegate<NumberPool>, DomainObject<NumberPool>, PdoProvider<NumberPool>, ProxyDelegate<NumberPool>, EffectiveClassProvider<NumberPool>, Interceptable, SessionProvider

@DomainObjectService(NumberPool.class) public class NumberPoolDomainImpl extends AbstractDomainObject<NumberPool, NumberPoolDomainImpl> implements NumberPoolDomain
NumberPool domain implementation.
Author:
harald
See Also:
  • Constructor Details

    • NumberPoolDomainImpl

      public NumberPoolDomainImpl(NumberPool pdo)
    • NumberPoolDomainImpl

      public NumberPoolDomainImpl()
  • Method Details

    • toString

      public String toString()
      Description copied from class: AbstractDomainObject
      Gets the string representation of this domain object.

      The default implementation returns the domain key if this is a root entity. If a component, its single-name will be returned. If evaluating the domain key failed, the generic string is returned along with the exception in parentheses. This is because toString() should never throw an exception as it is used for logging and debugging.

      Overrides:
      toString in class AbstractDomainObject<NumberPool, NumberPoolDomainImpl>
      Returns:
      the string representation
    • getCurrentRange

      public NumberRange getCurrentRange()
      Get the current range.
      This is the first non-empty range with the lowest "begin".

      Despite its name, the method modifies the pool: exhausted ranges are removed from NumberPoolPersistence.getNumberRangeList() along the way and are deleted from the database when the pool is next persisted. This also happens when the pool turns out to be empty, i.e., before the NumberSourceEmptyException is thrown.

      Invoke it only within a transaction that persists the pool afterward or is rolled back, and with the pool locked, as DefaultNumberSource does. It performs no locking itself.

      This method modifies the pool. While scanning for the lowest non-empty range it drops every exhausted range from NumberPoolPersistence.getNumberRangeList(). That list is a TrackedList, so the removed ranges are deleted from the database as soon as the pool is persisted (see NumberPoolPersistenceImpl.deleteReferencingRelations) — this is the intended housekeeping that keeps the range table from filling up with used-up rows.

      Two consequences for callers:

      • The pruning happens on the failure path as well: when the pool turns out to be empty, the ranges have already been removed before the NumberSourceEmptyException is thrown.
      • Call this within a transaction that either persists the pool afterward or is rolled back, and hold the pool locked while doing so — otherwise the in-memory list silently diverges from the database, or the deletions ride along with an unrelated later save.
      The method is not thread-safe and does not lock anything itself. DefaultNumberSource is the intended caller and provides all of it: its methods are synchronized, run inside a transaction, take a database row lock on the pool via reloadForUpdate(), and persist the pool at the end.
      Specified by:
      getCurrentRange in interface NumberPoolDomain
      Returns:
      the current range, never null
      Throws:
      NumberSourceEmptyException - if no non-empty range is left
    • isSlave

      public boolean isSlave()
      Description copied from interface: NumberPoolDomain
      Returns whether this pool is a slave pool and gets its ranges from an uplink.
      Specified by:
      isSlave in interface NumberPoolDomain
      Returns:
      true if slave