Class DynamicTypeBuilder
- java.lang.Object
-
- org.eclipse.persistence.dynamic.DynamicTypeBuilder
-
- Direct Known Subclasses:
JPADynamicTypeBuilder
public class DynamicTypeBuilder extends Object
The EntityTypeBuilder is a factory class for creating and extending dynamic entity types. After being constructed in either usage the application can then use the provided API to customize mapping information of the type.- Author:
- dclarke, mnorman
- Since:
- EclipseLink 1.2
-
-
Field Summary
Fields Modifier and Type Field Description protected org.eclipse.persistence.internal.dynamic.DynamicTypeImpl
entityType
The type being configured for dynamic use or being created/extended
-
Constructor Summary
Constructors Constructor Description DynamicTypeBuilder(Class<?> dynamicClass, DynamicType parentType, String... tableNames)
Create an EntityType for a new dynamic type.DynamicTypeBuilder(DynamicClassLoader dcl, ClassDescriptor descriptor, DynamicType parentType)
Create an EntityTypeBuilder for an existing descriptor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AggregateObjectMapping
addAggregateObjectMapping(String name, DynamicType refType, boolean allowsNull)
DirectCollectionMapping
addDirectCollectionMapping(String name, String targetTable, String valueColumn, Class<?> valueType, String... fkFieldNames)
Add aDirectCollectionMapping
to theentityType
being built or extended.DirectToFieldMapping
addDirectMapping(String name, Class<?> javaType, String fieldName)
AllowsDirectToFieldMapping
(@Basic) mapping to be added to a dynamic type through API.protected AbstractDirectMapping
addDirectMappingForEnum(String fieldName, String className, String columnName)
protected void
addDynamicClasses(DynamicClassLoader dcl, String className, DynamicType parentType)
Register aDynamicClassWriter
with the providedDynamicClassLoader
so that a dynamic class can be generated when needed.DynamicEnumBuilder
addEnum(String fieldName, String className, String columnName, DynamicClassLoader dcl)
void
addManyToManyMapping(String name, DynamicType refType, String relationshipTableName)
Add aManyToManyMapping
to theentityType
being built or extended.DatabaseMapping
addMapping(DatabaseMapping mapping)
Add the mapping to theentityType
's descriptor being built or extended.OneToManyMapping
addOneToManyMapping(String name, DynamicType refType, String... fkFieldNames)
Add aOneToManyMapping
to theentityType
being built or extended.OneToOneMapping
addOneToOneMapping(String name, DynamicType refType, String... fkFieldNames)
AllowsOneToOneMapping
(@OneToOne and @ManyToOne) mappings to be added to a dynamic type through API.protected void
configure(ClassDescriptor descriptor, String... tableNames)
Initialize a new or existing descriptor configuring the necessary policies as well asvoid
configureSequencing(String numberName, String numberFieldName)
Configure default sequencing.void
configureSequencing(Sequence sequence, String numberName, String numberFieldName)
Configure sequencing specifying the sequence type to use.DynamicType
getType()
static Project
loadDynamicProject(InputStream resourceStream, DatabaseLogin login, DynamicClassLoader dynamicClassLoader)
Load a dynamic project from deployment XML creating dynamic types for all descriptors where the provided class name does not exist.static Project
loadDynamicProject(String resourcePath, DatabaseLogin login, DynamicClassLoader dynamicClassLoader)
Load a dynamic project from deployment XML creating dynamic types for all descriptors where the provided class name does not exist.static Project
loadDynamicProject(Project project, DatabaseLogin login, DynamicClassLoader dynamicClassLoader)
void
setPrimaryKeyFields(String... pkFieldNames)
Set the PK field names on the underlying descriptor ensuring no duplicate names are added.
-
-
-
Constructor Detail
-
DynamicTypeBuilder
public DynamicTypeBuilder(Class<?> dynamicClass, DynamicType parentType, String... tableNames)
Create an EntityType for a new dynamic type. The contained EntityType and its wrapped descriptor are not automatically added to any session. This must be done by the application after the type's is fully configured.Creating new type Example:
DynamicHelper helper = new DynamicHelper(session); DynamicClassLoader dcl = helper.getDynamicClassLoader();
Class<?> javaType = dcl.creatDynamicClass("model.Simple");
DynamicTypeBuilder typeBuilder = new JPADynamicTypeBuilder(javaType, null, "SIMPLE_TYPE");
typeBuilder.setPrimaryKeyFields("SID");
typeBuilder.addDirectMapping("id", int.class, "SID");
typeBuilder.addDirectMapping("value1", String.class, "VAL_1");
typeBuilder.addDirectMapping("value2", boolean.class, "VAL_2");
typeBuilder.addDirectMapping("value3", Calendar.class, "VAL_3");
typeBuilder.addDirectMapping("value4", Character.class, "VAL_4");
helper.addTypes(true, true, typeBuilder.getType());
- Parameters:
dynamicClass
-parentType
-tableNames
-
-
DynamicTypeBuilder
public DynamicTypeBuilder(DynamicClassLoader dcl, ClassDescriptor descriptor, DynamicType parentType)
Create an EntityTypeBuilder for an existing descriptor. This is used- Parameters:
dcl
-descriptor
-parentType
- provided since the InheritancePolicy on the descriptor may not have its parent descriptor initialized.
-
-
Method Detail
-
addDynamicClasses
protected void addDynamicClasses(DynamicClassLoader dcl, String className, DynamicType parentType)
Register aDynamicClassWriter
with the providedDynamicClassLoader
so that a dynamic class can be generated when needed.
-
configure
protected void configure(ClassDescriptor descriptor, String... tableNames)
Initialize a new or existing descriptor configuring the necessary policies as well as
-
getType
public DynamicType getType()
-
setPrimaryKeyFields
public void setPrimaryKeyFields(String... pkFieldNames)
Set the PK field names on the underlying descriptor ensuring no duplicate names are added.- Parameters:
pkFieldNames
- qualified or unqualified field names
-
addDirectMapping
public DirectToFieldMapping addDirectMapping(String name, Class<?> javaType, String fieldName)
AllowsDirectToFieldMapping
(@Basic) mapping to be added to a dynamic type through API. This method can be used on a newDynamicTypeImpl
that has yet to be added to a session and have its descriptor initialized, or it can be called on an active (initialized) descriptor.There is no support currently for having the EclipseLink
SchemaManager
generate ALTER TABLE calls so any new columns expected must be added without the help of EclipseLink or use theSchemaManager.replaceObject(org.eclipse.persistence.tools.schemaframework.DatabaseObjectDefinition)
to DROP and CREATE the table. WARNING: This will cause data loss.- Parameters:
javaType
- is the type of the attribute. If the type is a primitive it will be converted to the comparable non-primitive type.
-
addOneToOneMapping
public OneToOneMapping addOneToOneMapping(String name, DynamicType refType, String... fkFieldNames)
AllowsOneToOneMapping
(@OneToOne and @ManyToOne) mappings to be added to a dynamic type through API. This method can be used on a newDynamicTypeImpl
that has yet to be added to a session and have its descriptor initialized, or it can be called on an active (initialized) descriptor.There is no support currently for having the EclipseLink
SchemaManager
generate ALTER TABLE calls so any new columns expected must be added without the help of EclipseLink or use theSchemaManager.replaceObject(org.eclipse.persistence.tools.schemaframework.DatabaseObjectDefinition)
to DROP and CREATE the table. WARNING: This will cause data loss.
-
addOneToManyMapping
public OneToManyMapping addOneToManyMapping(String name, DynamicType refType, String... fkFieldNames)
Add aOneToManyMapping
to theentityType
being built or extended. This mapping is created using standard foreign keys from the source table(s) to the target table(s) and transparent indirection (IndirectList
).- Parameters:
name
- attribute name to use in the dynamic entity. Also the property name used to access the state of the entityrefType
-fkFieldNames
- the FK field names specified in the same order to match the PK field names of the target class- Returns:
- the newly created, configured mappin. It will be initialized if the descriptor is already initialized.
-
addDirectCollectionMapping
public DirectCollectionMapping addDirectCollectionMapping(String name, String targetTable, String valueColumn, Class<?> valueType, String... fkFieldNames) throws IllegalArgumentException
Add aDirectCollectionMapping
to theentityType
being built or extended. This mapping is created using standard foreign keys from the target table(s) to the source table(s) and transparent indirection (IndirectList
).- Parameters:
name
- attribute name to use in the dynamic entity. Also the property name used to access the state of the entitytargetTable
- name of table holding the direct valuesvalueColumn
- name of column in target table holding the direct value for the collectionvalueType
- the type of the attribute assumed to be a known basic typefkFieldNames
- the FK field names on the source table specified in order to match the PK field names on the source.- Returns:
- the new mapping configured and initialized (if the descriptor is already initialized.
- Throws:
IllegalArgumentException
-
addAggregateObjectMapping
public AggregateObjectMapping addAggregateObjectMapping(String name, DynamicType refType, boolean allowsNull)
- Parameters:
name
- attribute name to use in the dynamic entity. Also the property name used to access the state of the entityrefType
- dynamic type re[presenting the Embeddable/AggregateObjectallowsNull
- true indicates that the attribute can be null if all values are null.- Returns:
- the new mapping configured and initialized (if the descriptor has been initialized).
-
addManyToManyMapping
public void addManyToManyMapping(String name, DynamicType refType, String relationshipTableName)
Add aManyToManyMapping
to theentityType
being built or extended. This method assumes that the columns names on the relationship table match the PK columns names they relate to. In the case of the target keys from the relationship table a '_' will be appended to the column names if they collide with the names from the source table.- Parameters:
name
- attribute name to use in the dynamic entity. Also the property name used to access the state of the entityrefType
- target dynamic entityrelationshipTableName
-
-
addMapping
public DatabaseMapping addMapping(DatabaseMapping mapping)
Add the mapping to theentityType
's descriptor being built or extended. This is where theValuesAccessor
is created and the position of the mapping in the descriptor is captured to use as its index.
-
configureSequencing
public void configureSequencing(String numberName, String numberFieldName)
Configure default sequencing.
-
configureSequencing
public void configureSequencing(Sequence sequence, String numberName, String numberFieldName)
Configure sequencing specifying the sequence type to use.
-
addEnum
public DynamicEnumBuilder addEnum(String fieldName, String className, String columnName, DynamicClassLoader dcl)
-
addDirectMappingForEnum
protected AbstractDirectMapping addDirectMappingForEnum(String fieldName, String className, String columnName)
-
loadDynamicProject
public static Project loadDynamicProject(String resourcePath, DatabaseLogin login, DynamicClassLoader dynamicClassLoader) throws IOException
Load a dynamic project from deployment XML creating dynamic types for all descriptors where the provided class name does not exist.- Parameters:
resourcePath
-login
-dynamicClassLoader
-- Returns:
- a Project with
DynamicClassLoader
and associatedDynamicClassWriter
configured. Ensure if a new Login/Platform is being configured that theConversionManager.getLoader()
is maintained.null
is returned if the resourcePath cannot locate a deployment XML - Throws:
IOException
-
loadDynamicProject
public static Project loadDynamicProject(InputStream resourceStream, DatabaseLogin login, DynamicClassLoader dynamicClassLoader) throws IOException
Load a dynamic project from deployment XML creating dynamic types for all descriptors where the provided class name does not exist.- Parameters:
resourceStream
-login
-dynamicClassLoader
-- Returns:
- a Project with
DynamicClassLoader
and associatedDynamicClassWriter
configured. Ensure if a new Login/Platform is being configured that theConversionManager.getLoader()
is maintained.null
is returned if the resourcePath cannot locate a deployment XML - Throws:
IOException
-
loadDynamicProject
public static Project loadDynamicProject(Project project, DatabaseLogin login, DynamicClassLoader dynamicClassLoader)
-
-