Class EntityImportPlan
- All Implemented Interfaces:
Serializable
EntityImportPlanBuilder
for building instances of EntityImportPlan
. EntityImportPlanBuilder
may be obtained with the EntityImportPlans
factory.
EntityImportPlan
describes how entity fields should be saved during the import performed by EntityImportExport
.
Only fields that are added as properties to the EntityImportPlan
will be saved.
For local entity
property the rule is simple: if property name is added to the plan, then the property will be saved. Use EntityImportPlanBuilder.addLocalProperty(String)
method for adding local property to the plan.
For many-to-one references there are two possible options:
- Create or update the referenced entity. Use
the
EntityImportPlanBuilder.addManyToOneProperty(String, EntityImportPlan)
method. The referenced entity will be saved according to theEntityImportPlan
passed as parameter - Try to find the reference in the
database and put it to the property value.
EntityImportPlanBuilder.addManyToOneProperty(String, ReferenceImportBehaviour)
must be used for this.ReferenceImportBehaviour
parameter specifies the behaviour in case when referenced entity is missed in the database: missing entity can be ignored or import may fail with an error.
For one-to-one references behavior is the same as for the many-to-one references. Just use the corresponding
methods for adding properties to the plan: EntityImportPlanBuilder.addOneToOneProperty(String, EntityImportPlan)
or EntityImportPlanBuilder.addOneToOneProperty(String, ReferenceImportBehaviour)
.
For one-to-many references you must specify the EntityImportPlan
which defines how entities from the
collection must be saved. The second parameter is the CollectionImportPolicy
which specifies what to do with
collection items that weren't passed to the import: they can be removed or remained.
For many-to-many references the following things must be defined:
- Whether the passed collection members must be created/updated or just searched in the database
- Whether the collection items not passed to the import must be removed or remain. Keep in mind that for many-to-many properties missing collection members will be removed from the collection only, not from the database
You can invoke methods for adding plan properties in fluent interface style. There are also useful methods like
EntityImportPlanBuilder.addLocalProperties()
, EntityImportPlanBuilder.addSystemProperties()
or EntityImportPlanBuilder.addProperties(String...)
Example of creating the EntityImportPlan object:
EntityImportPlan importPlan = entityImportPlans.builder(Group.class) .addLocalProperties() .addOneToManyProperty("constraints", entityImportPlans.builder(Constraint.class).addLocalProperties().build(), CollectionImportPolicy.KEEP_ABSENT_ITEMS) .addManyToOneProperty("parent", ReferenceImportBehaviour.ERROR_ON_MISSING) .build();
- See Also:
-
Constructor Summary
ConstructorDescriptionEntityImportPlan
(Class<?> entityClass) EntityImportPlan
(Class<?> entityClass, Map<String, EntityImportPlanProperty> properties) -
Method Summary
Modifier and TypeMethodDescriptionaddProperty
(EntityImportPlanProperty property) Class<?>
getProperty
(String name)
-
Constructor Details
-
EntityImportPlan
-
EntityImportPlan
-
-
Method Details
-
addProperty
-
getProperty
-
getProperties
-
getEntityClass
-