Package org.fastnate.data
Class EntityRegistration
java.lang.Object
org.fastnate.data.EntityRegistration
- All Implemented Interfaces:
DataProvider
Registers entities by their unique properties to offer them to other data providers.
- Author:
- Tobias Liefke
-
Constructor Summary
ConstructorsConstructorDescriptionEntityRegistration(org.fastnate.generator.context.GeneratorContext context) Creates a newEntityRegistrationinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidBuilds the entities that are accessed later usingDataProvider.writeEntities(EntitySqlGenerator).<E> EfindEntity(Class<E> entityClass, Object uniqueValue) Find an entity, that was registered withregisterEntity(Object)before.<E> EfindEntity(Class<E> entityClass, String[] uniqueProperties, Object[] uniqueValues) Find an entity, that was registered withregisterEntity(Object)before.<E> EfindEntity(Class<E> entityClass, String uniqueProperty, Object uniqueValue) Find an entity, that was registered withregisterEntity(Object)before.<E> voidinvokeOnEntity(E templateEntity, Consumer<E> invoker) Invokes an action on a specific entity as soon as this entity wasregistered.<E> voidinvokeOnEntity(Class<E> entityClass, Object uniqueValue, Consumer<E> invoker) Invokes an action on a specific entity as soon as this entity wasregistered.<E> voidinvokeOnEntity(Class<E> entityClass, String[] uniqueProperties, Object[] uniqueValues, Consumer<E> invoker) Invokes an action on a specific entity as soon as this entity wasregistered.<E> voidinvokeOnEntity(Class<E> entityClass, String uniqueProperty, Object uniqueValue, Consumer<E> invoker) Invokes an action on a specific entity as soon as this entity wasregistered.<E> voidinvokeOnEntity(org.fastnate.generator.context.EntityClass<E> entityClass, Object uniqueValue, Consumer<E> invoker) Invokes an action on a specific entity as soon as this entity wasregistered.<E> voidregisterEntity(E entity) Registers the entity under all of its unique properties.<E> voidregisterEntity(E entity, String[] propertyNames, Object[] propertyValues) Registers the entity under the given unique combination of properties.voidwriteEntities(org.fastnate.generator.EntitySqlGenerator sqlGenerator) Adds allentitiesto the SQL file using the given generator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.fastnate.data.DataProvider
getOrder
-
Constructor Details
-
EntityRegistration
public EntityRegistration(org.fastnate.generator.context.GeneratorContext context) Creates a newEntityRegistrationinstance.- Parameters:
context- The generation context contains the description of the entity classes, especially unique properties.
-
-
Method Details
-
buildEntities
Description copied from interface:DataProviderBuilds the entities that are accessed later usingDataProvider.writeEntities(EntitySqlGenerator).- Specified by:
buildEntitiesin interfaceDataProvider- Throws:
IOException- if something happens during any possible import of the generated entities
-
findEntity
Find an entity, that was registered withregisterEntity(Object)before.- Parameters:
entityClass- the class of the required entityuniqueValue- the value from the property- Returns:
- the found entity or
nullif not found - Throws:
IllegalArgumentException- if more than one unique property exists
-
findEntity
Find an entity, that was registered withregisterEntity(Object)before.- Parameters:
entityClass- the class of the required entityuniqueProperty- the name of the unique propertyuniqueValue- the value of the unique property- Returns:
- the found entity or
nullif not found
-
findEntity
Find an entity, that was registered withregisterEntity(Object)before.- Parameters:
entityClass- the class of the required entityuniqueProperties- the names of the set of unique propertiesuniqueValues- the values of the set of unique properties- Returns:
- the found entity or
nullif not found
-
invokeOnEntity
Invokes an action on a specific entity as soon as this entity wasregistered. Use only if just one unique property exists - otherwise useinvokeOnEntity(Class, String, Object, Consumer).- Parameters:
entityClass- the class of the required entityuniqueValue- the value from the unique propertyinvoker- 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 wasregistered.- Parameters:
entityClass- the class of the required entityuniqueProperty- the name of the unique propertyuniqueValue- the value from the unique propertyinvoker- 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 wasregistered.- Parameters:
entityClass- the class of the required entityuniqueProperties- the names of the set of unique propertiesuniqueValues- the values of the set of unique propertiesinvoker- the action to call on the entity as soon as it is registered
-
invokeOnEntity
Invokes an action on a specific entity as soon as this entity wasregistered.- 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 wasregistered. Use only if just one unique property exists - otherwise useinvokeOnEntity(Class, String, Object, Consumer).- Parameters:
entityClass- describes the class of the required entityuniqueValue- the value from the unique propertyinvoker- 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
Registers the entity under the given unique combination of properties.- Parameters:
entity- the entity to registerpropertyNames- the names of the properties that are (in combination) uniquepropertyValues- the values of the properties
-
writeEntities
public void writeEntities(org.fastnate.generator.EntitySqlGenerator sqlGenerator) throws IOException Description copied from interface:DataProviderAdds allentitiesto the SQL file using the given generator.- Specified by:
writeEntitiesin interfaceDataProvider- Parameters:
sqlGenerator- the SQL file generator- Throws:
IOException- if the generator throws one
-