mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-29 16:11:13 +00:00
#115 - Mapping - Add support for @ElementCollection enhancement
Initial support - simple List.
This commit is contained in:
@@ -184,8 +184,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
|
||||
private final BeanLifecycleAdapterFactory beanLifecycleAdapterFactory;
|
||||
|
||||
private final boolean eagerFetchLobs;
|
||||
|
||||
private final String asOfViewSuffix;
|
||||
|
||||
/**
|
||||
@@ -215,12 +213,11 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
this.databasePlatform = serverConfig.getDatabasePlatform();
|
||||
this.multiValueBind = config.getMultiValueBind();
|
||||
this.idBinderFactory = new IdBinderFactory(databasePlatform.isIdInExpandedForm(), multiValueBind);
|
||||
this.eagerFetchLobs = serverConfig.isEagerFetchLobs();
|
||||
this.queryPlanTTLSeconds = serverConfig.getQueryPlanTTLSeconds();
|
||||
|
||||
this.asOfViewSuffix = getAsOfViewSuffix(databasePlatform, serverConfig);
|
||||
String versionsBetweenSuffix = getVersionsBetweenSuffix(databasePlatform, serverConfig);
|
||||
this.readAnnotations = new ReadAnnotations(config.getGeneratedPropertyFactory(), asOfViewSuffix, versionsBetweenSuffix, serverConfig.isDisableL2Cache());
|
||||
this.readAnnotations = new ReadAnnotations(config.getGeneratedPropertyFactory(), asOfViewSuffix, versionsBetweenSuffix, serverConfig);
|
||||
this.bootupClasses = config.getBootupClasses();
|
||||
this.createProperties = config.getDeployCreateProperties();
|
||||
this.namingConvention = serverConfig.getNamingConvention();
|
||||
@@ -575,12 +572,14 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
// we can initialise them which sorts out circular
|
||||
// dependencies for OneToMany and ManyToOne etc
|
||||
|
||||
BeanDescriptorInitContext initContext = new BeanDescriptorInitContext(asOfTableMap, draftTableMap, asOfViewSuffix);
|
||||
|
||||
// PASS 1:
|
||||
// initialise the ID properties of all the beans
|
||||
// first (as they are needed to initialise the
|
||||
// associated properties in the second pass).
|
||||
for (BeanDescriptor<?> d : descMap.values()) {
|
||||
d.initialiseId(asOfTableMap, draftTableMap);
|
||||
d.initialiseId(initContext);
|
||||
}
|
||||
|
||||
// PASS 2:
|
||||
@@ -595,7 +594,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
// also look for intersection tables with
|
||||
// associated history support and register them
|
||||
// into the asOfTableMap
|
||||
d.initialiseOther(asOfTableMap, asOfViewSuffix, draftTableMap);
|
||||
d.initialiseOther(initContext);
|
||||
}
|
||||
|
||||
// PASS 4:
|
||||
@@ -656,6 +655,13 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
return beanTableMap.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a BeanTable for an ElementCollection.
|
||||
*/
|
||||
public BeanTable getCollectionBeanTable(String fullTableName, Class<?> targetType) {
|
||||
return new BeanTable(this, fullTableName, targetType);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> BeanManager<T> getBeanManager(Class<T> entityType) {
|
||||
|
||||
@@ -1025,7 +1031,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
* </p>
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private void makeUnidirectional(DeployBeanInfo<?> info, DeployBeanPropertyAssocMany<?> oneToMany) {
|
||||
private void makeUnidirectional(DeployBeanPropertyAssocMany<?> oneToMany) {
|
||||
|
||||
DeployBeanDescriptor<?> targetDesc = getTargetDescriptor(oneToMany);
|
||||
|
||||
@@ -1045,34 +1051,36 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
// mark this property as unidirectional
|
||||
oneToMany.setUnidirectional();
|
||||
|
||||
// create the 'shadow' unidirectional property
|
||||
// which is put on the target descriptor
|
||||
DeployBeanPropertyAssocOne<?> unidirectional = new DeployBeanPropertyAssocOne(targetDesc, owningType);
|
||||
unidirectional.setUndirectionalShadow();
|
||||
unidirectional.setNullable(false);
|
||||
unidirectional.setDbRead(true);
|
||||
unidirectional.setDbInsertable(true);
|
||||
unidirectional.setDbUpdateable(false);
|
||||
|
||||
targetDesc.setUnidirectional(unidirectional);
|
||||
|
||||
// specify table and table alias...
|
||||
BeanTable beanTable = getBeanTable(owningType);
|
||||
unidirectional.setBeanTable(beanTable);
|
||||
unidirectional.setName(beanTable.getBaseTable());
|
||||
|
||||
info.setBeanJoinType(unidirectional, true);
|
||||
|
||||
// define the TableJoin
|
||||
DeployTableJoin oneToManyJoin = oneToMany.getTableJoin();
|
||||
if (!oneToManyJoin.hasJoinColumns()) {
|
||||
throw new RuntimeException("No join columns");
|
||||
}
|
||||
createUnidirectional(targetDesc, owningType, beanTable, oneToManyJoin);
|
||||
}
|
||||
|
||||
// inverse of the oneToManyJoin
|
||||
DeployTableJoin unidirectionalJoin = unidirectional.getTableJoin();
|
||||
unidirectionalJoin.setColumns(oneToManyJoin.columns(), true);
|
||||
/**
|
||||
* Create and add a Unidirectional property (for ElementCollection) which maps to the foreign key.
|
||||
*/
|
||||
public <A> void createUnidirectional(DeployBeanDescriptor<?> targetDesc, Class<A> targetType, BeanTable beanTable, DeployTableJoin oneToManyJoin) {
|
||||
|
||||
// create the 'shadow' unidirectional property
|
||||
// which is put on the target descriptor
|
||||
DeployBeanPropertyAssocOne<A> unidirectional = new DeployBeanPropertyAssocOne<>(targetDesc, targetType);
|
||||
unidirectional.setUndirectionalShadow();
|
||||
unidirectional.setNullable(false);
|
||||
unidirectional.setDbRead(true);
|
||||
unidirectional.setDbInsertable(true);
|
||||
unidirectional.setDbUpdateable(false);
|
||||
unidirectional.setBeanTable(beanTable);
|
||||
unidirectional.setName(beanTable.getBaseTable());
|
||||
unidirectional.setJoinType(true);
|
||||
unidirectional.setJoinColumns(oneToManyJoin.columns(), true);
|
||||
|
||||
targetDesc.setUnidirectional(unidirectional);
|
||||
}
|
||||
|
||||
private void checkMappedByOneToOne(DeployBeanPropertyAssocOne<?> prop) {
|
||||
@@ -1137,6 +1145,10 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
*/
|
||||
private void checkMappedByOneToMany(DeployBeanInfo<?> info, DeployBeanPropertyAssocMany<?> prop) {
|
||||
|
||||
if (prop.isElementCollection()) {
|
||||
// skip mapping check
|
||||
return;
|
||||
}
|
||||
DeployBeanDescriptor<?> targetDesc = getTargetDescriptor(prop);
|
||||
|
||||
if (targetDesc.isDraftableElement()) {
|
||||
@@ -1159,7 +1171,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
|
||||
if (!findMappedBy(prop)) {
|
||||
if (!prop.isO2mJoinTable()) {
|
||||
makeUnidirectional(info, prop);
|
||||
makeUnidirectional(prop);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1311,7 +1323,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
|
||||
DeployBeanInfo<T> info = new DeployBeanInfo<>(deployUtil, desc);
|
||||
|
||||
readAnnotations.readInitial(info, eagerFetchLobs);
|
||||
readAnnotations.readInitial(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -1636,6 +1648,20 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
target.setPrimaryKeyJoin(inverseJoin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a DeployBeanDescriptor for an ElementCollection target.
|
||||
*/
|
||||
public <A> DeployBeanDescriptor<A> createDeployDescriptor(Class<A> targetType) {
|
||||
return new DeployBeanDescriptor<>(this, targetType, serverConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a BeanDescriptor for an ElementCollection target.
|
||||
*/
|
||||
public <A> BeanDescriptor<A> createElementDescriptor(DeployBeanDescriptor<A> elementDescriptor) {
|
||||
return new BeanDescriptorElement<>(this, elementDescriptor);
|
||||
}
|
||||
|
||||
public void visitMetrics(MetricVisitor visitor) {
|
||||
for (BeanDescriptor<?> desc : immutableDescriptorList) {
|
||||
desc.visitMetrics(visitor);
|
||||
|
||||
Reference in New Issue
Block a user