From 4e1cda691ff0a42a8eea87ebcc0c52b0583a224b Mon Sep 17 00:00:00 2001 From: rbygrave Date: Tue, 19 May 2015 01:35:27 +1200 Subject: [PATCH] No effective change - reformat and tidy --- .../server/deploy/BeanProperty.java | 1875 +++++++++-------- .../server/deploy/BeanPropertyAssoc.java | 2 +- .../server/deploy/BeanPropertyCompound.java | 288 ++- .../server/transaction/BeanDeltaProperty.java | 46 +- 4 files changed, 1106 insertions(+), 1105 deletions(-) diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java index d0ea03299..9ccaf53c4 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java @@ -1,17 +1,5 @@ package com.avaje.ebeaninternal.server.deploy; -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.sql.SQLException; -import java.sql.Types; -import java.util.List; -import java.util.Map; - -import javax.persistence.PersistenceException; - import com.avaje.ebean.bean.EntityBean; import com.avaje.ebean.config.EncryptKey; import com.avaje.ebean.config.dbplatform.DbEncryptFunction; @@ -25,1042 +13,1057 @@ import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty; import com.avaje.ebeaninternal.server.el.ElPropertyChainBuilder; import com.avaje.ebeaninternal.server.el.ElPropertyValue; import com.avaje.ebeaninternal.server.lib.util.StringHelper; -import com.avaje.ebeaninternal.server.query.SqlBeanLoad; -import com.avaje.ebeaninternal.server.query.SqlJoinType; import com.avaje.ebeaninternal.server.properties.BeanPropertyGetter; import com.avaje.ebeaninternal.server.properties.BeanPropertySetter; +import com.avaje.ebeaninternal.server.query.SqlBeanLoad; +import com.avaje.ebeaninternal.server.query.SqlJoinType; import com.avaje.ebeaninternal.server.text.json.WriteJson; import com.avaje.ebeaninternal.server.type.DataBind; import com.avaje.ebeaninternal.server.type.ScalarType; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import javax.persistence.PersistenceException; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.lang.reflect.Field; +import java.sql.SQLException; +import java.sql.Types; +import java.util.List; +import java.util.Map; + /** * Description of a property of a bean. Includes its deployment information such * as database column mapping information. */ public class BeanProperty implements ElPropertyValue { - /** - * Flag to mark this at part of the unique id. - */ - final boolean id; + /** + * Flag to mark this at part of the unique id. + */ + final boolean id; - /** - * Flag to make this as a dummy property for unidirecitonal relationships. - */ - final boolean unidirectionalShadow; + /** + * Flag to make this as a dummy property for unidirecitonal relationships. + */ + final boolean unidirectionalShadow; - /** - * Flag set if this maps to the inheritance discriminator column - */ - 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 set if this maps to the inheritance discriminator column + */ + final boolean discriminator; - /** - * Flag indicating if this the version property. - */ - final boolean version; + /** + * 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; - final boolean naturalKey; - - /** - * Set if this property is nullable. - */ - final boolean nullable; + /** + * Flag indicating if this the version property. + */ + final boolean version; - final boolean unique; + final boolean naturalKey; - /** - * Is this property include in database resultSet. - */ - final boolean dbRead; + /** + * Set if this property is nullable. + */ + final boolean nullable; - /** - * Include in DB insert. - */ - final boolean dbInsertable; + final boolean unique; - /** - * Include in DB update. - */ - final boolean dbUpdatable; + /** + * Is this property include in database resultSet. + */ + final boolean dbRead; - /** - * True if the property is based on a SECONDARY table. - */ - final boolean secondaryTable; + /** + * Include in DB insert. + */ + final boolean dbInsertable; - final TableJoin secondaryTableJoin; - final String secondaryTableJoinPrefix; + /** + * Include in DB update. + */ + final boolean dbUpdatable; - /** - * The property is inherited from a super class. - */ - final boolean inherited; + /** + * True if the property is based on a SECONDARY table. + */ + final boolean secondaryTable; - final Class owningType; + final TableJoin secondaryTableJoin; + final String secondaryTableJoinPrefix; - final boolean local; + /** + * The property is inherited from a super class. + */ + final boolean inherited; - /** - * True if the property is a Clob, Blob LongVarchar or LongVarbinary. - */ - final boolean lob; - - final boolean fetchEager; + final Class owningType; - final boolean isTransient; + final boolean local; - /** - * The logical bean property name. - */ - final String name; + /** + * True if the property is a Clob, Blob LongVarchar or LongVarbinary. + */ + final boolean lob; - final int propertyIndex; - - /** - * The reflected field. - */ - final Field field; + final boolean fetchEager; - /** - * The bean type. - */ - final Class propertyType; + final boolean isTransient; - final String dbBind; + /** + * The logical bean property name. + */ + final String name; - /** - * The database column. This can include quoted identifiers. - */ - final String dbColumn; + final int propertyIndex; - final String elPlaceHolder; - final String elPlaceHolderEncrypted; + /** + * The reflected field. + */ + final Field field; - /** - * Select part of a SQL Formula used to populate this property. - */ - final String sqlFormulaSelect; + /** + * The bean type. + */ + final Class propertyType; - /** - * Join part of a SQL Formula. - */ - final String sqlFormulaJoin; + final String dbBind; - final boolean formula; + /** + * The database column. This can include quoted identifiers. + */ + final String dbColumn; - /** - * Set to true if stored encrypted. - */ - final boolean dbEncrypted; + final String elPlaceHolder; + final String elPlaceHolderEncrypted; - final boolean localEncrypted; + /** + * Select part of a SQL Formula used to populate this property. + */ + final String sqlFormulaSelect; - final int dbEncryptedType; + /** + * Join part of a SQL Formula. + */ + final String sqlFormulaJoin; - /** - * The jdbc data type this maps to. - */ - final int dbType; + final boolean formula; - /** - * The default value to insert if null. - */ - final Object defaultValue; + /** + * Set to true if stored encrypted. + */ + final boolean dbEncrypted; - /** - * Extra deployment parameters. - */ - final Map extraAttributeMap; + final boolean localEncrypted; - /** - * Generator for insert or update timestamp etc. - */ - final GeneratedProperty generatedProperty; + final int dbEncryptedType; - final BeanPropertyGetter getter; + /** + * The jdbc data type this maps to. + */ + final int dbType; - final BeanPropertySetter setter; + /** + * The default value to insert if null. + */ + final Object defaultValue; - final BeanDescriptor descriptor; + /** + * Extra deployment parameters. + */ + final Map extraAttributeMap; - /** - * Used for non-jdbc native types (java.util.Date Enums etc). Converts from - * logical to jdbc types. - */ - @SuppressWarnings("rawtypes") - final ScalarType scalarType; + /** + * Generator for insert or update timestamp etc. + */ + final GeneratedProperty generatedProperty; - boolean cascadeValidate; + final BeanPropertyGetter getter; - /** - * The length or precision for DB column. - */ - final int dbLength; + final BeanPropertySetter setter; - /** - * The scale for DB column (decimal). - */ - final int dbScale; + final BeanDescriptor descriptor; - /** - * Deployment defined DB column definition. - */ - final String dbColumnDefn; + /** + * Used for non-jdbc native types (java.util.Date Enums etc). Converts from + * logical to jdbc types. + */ + @SuppressWarnings("rawtypes") + final ScalarType scalarType; - /** - * DB Constraint (typically check constraint on enum) - */ - final String dbConstraintExpression; + boolean cascadeValidate; - final DbEncryptFunction dbEncryptFunction; + /** + * The length or precision for DB column. + */ + final int dbLength; - int deployOrder; + /** + * The scale for DB column (decimal). + */ + final int dbScale; - final boolean jsonSerialize; + /** + * Deployment defined DB column definition. + */ + final String dbColumnDefn; - final boolean jsonDeserialize; + /** + * DB Constraint (typically check constraint on enum) + */ + final String dbConstraintExpression; - final boolean indexed; + final DbEncryptFunction dbEncryptFunction; - final String indexName; - public BeanProperty(DeployBeanProperty deploy) { - this(null, null, deploy); + int deployOrder; + + final boolean jsonSerialize; + + final boolean jsonDeserialize; + + final boolean indexed; + + final String indexName; + + public BeanProperty(DeployBeanProperty deploy) { + this(null, deploy); + } + + public BeanProperty(BeanDescriptor descriptor, DeployBeanProperty deploy) { + + this.descriptor = descriptor; + this.name = InternString.intern(deploy.getName()); + this.propertyIndex = deploy.getPropertyIndex(); + this.indexed = deploy.isIndexed(); + this.indexName = deploy.getIndexName(); + this.unidirectionalShadow = deploy.isUndirectionalShadow(); + this.discriminator = deploy.isDiscriminator(); + this.localEncrypted = deploy.isLocalEncrypted(); + this.dbEncrypted = deploy.isDbEncrypted(); + this.dbEncryptedType = deploy.getDbEncryptedType(); + this.dbEncryptFunction = deploy.getDbEncryptFunction(); + this.dbBind = deploy.getDbBind(); + this.dbRead = deploy.isDbRead(); + this.dbInsertable = deploy.isDbInsertable(); + this.dbUpdatable = deploy.isDbUpdateable(); + + this.secondaryTable = deploy.isSecondaryTable(); + if (secondaryTable) { + this.secondaryTableJoin = new TableJoin(deploy.getSecondaryTableJoin(), null); + this.secondaryTableJoinPrefix = deploy.getSecondaryTableJoinPrefix(); + } else { + this.secondaryTableJoin = null; + this.secondaryTableJoinPrefix = null; } + this.fetchEager = deploy.isFetchEager(); + this.isTransient = deploy.isTransient(); + this.nullable = deploy.isNullable(); + this.unique = deploy.isUnique(); + this.naturalKey = deploy.isNaturalKey(); + this.dbLength = deploy.getDbLength(); + this.dbScale = deploy.getDbScale(); + this.dbColumnDefn = InternString.intern(deploy.getDbColumnDefn()); + this.dbConstraintExpression = InternString.intern(deploy.getDbConstraintExpression()); - public BeanProperty(BeanDescriptorMap owner, BeanDescriptor descriptor, DeployBeanProperty deploy) { + this.inherited = false;// deploy.isInherited(); + this.owningType = deploy.getOwningType(); + this.local = deploy.isLocal(); - this.descriptor = descriptor; - this.name = InternString.intern(deploy.getName()); - this.propertyIndex = deploy.getPropertyIndex(); - this.indexed = deploy.isIndexed(); - this.indexName = deploy.getIndexName(); - this.unidirectionalShadow = deploy.isUndirectionalShadow(); - this.discriminator = deploy.isDiscriminator(); - this.localEncrypted = deploy.isLocalEncrypted(); - this.dbEncrypted = deploy.isDbEncrypted(); - this.dbEncryptedType = deploy.getDbEncryptedType(); - this.dbEncryptFunction = deploy.getDbEncryptFunction(); - this.dbBind = deploy.getDbBind(); - this.dbRead = deploy.isDbRead(); - this.dbInsertable = deploy.isDbInsertable(); - this.dbUpdatable = deploy.isDbUpdateable(); + this.version = deploy.isVersionColumn(); + this.embedded = deploy.isEmbedded(); + this.id = deploy.isId(); + this.generatedProperty = deploy.getGeneratedProperty(); + this.getter = deploy.getGetter(); + this.setter = deploy.getSetter(); - this.secondaryTable = deploy.isSecondaryTable(); - if (secondaryTable) { - this.secondaryTableJoin = new TableJoin(deploy.getSecondaryTableJoin(), null); - this.secondaryTableJoinPrefix = deploy.getSecondaryTableJoinPrefix(); - } else { - this.secondaryTableJoin = null; - this.secondaryTableJoinPrefix = null; - } - this.fetchEager = deploy.isFetchEager(); - this.isTransient = deploy.isTransient(); - this.nullable = deploy.isNullable(); - this.unique = deploy.isUnique(); - this.naturalKey = deploy.isNaturalKey(); - this.dbLength = deploy.getDbLength(); - this.dbScale = deploy.getDbScale(); - this.dbColumnDefn = InternString.intern(deploy.getDbColumnDefn()); - this.dbConstraintExpression = InternString.intern(deploy.getDbConstraintExpression()); + this.dbColumn = tableAliasIntern(descriptor, deploy.getDbColumn(), false, null); + this.sqlFormulaJoin = InternString.intern(deploy.getSqlFormulaJoin()); + this.sqlFormulaSelect = InternString.intern(deploy.getSqlFormulaSelect()); + this.formula = sqlFormulaSelect != null; - this.inherited = false;// deploy.isInherited(); - this.owningType = deploy.getOwningType(); - this.local = deploy.isLocal(); + this.extraAttributeMap = deploy.getExtraAttributeMap(); + this.defaultValue = deploy.getDefaultValue(); + this.dbType = deploy.getDbType(); + this.scalarType = deploy.getScalarType(); + this.lob = isLobType(dbType); + this.propertyType = deploy.getPropertyType(); + this.field = deploy.getField(); - this.version = deploy.isVersionColumn(); - this.embedded = deploy.isEmbedded(); - this.id = deploy.isId(); - this.generatedProperty = deploy.getGeneratedProperty(); - this.getter = deploy.getGetter(); - this.setter = deploy.getSetter(); + EntityType et = descriptor == null ? null : descriptor.getEntityType(); + this.elPlaceHolder = tableAliasIntern(descriptor, deploy.getElPlaceHolder(et), false, null); + this.elPlaceHolderEncrypted = tableAliasIntern(descriptor, deploy.getElPlaceHolder(et), dbEncrypted, dbColumn); - this.dbColumn = tableAliasIntern(descriptor, deploy.getDbColumn(), false, null); - this.sqlFormulaJoin = InternString.intern(deploy.getSqlFormulaJoin()); - this.sqlFormulaSelect = InternString.intern(deploy.getSqlFormulaSelect()); - this.formula = sqlFormulaSelect != null; + this.jsonSerialize = deploy.isExposeSerialize(); + this.jsonDeserialize = deploy.isExposeDeserialize(); + } - this.extraAttributeMap = deploy.getExtraAttributeMap(); - this.defaultValue = deploy.getDefaultValue(); - this.dbType = deploy.getDbType(); - this.scalarType = deploy.getScalarType(); - this.lob = isLobType(dbType); - this.propertyType = deploy.getPropertyType(); - this.field = deploy.getField(); - - EntityType et = descriptor == null ? null : descriptor.getEntityType(); - this.elPlaceHolder = tableAliasIntern(descriptor, deploy.getElPlaceHolder(et), false, null); - this.elPlaceHolderEncrypted = tableAliasIntern(descriptor, deploy.getElPlaceHolder(et), dbEncrypted, dbColumn); + private String tableAliasIntern(BeanDescriptor descriptor, String s, boolean dbEncrypted, String dbColumn) { + if (descriptor != null) { + s = StringHelper.replaceString(s, "${ta}.", "${}"); + s = StringHelper.replaceString(s, "${ta}", "${}"); - this.jsonSerialize = deploy.isExposeSerialize(); - this.jsonDeserialize = deploy.isExposeDeserialize(); + if (dbEncrypted) { + s = dbEncryptFunction.getDecryptSql(s); + String namedParam = ":encryptkey_" + descriptor.getBaseTable() + "___" + dbColumn; + s = StringHelper.replaceString(s, "?", namedParam); + } } + return InternString.intern(s); + } - private String tableAliasIntern(BeanDescriptor descriptor, String s, boolean dbEncrypted, String dbColumn) { - if (descriptor != null) { - s = StringHelper.replaceString(s, "${ta}.", "${}"); - s = StringHelper.replaceString(s, "${ta}", "${}"); + /** + * Create a Matching BeanProperty with some attributes overridden. + *

+ * Primarily for supporting Embedded beans with overridden dbColumn + * mappings. + *

+ */ + public BeanProperty(BeanProperty source, BeanPropertyOverride override) { - if (dbEncrypted) { - s = dbEncryptFunction.getDecryptSql(s); - String namedParam = ":encryptkey_" + descriptor.getBaseTable() + "___" + dbColumn; - s = StringHelper.replaceString(s, "?", namedParam); - } - } - return InternString.intern(s); + this.descriptor = source.descriptor; + this.name = InternString.intern(source.getName()); + this.propertyIndex = source.propertyIndex; + + this.indexed = source.isIndexed(); + this.indexName = source.getIndexName(); + this.dbColumn = InternString.intern(override.getDbColumn()); + this.sqlFormulaJoin = InternString.intern(override.getSqlFormulaJoin()); + this.sqlFormulaSelect = InternString.intern(override.getSqlFormulaSelect()); + this.formula = sqlFormulaSelect != null; + + this.fetchEager = source.fetchEager; + this.unidirectionalShadow = source.unidirectionalShadow; + this.discriminator = source.discriminator; + this.localEncrypted = source.isLocalEncrypted(); + this.isTransient = source.isTransient(); + this.secondaryTable = source.isSecondaryTable(); + this.secondaryTableJoin = source.secondaryTableJoin; + this.secondaryTableJoinPrefix = source.secondaryTableJoinPrefix; + + this.dbBind = source.getDbBind(); + this.dbEncrypted = source.isDbEncrypted(); + this.dbEncryptedType = source.getDbEncryptedType(); + this.dbEncryptFunction = source.dbEncryptFunction; + this.dbRead = source.isDbRead(); + this.dbInsertable = source.isDbInsertable(); + this.dbUpdatable = source.isDbUpdatable(); + this.nullable = source.isNullable(); + this.unique = source.isUnique(); + this.naturalKey = source.isNaturalKey(); + this.dbLength = source.getDbLength(); + this.dbScale = source.getDbScale(); + this.dbColumnDefn = InternString.intern(source.getDbColumnDefn()); + this.dbConstraintExpression = InternString.intern(source.getDbConstraintExpression()); + + this.inherited = source.isInherited(); + this.owningType = source.owningType; + this.local = owningType.equals(descriptor.getBeanType()); + + this.version = source.isVersion(); + this.embedded = source.isEmbedded(); + this.id = source.isId(); + this.generatedProperty = source.getGeneratedProperty(); + this.getter = source.getter; + this.setter = source.setter; + this.extraAttributeMap = source.extraAttributeMap; + this.defaultValue = source.getDefaultValue(); + this.dbType = source.getDbType(); + this.scalarType = source.scalarType; + this.lob = isLobType(dbType); + this.propertyType = source.getPropertyType(); + this.field = source.getField(); + + this.elPlaceHolder = override.replace(source.elPlaceHolder, source.dbColumn); + this.elPlaceHolderEncrypted = override.replace(source.elPlaceHolderEncrypted, source.dbColumn); + + this.jsonSerialize = source.jsonSerialize; + this.jsonDeserialize = source.jsonDeserialize; + } + + /** + * Initialise the property before returning to client code. Used to + * initialise variables that can't be done in construction due to recursive + * issues. + */ + public void initialise() { + // do nothing for normal BeanProperty + if (!isTransient && scalarType == null) { + String msg = "No ScalarType assigned to " + descriptor.getFullName() + "." + getName(); + throw new RuntimeException(msg); } + } - /** - * Create a Matching BeanProperty with some attributes overridden. - *

- * Primarily for supporting Embedded beans with overridden dbColumn - * mappings. - *

- */ - public BeanProperty(BeanProperty source, BeanPropertyOverride override) { + /** + * Return the order this property appears in the bean. + */ + public int getDeployOrder() { + return deployOrder; + } - this.descriptor = source.descriptor; - this.name = InternString.intern(source.getName()); - this.propertyIndex = source.propertyIndex; + /** + * Set the order this property appears in the bean. + */ + public void setDeployOrder(int deployOrder) { + this.deployOrder = deployOrder; + } - this.indexed = source.isIndexed(); - this.indexName = source.getIndexName(); - this.dbColumn = InternString.intern(override.getDbColumn()); - this.sqlFormulaJoin = InternString.intern(override.getSqlFormulaJoin()); - this.sqlFormulaSelect = InternString.intern(override.getSqlFormulaSelect()); - this.formula = sqlFormulaSelect != null; + public ElPropertyValue buildElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, + boolean propertyDeploy) { + throw new PersistenceException("Not valid on scalar bean property " + getFullBeanName()); + } - this.fetchEager = source.fetchEager; - this.unidirectionalShadow = source.unidirectionalShadow; - this.discriminator = source.discriminator; - this.localEncrypted = source.isLocalEncrypted(); - this.isTransient = source.isTransient(); - this.secondaryTable = source.isSecondaryTable(); - this.secondaryTableJoin = source.secondaryTableJoin; - this.secondaryTableJoinPrefix = source.secondaryTableJoinPrefix; + /** + * Return the BeanDescriptor that owns this property. + */ + public BeanDescriptor getBeanDescriptor() { + return descriptor; + } - this.dbBind = source.getDbBind(); - this.dbEncrypted = source.isDbEncrypted(); - this.dbEncryptedType = source.getDbEncryptedType(); - this.dbEncryptFunction = source.dbEncryptFunction; - this.dbRead = source.isDbRead(); - this.dbInsertable = source.isDbInsertable(); - this.dbUpdatable = source.isDbUpdatable(); - this.nullable = source.isNullable(); - this.unique = source.isUnique(); - this.naturalKey = source.isNaturalKey(); - this.dbLength = source.getDbLength(); - this.dbScale = source.getDbScale(); - this.dbColumnDefn = InternString.intern(source.getDbColumnDefn()); - this.dbConstraintExpression = InternString.intern(source.getDbConstraintExpression()); + /** + * Return true is this is a simple scalar property. + */ + public boolean isScalar() { + return true; + } - this.inherited = source.isInherited(); - this.owningType = source.owningType; - this.local = owningType.equals(descriptor.getBeanType()); + /** + * Return true if this property is based on a formula. + */ + public boolean isFormula() { + return formula; + } - this.version = source.isVersion(); - this.embedded = source.isEmbedded(); - this.id = source.isId(); - this.generatedProperty = source.getGeneratedProperty(); - this.getter = source.getter; - this.setter = source.setter; - this.extraAttributeMap = source.extraAttributeMap; - this.defaultValue = source.getDefaultValue(); - this.dbType = source.getDbType(); - this.scalarType = source.scalarType; - this.lob = isLobType(dbType); - this.propertyType = source.getPropertyType(); - this.field = source.getField(); - - this.elPlaceHolder = override.replace(source.elPlaceHolder, source.dbColumn); - this.elPlaceHolderEncrypted = override.replace(source.elPlaceHolderEncrypted, source.dbColumn); + /** + * Return true if this property maps to the inheritance discriminator column. + */ + public boolean isDiscriminator() { + return discriminator; + } - this.jsonSerialize = source.jsonSerialize; - this.jsonDeserialize = source.jsonDeserialize; + /** + * Return true if the underlying type is mutable. + */ + public boolean isMutableScalarType() { + return scalarType != null && scalarType.isMutable(); + } + + /** + * Return the encrypt key for the column matching this property. + */ + public EncryptKey getEncryptKey() { + return descriptor.getEncryptKey(this); + } + + public String getDecryptProperty(String propertyName) { + return dbEncryptFunction.getDecryptSql(propertyName); + } + + public String getDecryptSql() { + return dbEncryptFunction.getDecryptSql(this.getDbColumn()); + } + + public String getDecryptSql(String tableAlias) { + return dbEncryptFunction.getDecryptSql(tableAlias + "." + this.getDbColumn()); + } + + /** + * Add any extra joins required to support this property. Generally a no + * operation except for a OneToOne exported. + */ + public void appendFrom(DbSqlContext ctx, SqlJoinType joinType) { + if (formula && sqlFormulaJoin != null) { + ctx.appendFormulaJoin(sqlFormulaJoin, joinType); + + } else if (secondaryTableJoin != null) { + + String relativePrefix = ctx.getRelativePrefix(secondaryTableJoinPrefix); + secondaryTableJoin.addJoin(joinType, relativePrefix, ctx); } + } - /** - * Initialise the property before returning to client code. Used to - * initialise variables that can't be done in construction due to recursive - * issues. - */ - public void initialise() { - // do nothing for normal BeanProperty - if (!isTransient && scalarType == null) { - String msg = "No ScalarType assigned to " + descriptor.getFullName() + "." + getName(); - throw new RuntimeException(msg); - } + /** + * Returns null unless this property is using a secondary table. In that + * case this returns the logical property prefix. + */ + public String getSecondaryTableJoinPrefix() { + return secondaryTableJoinPrefix; + } + + public void appendSelect(DbSqlContext ctx, boolean subQuery) { + if (formula) { + ctx.appendFormulaSelect(sqlFormulaSelect); + + } else if (!isTransient) { + + if (secondaryTableJoin != null) { + String relativePrefix = ctx.getRelativePrefix(secondaryTableJoinPrefix); + ctx.pushTableAlias(relativePrefix); + } + + if (dbEncrypted) { + String decryptSql = getDecryptSql(ctx.peekTableAlias()); + ctx.appendRawColumn(decryptSql); + ctx.addEncryptedProp(this); + + } else { + ctx.appendColumn(dbColumn); + } + + if (secondaryTableJoin != null) { + ctx.popTableAlias(); + } } + } - /** - * Return the order this property appears in the bean. - */ - public int getDeployOrder() { - return deployOrder; + public boolean isAssignableFrom(Class type) { + return owningType.isAssignableFrom(type); + } + + public void loadIgnore(DbReadContext ctx) { + scalarType.loadIgnore(ctx.getDataReader()); + } + + public void load(SqlBeanLoad sqlBeanLoad) throws SQLException { + sqlBeanLoad.load(this); + } + + public void buildSelectExpressionChain(String prefix, List selectChain) { + if (prefix == null) { + selectChain.add(name); + } else { + selectChain.add(prefix + "." + name); } + } - /** - * Set the order this property appears in the bean. - */ - public void setDeployOrder(int deployOrder) { - this.deployOrder = deployOrder; + public Object read(DbReadContext ctx) throws SQLException { + return scalarType.read(ctx.getDataReader()); + } + + public Object readSet(DbReadContext ctx, EntityBean bean, Class type) throws SQLException { + + try { + Object value = scalarType.read(ctx.getDataReader()); + if (bean != null && ((type == null || owningType.isAssignableFrom(type)))) { + setValue(bean, value); + } + return value; + } catch (Exception e) { + throw new PersistenceException("Error readSet on " + descriptor + "." + name, e); } + } - public ElPropertyValue buildElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, - boolean propertyDeploy) { - throw new PersistenceException("Not valid on scalar bean property " + getFullBeanName()); + /** + * Convert the type to the bean type if required. + *

+ * Generally only used to ensure id properties are converted for + * Query.setId() use. + *

+ */ + public Object toBeanType(Object value) { + return scalarType.toBeanType(value); + } + + @SuppressWarnings("unchecked") + public void bind(DataBind b, Object value) throws SQLException { + scalarType.bind(b, value); + } + + @SuppressWarnings(value = "unchecked") + public void writeData(DataOutput dataOutput, Object value) throws IOException { + scalarType.writeData(dataOutput, value); + } + + public Object readData(DataInput dataInput) throws IOException { + return scalarType.readData(dataInput); + } + + public BeanProperty getBeanProperty() { + return this; + } + + public boolean isIndexed() { + return indexed; + } + + public String getIndexName() { + return indexName; + } + + /** + * Return true if this object is part of an inheritance hierarchy. + */ + public boolean isInherited() { + return inherited; + } + + /** + * Return true is this type is not from a super type. + */ + public boolean isLocal() { + return local; + } + + /** + * Set the value of the property without interception or + * PropertyChangeSupport. + */ + public void setValue(EntityBean bean, Object value) { + try { + setter.set(bean, value); + } catch (Exception ex) { + String beanType = bean == null ? "null" : bean.getClass().getName(); + String msg = "set " + name + " on [" + descriptor + "] arg[" + value + "] type[" + beanType + + "] threw error"; + throw new RuntimeException(msg, ex); } + } - /** - * Return the BeanDescriptor that owns this property. - */ - public BeanDescriptor getBeanDescriptor() { - return descriptor; + /** + * Set the value of the property. + */ + public void setValueIntercept(EntityBean bean, Object value) { + try { + setter.setIntercept(bean, value); + } catch (Exception ex) { + String beanType = bean == null ? "null" : bean.getClass().getName(); + String msg = "setIntercept " + name + " on [" + descriptor + "] arg[" + value + "] type[" + beanType + + "] threw error"; + throw new RuntimeException(msg, ex); } + } - /** - * Return true is this is a simple scalar property. - */ - public boolean isScalar() { + public Object getCacheDataValue(EntityBean bean) { + return getValue(bean); + } + + public void setCacheDataValue(EntityBean bean, Object cacheData) { + setValue(bean, cacheData); + } + + /** + * Get the property value from a compound value type. + */ + public Object getValueObject(Object bean) { + throw new RuntimeException("Expected to be called only on BeanPropertyCompoundScalar"); + } + + /** + * Return the value of the property method. + */ + public Object getValue(EntityBean bean) { + try { + return getter.get(bean); + } catch (Exception ex) { + String beanType = bean == null ? "null" : bean.getClass().getName(); + String msg = "get " + name + " on [" + descriptor + "] type[" + beanType + "] threw error."; + throw new RuntimeException(msg, ex); + } + } + + public Object getValueIntercept(EntityBean bean) { + try { + return getter.getIntercept(bean); + } catch (Exception ex) { + String beanType = bean == null ? "null" : bean.getClass().getName(); + String msg = "getIntercept " + name + " on [" + descriptor + "] type[" + beanType + "] threw error."; + throw new RuntimeException(msg, ex); + } + } + + public Object elConvertType(Object value) { + if (value == null) { + return null; + } + return convertToLogicalType(value); + } + + public void elSetValue(EntityBean bean, Object value, boolean populate) { + if (bean != null) { + // Not using setValueIntercept at this stage + setValue(bean, value); + } + } + + public Object elGetValue(EntityBean bean) { + if (bean == null) { + return null; + } + return getValueIntercept(bean); + } + + public Object elGetReference(EntityBean bean) { + throw new RuntimeException("Not expected to call this"); + } + + /** + * Return the name of the property. + */ + public String getName() { + return name; + } + + /** + * Return the position of this property in the enhanced bean. + */ + public int getPropertyIndex() { + return propertyIndex; + } + + public String getElName() { + return name; + } + + @Override + public boolean containsFormulaWithJoin() { + return formula && sqlFormulaJoin != null; + } + + public boolean containsManySince(String sinceProperty) { + return containsMany(); + } + + public boolean containsMany() { + return false; + } + + public Object[] getAssocOneIdValues(EntityBean bean) { + // Returns null as not an AssocOne. + return null; + } + + public String getAssocOneIdExpr(String prefix, String operator) { + // Returns null as not an AssocOne. + return null; + } + + public String getAssocIdInExpr(String prefix) { + // Returns null as not an AssocOne. + return null; + } + + public String getAssocIdInValueExpr(int size) { + // Returns null as not an AssocOne. + return null; + } + + public boolean isAssocId() { + // Returns false - override in BeanPropertyAssocOne. + return false; + } + + public boolean isAssocProperty() { + // Returns false - override in BeanPropertyAssocOne. + return false; + } + + public String getElPlaceholder(boolean encrypted) { + return encrypted ? elPlaceHolderEncrypted : elPlaceHolder; + } + + public String getElPrefix() { + return secondaryTableJoinPrefix; + } + + /** + * Return the full name of this property. + */ + public String getFullBeanName() { + return descriptor.getFullName() + "." + name; + } + + /** + * Return true if the mutable value is considered dirty. + * This is only used for 'mutable' scalar types like hstore etc. + */ + public boolean isDirtyValue(Object value) { + return scalarType.isDirty(value); + } + + /** + * Return the scalarType. + */ + @SuppressWarnings(value = "unchecked") + public ScalarType getScalarType() { + return scalarType; + } + + public StringFormatter getStringFormatter() { + return scalarType; + } + + public StringParser getStringParser() { + return scalarType; + } + + public boolean isDateTimeCapable() { + return scalarType != null && scalarType.isDateTimeCapable(); + } + + public int getJdbcType() { + return scalarType == null ? 0 : scalarType.getJdbcType(); + } + + public Object parseDateTime(long systemTimeMillis) { + return scalarType.convertFromMillis(systemTimeMillis); + } + + /** + * Return the DB max length (varchar) or precision (decimal). + */ + public int getDbLength() { + return dbLength; + } + + /** + * Return the DB scale for numeric columns. + */ + public int getDbScale() { + return dbScale; + } + + /** + * Return a specific column DDL definition if specified (otherwise null). + */ + public String getDbColumnDefn() { + return dbColumnDefn; + } + + /** + * Return the DB constraint expression (can be null). + *

+ * For an Enum returns IN expression for the set of Enum values. + *

+ */ + public String getDbConstraintExpression() { + return dbConstraintExpression; + } + + /** + * Return the DB column type definition. + */ + public String renderDbType(DbType dbType) { + if (dbColumnDefn != null) { + return dbColumnDefn; + } + return dbType.renderType(dbLength, dbScale); + } + + /** + * Return the bean Field associated with this property. + */ + public Field getField() { + return field; + } + + /** + * Return the GeneratedValue. Used to generate update timestamp etc. + */ + public GeneratedProperty getGeneratedProperty() { + return generatedProperty; + } + + /** + * Return true if this is the natural key property. + */ + public boolean isNaturalKey() { + return naturalKey; + } + + /** + * Return true if this property is mandatory. + */ + public boolean isNullable() { + return nullable; + } + + /** + * Return true if DDL Not NULL constraint should be defined for this column + * based on it being a version column or having a generated property. + */ + public boolean isDDLNotNull() { + return isVersion() || (generatedProperty != null && generatedProperty.isDDLNotNullable()); + } + + /** + * Return true if the DB column should be unique. + */ + public boolean isUnique() { + return unique; + } + + /** + * Return true if the property is transient. + */ + public boolean isTransient() { + return isTransient; + } + + /** + * Return true if this property is loadable from a resultSet. + */ + public boolean isLoadProperty() { + return !isTransient || formula; + } + + /** + * Return true if this is a version column used for concurrency checking. + */ + public boolean isVersion() { + return version; + } + + /** + * The database column name this is mapped to. + */ + public String getDbColumn() { + return dbColumn; + } + + /** + * Return the database jdbc data type this is mapped to. + */ + public int getDbType() { + return dbType; + } + + /** + * Perform DB to Logical type conversion (if necessary). + */ + public Object convertToLogicalType(Object value) { + if (scalarType != null) { + return scalarType.toBeanType(value); + } + return value; + } + + /** + * Return true if by default this property is set to fetch eager. + * Lob's usually default to fetch lazy. + */ + public boolean isFetchEager() { + return fetchEager; + } + + /** + * Return true if this is mapped to a Clob Blob LongVarchar or + * LongVarbinary. + */ + public boolean isLob() { + return lob; + } + + private boolean isLobType(int type) { + switch (type) { + case Types.CLOB: + return true; + case Types.BLOB: + return true; + case Types.LONGVARBINARY: + return true; + case Types.LONGVARCHAR: return true; - } - /** - * Return true if this property is based on a formula. - */ - public boolean isFormula() { - return formula; - } - - /** - * Return true if this property maps to the inheritance discriminator column. - */ - public boolean isDiscriminator() { - return discriminator; - } - - /** - * Return true if the underlying type is mutable. - */ - public boolean isMutableScalarType() { - return scalarType != null && scalarType.isMutable(); - } - - /** - * Return the encrypt key for the column matching this property. - */ - public EncryptKey getEncryptKey() { - return descriptor.getEncryptKey(this); - } - - public String getDecryptProperty(String propertyName) { - return dbEncryptFunction.getDecryptSql(propertyName); - } - - public String getDecryptSql() { - return dbEncryptFunction.getDecryptSql(this.getDbColumn()); - } - - public String getDecryptSql(String tableAlias) { - return dbEncryptFunction.getDecryptSql(tableAlias + "." + this.getDbColumn()); - } - - /** - * Add any extra joins required to support this property. Generally a no - * operation except for a OneToOne exported. - */ - public void appendFrom(DbSqlContext ctx, SqlJoinType joinType) { - if (formula && sqlFormulaJoin != null) { - ctx.appendFormulaJoin(sqlFormulaJoin, joinType); - - } else if (secondaryTableJoin != null) { - - String relativePrefix = ctx.getRelativePrefix(secondaryTableJoinPrefix); - secondaryTableJoin.addJoin(joinType, relativePrefix, ctx); - } - } - - /** - * Returns null unless this property is using a secondary table. In that - * case this returns the logical property prefix. - */ - public String getSecondaryTableJoinPrefix() { - return secondaryTableJoinPrefix; - } - - public void appendSelect(DbSqlContext ctx, boolean subQuery) { - if (formula) { - ctx.appendFormulaSelect(sqlFormulaSelect); - - } else if (!isTransient) { - - if (secondaryTableJoin != null) { - String relativePrefix = ctx.getRelativePrefix(secondaryTableJoinPrefix); - ctx.pushTableAlias(relativePrefix); - } - - if (dbEncrypted) { - String decryptSql = getDecryptSql(ctx.peekTableAlias()); - ctx.appendRawColumn(decryptSql); - ctx.addEncryptedProp(this); - - } else { - ctx.appendColumn(dbColumn); - } - - if (secondaryTableJoin != null) { - ctx.popTableAlias(); - } - } - } - - public boolean isAssignableFrom(Class type) { - return owningType.isAssignableFrom(type); - } - - public void loadIgnore(DbReadContext ctx) { - scalarType.loadIgnore(ctx.getDataReader()); - } - - public void load(SqlBeanLoad sqlBeanLoad) throws SQLException { - sqlBeanLoad.load(this); - } - - public void buildSelectExpressionChain(String prefix, List selectChain) { - if (prefix == null) { - selectChain.add(name); - } else { - selectChain.add(prefix + "." + name); - } - } - - public Object read(DbReadContext ctx) throws SQLException { - return scalarType.read(ctx.getDataReader()); - } - - public Object readSet(DbReadContext ctx, EntityBean bean, Class type) throws SQLException { - - try { - Object value = scalarType.read(ctx.getDataReader()); - if (bean != null && ((type == null || owningType.isAssignableFrom(type)))) { - setValue(bean, value); - } - return value; - } catch (Exception e) { - throw new PersistenceException("Error readSet on " + descriptor + "." + name, e); - } - } - - /** - * Convert the type to the bean type if required. - *

- * Generally only used to ensure id properties are converted for - * Query.setId() use. - *

- */ - public Object toBeanType(Object value) { - return scalarType.toBeanType(value); - } - - @SuppressWarnings("unchecked") - public void bind(DataBind b, Object value) throws SQLException { - scalarType.bind(b, value); - } - - public void writeData(DataOutput dataOutput, Object value) throws IOException { - scalarType.writeData(dataOutput, value); - } - - public Object readData(DataInput dataInput) throws IOException { - return scalarType.readData(dataInput); - } - - public BeanProperty getBeanProperty() { - return this; - } - - public boolean isIndexed() { - return indexed; - } - - public String getIndexName() { - return indexName; - } - - /** - * Return true if this object is part of an inheritance hierarchy. - */ - public boolean isInherited() { - return inherited; - } - - /** - * Return true is this type is not from a super type. - */ - public boolean isLocal() { - return local; - } - - /** - * Set the value of the property without interception or - * PropertyChangeSupport. - */ - public void setValue(EntityBean bean, Object value) { - try { - setter.set(bean, value); - } catch (Exception ex) { - String beanType = bean == null ? "null" : bean.getClass().getName(); - String msg = "set " + name + " on [" + descriptor + "] arg[" + value + "] type[" + beanType - + "] threw error"; - throw new RuntimeException(msg, ex); - } - } - - /** - * Set the value of the property. - */ - public void setValueIntercept(EntityBean bean, Object value) { - try { - setter.setIntercept(bean, value); - } catch (Exception ex) { - String beanType = bean == null ? "null" : bean.getClass().getName(); - String msg = "setIntercept " + name + " on [" + descriptor + "] arg[" + value + "] type[" + beanType - + "] threw error"; - throw new RuntimeException(msg, ex); - } - } - - public Object getCacheDataValue(EntityBean bean) { - return getValue(bean); - } - - public void setCacheDataValue(EntityBean bean, Object cacheData) { - setValue(bean, cacheData); - } - - /** - * Get the property value from a compound value type. - */ - public Object getValueObject(Object bean) { - throw new RuntimeException("Expected to be called only on BeanPropertyCompoundScalar"); - } - - /** - * Return the value of the property method. - */ - public Object getValue(EntityBean bean) { - try { - return getter.get(bean); - } catch (Exception ex) { - String beanType = bean == null ? "null" : bean.getClass().getName(); - String msg = "get " + name + " on [" + descriptor + "] type[" + beanType + "] threw error."; - throw new RuntimeException(msg, ex); - } - } - - public Object getValueIntercept(EntityBean bean) { - try { - return getter.getIntercept(bean); - } catch (Exception ex) { - String beanType = bean == null ? "null" : bean.getClass().getName(); - String msg = "getIntercept " + name + " on [" + descriptor + "] type[" + beanType + "] threw error."; - throw new RuntimeException(msg, ex); - } - } - - public Object elConvertType(Object value) { - if (value == null) { - return null; - } - return convertToLogicalType(value); - } - - public void elSetValue(EntityBean bean, Object value, boolean populate) { - if (bean != null) { - // Not using setValueIntercept at this stage - setValue(bean, value); - } - } - - public Object elGetValue(EntityBean bean) { - if (bean == null) { - return null; - } - return getValueIntercept(bean); - } - - public Object elGetReference(EntityBean bean) { - throw new RuntimeException("Not expected to call this"); - } - - /** - * Return the name of the property. - */ - public String getName() { - return name; - } - - /** - * Return the position of this property in the enhanced bean. - */ - public int getPropertyIndex() { - return propertyIndex; - } - - public String getElName() { - return name; - } - - @Override - public boolean containsFormulaWithJoin() { - return formula && sqlFormulaJoin != null; - } - - public boolean containsManySince(String sinceProperty) { - return containsMany(); - } - - public boolean containsMany() { + default: return false; } + } - public Object[] getAssocOneIdValues(EntityBean bean) { - // Returns null as not an AssocOne. - return null; - } + /** + * Return the DB bind parameter. Typically is "?" but different for + * encrypted bind. + */ + public String getDbBind() { + return dbBind; + } - public String getAssocOneIdExpr(String prefix, String operator) { - // Returns null as not an AssocOne. - return null; - } + /** + * Returns true if DB encrypted. + */ + public boolean isLocalEncrypted() { + return localEncrypted; + } - public String getAssocIdInExpr(String prefix) { - // Returns null as not an AssocOne. - return null; - } + /** + * Return true if this property is stored encrypted. + */ + public boolean isDbEncrypted() { + return dbEncrypted; + } - public String getAssocIdInValueExpr(int size) { - // Returns null as not an AssocOne. - return null; - } + public int getDbEncryptedType() { + return dbEncryptedType; + } - public boolean isAssocId() { - // Returns false - override in BeanPropertyAssocOne. - return false; - } + /** + * Return true if this property should be included in an Insert. + */ + public boolean isDbInsertable() { + return dbInsertable; + } - public boolean isAssocProperty() { - // Returns false - override in BeanPropertyAssocOne. - return false; - } + /** + * Return true if this property should be included in an Update. + */ + public boolean isDbUpdatable() { + return dbUpdatable; + } - public String getElPlaceholder(boolean encrypted) { - return encrypted ? elPlaceHolderEncrypted : elPlaceHolder; - } + /** + * Return true if this property is included in database queries. + */ + public boolean isDbRead() { + return dbRead; + } - public String getElPrefix() { - return secondaryTableJoinPrefix; - } + /** + * Return true if this property is based on a secondary table (not the base + * table). + */ + public boolean isSecondaryTable() { + return secondaryTable; + } - /** - * Return the full name of this property. - */ - public String getFullBeanName() { - return descriptor.getFullName() + "." + name; - } + /** + * Return the property type. + */ + public Class getPropertyType() { + return propertyType; + } - /** - * Return true if the mutable value is considered dirty. - * This is only used for 'mutable' scalar types like hstore etc. - */ - public boolean isDirtyValue(Object value) { - return scalarType.isDirty(value); - } - - /** - * Return the scalarType. - */ - public ScalarType getScalarType() { - return scalarType; - } + /** + * Return true if this is included in the unique id. + */ + public boolean isId() { + return id; + } - public StringFormatter getStringFormatter() { - return scalarType; - } + /** + * Return true if this is an Embedded property. In this case it shares the + * table and primary key of its owner object. + */ + public boolean isEmbedded() { + return embedded; + } - public StringParser getStringParser() { - return scalarType; - } + /** + * Return the default value. + */ + public Object getDefaultValue() { + return defaultValue; + } - public boolean isDateTimeCapable() { - return scalarType != null && scalarType.isDateTimeCapable(); - } - - public int getJdbcType() { - return scalarType == null ? 0 : scalarType.getJdbcType(); - } + public String toString() { + return name; + } - public Object parseDateTime(long systemTimeMillis) { - return scalarType.convertFromMillis(systemTimeMillis); - } - - /** - * Return the DB max length (varchar) or precision (decimal). - */ - public int getDbLength() { - return dbLength; - } - - /** - * Return the DB scale for numeric columns. - */ - public int getDbScale() { - return dbScale; - } - - /** - * Return a specific column DDL definition if specified (otherwise null). - */ - public String getDbColumnDefn() { - return dbColumnDefn; - } - - /** - * Return the DB constraint expression (can be null). - *

- * For an Enum returns IN expression for the set of Enum values. - *

- */ - public String getDbConstraintExpression() { - return dbConstraintExpression; - } - - /** - * Return the DB column type definition. - */ - public String renderDbType(DbType dbType) { - if (dbColumnDefn != null) { - return dbColumnDefn; - } - return dbType.renderType(dbLength, dbScale); - } - - /** - * Return the bean Field associated with this property. - */ - public Field getField() { - return field; - } - - /** - * Return the GeneratedValue. Used to generate update timestamp etc. - */ - public GeneratedProperty getGeneratedProperty() { - return generatedProperty; - } - - /** - * Return true if this is the natural key property. - */ - public boolean isNaturalKey() { - return naturalKey; - } - - /** - * Return true if this property is mandatory. - */ - public boolean isNullable() { - return nullable; - } - - /** - * Return true if DDL Not NULL constraint should be defined for this column - * based on it being a version column or having a generated property. - */ - public boolean isDDLNotNull() { - return isVersion() || (generatedProperty != null && generatedProperty.isDDLNotNullable()); - } - - /** - * Return true if the DB column should be unique. - */ - public boolean isUnique() { - return unique; - } - - /** - * Return true if the property is transient. - */ - public boolean isTransient() { - return isTransient; - } - - /** - * Return true if this property is loadable from a resultSet. - */ - public boolean isLoadProperty() { - return !isTransient || formula; - } - - /** - * Return true if this is a version column used for concurrency checking. - */ - public boolean isVersion() { - return version; - } - - /** - * The database column name this is mapped to. - */ - public String getDbColumn() { - return dbColumn; - } - - /** - * Return the database jdbc data type this is mapped to. - */ - public int getDbType() { - return dbType; - } - - /** - * Perform DB to Logical type conversion (if necessary). - */ - public Object convertToLogicalType(Object value) { - if (scalarType != null) { - return scalarType.toBeanType(value); - } - return value; - } - - /** - * Return true if by default this property is set to fetch eager. - * Lob's usually default to fetch lazy. - */ - public boolean isFetchEager() { - return fetchEager; - } - - /** - * Return true if this is mapped to a Clob Blob LongVarchar or - * LongVarbinary. - */ - public boolean isLob() { - return lob; - } - - private boolean isLobType(int type) { - switch (type) { - case Types.CLOB: - return true; - case Types.BLOB: - return true; - case Types.LONGVARBINARY: - return true; - case Types.LONGVARCHAR: - return true; - - default: - return false; - } - } - - /** - * Return the DB bind parameter. Typically is "?" but different for - * encrypted bind. - */ - public String getDbBind() { - return dbBind; - } - - /** - * Returns true if DB encrypted. - */ - public boolean isLocalEncrypted() { - return localEncrypted; - } - - /** - * Return true if this property is stored encrypted. - */ - public boolean isDbEncrypted() { - return dbEncrypted; - } - - public int getDbEncryptedType() { - return dbEncryptedType; - } - - /** - * Return true if this property should be included in an Insert. - */ - public boolean isDbInsertable() { - return dbInsertable; - } - - /** - * Return true if this property should be included in an Update. - */ - public boolean isDbUpdatable() { - return dbUpdatable; - } - - /** - * Return true if this property is included in database queries. - */ - public boolean isDbRead() { - return dbRead; - } - - /** - * Return true if this property is based on a secondary table (not the base - * table). - */ - public boolean isSecondaryTable() { - return secondaryTable; - } - - /** - * Return the property type. - */ - public Class getPropertyType() { - return propertyType; - } - - /** - * Return true if this is included in the unique id. - */ - public boolean isId() { - return id; - } - - /** - * Return true if this is an Embedded property. In this case it shares the - * table and primary key of its owner object. - */ - public boolean isEmbedded() { - return embedded; - } - - /** - * Return the default value. - */ - public Object getDefaultValue() { - return defaultValue; - } - - public String toString() { - return name; - } + @SuppressWarnings(value = "unchecked") public void jsonWrite(WriteJson writeJson, EntityBean bean) throws IOException { if (!jsonSerialize) { return; diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyAssoc.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyAssoc.java index 76382aa43..66fed4107 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyAssoc.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyAssoc.java @@ -74,7 +74,7 @@ public abstract class BeanPropertyAssoc extends BeanProperty { * Construct the property. */ public BeanPropertyAssoc(BeanDescriptorMap owner, BeanDescriptor descriptor, DeployBeanPropertyAssoc deploy) { - super(owner, descriptor, deploy); + super(descriptor, deploy); this.extraWhere = InternString.intern(deploy.getExtraWhere()); this.isOuterJoin = deploy.isOuterJoin(); this.beanTable = deploy.getBeanTable(); diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyCompound.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyCompound.java index d73f74fde..a4a043e42 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyCompound.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyCompound.java @@ -28,171 +28,169 @@ import com.fasterxml.jackson.core.JsonParser; */ public class BeanPropertyCompound extends BeanProperty { - private final CtCompoundType compoundType; + private final CtCompoundType compoundType; - /** - * Type Converter for scala.Option and similar type wrapping. - */ - @SuppressWarnings("rawtypes") - private final ScalarTypeConverter typeConverter; - - private final BeanProperty[] scalarProperties; + /** + * Type Converter for scala.Option and similar type wrapping. + */ + @SuppressWarnings("rawtypes") + private final ScalarTypeConverter typeConverter; - private final LinkedHashMap propertyMap = new LinkedHashMap(); + private final BeanProperty[] scalarProperties; - private final LinkedHashMap nonScalarMap = new LinkedHashMap(); + private final LinkedHashMap propertyMap = new LinkedHashMap(); - private final BeanPropertyCompoundRoot root; - - /** - * Create the property. - */ - public BeanPropertyCompound(BeanDescriptorMap owner, BeanDescriptor descriptor, DeployBeanPropertyCompound deploy) { + private final LinkedHashMap nonScalarMap = new LinkedHashMap(); - super(owner, descriptor, deploy); + /** + * Create the property. + */ + public BeanPropertyCompound(BeanDescriptorMap owner, BeanDescriptor descriptor, DeployBeanPropertyCompound deploy) { - this.compoundType = deploy.getCompoundType(); - this.typeConverter = deploy.getTypeConverter(); - - this.root = deploy.getFlatProperties(owner, descriptor); + super(descriptor, deploy); - this.scalarProperties = root.getScalarProperties(); + this.compoundType = deploy.getCompoundType(); + this.typeConverter = deploy.getTypeConverter(); - for (int i = 0; i < scalarProperties.length; i++) { - propertyMap.put(scalarProperties[i].getName(), scalarProperties[i]); - } + BeanPropertyCompoundRoot root = deploy.getFlatProperties(owner, descriptor); - List nonScalarPropsList = root.getNonScalarProperties(); - - for (int i = 0; i < nonScalarPropsList.size(); i++) { - CtCompoundProperty ctProp = nonScalarPropsList.get(i); - CtCompoundPropertyElAdapter adapter = new CtCompoundPropertyElAdapter(ctProp); - nonScalarMap.put(ctProp.getRelativeName(), adapter); - } + this.scalarProperties = root.getScalarProperties(); + for (int i = 0; i < scalarProperties.length; i++) { + propertyMap.put(scalarProperties[i].getName(), scalarProperties[i]); } - @Override - public void initialise() { - // do nothing for normal BeanProperty - if (!isTransient && compoundType == null) { - String msg = "No cvoInternalType assigned to " + descriptor.getFullName() + "." + getName(); - throw new RuntimeException(msg); - } + List nonScalarPropsList = root.getNonScalarProperties(); + + for (int i = 0; i < nonScalarPropsList.size(); i++) { + CtCompoundProperty ctProp = nonScalarPropsList.get(i); + CtCompoundPropertyElAdapter adapter = new CtCompoundPropertyElAdapter(ctProp); + nonScalarMap.put(ctProp.getRelativeName(), adapter); } - @Override - public void setDeployOrder(int deployOrder) { - this.deployOrder = deployOrder; - for (CtCompoundPropertyElAdapter adapter : nonScalarMap.values()) { - adapter.setDeployOrder(deployOrder); - } + } + + @Override + public void initialise() { + // do nothing for normal BeanProperty + if (!isTransient && compoundType == null) { + String msg = "No cvoInternalType assigned to " + descriptor.getFullName() + "." + getName(); + throw new RuntimeException(msg); + } + } + + @Override + public void setDeployOrder(int deployOrder) { + this.deployOrder = deployOrder; + for (CtCompoundPropertyElAdapter adapter : nonScalarMap.values()) { + adapter.setDeployOrder(deployOrder); + } + } + + public ElPropertyValue buildElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) { + + if (chain == null) { + chain = new ElPropertyChainBuilder(true, propName); } - public ElPropertyValue buildElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) { + // first add this property + chain.add(this); - if (chain == null) { - chain = new ElPropertyChainBuilder(true, propName); - } - - // first add this property - chain.add(this); - - // handle all the rest of the chain handled by the - // BeanProperty (all depth for nested compound type) - BeanProperty p = propertyMap.get(remainder); - if (p != null) { - return chain.add(p).build(); - } - CtCompoundPropertyElAdapter elAdapter = nonScalarMap.get(remainder); - if (elAdapter == null) { - throw new RuntimeException("property [" + remainder + "] not found in " + getFullBeanName()); - } - return chain.add(elAdapter).build(); + // handle all the rest of the chain handled by the + // BeanProperty (all depth for nested compound type) + BeanProperty p = propertyMap.get(remainder); + if (p != null) { + return chain.add(p).build(); } - - @Override - public void appendSelect(DbSqlContext ctx, boolean subQuery) { - if (!isTransient) { - for (int i = 0; i < scalarProperties.length; i++) { - scalarProperties[i].appendSelect(ctx, subQuery); - } - } + CtCompoundPropertyElAdapter elAdapter = nonScalarMap.get(remainder); + if (elAdapter == null) { + throw new RuntimeException("property [" + remainder + "] not found in " + getFullBeanName()); } + return chain.add(elAdapter).build(); + } - public BeanProperty[] getScalarProperties() { - return scalarProperties; - } - - @Override - public Object readSet(DbReadContext ctx, EntityBean bean, Class type) throws SQLException { - - boolean assignable = (type == null || owningType.isAssignableFrom(type)); - - Object v = compoundType.read(ctx.getDataReader()); - if (assignable) { - setValue(bean, v); - } - - return v; - } - - /** - * Read the data from the resultSet effectively ignoring it and returning - * null. - */ - @SuppressWarnings("unchecked") - @Override - public Object read(DbReadContext ctx) throws SQLException { - - Object v = compoundType.read(ctx.getDataReader()); - if (typeConverter != null){ - v = typeConverter.wrapValue(v); - } - return v; - } - - @Override - public void loadIgnore(DbReadContext ctx) { - compoundType.loadIgnore(ctx.getDataReader()); - } - - @Override - public void load(SqlBeanLoad sqlBeanLoad) throws SQLException { - sqlBeanLoad.load(this); - } - - @Override - public Object elGetReference(EntityBean bean) { - return bean; - } - - public void jsonWrite(WriteJson ctx, EntityBean bean) throws IOException { - if (!jsonSerialize) { - return; - } - Object value = getValueIntercept(bean); - if (value == null) { - ctx.writeNull(name); - } else { - compoundType.jsonWrite(ctx, value, name); - } - } - - public void jsonRead(JsonParser ctx, EntityBean bean) throws IOException { - - if (!jsonDeserialize) { - return; - } - - Object value = EJson.parse(ctx); - if (value == null) { - setValue(bean, null); - } else { - @SuppressWarnings("unchecked") - Map map = (Map)value; - Object objValue = compoundType.jsonConvert(map); - setValue(bean, objValue); + @Override + public void appendSelect(DbSqlContext ctx, boolean subQuery) { + if (!isTransient) { + for (int i = 0; i < scalarProperties.length; i++) { + scalarProperties[i].appendSelect(ctx, subQuery); } } + } + + public BeanProperty[] getScalarProperties() { + return scalarProperties; + } + + @Override + public Object readSet(DbReadContext ctx, EntityBean bean, Class type) throws SQLException { + + boolean assignable = (type == null || owningType.isAssignableFrom(type)); + + Object v = compoundType.read(ctx.getDataReader()); + if (assignable) { + setValue(bean, v); + } + + return v; + } + + /** + * Read the data from the resultSet effectively ignoring it and returning + * null. + */ + @SuppressWarnings("unchecked") + @Override + public Object read(DbReadContext ctx) throws SQLException { + + Object v = compoundType.read(ctx.getDataReader()); + if (typeConverter != null) { + v = typeConverter.wrapValue(v); + } + return v; + } + + @Override + public void loadIgnore(DbReadContext ctx) { + compoundType.loadIgnore(ctx.getDataReader()); + } + + @Override + public void load(SqlBeanLoad sqlBeanLoad) throws SQLException { + sqlBeanLoad.load(this); + } + + @Override + public Object elGetReference(EntityBean bean) { + return bean; + } + + public void jsonWrite(WriteJson ctx, EntityBean bean) throws IOException { + if (!jsonSerialize) { + return; + } + Object value = getValueIntercept(bean); + if (value == null) { + ctx.writeNull(name); + } else { + compoundType.jsonWrite(ctx, value, name); + } + } + + public void jsonRead(JsonParser ctx, EntityBean bean) throws IOException { + + if (!jsonDeserialize) { + return; + } + + Object value = EJson.parse(ctx); + if (value == null) { + setValue(bean, null); + } else { + @SuppressWarnings("unchecked") + Map map = (Map) value; + Object objValue = compoundType.jsonConvert(map); + setValue(bean, objValue); + } + } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/transaction/BeanDeltaProperty.java b/src/main/java/com/avaje/ebeaninternal/server/transaction/BeanDeltaProperty.java index 2085af801..eb078a370 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/transaction/BeanDeltaProperty.java +++ b/src/main/java/com/avaje/ebeaninternal/server/transaction/BeanDeltaProperty.java @@ -9,28 +9,28 @@ import com.avaje.ebeaninternal.server.deploy.BeanProperty; public class BeanDeltaProperty { - private final BeanProperty beanProperty; - - private final Object value; - - public BeanDeltaProperty(BeanProperty beanProperty, Object value) { - this.beanProperty = beanProperty; - this.value = value; - } - - public String toString() { - return beanProperty.getName()+":"+value; - } - - public void apply(EntityBean bean) { - beanProperty.setValue(bean, value); - } - - public void writeBinaryMessage(BinaryMessage m) throws IOException { + private final BeanProperty beanProperty; + + private final Object value; + + public BeanDeltaProperty(BeanProperty beanProperty, Object value) { + this.beanProperty = beanProperty; + this.value = value; + } + + public String toString() { + return beanProperty.getName() + ":" + value; + } + + public void apply(EntityBean bean) { + beanProperty.setValue(bean, value); + } + + public void writeBinaryMessage(BinaryMessage m) throws IOException { + + DataOutputStream os = m.getOs(); + os.writeUTF(beanProperty.getName()); + beanProperty.getScalarType().writeData(os, value); + } - DataOutputStream os = m.getOs(); - os.writeUTF(beanProperty.getName()); - beanProperty.getScalarType().writeData(os, value); - } - }