#2318 - Refactor internals - trim whitespace in deploy package

This commit is contained in:
rbygrave
2021-08-20 16:58:37 +12:00
parent 9649d71082
commit 90e321ddbd
16 changed files with 23 additions and 292 deletions
@@ -69,150 +69,76 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
* Flag to mark this is the id property.
*/
private final boolean id;
private final boolean importedPrimaryKey;
/**
* Flag to make this as a dummy property for unidirecitonal relationships.
*/
private final boolean unidirectionalShadow;
/**
* Flag set if this maps to the inheritance discriminator column
*/
private final boolean discriminator;
/**
* Flag to mark the property as embedded. This could be on
* BeanPropertyAssocOne rather than here. Put it here for checking Id type
* (embedded or not).
*/
final boolean embedded;
/**
* Flag indicating if this the version property.
*/
private final boolean version;
private final boolean naturalKey;
/**
* Set if this property is nullable.
*/
private final boolean nullable;
private final boolean unique;
/**
* Is this property include in database resultSet.
*/
private final boolean dbRead;
/**
* Include in DB insert.
*/
private final boolean dbInsertable;
/**
* Include in DB update.
*/
private final boolean dbUpdatable;
/**
* True if the property is based on a SECONDARY table.
*/
private final boolean secondaryTable;
private final TableJoin secondaryTableJoin;
private final String secondaryTableJoinPrefix;
/**
* The property is inherited from a super class.
*/
private final boolean inherited;
private final Class<?> owningType;
private final boolean local;
/**
* True if the property is a Clob, Blob LongVarchar or LongVarbinary.
*/
private final boolean lob;
private final boolean fetchEager;
final boolean isTransient;
/**
* The logical bean property name.
*/
final String name;
final int propertyIndex;
/**
* The reflected field.
*/
private final Field field;
/**
* The bean type.
*/
private final Class<?> propertyType;
private final String dbBind;
/**
* The database column. This can include quoted identifiers.
*/
final String dbColumn;
private final String elPrefix;
final String elPlaceHolder;
final String elPlaceHolderEncrypted;
/**
* Select part of a SQL Formula used to populate this property.
*/
private final String sqlFormulaSelect;
/**
* Join part of a SQL Formula.
*/
final String sqlFormulaJoin;
private final String aggregation;
private final boolean formula;
/**
* Set to true if stored encrypted.
*/
private final boolean dbEncrypted;
private final boolean localEncrypted;
private final int dbEncryptedType;
/**
* The jdbc data type this maps to.
*/
private final int dbType;
final boolean excludedFromHistory;
/**
* Generator for insert or update timestamp etc.
*/
private final GeneratedProperty generatedProperty;
private final BeanPropertyGetter getter;
private final BeanPropertySetter setter;
final BeanDescriptor<?> descriptor;
/**
* Used for non-jdbc native types (java.util.Date Enums etc). Converts from
* logical to jdbc types.
@@ -221,54 +147,39 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
final ScalarType scalarType;
private final DocPropertyOptions docOptions;
/**
* The length or precision for DB column.
*/
private final int dbLength;
/**
* The scale for DB column (decimal).
*/
private final int dbScale;
/**
* Deployment defined DB column definition.
*/
private final String dbColumnDefn;
/**
* DB Column default value for DDL definition (FALSE, NOW etc).
*/
private final String dbColumnDefault;
private final List<DbMigrationInfo> dbMigrationInfos;
/**
* Database DDL column comment.
*/
private final String dbComment;
private final DbEncryptFunction dbEncryptFunction;
private int deployOrder;
final boolean jsonSerialize;
final boolean jsonDeserialize;
private final boolean unmappedJson;
private final boolean tenantId;
private final boolean draft;
private final boolean draftOnly;
private final boolean draftDirty;
private final boolean draftReset;
private final boolean softDelete;
private final String softDeleteDbSet;
private final String softDeleteDbPredicate;
public BeanProperty(DeployBeanProperty deploy) {
@@ -574,9 +485,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
ctx.appendFormulaSelect(aggregation);
} else if (formula) {
ctx.appendFormulaSelect(sqlFormulaSelect);
} else if (!isTransient && !ignoreDraftOnlyProperty(ctx.isDraftQuery())) {
if (secondaryTableJoin != null) {
ctx.pushTableAlias(ctx.getRelativePrefix(secondaryTableJoinPrefix));
}
@@ -43,48 +43,34 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
* so as to avoid a dependency loop between BeanDescriptors.
*/
BeanDescriptor<T> targetDescriptor;
IdBinder targetIdBinder;
InheritInfo targetInheritInfo;
String targetIdProperty;
/**
* Derived list of exported property and matching foreignKey
*/
ExportedProperty[] exportedProperties;
/**
* Persist settings.
*/
final BeanCascadeInfo cascadeInfo;
/**
* Join between the beans.
*/
final TableJoin tableJoin;
final PropertyForeignKey foreignKey;
/**
* The type of the joined bean.
*/
private final Class<T> targetType;
/**
* The join table information.
*/
final BeanTable beanTable;
final String mappedBy;
private final String docStoreDoc;
private final String extraWhere;
private final int fetchPreference;
private boolean saveRecurseSkippable;
/**
@@ -98,7 +84,6 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
this.mappedBy = InternString.intern(deploy.getMappedBy());
this.docStoreDoc = deploy.getDocStoreDoc();
this.tableJoin = new TableJoin(deploy.getTableJoin());
this.targetType = deploy.getTargetType();
this.cascadeInfo = deploy.getCascadeInfo();
this.fetchPreference = deploy.getFetchPreference();
@@ -173,10 +158,8 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
* Create a ElPropertyValue for a *ToOne or *ToMany.
*/
ElPropertyValue createElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) {
// associated or embedded bean
BeanDescriptor<?> embDesc = getTargetDescriptor();
if (chain == null) {
chain = new ElPropertyChainBuilder(isEmbedded(), propName);
}
@@ -300,7 +283,6 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
* Return true if the unique id properties are all not null for this bean.
*/
public boolean hasId(EntityBean bean) {
BeanDescriptor<?> targetDesc = getTargetDescriptor();
BeanProperty idProp = targetDesc.getIdProperty();
// all the unique properties are non-null
@@ -339,7 +321,6 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
*/
@Override
public void docStoreInclude(boolean includeByDefault, DocStructure docStructure) {
String embeddedDoc = getDocStoreDoc();
if (embeddedDoc == null) {
// not annotated so use include by default
@@ -367,17 +348,14 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
@Override
public void docStoreMapping(DocMappingBuilder mapping, String prefix) {
if (mapping.includesPath(prefix, name)) {
String fullName = SplitName.add(prefix, name);
DocPropertyType type = isMany() ? DocPropertyType.LIST : DocPropertyType.OBJECT;
DocPropertyMapping nested = new DocPropertyMapping(name, type);
mapping.push(nested);
targetDescriptor.docStoreMapping(mapping, fullName);
mapping.pop();
if (!nested.getChildren().isEmpty()) {
mapping.add(nested);
}
@@ -444,20 +422,16 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
* descriptor back to local database columns in the TableJoin.
*/
ImportedId createImportedId(BeanPropertyAssoc<?> owner, BeanDescriptor<?> target, TableJoin join) {
BeanProperty idProp = target.getIdProperty();
BeanProperty[] others = target.propertiesBaseScalar();
if (descriptor.isRawSqlBased()) {
String dbColumn = owner.getDbColumn();
return new ImportedIdSimple(owner, dbColumn, null, idProp, 0);
}
TableJoinColumn[] cols = join.columns();
if (idProp == null) {
return null;
}
TableJoinColumn[] cols = join.columns();
if (!idProp.isEmbedded()) {
// simple single scalar id
if (cols.length != 1) {
@@ -473,42 +447,34 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
BeanPropertyAssocOne<?> embProp = (BeanPropertyAssocOne<?>) idProp;
BeanProperty[] embBaseProps = embProp.getTargetDescriptor().propertiesBaseScalar();
ImportedIdSimple[] scalars = createImportedList(owner, cols, embBaseProps, others);
return new ImportedIdEmbedded(owner, embProp, scalars);
}
}
private ImportedIdSimple[] createImportedList(BeanPropertyAssoc<?> owner, TableJoinColumn[] cols, BeanProperty[] props, BeanProperty[] others) {
ArrayList<ImportedIdSimple> list = new ArrayList<>(cols.length);
for (TableJoinColumn col : cols) {
list.add(createImportedScalar(owner, col, props, others));
}
return ImportedIdSimple.sort(list);
}
private ImportedIdSimple createImportedScalar(BeanPropertyAssoc<?> owner, TableJoinColumn col, BeanProperty[] props, BeanProperty[] others) {
String matchColumn = col.getForeignDbColumn();
String localColumn = col.getLocalDbColumn();
String localSqlFormula = col.getLocalSqlFormula();
boolean insertable = col.isInsertable();
boolean updateable = col.isUpdateable();
for (int j = 0; j < props.length; j++) {
if (props[j].getDbColumn().equalsIgnoreCase(matchColumn)) {
return new ImportedIdSimple(owner, localColumn, localSqlFormula, props[j], j, insertable, updateable);
}
}
for (int j = 0; j < others.length; j++) {
if (others[j].getDbColumn().equalsIgnoreCase(matchColumn)) {
return new ImportedIdSimple(owner, localColumn, localSqlFormula, others[j], j + props.length, insertable, updateable);
}
}
String msg = "Error with the Join on [" + getFullBeanName()
+ "]. Could not find the local match for [" + matchColumn + "] "//in table["+searchTable+"]?"
+ " Perhaps an error in a @JoinColumn";
@@ -530,10 +496,8 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
}
private void flatten(List<Object> bindValues, Object parentId) {
if (isExportedSimple()) {
bindValues.add(parentId);
} else {
EntityBean parent = (EntityBean) parentId;
for (ExportedProperty exportedProperty : exportedProperties) {
@@ -543,7 +507,6 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
}
void bindParentIds(DefaultSqlUpdate delete, List<Object> parentIds) {
if (isExportedSimple()) {
delete.setParameter(new MultiValueWrapper(parentIds));
} else {
@@ -556,7 +519,6 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
}
void bindParentId(DefaultSqlUpdate sqlUpd, Object parentId) {
if (isExportedSimple()) {
sqlUpd.setParameter(parentId);
return;
@@ -595,12 +557,9 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
* Find and return the exported property matching to this property.
*/
ExportedProperty findMatch(boolean embedded, BeanProperty prop, String matchColumn, TableJoin tableJoin) {
String searchTable = tableJoin.getTable();
for (TableJoinColumn column : tableJoin.columns()) {
String matchTo = column.getLocalDbColumn();
if (matchColumn.equalsIgnoreCase(matchTo)) {
String foreignCol = column.getForeignDbColumn();
return new ExportedProperty(embedded, foreignCol, prop);
@@ -43,7 +43,6 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
private static final Logger logger = LoggerFactory.getLogger(BeanPropertyAssocMany.class);
private final BeanPropertyAssocManyJsonHelp jsonHelp;
/**
* Join for manyToMany intersection table.
*/
@@ -51,72 +50,46 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
private final String intersectionPublishTable;
private final String intersectionDraftTable;
private final boolean orphanRemoval;
private IntersectionTable intersectionTable;
/**
* For ManyToMany this is the Inverse join used to build reference queries.
*/
final TableJoin inverseJoin;
/**
* Flag to indicate that this is a unidirectional relationship.
*/
private final boolean unidirectional;
private final boolean o2mJoinTable;
/**
* Flag to indicate that the target has a order column to auto populate.
*/
private final boolean hasOrderColumn;
/**
* Flag to indicate manyToMany relationship.
*/
private final boolean manyToMany;
private final boolean elementCollection;
/**
* Descriptor for the 'target' when the property maps to an element collection.
*/
final BeanDescriptor<T> elementDescriptor;
/**
* Order by used when fetch joining the associated many.
*/
private final String fetchOrderBy;
/**
* Order by used when lazy loading the associated many.
*/
private String lazyFetchOrderBy;
private final String mapKey;
/**
* The type of the many, set, list or map.
*/
private final ManyType manyType;
private final ModifyListenMode modifyListenMode;
private BeanProperty mapKeyProperty;
/**
* Property on the 'child' bean that links back to the 'master'.
*/
private BeanPropertyAssocOne<?> childMasterProperty;
private String childMasterIdProperty;
private boolean embeddedExportedProperties;
private BeanCollectionHelp<T> help;
private ImportedId importedId;
private BeanPropertyAssocManySqlHelp<T> sqlHelp;
/**
@@ -234,6 +207,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
/**
* Return the underlying collection of beans.
*/
@SuppressWarnings("rawtypes")
public Collection getRawCollection(EntityBean bean) {
return help.underlying(getVal(bean));
}
@@ -399,8 +373,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
}
/**
* Return the mode for listening to modifications to collections for this
* association.
* Return the mode for listening to modifications to collections for this association.
*/
public ModifyListenMode getModifyListenMode() {
return modifyListenMode;
@@ -470,8 +443,6 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
sb.append(getExtraWhere().replace("${ta}", "x"));
}
}
if (softDelete) {
String alias = hasJoinTable() ? "x2" : "x";
sb.append(" and ").append(targetDescriptor.getSoftDeletePredicate(alias));
@@ -720,7 +691,6 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
* <p>
* Note that childMasterProperty will be null if a field is used instead of
* a ManyToOne bean association.
* </p>
*/
private BeanPropertyAssocOne<?> initChildMasterProperty() {
if (unidirectional) {
@@ -907,7 +877,6 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
// add new relationship (Map not allowed here)
liveVal.addBean(targetDescriptor.createReference(id, null));
}
} else {
// recursively publish the OneToMany child bean
T newLive = targetDescriptor.publish(bean, liveBean);
@@ -917,7 +886,6 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
}
}
}
// anything remaining should be deleted (so remove from modify aware collection)
Collection<T> values = liveBeansAsMap.values();
for (T value : values) {
@@ -930,7 +898,6 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
liveVal.size();
Collection<?> liveBeans = liveVal.getActualDetails();
Map<Object, T> liveMap = new LinkedHashMap<>();
for (Object liveBean : liveBeans) {
Object id = targetDescriptor.getId((EntityBean) liveBean);
liveMap.put(id, (T) liveBean);
@@ -17,7 +17,6 @@ class BeanPropertyAssocManyJsonHelp {
* The associated many property.
*/
private final BeanPropertyAssocMany<?> many;
/**
* Helper used to read json for transient 'many' properties.
*/
@@ -36,7 +35,6 @@ class BeanPropertyAssocManyJsonHelp {
* Read the JSON for this property.
*/
public void jsonRead(SpiJsonReader readJson, EntityBean parentBean) throws IOException {
if (!this.many.jsonDeserialize) {
return;
}
@@ -59,7 +57,6 @@ class BeanPropertyAssocManyJsonHelp {
* Read a Transient property using Jackson ObjectMapper.
*/
private void jsonReadTransientUsingObjectMapper(SpiJsonReader readJson, EntityBean parentBean) throws IOException {
if (jsonTransient == null) {
throw new IllegalStateException("Jackson ObjectMapper is required to read this Transient property " + many.getFullBeanName());
}
@@ -20,9 +20,7 @@ class BeanPropertyAssocManyJsonTransient {
* Use Jackson ObjectMapper to read the transient 'many' property.
*/
void jsonReadUsingObjectMapper(BeanPropertyAssocMany<?> many, SpiJsonReader readJson, EntityBean parentBean) throws IOException {
ObjectMapper mapper = readJson.getObjectMapper();
ManyType manyType = many.getManyType();
Object value;
@@ -32,13 +30,11 @@ class BeanPropertyAssocManyJsonTransient {
JavaType target = typeFactory.constructType(many.getTargetType());
MapType jacksonType = typeFactory.constructMapType(LinkedHashMap.class, TypeFactory.unknownType(), target);
value = mapper.readValue(readJson.getParser(), jacksonType);
} else {
// read list or set using Jackson object mapper
CollectionType jacksonType = mapper.getTypeFactory().constructCollectionType(manyType.getCollectionType(), many.getTargetType());
value = mapper.readValue(readJson.getParser(), jacksonType);
}
many.setValue(parentBean, value);
}
}
@@ -7,6 +7,7 @@ import io.ebeaninternal.api.SpiSqlUpdate;
import io.ebeaninternal.server.deploy.visitor.BaseTablePropertyVisitor;
import io.ebeaninternal.server.deploy.visitor.VisitProperties;
import io.ebeaninternal.server.core.DefaultSqlUpdate;
import io.ebeaninternal.server.util.Str;
import java.util.List;
@@ -44,7 +45,6 @@ class BeanPropertyAssocManySqlHelp<T> {
}
private String elementCollectionInsert() {
StringBuilder sb = new StringBuilder(200);
sb.append("insert into ").append(many.targetTable()).append(" (");
append(sb);
@@ -55,7 +55,6 @@ class BeanPropertyAssocManySqlHelp<T> {
appendBind(sb, exportedProperties.length, true);
appendBind(sb, cols.colCount, false);
sb.append(")");
return sb.toString();
}
@@ -66,7 +65,6 @@ class BeanPropertyAssocManySqlHelp<T> {
private static class Cols extends BaseTablePropertyVisitor {
int colCount;
private final StringBuilder sb;
private Cols(StringBuilder sb) {
@@ -97,7 +95,6 @@ class BeanPropertyAssocManySqlHelp<T> {
}
String lazyFetchOrderBy(String fetchOrderBy) {
// derive lazyFetchOrderBy
StringBuilder sb = new StringBuilder(50);
for (int i = 0; i < exportedProperties.length; i++) {
@@ -116,21 +113,17 @@ class BeanPropertyAssocManySqlHelp<T> {
* Add a where clause to the query for a given list of parent Id's.
*/
void addWhereParentIdIn(SpiQuery<?> query, List<Object> parentIds) {
String tableAlias = hasJoinTable ? "int_." : "t0.";
if (hasJoinTable) {
query.setM2MIncludeJoin(many.inverseJoin);
}
String rawWhere = deriveWhereParentIdSql(true, tableAlias);
String expr = descriptor.getParentIdInExpr(parentIds.size(), rawWhere);
many.bindParentIdsIn(expr, parentIds, query);
}
List<Object> findIdsByParentId(Object parentId, Transaction t, List<Object> excludeDetailIds, boolean hard) {
String rawWhere = deriveWhereParentIdSql(false, "");
SpiEbeanServer server = descriptor.getEbeanServer();
SpiQuery<?> q = many.newQuery(server);
many.bindParentIdEq(rawWhere, parentId, q);
@@ -140,15 +133,12 @@ class BeanPropertyAssocManySqlHelp<T> {
if (excludeDetailIds != null && !excludeDetailIds.isEmpty()) {
q.where().not(q.getExpressionFactory().idIn(excludeDetailIds));
}
return server.findIds(q, t);
}
List<Object> findIdsByParentIdList(List<Object> parentIds, Transaction t, List<Object> excludeDetailIds, boolean hard) {
String rawWhere = deriveWhereParentIdSql(true, "");
String inClause = buildInClauseBinding(parentIds.size(), exportedPropertyBindProto);
String expr = rawWhere + inClause;
SpiEbeanServer server = descriptor.getEbeanServer();
@@ -161,7 +151,6 @@ class BeanPropertyAssocManySqlHelp<T> {
if (excludeDetailIds != null && !excludeDetailIds.isEmpty()) {
q.where().not(q.getExpressionFactory().idIn(excludeDetailIds));
}
return server.findIds(q, t);
}
@@ -172,12 +161,8 @@ class BeanPropertyAssocManySqlHelp<T> {
}
SpiSqlUpdate deleteByParentIdList(List<Object> parentIds) {
StringBuilder sb = new StringBuilder(100);
sb.append(deleteByParentIdInSql);
sb.append(buildInClauseBinding(parentIds.size(), exportedPropertyBindProto));
DefaultSqlUpdate delete = new DefaultSqlUpdate(sb.toString());
String sql = Str.add(deleteByParentIdInSql, buildInClauseBinding(parentIds.size(), exportedPropertyBindProto));
DefaultSqlUpdate delete = new DefaultSqlUpdate(sql);
many.bindParentIds(delete, parentIds);
return delete;
}
@@ -202,17 +187,14 @@ class BeanPropertyAssocManySqlHelp<T> {
}
private String deriveWhereParentIdSql(boolean inClause, String tableAlias) {
StringBuilder sb = new StringBuilder();
if (inClause) {
sb.append("(");
}
for (int i = 0; i < exportedProperties.length; i++) {
String fkColumn = exportedProperties[i].getForeignDbColumn();
if (i > 0) {
String s = inClause ? "," : " and ";
sb.append(s);
sb.append(inClause ? "," : " and ");
}
sb.append(tableAlias).append(fkColumn);
if (!inClause) {
@@ -226,7 +208,6 @@ class BeanPropertyAssocManySqlHelp<T> {
}
private String buildInClauseBinding(int size, String bindProto) {
if (descriptor.isSimpleId()) {
return descriptor.getIdBinder().getIdInValueExpr(false, size);
}
@@ -47,16 +47,11 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
private final boolean primaryKeyJoin;
private AssocOneHelp localHelp;
final BeanProperty[] embeddedProps;
private final HashMap<String, BeanProperty> embeddedPropsMap;
ImportedId importedId;
private String deleteByParentIdSql;
private String deleteByParentIdInSql;
private BeanPropertyAssocMany<?> relationshipProperty;
private boolean cacheNotifyRelationship;
@@ -72,14 +67,12 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
*/
public BeanPropertyAssocOne(BeanDescriptorMap owner, BeanDescriptor<?> descriptor,
DeployBeanPropertyAssocOne<T> deploy) {
super(descriptor, deploy);
primaryKeyExport = deploy.isPrimaryKeyExport();
primaryKeyJoin = deploy.isPrimaryKeyJoin();
oneToOne = deploy.isOneToOne();
oneToOneExported = deploy.isOneToOneExported();
orphanRemoval = deploy.isOrphanRemoval();
if (embedded) {
// Overriding of the columns and use table alias of owning BeanDescriptor
BeanEmbeddedMeta overrideMeta = BeanEmbeddedMetaFactory.create(owner, deploy);
@@ -126,7 +119,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
private void initialiseAssocOne(String embeddedPrefix) {
localHelp = createHelp(embedded, oneToOneExported, embeddedPrefix);
if (!isTransient) {
//noinspection StatementWithEmptyBody
if (embedded || descriptor.isDocStoreOnly()) {
@@ -143,10 +135,8 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
+ " - joining to " + foreignJoinColumn + " and not " + foreignIdColumn);
}
}
} else {
exportedProperties = createExported();
String delStmt = "delete from " + targetDescriptor.getBaseTable() + " where ";
deleteByParentIdSql = delStmt + deriveWhereParentIdSql(false);
deleteByParentIdInSql = delStmt + deriveWhereParentIdSql(true);
@@ -198,7 +188,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
* Clear part of the L2 relationship cache for this property.
*/
void cacheDelete(boolean clear, EntityBean bean, CacheChangeSet changeSet) {
if (cacheNotifyRelationship) {
if (clear) {
changeSet.addManyClear(targetDescriptor, relationshipProperty.getName());
@@ -224,7 +213,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
@Override
public ElPropertyValue buildElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) {
if (embedded) {
BeanProperty embProp = embeddedPropsMap.get(remainder);
if (embProp == null) {
@@ -236,10 +224,8 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
}
chain.add(this);
chain.setEmbedded(true);
return chain.add(embProp).build();
}
return createElPropertyValue(propName, remainder, chain, propertyDeploy);
}
@@ -264,7 +250,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
}
private SqlUpdate deleteByParentId(Object parentId) {
DefaultSqlUpdate delete = new DefaultSqlUpdate(deleteByParentIdSql);
bindParentId(delete, parentId);
return delete;
@@ -279,9 +264,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
}
private List<Object> findIdsByParentId(Object parentId, Transaction t) {
String rawWhere = deriveWhereParentIdSql(false);
SpiEbeanServer server = server();
Query<?> q = server.find(getPropertyType());
bindParentIdEq(rawWhere, parentId, q);
@@ -289,15 +272,12 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
}
private List<Object> findIdsByParentIdList(List<Object> parentIds, Transaction t) {
String rawWhere = deriveWhereParentIdSql(true);
String inClause = getIdBinder().getIdInValueExpr(false, parentIds.size());
String expr = rawWhere + inClause;
SpiEbeanServer server = server();
Query<?> q = server.find(getPropertyType());
bindParentIdsIn(expr, parentIds, q);
return server.findIds(q, t);
}
@@ -321,7 +301,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
BeanProperty idProperty = target.getIdProperty();
desc.registerColumn(dbColumn, SplitName.add(basePath, idProperty.getName()));
}
desc.registerTable(target.getBaseTable(), this);
}
}
@@ -337,9 +316,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
@Override
public void buildRawSqlSelectChain(String prefix, List<String> selectChain) {
prefix = SplitName.add(prefix, name);
if (!embedded) {
InheritInfo inheritInfo = targetDescriptor.getInheritInfo();
if (inheritInfo != null) {
@@ -355,7 +332,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
+ ". Probably a missing @OneToOne mapping annotation on this relationship?");
}
targetIdBinder.buildRawSqlSelectChain(prefix, selectChain);
} else {
for (BeanProperty embeddedProp : embeddedProps) {
embeddedProp.buildRawSqlSelectChain(prefix, selectChain);
@@ -387,7 +363,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
@Override
public void diff(String prefix, Map<String, ValuePair> map, EntityBean newBean, EntityBean oldBean) {
Object newEmb = (newBean == null) ? null : getValue(newBean);
Object oldEmb = (oldBean == null) ? null : getValue(oldBean);
if (newEmb == null && oldEmb == null) {
@@ -395,7 +370,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
}
String nextPrefix = (prefix == null) ? name : prefix + "." + name;
if (embedded) {
BeanDescriptor<T> targetDescriptor = getTargetDescriptor();
targetDescriptor.diff(nextPrefix, map, (EntityBean) newEmb, (EntityBean) oldEmb);
@@ -545,7 +519,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
return !embedded;
}
/**
* Create a bean of the target type to be used as an embeddedId
* value.
@@ -569,9 +542,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
}
private String deriveWhereParentIdSql(boolean inClause) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < exportedProperties.length; i++) {
String fkColumn = exportedProperties[i].getForeignDbColumn();
if (i > 0) {
@@ -590,13 +561,9 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
* Create the array of ExportedProperty used to build reference objects.
*/
private ExportedProperty[] createExported() {
BeanProperty idProp = descriptor.getIdProperty();
ArrayList<ExportedProperty> list = new ArrayList<>();
if (idProp != null && idProp.isEmbedded()) {
BeanPropertyAssocOne<?> one = (BeanPropertyAssocOne<?>) idProp;
BeanDescriptor<?> targetDesc = one.getTargetDescriptor();
BeanProperty[] emIds = targetDesc.propertiesBaseScalar();
@@ -608,13 +575,11 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
// not found as individual scalar properties
e.printStackTrace();
}
} else {
if (idProp != null) {
list.add(findMatch(false, idProp));
}
}
return list.toArray(new ExportedProperty[0]);
}
@@ -622,11 +587,9 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
* Find the matching foreignDbColumn for a given local property.
*/
private ExportedProperty findMatch(boolean embeddedProp, BeanProperty prop) {
return findMatch(embeddedProp, prop, prop.getDbColumn(), tableJoin);
}
@Override
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
if (!isTransient) {
@@ -744,7 +707,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
*/
@Override
public void jsonWriteForInsert(SpiJsonWriter writeJson, EntityBean bean) throws IOException {
if (!jsonSerialize) {
return;
}
@@ -763,13 +725,11 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
}
private void jsonWriteBean(SpiJsonWriter writeJson, Object value) throws IOException {
if (value instanceof EntityBean) {
if (embedded) {
writeJson.writeFieldName(name);
BeanDescriptor<?> refDesc = descriptor.getBeanDescriptor(value.getClass());
refDesc.jsonWriteForInsert(writeJson, (EntityBean) value);
} else {
jsonWriteTargetId(writeJson, (EntityBean) value);
}
@@ -790,15 +750,12 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
@Override
public void jsonWrite(SpiJsonWriter writeJson, EntityBean bean) throws IOException {
if (!jsonSerialize) {
return;
}
Object value = getValueIntercept(bean);
if (value == null) {
writeJson.writeNullField(name);
} else {
if (!writeJson.isParentBean(value)) {
// Hmmm, not writing complex non-entity bean
@@ -829,12 +786,10 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
* Set the parent bean to the child bean if it has not already been set.
*/
public void setParentBeanToChild(EntityBean parent, EntityBean child) {
if (primaryKeyExport) {
Object parentId = descriptor.getId(parent);
targetDescriptor.convertSetId(parentId, child);
}
if (mappedBy != null) {
BeanProperty beanProperty = targetDescriptor.getBeanProperty(mappedBy);
if (beanProperty != null && beanProperty.getValue(child) == null) {
@@ -18,8 +18,7 @@ final class BeanQueryAdapterManager {
private final List<BeanQueryAdapter> list;
BeanQueryAdapterManager(BootupClasses bootupClasses) {
list = bootupClasses.getBeanQueryAdapters();
this.list = bootupClasses.getBeanQueryAdapters();
}
int getRegisterCount() {
@@ -30,7 +29,6 @@ final class BeanQueryAdapterManager {
* Return the BeanPersistController for a given entity type.
*/
void addQueryAdapter(DeployBeanDescriptor<?> deployDesc) {
for (BeanQueryAdapter c : list) {
if (c.isRegisterFor(deployDesc.getBeanType())) {
logger.debug("BeanQueryAdapter on[{}] {}", deployDesc.getFullName(), c.getClass().getName());
@@ -40,7 +40,6 @@ public class BeanSetHelp<T> extends BaseCollectionHelp<T> {
beanSet.setActualSet(new LinkedHashSet<>());
}
return beanSet;
} else {
throw new RuntimeException("Unhandled type " + bc);
}
@@ -62,7 +61,6 @@ public class BeanSetHelp<T> extends BaseCollectionHelp<T> {
@Override
public BeanCollection<T> createReference(EntityBean parentBean) {
BeanSet<T> beanSet = new BeanSet<>(loader, parentBean, propertyName);
beanSet.setModifyListening(many.getModifyListenMode());
return beanSet;
@@ -70,18 +68,14 @@ public class BeanSetHelp<T> extends BaseCollectionHelp<T> {
@Override
public void refresh(SpiEbeanServer server, Query<?> query, Transaction t, EntityBean parentBean) {
BeanSet<?> newBeanSet = (BeanSet<?>) server.findSet(query, t);
refresh(newBeanSet, parentBean);
}
@Override
public void refresh(BeanCollection<?> bc, EntityBean parentBean) {
BeanSet<?> newBeanSet = (BeanSet<?>) bc;
Set<?> current = (Set<?>) many.getValue(parentBean);
newBeanSet.setModifyListening(many.getModifyListenMode());
if (current == null) {
// the currentList is null? Not really expecting this...
@@ -101,7 +95,6 @@ public class BeanSetHelp<T> extends BaseCollectionHelp<T> {
@Override
public void jsonWrite(SpiJsonWriter ctx, String name, Object collection, boolean explicitInclude) throws IOException {
Set<?> set;
if (collection instanceof BeanCollection<?>) {
BeanSet<?> bc = (BeanSet<?>) collection;
@@ -85,11 +85,9 @@ public final class BeanTable {
}
public void createJoinColumn(String foreignKeyPrefix, DeployTableJoin join, boolean reverse, String sqlFormulaSelect) {
if (idProperty == null) {
return;
}
if (idProperty instanceof BeanPropertyAssocOne<?>) {
BeanPropertyAssocOne<?> assocOne = (BeanPropertyAssocOne<?>) idProperty;
BeanProperty[] props = assocOne.getProperties();
@@ -102,13 +100,11 @@ public final class BeanTable {
}
private void addToJoin(String foreignKeyPrefix, DeployTableJoin join, boolean reverse, String sqlFormulaSelect, boolean complexKey, BeanProperty prop) {
String lc = prop.getDbColumn();
String fk = lc;
if (foreignKeyPrefix != null) {
fk = owner.getNamingConvention().getForeignKey(foreignKeyPrefix, fk);
}
if (complexKey) {
// just to copy the column name rather than prefix with the foreignKeyPrefix.
// I think that with complex keys this is the more common approach.
@@ -118,7 +114,6 @@ public final class BeanTable {
if (sqlFormulaSelect != null) {
fk = sqlFormulaSelect;
}
DeployTableJoinColumn joinCol = new DeployTableJoinColumn(lc, fk);
joinCol.setForeignSqlFormula(sqlFormulaSelect);
if (reverse) {
@@ -19,7 +19,6 @@ public final class ChainedBeanPersistController implements BeanPersistController
private static final Sorter SORTER = new Sorter();
private final List<BeanPersistController> list;
private final BeanPersistController[] chain;
/**
@@ -178,15 +177,10 @@ public final class ChainedBeanPersistController implements BeanPersistController
/**
* Helper to order the BeanPersistController's in a chain.
*/
private static class Sorter implements Comparator<BeanPersistController> {
private static final class Sorter implements Comparator<BeanPersistController> {
@Override
public int compare(BeanPersistController o1, BeanPersistController o2) {
int i1 = o1.getExecutionOrder();
int i2 = o2.getExecutionOrder();
return Integer.compare(i1, i2);
return Integer.compare(o1.getExecutionOrder(), o2.getExecutionOrder());
}
}
}
@@ -24,7 +24,7 @@ public final class ChainedBeanPersistListener implements BeanPersistListener {
/**
* Return the size of the chain.
*/
protected int size() {
int size() {
return chain.length;
}
@@ -61,7 +61,6 @@ public final class ChainedBeanPersistListener implements BeanPersistListener {
} else {
List<BeanPersistListener> newList = new ArrayList<>(list);
newList.add(c);
return new ChainedBeanPersistListener(newList);
}
}
@@ -75,7 +74,6 @@ public final class ChainedBeanPersistListener implements BeanPersistListener {
} else {
List<BeanPersistListener> newList = new ArrayList<>(list);
newList.remove(c);
return new ChainedBeanPersistListener(newList);
}
}
@@ -30,7 +30,6 @@ public final class ChainedBeanPostConstructListener implements BeanPostConstruct
} else {
List<BeanPostConstructListener> newList = new ArrayList<>(list);
newList.add(c);
return new ChainedBeanPostConstructListener(newList);
}
}
@@ -44,17 +43,16 @@ public final class ChainedBeanPostConstructListener implements BeanPostConstruct
} else {
ArrayList<BeanPostConstructListener> newList = new ArrayList<>(list);
newList.remove(c);
return new ChainedBeanPostConstructListener(newList);
}
}
/**
* Return the size of the chain.
*/
protected int size() {
return chain.length;
}
// /**
// * Return the size of the chain.
// */
// int size() {
// return chain.length;
// }
@Override
public boolean isRegisterFor(Class<?> cls) {
@@ -30,7 +30,6 @@ public final class ChainedBeanPostLoad implements BeanPostLoad {
} else {
List<BeanPostLoad> newList = new ArrayList<>(list);
newList.add(c);
return new ChainedBeanPostLoad(newList);
}
}
@@ -44,17 +43,16 @@ public final class ChainedBeanPostLoad implements BeanPostLoad {
} else {
List<BeanPostLoad> newList = new ArrayList<>(list);
newList.remove(c);
return new ChainedBeanPostLoad(newList);
}
}
/**
* Return the size of the chain.
*/
protected int size() {
return chain.length;
}
// /**
// * Return the size of the chain.
// */
// int size() {
// return chain.length;
// }
@Override
public boolean isRegisterFor(Class<?> cls) {
@@ -37,7 +37,6 @@ public final class ChainedBeanQueryAdapter implements BeanQueryAdapter {
} else {
List<BeanQueryAdapter> newList = new ArrayList<>(list);
newList.add(c);
return new ChainedBeanQueryAdapter(newList);
}
}
@@ -51,12 +50,10 @@ public final class ChainedBeanQueryAdapter implements BeanQueryAdapter {
} else {
List<BeanQueryAdapter> newList = new ArrayList<>(list);
newList.remove(c);
return new ChainedBeanQueryAdapter(newList);
}
}
/**
* Return 0 as not used by this Chained adapter.
*/
@@ -75,7 +72,6 @@ public final class ChainedBeanQueryAdapter implements BeanQueryAdapter {
@Override
public void preQuery(BeanQueryRequest<?> request) {
for (BeanQueryAdapter aChain : chain) {
aChain.preQuery(request);
}
@@ -85,11 +81,9 @@ public final class ChainedBeanQueryAdapter implements BeanQueryAdapter {
* Helper to order the BeanQueryAdapter's in a chain.
*/
private static class Sorter implements Comparator<BeanQueryAdapter> {
@Override
public int compare(BeanQueryAdapter o1, BeanQueryAdapter o2) {
return Integer.compare(o1.getExecutionOrder(), o2.getExecutionOrder());
}
}
}
@@ -65,5 +65,4 @@ public final class DbMigrationInfo {
}
}
}