Class Domain

    • Field Detail

      • ENABLE_REDEFINE_ENTITY

        public static final PropertyValue<Boolean> ENABLE_REDEFINE_ENTITY
        Specifies whether to enable entities to be re-defined, that is, allow a new definition to replace an old one. Value type: Boolean
        Default value: false
    • Constructor Detail

      • Domain

        public Domain()
        Instantiates a new Domain with the simple name of the class as domain id
        See Also:
        Class.getSimpleName()
      • Domain

        public Domain​(String domainId)
        Instantiates a new Domain
        Parameters:
        domainId - the domain identifier
      • Domain

        public Domain​(Domain domain)
        Instantiates a new domain and copies all the entity definitions and database operations from domain
        Parameters:
        domain - the domain to copy
    • Method Detail

      • getDomainId

        public final String getDomainId()
        Returns:
        the domain Id
      • entity

        public final Entity entity​(String entityId)
        Creates a new Entity instance with the given entityId
        Parameters:
        entityId - the entity id
        Returns:
        a new Entity instance
      • entity

        public final Entity entity​(Entity.Key key)
        Creates a new Entity instance with the given primary key
        Parameters:
        key - the primary key
        Returns:
        a new Entity instance
      • entity

        public final Entity entity​(String entityId,
                                   Map<Property,​Object> values,
                                   Map<Property,​Object> originalValues)
        Instantiates a new Entity instance with the given values and original values.
        Parameters:
        entityId - the entity id
        values - the values
        originalValues - the original values
        Returns:
        a new Entity instance
        Throws:
        IllegalArgumentException - in case any of the properties are not part of the entity.
      • entity

        public final Entity entity​(EntityDefinition entityDefinition,
                                   Map<Property,​Object> values,
                                   Map<Property,​Object> originalValues)
        Instantiates a new Entity instance with the given values and original values.
        Parameters:
        entityDefinition - the entity definition
        values - the values
        originalValues - the original values
        Returns:
        a new Entity instance
        Throws:
        IllegalArgumentException - in case any of the properties are not part of the entity.
      • key

        public final Entity.Key key​(String entityId)
        Creates a new Entity.Key instance with the given entityId
        Parameters:
        entityId - the entity id
        Returns:
        a new Entity.Key instance
      • key

        public final Entity.Key key​(String entityId,
                                    Long value)
        Creates a new Entity.Key instance with the given entityId, initialised with the given value
        Parameters:
        entityId - the entity id
        value - the key value, assumes a single long key
        Returns:
        a new Entity.Key instance
        Throws:
        IllegalArgumentException - in case the given primary key is a composite key
        NullPointerException - in case entityId or value is null
      • keys

        public final List<Entity.Key> keys​(String entityId,
                                           Long... values)
        Creates new Entity.Key instances with the given entityId, initialised with the given values
        Parameters:
        entityId - the entity id
        values - the key values, assumes a single integer key
        Returns:
        new Entity.Key instances
        Throws:
        IllegalArgumentException - in case the given primary key is a composite key
        NullPointerException - in case entityId or values is null
      • deepCopyEntities

        public final List<Entity> deepCopyEntities​(List<Entity> entities)
        Copies the given entities, with new copied instances of all foreign key value entities.
        Parameters:
        entities - the entities to copy
        Returns:
        deep copies of the entities, in the same order as they are received
      • copyEntity

        public final Entity copyEntity​(Entity entity)
        Copies the given entity.
        Parameters:
        entity - the entity to copy
        Returns:
        copy of the given entity
      • deepCopyEntity

        public final Entity deepCopyEntity​(Entity entity)
        Copies the given entity, with new copied instances of all foreign key value entities.
        Parameters:
        entity - the entity to copy
        Returns:
        a deep copy of the given entity
      • copyKey

        public final Entity.Key copyKey​(Entity.Key key)
        Copies the given key.
        Parameters:
        key - the key to copy
        Returns:
        a copy of the given key
      • createToStringEntity

        public final Entity createToStringEntity​(String entityId,
                                                 String toStringValue)
        Creates an empty Entity instance returning the given string on a call to toString(), all other method calls are routed to an empty Entity instance.
        Parameters:
        entityId - the entityId
        toStringValue - the string to return by a call to toString() on the resulting entity
        Returns:
        an empty entity wrapping a string
      • addOperation

        public final void addOperation​(DatabaseOperation operation)
        Adds the given Operation to this domain
        Parameters:
        operation - the operation to add
        Throws:
        IllegalArgumentException - in case an operation with the same id has already been added
      • getProcedure

        public final <C> DatabaseProcedure<C> getProcedure​(String procedureId)
        Retrievs the procedure with the given id.
        Type Parameters:
        C - the type of the database connection this procedure requires
        Parameters:
        procedureId - the procedure id
        Returns:
        the procedure
        Throws:
        IllegalArgumentException - in case the procedure is not found
      • getFunction

        public final <C,​T> DatabaseFunction<C,​T> getFunction​(String functionId)
        Retrievs the function with the given id.
        Type Parameters:
        C - the type of the database connection this function requires
        T - the result type
        Parameters:
        functionId - the function id
        Returns:
        the function
        Throws:
        IllegalArgumentException - in case the function is not found
      • registerDomain

        public final Domain registerDomain()
        Registers this instance for lookup via getDomain(String), required for serialization of domain objects, entities and related classes.
        Returns:
        this Domain instance
        See Also:
        getDomainId()
      • getDomain

        public static Domain getDomain​(String domainId)
        Retrievs the Domain with the given id.
        Parameters:
        domainId - the id of the domain for which to retrieve the entity definitions
        Returns:
        the domain instance registered for the given domainId
        Throws:
        IllegalArgumentException - in case the domain has not been registered
        See Also:
        registerDomain()
      • setStrictForeignKeys

        protected final void setStrictForeignKeys​(boolean strictForeignKeys)
        Specifies whether it should be possible to define foreign keys referencing entities that have not been defined, this can be disabled in cases where entities have circular references.
        Parameters:
        strictForeignKeys - true for strict foreign key validation