diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java index 413d0b460..74e75702a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java @@ -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 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)); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java index 739021196..33304f5f9 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java @@ -43,48 +43,34 @@ public abstract class BeanPropertyAssoc extends BeanProperty implements STree * so as to avoid a dependency loop between BeanDescriptors. */ BeanDescriptor 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 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 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 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 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 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 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 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 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 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 extends BeanProperty implements STree } private void flatten(List 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 extends BeanProperty implements STree } void bindParentIds(DefaultSqlUpdate delete, List parentIds) { - if (isExportedSimple()) { delete.setParameter(new MultiValueWrapper(parentIds)); } else { @@ -556,7 +519,6 @@ public abstract class BeanPropertyAssoc extends BeanProperty implements STree } void bindParentId(DefaultSqlUpdate sqlUpd, Object parentId) { - if (isExportedSimple()) { sqlUpd.setParameter(parentId); return; @@ -595,12 +557,9 @@ public abstract class BeanPropertyAssoc 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); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java index de13412d9..37e5b7990 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java @@ -43,7 +43,6 @@ public class BeanPropertyAssocMany extends BeanPropertyAssoc 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 extends BeanPropertyAssoc 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 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 help; - private ImportedId importedId; - private BeanPropertyAssocManySqlHelp sqlHelp; /** @@ -234,6 +207,7 @@ public class BeanPropertyAssocMany extends BeanPropertyAssoc 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 extends BeanPropertyAssoc 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 extends BeanPropertyAssoc 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 extends BeanPropertyAssoc implements ST *

* Note that childMasterProperty will be null if a field is used instead of * a ManyToOne bean association. - *

*/ private BeanPropertyAssocOne initChildMasterProperty() { if (unidirectional) { @@ -907,7 +877,6 @@ public class BeanPropertyAssocMany extends BeanPropertyAssoc 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 extends BeanPropertyAssoc implements ST } } } - // anything remaining should be deleted (so remove from modify aware collection) Collection values = liveBeansAsMap.values(); for (T value : values) { @@ -930,7 +898,6 @@ public class BeanPropertyAssocMany extends BeanPropertyAssoc implements ST liveVal.size(); Collection liveBeans = liveVal.getActualDetails(); Map liveMap = new LinkedHashMap<>(); - for (Object liveBean : liveBeans) { Object id = targetDescriptor.getId((EntityBean) liveBean); liveMap.put(id, (T) liveBean); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocManyJsonHelp.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocManyJsonHelp.java index d448c157c..b84889833 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocManyJsonHelp.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocManyJsonHelp.java @@ -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()); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocManyJsonTransient.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocManyJsonTransient.java index 5b05b3261..cc43cb9e7 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocManyJsonTransient.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocManyJsonTransient.java @@ -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); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocManySqlHelp.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocManySqlHelp.java index 06a2a2145..8a5eade8b 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocManySqlHelp.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocManySqlHelp.java @@ -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 { } private String elementCollectionInsert() { - StringBuilder sb = new StringBuilder(200); sb.append("insert into ").append(many.targetTable()).append(" ("); append(sb); @@ -55,7 +55,6 @@ class BeanPropertyAssocManySqlHelp { appendBind(sb, exportedProperties.length, true); appendBind(sb, cols.colCount, false); sb.append(")"); - return sb.toString(); } @@ -66,7 +65,6 @@ class BeanPropertyAssocManySqlHelp { private static class Cols extends BaseTablePropertyVisitor { int colCount; - private final StringBuilder sb; private Cols(StringBuilder sb) { @@ -97,7 +95,6 @@ class BeanPropertyAssocManySqlHelp { } 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 { * Add a where clause to the query for a given list of parent Id's. */ void addWhereParentIdIn(SpiQuery query, List 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 findIdsByParentId(Object parentId, Transaction t, List 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 { if (excludeDetailIds != null && !excludeDetailIds.isEmpty()) { q.where().not(q.getExpressionFactory().idIn(excludeDetailIds)); } - return server.findIds(q, t); } List findIdsByParentIdList(List parentIds, Transaction t, List 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 { if (excludeDetailIds != null && !excludeDetailIds.isEmpty()) { q.where().not(q.getExpressionFactory().idIn(excludeDetailIds)); } - return server.findIds(q, t); } @@ -172,12 +161,8 @@ class BeanPropertyAssocManySqlHelp { } SpiSqlUpdate deleteByParentIdList(List 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 { } 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 { } private String buildInClauseBinding(int size, String bindProto) { - if (descriptor.isSimpleId()) { return descriptor.getIdBinder().getIdInValueExpr(false, size); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocOne.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocOne.java index 9a69b8c9c..3b3c5946c 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocOne.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocOne.java @@ -47,16 +47,11 @@ public class BeanPropertyAssocOne extends BeanPropertyAssoc implements STr private final boolean primaryKeyJoin; private AssocOneHelp localHelp; - final BeanProperty[] embeddedProps; - private final HashMap embeddedPropsMap; - ImportedId importedId; - private String deleteByParentIdSql; private String deleteByParentIdInSql; - private BeanPropertyAssocMany relationshipProperty; private boolean cacheNotifyRelationship; @@ -72,14 +67,12 @@ public class BeanPropertyAssocOne extends BeanPropertyAssoc implements STr */ public BeanPropertyAssocOne(BeanDescriptorMap owner, BeanDescriptor descriptor, DeployBeanPropertyAssocOne 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 extends BeanPropertyAssoc 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 extends BeanPropertyAssoc 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 extends BeanPropertyAssoc 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 extends BeanPropertyAssoc 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 extends BeanPropertyAssoc 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 extends BeanPropertyAssoc implements STr } private SqlUpdate deleteByParentId(Object parentId) { - DefaultSqlUpdate delete = new DefaultSqlUpdate(deleteByParentIdSql); bindParentId(delete, parentId); return delete; @@ -279,9 +264,7 @@ public class BeanPropertyAssocOne extends BeanPropertyAssoc implements STr } private List 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 extends BeanPropertyAssoc implements STr } private List findIdsByParentIdList(List 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 extends BeanPropertyAssoc 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 extends BeanPropertyAssoc implements STr @Override public void buildRawSqlSelectChain(String prefix, List selectChain) { - prefix = SplitName.add(prefix, name); - if (!embedded) { InheritInfo inheritInfo = targetDescriptor.getInheritInfo(); if (inheritInfo != null) { @@ -355,7 +332,6 @@ public class BeanPropertyAssocOne extends BeanPropertyAssoc 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 extends BeanPropertyAssoc implements STr @Override public void diff(String prefix, Map 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 extends BeanPropertyAssoc implements STr } String nextPrefix = (prefix == null) ? name : prefix + "." + name; - if (embedded) { BeanDescriptor targetDescriptor = getTargetDescriptor(); targetDescriptor.diff(nextPrefix, map, (EntityBean) newEmb, (EntityBean) oldEmb); @@ -545,7 +519,6 @@ public class BeanPropertyAssocOne extends BeanPropertyAssoc 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 extends BeanPropertyAssoc 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 extends BeanPropertyAssoc implements STr * Create the array of ExportedProperty used to build reference objects. */ private ExportedProperty[] createExported() { - BeanProperty idProp = descriptor.getIdProperty(); - ArrayList 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 extends BeanPropertyAssoc 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 extends BeanPropertyAssoc 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 extends BeanPropertyAssoc implements STr */ @Override public void jsonWriteForInsert(SpiJsonWriter writeJson, EntityBean bean) throws IOException { - if (!jsonSerialize) { return; } @@ -763,13 +725,11 @@ public class BeanPropertyAssocOne extends BeanPropertyAssoc 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 extends BeanPropertyAssoc 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 extends BeanPropertyAssoc 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) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanQueryAdapterManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanQueryAdapterManager.java index 2f8f05317..dbaecc265 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanQueryAdapterManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanQueryAdapterManager.java @@ -18,8 +18,7 @@ final class BeanQueryAdapterManager { private final List 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()); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanSetHelp.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanSetHelp.java index 4acc23347..f275d0988 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanSetHelp.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanSetHelp.java @@ -40,7 +40,6 @@ public class BeanSetHelp extends BaseCollectionHelp { beanSet.setActualSet(new LinkedHashSet<>()); } return beanSet; - } else { throw new RuntimeException("Unhandled type " + bc); } @@ -62,7 +61,6 @@ public class BeanSetHelp extends BaseCollectionHelp { @Override public BeanCollection createReference(EntityBean parentBean) { - BeanSet beanSet = new BeanSet<>(loader, parentBean, propertyName); beanSet.setModifyListening(many.getModifyListenMode()); return beanSet; @@ -70,18 +68,14 @@ public class BeanSetHelp extends BaseCollectionHelp { @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 extends BaseCollectionHelp { @Override public void jsonWrite(SpiJsonWriter ctx, String name, Object collection, boolean explicitInclude) throws IOException { - Set set; if (collection instanceof BeanCollection) { BeanSet bc = (BeanSet) collection; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanTable.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanTable.java index 3ccdb8218..ecd0b7a37 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanTable.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanTable.java @@ -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) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPersistController.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPersistController.java index dfb2c302a..6ffbae176 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPersistController.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPersistController.java @@ -19,7 +19,6 @@ public final class ChainedBeanPersistController implements BeanPersistController private static final Sorter SORTER = new Sorter(); private final List 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 { - + private static final class Sorter implements Comparator { @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()); } - } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPersistListener.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPersistListener.java index d49380577..624ac6540 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPersistListener.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPersistListener.java @@ -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 newList = new ArrayList<>(list); newList.add(c); - return new ChainedBeanPersistListener(newList); } } @@ -75,7 +74,6 @@ public final class ChainedBeanPersistListener implements BeanPersistListener { } else { List newList = new ArrayList<>(list); newList.remove(c); - return new ChainedBeanPersistListener(newList); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPostConstructListener.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPostConstructListener.java index c615f8b20..d8f297628 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPostConstructListener.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPostConstructListener.java @@ -30,7 +30,6 @@ public final class ChainedBeanPostConstructListener implements BeanPostConstruct } else { List newList = new ArrayList<>(list); newList.add(c); - return new ChainedBeanPostConstructListener(newList); } } @@ -44,17 +43,16 @@ public final class ChainedBeanPostConstructListener implements BeanPostConstruct } else { ArrayList 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) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPostLoad.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPostLoad.java index 4d7cff8ef..c3191a151 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPostLoad.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanPostLoad.java @@ -30,7 +30,6 @@ public final class ChainedBeanPostLoad implements BeanPostLoad { } else { List newList = new ArrayList<>(list); newList.add(c); - return new ChainedBeanPostLoad(newList); } } @@ -44,17 +43,16 @@ public final class ChainedBeanPostLoad implements BeanPostLoad { } else { List 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) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanQueryAdapter.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanQueryAdapter.java index ca67a0746..be7c082f6 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanQueryAdapter.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/ChainedBeanQueryAdapter.java @@ -37,7 +37,6 @@ public final class ChainedBeanQueryAdapter implements BeanQueryAdapter { } else { List newList = new ArrayList<>(list); newList.add(c); - return new ChainedBeanQueryAdapter(newList); } } @@ -51,12 +50,10 @@ public final class ChainedBeanQueryAdapter implements BeanQueryAdapter { } else { List 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 { - @Override public int compare(BeanQueryAdapter o1, BeanQueryAdapter o2) { return Integer.compare(o1.getExecutionOrder(), o2.getExecutionOrder()); } - } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbMigrationInfo.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbMigrationInfo.java index e6e4a3eef..d41f781f5 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbMigrationInfo.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbMigrationInfo.java @@ -65,5 +65,4 @@ public final class DbMigrationInfo { } } - }