mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 15:55:55 +00:00
No effective change - code format
This commit is contained in:
+161
-161
@@ -28,186 +28,186 @@ import com.avaje.ebeaninternal.server.query.SqlJoinType;
|
||||
*/
|
||||
public class AnnotationAssocOnes extends AnnotationParser {
|
||||
|
||||
private final BeanDescriptorManager factory;
|
||||
private final BeanDescriptorManager factory;
|
||||
|
||||
/**
|
||||
* Create with the deploy Info.
|
||||
*/
|
||||
public AnnotationAssocOnes(DeployBeanInfo<?> info, boolean javaxValidationAnnotations, BeanDescriptorManager factory) {
|
||||
super(info, javaxValidationAnnotations);
|
||||
this.factory = factory;
|
||||
/**
|
||||
* Create with the deploy Info.
|
||||
*/
|
||||
public AnnotationAssocOnes(DeployBeanInfo<?> info, boolean javaxValidationAnnotations, BeanDescriptorManager factory) {
|
||||
super(info, javaxValidationAnnotations);
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the annotation.
|
||||
*/
|
||||
public void parse() {
|
||||
|
||||
for (DeployBeanProperty prop : descriptor.propertiesAll()) {
|
||||
if (prop instanceof DeployBeanPropertyAssocOne<?>) {
|
||||
readAssocOne((DeployBeanPropertyAssocOne<?>) prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void readAssocOne(DeployBeanPropertyAssocOne<?> prop) {
|
||||
|
||||
ManyToOne manyToOne = get(prop, ManyToOne.class);
|
||||
if (manyToOne != null) {
|
||||
readManyToOne(manyToOne, prop);
|
||||
}
|
||||
OneToOne oneToOne = get(prop, OneToOne.class);
|
||||
if (oneToOne != null) {
|
||||
readOneToOne(oneToOne, prop);
|
||||
}
|
||||
Embedded embedded = get(prop, Embedded.class);
|
||||
if (embedded != null) {
|
||||
readEmbedded(embedded, prop);
|
||||
}
|
||||
EmbeddedId emId = get(prop, EmbeddedId.class);
|
||||
if (emId != null) {
|
||||
prop.setEmbedded(true);
|
||||
prop.setId(true);
|
||||
prop.setNullable(false);
|
||||
}
|
||||
Column column = get(prop, Column.class);
|
||||
if (column != null && !isEmpty(column.name())) {
|
||||
// have this in for AssocOnes used on
|
||||
// Sql based beans...
|
||||
prop.setDbColumn(column.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the annotation.
|
||||
*/
|
||||
public void parse() {
|
||||
|
||||
for (DeployBeanProperty prop : descriptor.propertiesAll()) {
|
||||
if (prop instanceof DeployBeanPropertyAssocOne<?>) {
|
||||
readAssocOne((DeployBeanPropertyAssocOne<?>) prop);
|
||||
}
|
||||
}
|
||||
// May as well check for Id. Makes sense to me.
|
||||
Id id = get(prop, Id.class);
|
||||
if (id != null) {
|
||||
prop.setEmbedded(true);
|
||||
prop.setId(true);
|
||||
prop.setNullable(false);
|
||||
}
|
||||
|
||||
private void readAssocOne(DeployBeanPropertyAssocOne<?> prop) {
|
||||
|
||||
ManyToOne manyToOne = get(prop, ManyToOne.class);
|
||||
if (manyToOne != null) {
|
||||
readManyToOne(manyToOne, prop);
|
||||
}
|
||||
OneToOne oneToOne = get(prop, OneToOne.class);
|
||||
if (oneToOne != null) {
|
||||
readOneToOne(oneToOne, prop);
|
||||
}
|
||||
Embedded embedded = get(prop, Embedded.class);
|
||||
if (embedded != null) {
|
||||
readEmbedded(embedded, prop);
|
||||
}
|
||||
EmbeddedId emId = get(prop, EmbeddedId.class);
|
||||
if (emId != null) {
|
||||
prop.setEmbedded(true);
|
||||
prop.setId(true);
|
||||
prop.setNullable(false);
|
||||
}
|
||||
Column column = get(prop, Column.class);
|
||||
if (column != null && !isEmpty(column.name())) {
|
||||
// have this in for AssocOnes used on
|
||||
// Sql based beans...
|
||||
prop.setDbColumn(column.name());
|
||||
}
|
||||
|
||||
// May as well check for Id. Makes sense to me.
|
||||
Id id = get(prop, Id.class);
|
||||
if (id != null) {
|
||||
prop.setEmbedded(true);
|
||||
prop.setId(true);
|
||||
prop.setNullable(false);
|
||||
}
|
||||
|
||||
Where where = get(prop, Where.class);
|
||||
if (where != null) {
|
||||
// not expecting this to be used on assoc one properties
|
||||
prop.setExtraWhere(where.clause());
|
||||
}
|
||||
|
||||
if (validationAnnotations) {
|
||||
NotNull notNull = get(prop, NotNull.class);
|
||||
if (notNull != null) {
|
||||
prop.setNullable(false);
|
||||
// overrides optional attribute of ManyToOne etc
|
||||
prop.getTableJoin().setType(SqlJoinType.INNER);
|
||||
}
|
||||
}
|
||||
|
||||
// check for manually defined joins
|
||||
BeanTable beanTable = prop.getBeanTable();
|
||||
JoinColumn joinColumn = get(prop, JoinColumn.class);
|
||||
if (joinColumn != null) {
|
||||
prop.getTableJoin().addJoinColumn(false, joinColumn, beanTable);
|
||||
if (!joinColumn.updatable()) {
|
||||
prop.setDbUpdateable(false);
|
||||
}
|
||||
if (!joinColumn.nullable()) {
|
||||
prop.setNullable(false);
|
||||
}
|
||||
}
|
||||
|
||||
JoinColumns joinColumns = get(prop, JoinColumns.class);
|
||||
if (joinColumns != null) {
|
||||
prop.getTableJoin().addJoinColumn(false, joinColumns.value(), beanTable);
|
||||
}
|
||||
|
||||
JoinTable joinTable = get(prop, JoinTable.class);
|
||||
if (joinTable != null) {
|
||||
prop.getTableJoin().addJoinColumn(false, joinTable.joinColumns(), beanTable);
|
||||
}
|
||||
|
||||
info.setBeanJoinType(prop, prop.isNullable());
|
||||
|
||||
if (!prop.getTableJoin().hasJoinColumns() && beanTable != null) {
|
||||
|
||||
if (prop.getMappedBy() != null) {
|
||||
// the join is derived by reversing the join information
|
||||
// from the mapped by property.
|
||||
// Refer BeanDescriptorManager.readEntityRelationships()
|
||||
|
||||
} else {
|
||||
// use naming convention to define join.
|
||||
NamingConvention nc = factory.getNamingConvention();
|
||||
|
||||
String fkeyPrefix = null;
|
||||
if (nc.isUseForeignKeyPrefix()){
|
||||
fkeyPrefix = nc.getColumnFromProperty(beanType, prop.getName());
|
||||
}
|
||||
|
||||
beanTable.createJoinColumn(fkeyPrefix, prop.getTableJoin(), true);
|
||||
}
|
||||
}
|
||||
Where where = get(prop, Where.class);
|
||||
if (where != null) {
|
||||
// not expecting this to be used on assoc one properties
|
||||
prop.setExtraWhere(where.clause());
|
||||
}
|
||||
|
||||
private String errorMsgMissingBeanTable(Class<?> type, String from) {
|
||||
return "Error with association to [" + type + "] from [" + from + "]. Is " + type + " registered?";
|
||||
if (validationAnnotations) {
|
||||
NotNull notNull = get(prop, NotNull.class);
|
||||
if (notNull != null) {
|
||||
prop.setNullable(false);
|
||||
// overrides optional attribute of ManyToOne etc
|
||||
prop.getTableJoin().setType(SqlJoinType.INNER);
|
||||
}
|
||||
}
|
||||
|
||||
private void readManyToOne(ManyToOne propAnn, DeployBeanProperty prop) {
|
||||
|
||||
DeployBeanPropertyAssocOne<?> beanProp = (DeployBeanPropertyAssocOne<?>) prop;
|
||||
|
||||
setCascadeTypes(propAnn.cascade(), beanProp.getCascadeInfo());
|
||||
|
||||
BeanTable assoc = factory.getBeanTable(beanProp.getPropertyType());
|
||||
if (assoc == null) {
|
||||
String msg = errorMsgMissingBeanTable(beanProp.getPropertyType(), prop.getFullBeanName());
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
beanProp.setBeanTable(assoc);
|
||||
beanProp.setDbInsertable(true);
|
||||
beanProp.setDbUpdateable(true);
|
||||
beanProp.setNullable(propAnn.optional());
|
||||
beanProp.setFetchType(propAnn.fetch());
|
||||
// check for manually defined joins
|
||||
BeanTable beanTable = prop.getBeanTable();
|
||||
JoinColumn joinColumn = get(prop, JoinColumn.class);
|
||||
if (joinColumn != null) {
|
||||
prop.getTableJoin().addJoinColumn(false, joinColumn, beanTable);
|
||||
if (!joinColumn.updatable()) {
|
||||
prop.setDbUpdateable(false);
|
||||
}
|
||||
if (!joinColumn.nullable()) {
|
||||
prop.setNullable(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void readOneToOne(OneToOne propAnn, DeployBeanPropertyAssocOne<?> prop) {
|
||||
|
||||
prop.setOneToOne(true);
|
||||
prop.setDbInsertable(true);
|
||||
prop.setDbUpdateable(true);
|
||||
prop.setNullable(propAnn.optional());
|
||||
prop.setFetchType(propAnn.fetch());
|
||||
prop.setMappedBy(propAnn.mappedBy());
|
||||
if (!"".equals(propAnn.mappedBy())) {
|
||||
prop.setOneToOneExported(true);
|
||||
}
|
||||
|
||||
setCascadeTypes(propAnn.cascade(), prop.getCascadeInfo());
|
||||
|
||||
BeanTable assoc = factory.getBeanTable(prop.getPropertyType());
|
||||
if (assoc == null) {
|
||||
String msg = errorMsgMissingBeanTable(prop.getPropertyType(), prop.getFullBeanName());
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
prop.setBeanTable(assoc);
|
||||
JoinColumns joinColumns = get(prop, JoinColumns.class);
|
||||
if (joinColumns != null) {
|
||||
prop.getTableJoin().addJoinColumn(false, joinColumns.value(), beanTable);
|
||||
}
|
||||
|
||||
private void readEmbedded(Embedded propAnn, DeployBeanPropertyAssocOne<?> prop) {
|
||||
JoinTable joinTable = get(prop, JoinTable.class);
|
||||
if (joinTable != null) {
|
||||
prop.getTableJoin().addJoinColumn(false, joinTable.joinColumns(), beanTable);
|
||||
}
|
||||
|
||||
prop.setEmbedded(true);
|
||||
prop.setDbInsertable(true);
|
||||
prop.setDbUpdateable(true);
|
||||
info.setBeanJoinType(prop, prop.isNullable());
|
||||
|
||||
EmbeddedColumns columns = get(prop, EmbeddedColumns.class);
|
||||
if (columns != null) {
|
||||
if (!prop.getTableJoin().hasJoinColumns() && beanTable != null) {
|
||||
|
||||
// convert into a Map
|
||||
String propColumns = columns.columns();
|
||||
Map<String, String> propMap = StringHelper.delimitedToMap(propColumns, ",", "=");
|
||||
if (prop.getMappedBy() != null) {
|
||||
// the join is derived by reversing the join information
|
||||
// from the mapped by property.
|
||||
// Refer BeanDescriptorManager.readEntityRelationships()
|
||||
|
||||
prop.getDeployEmbedded().putAll(propMap);
|
||||
} else {
|
||||
// use naming convention to define join.
|
||||
NamingConvention nc = factory.getNamingConvention();
|
||||
|
||||
String fkeyPrefix = null;
|
||||
if (nc.isUseForeignKeyPrefix()) {
|
||||
fkeyPrefix = nc.getColumnFromProperty(beanType, prop.getName());
|
||||
}
|
||||
|
||||
readEmbeddedAttributeOverrides(prop);
|
||||
beanTable.createJoinColumn(fkeyPrefix, prop.getTableJoin(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String errorMsgMissingBeanTable(Class<?> type, String from) {
|
||||
return "Error with association to [" + type + "] from [" + from + "]. Is " + type + " registered?";
|
||||
}
|
||||
|
||||
private void readManyToOne(ManyToOne propAnn, DeployBeanProperty prop) {
|
||||
|
||||
DeployBeanPropertyAssocOne<?> beanProp = (DeployBeanPropertyAssocOne<?>) prop;
|
||||
|
||||
setCascadeTypes(propAnn.cascade(), beanProp.getCascadeInfo());
|
||||
|
||||
BeanTable assoc = factory.getBeanTable(beanProp.getPropertyType());
|
||||
if (assoc == null) {
|
||||
String msg = errorMsgMissingBeanTable(beanProp.getPropertyType(), prop.getFullBeanName());
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
beanProp.setBeanTable(assoc);
|
||||
beanProp.setDbInsertable(true);
|
||||
beanProp.setDbUpdateable(true);
|
||||
beanProp.setNullable(propAnn.optional());
|
||||
beanProp.setFetchType(propAnn.fetch());
|
||||
}
|
||||
|
||||
private void readOneToOne(OneToOne propAnn, DeployBeanPropertyAssocOne<?> prop) {
|
||||
|
||||
prop.setOneToOne(true);
|
||||
prop.setDbInsertable(true);
|
||||
prop.setDbUpdateable(true);
|
||||
prop.setNullable(propAnn.optional());
|
||||
prop.setFetchType(propAnn.fetch());
|
||||
prop.setMappedBy(propAnn.mappedBy());
|
||||
if (!"".equals(propAnn.mappedBy())) {
|
||||
prop.setOneToOneExported(true);
|
||||
}
|
||||
|
||||
setCascadeTypes(propAnn.cascade(), prop.getCascadeInfo());
|
||||
|
||||
BeanTable assoc = factory.getBeanTable(prop.getPropertyType());
|
||||
if (assoc == null) {
|
||||
String msg = errorMsgMissingBeanTable(prop.getPropertyType(), prop.getFullBeanName());
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
prop.setBeanTable(assoc);
|
||||
}
|
||||
|
||||
private void readEmbedded(Embedded propAnn, DeployBeanPropertyAssocOne<?> prop) {
|
||||
|
||||
prop.setEmbedded(true);
|
||||
prop.setDbInsertable(true);
|
||||
prop.setDbUpdateable(true);
|
||||
|
||||
EmbeddedColumns columns = get(prop, EmbeddedColumns.class);
|
||||
if (columns != null) {
|
||||
|
||||
// convert into a Map
|
||||
String propColumns = columns.columns();
|
||||
Map<String, String> propMap = StringHelper.delimitedToMap(propColumns, ",", "=");
|
||||
|
||||
prop.getDeployEmbedded().putAll(propMap);
|
||||
}
|
||||
|
||||
readEmbeddedAttributeOverrides(prop);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user