Class EntityRegistration

java.lang.Object
org.fastnate.data.EntityRegistration
All Implemented Interfaces:
DataProvider

public class EntityRegistration extends Object implements DataProvider
Registers entities by their unique properties to offer them to other data providers.
Author:
Tobias Liefke
  • Constructor Details

    • EntityRegistration

      public EntityRegistration(org.fastnate.generator.context.GeneratorContext context)
      Creates a new EntityRegistration instance.
      Parameters:
      context - The generation context contains the description of the entity classes, especially unique properties.
  • Method Details

    • buildEntities

      public void buildEntities() throws IOException
      Description copied from interface: DataProvider
      Builds the entities that are accessed later using DataProvider.writeEntities(EntitySqlGenerator).
      Specified by:
      buildEntities in interface DataProvider
      Throws:
      IOException - if something happens during any possible import of the generated entities
    • findEntity

      public <E> E findEntity(Class<E> entityClass, Object uniqueValue)
      Find an entity, that was registered with registerEntity(Object) before.
      Parameters:
      entityClass - the class of the required entity
      uniqueValue - the value from the property
      Returns:
      the found entity or null if not found
      Throws:
      IllegalArgumentException - if more than one unique property exists
    • findEntity

      public <E> E findEntity(Class<E> entityClass, String uniqueProperty, Object uniqueValue)
      Find an entity, that was registered with registerEntity(Object) before.
      Parameters:
      entityClass - the class of the required entity
      uniqueProperty - the name of the unique property
      uniqueValue - the value of the unique property
      Returns:
      the found entity or null if not found
    • findEntity

      public <E> E findEntity(Class<E> entityClass, String[] uniqueProperties, Object[] uniqueValues)
      Find an entity, that was registered with registerEntity(Object) before.
      Parameters:
      entityClass - the class of the required entity
      uniqueProperties - the names of the set of unique properties
      uniqueValues - the values of the set of unique properties
      Returns:
      the found entity or null if not found
    • invokeOnEntity

      public <E> void invokeOnEntity(Class<E> entityClass, Object uniqueValue, Consumer<E> invoker)
      Invokes an action on a specific entity as soon as this entity was registered. Use only if just one unique property exists - otherwise use invokeOnEntity(Class, String, Object, Consumer).
      Parameters:
      entityClass - the class of the required entity
      uniqueValue - the value from the unique property
      invoker - the action to call on the entity as soon as it is registered
      Throws:
      IllegalArgumentException - if more than one unique property exists
    • invokeOnEntity

      public <E> void invokeOnEntity(Class<E> entityClass, String uniqueProperty, Object uniqueValue, Consumer<E> invoker)
      Invokes an action on a specific entity as soon as this entity was registered.
      Parameters:
      entityClass - the class of the required entity
      uniqueProperty - the name of the unique property
      uniqueValue - the value from the unique property
      invoker - the action to call on the entity as soon as it is registered
    • invokeOnEntity

      public <E> void invokeOnEntity(Class<E> entityClass, String[] uniqueProperties, Object[] uniqueValues, Consumer<E> invoker)
      Invokes an action on a specific entity as soon as this entity was registered.
      Parameters:
      entityClass - the class of the required entity
      uniqueProperties - the names of the set of unique properties
      uniqueValues - the values of the set of unique properties
      invoker - the action to call on the entity as soon as it is registered
    • invokeOnEntity

      public <E> void invokeOnEntity(E templateEntity, Consumer<E> invoker)
      Invokes an action on a specific entity as soon as this entity was registered.
      Parameters:
      templateEntity - the template that describes the referenced entity (contains a value in at least one set of unique properties)
      invoker - the action to call on the entity as soon as it is registered
    • invokeOnEntity

      public <E> void invokeOnEntity(org.fastnate.generator.context.EntityClass<E> entityClass, Object uniqueValue, Consumer<E> invoker)
      Invokes an action on a specific entity as soon as this entity was registered. Use only if just one unique property exists - otherwise use invokeOnEntity(Class, String, Object, Consumer).
      Parameters:
      entityClass - describes the class of the required entity
      uniqueValue - the value from the unique property
      invoker - the action to call on the entity as soon as it is registered
      Throws:
      IllegalArgumentException - if more than one unique property exists
    • registerEntity

      public <E> void registerEntity(E entity)
      Registers the entity under all of its unique properties.
      Parameters:
      entity - the entity
    • registerEntity

      public <E> void registerEntity(E entity, String[] propertyNames, Object[] propertyValues)
      Registers the entity under the given unique combination of properties.
      Parameters:
      entity - the entity to register
      propertyNames - the names of the properties that are (in combination) unique
      propertyValues - the values of the properties
    • writeEntities

      public void writeEntities(org.fastnate.generator.EntitySqlGenerator sqlGenerator) throws IOException
      Description copied from interface: DataProvider
      Adds all entities to the SQL file using the given generator.
      Specified by:
      writeEntities in interface DataProvider
      Parameters:
      sqlGenerator - the SQL file generator
      Throws:
      IOException - if the generator throws one