Add Period support via CompoundTypePeriod, rename server/reflect to server/properties

This commit is contained in:
rbygrave
2014-11-18 23:09:26 +13:00
parent 98f6e1e6af
commit 07cdb69a5b
27 changed files with 501 additions and 333 deletions
@@ -62,10 +62,10 @@ import com.avaje.ebeaninternal.server.deploy.parse.ReadAnnotations;
import com.avaje.ebeaninternal.server.deploy.parse.TransientProperties;
import com.avaje.ebeaninternal.server.idgen.UuidIdGenerator;
import com.avaje.ebeaninternal.server.lib.util.Dnode;
import com.avaje.ebeaninternal.server.reflect.BeanReflect;
import com.avaje.ebeaninternal.server.reflect.BeanReflectFactory;
import com.avaje.ebeaninternal.server.reflect.BeanReflectProperties;
import com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflectFactory;
import com.avaje.ebeaninternal.server.properties.BeanPropertyInfo;
import com.avaje.ebeaninternal.server.properties.BeanPropertyInfoFactory;
import com.avaje.ebeaninternal.server.properties.BeanPropertiesReader;
import com.avaje.ebeaninternal.server.properties.EnhanceBeanPropertyInfoFactory;
import com.avaje.ebeaninternal.server.type.TypeManager;
/**
@@ -86,7 +86,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
*/
private final DeployInherit deplyInherit;
private final BeanReflectFactory reflectFactory;
private final BeanPropertyInfoFactory reflectFactory;
private final DeployUtil deployUtil;
@@ -1274,9 +1274,9 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
}
}
private BeanReflectFactory createReflectionFactory() {
private BeanPropertyInfoFactory createReflectionFactory() {
return new EnhanceBeanReflectFactory();
return new EnhanceBeanPropertyInfoFactory();
}
/**
@@ -1295,9 +1295,9 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
Class<?> beanType = desc.getBeanType();
BeanReflectProperties reflectProps = new BeanReflectProperties(beanType);
BeanPropertiesReader reflectProps = new BeanPropertiesReader(beanType);
BeanReflect beanReflect = reflectFactory.create(beanType);
BeanPropertyInfo beanReflect = reflectFactory.create(beanType);
desc.setBeanReflect(beanReflect);
desc.setProperties(reflectProps.getProperties());
@@ -27,8 +27,8 @@ 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.reflect.BeanReflectGetter;
import com.avaje.ebeaninternal.server.reflect.BeanReflectSetter;
import com.avaje.ebeaninternal.server.properties.BeanPropertyGetter;
import com.avaje.ebeaninternal.server.properties.BeanPropertySetter;
import com.avaje.ebeaninternal.server.text.json.WriteJson;
import com.avaje.ebeaninternal.server.type.DataBind;
import com.avaje.ebeaninternal.server.type.ScalarType;
@@ -196,9 +196,9 @@ public class BeanProperty implements ElPropertyValue {
*/
final GeneratedProperty generatedProperty;
final BeanReflectGetter getter;
final BeanPropertyGetter getter;
final BeanReflectSetter setter;
final BeanPropertySetter setter;
final BeanDescriptor<?> descriptor;
@@ -673,7 +673,14 @@ public class BeanProperty implements ElPropertyValue {
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.
*/
@@ -89,19 +89,6 @@ public class BeanPropertyCompound extends BeanProperty {
}
}
/**
* Get the underlying compound type.
*/
@SuppressWarnings("unchecked")
public Object getValueUnderlying(EntityBean bean) {
Object value = getValue(bean);
if (typeConverter != null){
value = typeConverter.unwrapValue(value);
}
return value;
}
public ElPropertyValue buildElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) {
if (chain == null) {
@@ -7,7 +7,7 @@ import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
import com.avaje.ebeaninternal.server.reflect.BeanReflectSetter;
import com.avaje.ebeaninternal.server.properties.BeanPropertySetter;
import com.avaje.ebeaninternal.server.type.CtCompoundProperty;
/**
@@ -22,7 +22,7 @@ import com.avaje.ebeaninternal.server.type.CtCompoundProperty;
*/
public class BeanPropertyCompoundRoot {
private final BeanReflectSetter setter;
private final BeanPropertySetter setter;
/**
* The method used to write the property.
@@ -6,93 +6,100 @@ import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
import com.avaje.ebeaninternal.server.type.CtCompoundProperty;
/**
* A BeanProperty owned by a Compound value object that maps to
* A BeanProperty owned by a Compound value object that maps to
* a real scalar type.
*
* @author rbygrave
*/
public class BeanPropertyCompoundScalar extends BeanProperty {
private final BeanPropertyCompoundRoot rootProperty;
private final CtCompoundProperty ctProperty;
@SuppressWarnings("rawtypes")
private final ScalarTypeConverter typeConverter;
public BeanPropertyCompoundScalar(BeanPropertyCompoundRoot rootProperty, DeployBeanProperty scalarDeploy,
CtCompoundProperty ctProperty, ScalarTypeConverter<?, ?> typeConverter) {
super(scalarDeploy);
this.rootProperty = rootProperty;
this.ctProperty = ctProperty;
this.typeConverter = typeConverter;
}
private final BeanPropertyCompoundRoot rootProperty;
@SuppressWarnings("unchecked")
@Override
public Object getValue(EntityBean valueObject) {
Object val = valueObject;
if (typeConverter != null){
val = typeConverter.unwrapValue(val);
}
return ctProperty.getValue(val);
}
private final CtCompoundProperty ctProperty;
@Override
public void setValue(EntityBean bean, Object value) {
setValueInCompound(bean, value, false);
}
@SuppressWarnings("unchecked")
public void setValueInCompound(EntityBean bean, Object value, boolean intercept) {
Object compoundValue = ctProperty.setValue(bean, value);
if (compoundValue != null){
if (typeConverter != null){
compoundValue = typeConverter.wrapValue(compoundValue);
}
// we are at the top level and we have a compound value
// that we can set using the root property
if (intercept){
rootProperty.setRootValueIntercept(bean, compoundValue);
} else {
rootProperty.setRootValue(bean, compoundValue);
}
}
}
@SuppressWarnings("rawtypes")
private final ScalarTypeConverter typeConverter;
/**
* No interception on embedded scalar values inside a CVO.
*/
@Override
public void setValueIntercept(EntityBean bean, Object value) {
setValueInCompound(bean, value, true);
}
public BeanPropertyCompoundScalar(BeanPropertyCompoundRoot rootProperty, DeployBeanProperty scalarDeploy,
CtCompoundProperty ctProperty, ScalarTypeConverter<?, ?> typeConverter) {
/**
* No interception on embedded scalar values inside a CVO.
*/
@Override
public Object getValueIntercept(EntityBean bean) {
return getValue(bean);
}
super(scalarDeploy);
this.rootProperty = rootProperty;
this.ctProperty = ctProperty;
this.typeConverter = typeConverter;
}
@Override
public Object elGetReference(EntityBean bean) {
return getValue(bean);
/**
* Return one of the scalar values from a compound type.
*/
public Object getValueObject(Object compoundValue) {
if (typeConverter != null) {
compoundValue = typeConverter.unwrapValue(compoundValue);
}
return ctProperty.getValue(compoundValue);
}
@Override
public Object elGetValue(EntityBean bean) {
return getValue(bean);
@SuppressWarnings("unchecked")
@Override
public Object getValue(EntityBean valueObject) {
Object val = valueObject;
if (typeConverter != null) {
val = typeConverter.unwrapValue(val);
}
return ctProperty.getValue(val);
}
@Override
public void elSetValue(EntityBean bean, Object value, boolean populate) {//, boolean reference) {
super.elSetValue(bean, value, populate);
@Override
public void setValue(EntityBean bean, Object value) {
setValueInCompound(bean, value, false);
}
@SuppressWarnings("unchecked")
public void setValueInCompound(EntityBean bean, Object value, boolean intercept) {
Object compoundValue = ctProperty.setValue(bean, value);
if (compoundValue != null) {
if (typeConverter != null) {
compoundValue = typeConverter.wrapValue(compoundValue);
}
// we are at the top level and we have a compound value
// that we can set using the root property
if (intercept) {
rootProperty.setRootValueIntercept(bean, compoundValue);
} else {
rootProperty.setRootValue(bean, compoundValue);
}
}
}
/**
* No interception on embedded scalar values inside a CVO.
*/
@Override
public void setValueIntercept(EntityBean bean, Object value) {
setValueInCompound(bean, value, true);
}
/**
* No interception on embedded scalar values inside a CVO.
*/
@Override
public Object getValueIntercept(EntityBean bean) {
return getValue(bean);
}
@Override
public Object elGetReference(EntityBean bean) {
return getValue(bean);
}
@Override
public Object elGetValue(EntityBean bean) {
return getValue(bean);
}
@Override
public void elSetValue(EntityBean bean, Object value, boolean populate) {//, boolean reference) {
super.elSetValue(bean, value, populate);
}
}
@@ -36,7 +36,7 @@ import com.avaje.ebeaninternal.server.deploy.DRawSqlMeta;
import com.avaje.ebeaninternal.server.deploy.DeployNamedQuery;
import com.avaje.ebeaninternal.server.deploy.DeployNamedUpdate;
import com.avaje.ebeaninternal.server.deploy.InheritInfo;
import com.avaje.ebeaninternal.server.reflect.BeanReflect;
import com.avaje.ebeaninternal.server.properties.BeanPropertyInfo;
/**
* Describes Beans including their deployment information.
@@ -127,7 +127,7 @@ public class DeployBeanDescriptor<T> {
* Used to provide mechanism to new EntityBean instances. Generated code
* faster than reflection at this stage.
*/
private BeanReflect beanReflect;
private BeanPropertyInfo beanReflect;
private String[] properties;
/**
@@ -302,7 +302,7 @@ public class DeployBeanDescriptor<T> {
this.properties = props;
}
public BeanReflect getBeanReflect() {
public BeanPropertyInfo getBeanReflect() {
return beanReflect;
}
@@ -317,7 +317,7 @@ public class DeployBeanDescriptor<T> {
* Set the BeanReflect used to create new instances of an EntityBean. This
* could use reflection or code generation to do this.
*/
public void setBeanReflect(BeanReflect beanReflect) {
public void setBeanReflect(BeanPropertyInfo beanReflect) {
this.beanReflect = beanReflect;
}
@@ -20,8 +20,8 @@ import com.avaje.ebeaninternal.server.core.InternString;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
import com.avaje.ebeaninternal.server.reflect.BeanReflectGetter;
import com.avaje.ebeaninternal.server.reflect.BeanReflectSetter;
import com.avaje.ebeaninternal.server.properties.BeanPropertyGetter;
import com.avaje.ebeaninternal.server.properties.BeanPropertySetter;
import com.avaje.ebeaninternal.server.type.ScalarType;
import com.avaje.ebeaninternal.server.type.ScalarTypeEnum;
import com.avaje.ebeaninternal.server.type.ScalarTypeWrapper;
@@ -202,9 +202,9 @@ public class DeployBeanProperty {
private int propertyIndex;
private BeanReflectGetter getter;
private BeanPropertyGetter getter;
private BeanReflectSetter setter;
private BeanPropertySetter setter;
/**
* Generator for insert or update timestamp etc.
@@ -439,11 +439,11 @@ public class DeployBeanProperty {
this.propertyIndex = propertyIndex;
}
public BeanReflectGetter getGetter() {
public BeanPropertyGetter getGetter() {
return getter;
}
public BeanReflectSetter getSetter() {
public BeanPropertySetter getSetter() {
return setter;
}
@@ -482,14 +482,14 @@ public class DeployBeanProperty {
/**
* Set the getter used to read the property value from a bean.
*/
public void setGetter(BeanReflectGetter getter) {
public void setGetter(BeanPropertyGetter getter) {
this.getter = getter;
}
/**
* Set the setter used to set the property value to a bean.
*/
public void setSetter(BeanReflectSetter setter) {
public void setSetter(BeanPropertySetter setter) {
this.setter = setter;
}
@@ -21,99 +21,99 @@ import com.avaje.ebeaninternal.server.type.ScalarType;
*/
public class DeployBeanPropertyCompound extends DeployBeanProperty {
final CtCompoundType<?> compoundType;
final CtCompoundType<?> compoundType;
final ScalarTypeConverter<?, ?> typeConverter;
final ScalarTypeConverter<?, ?> typeConverter;
DeployBeanEmbedded deployEmbedded;
/**
* Create the property.
*/
public DeployBeanPropertyCompound(DeployBeanDescriptor<?> desc, Class<?> targetType,
CtCompoundType<?> compoundType, ScalarTypeConverter<?, ?> typeConverter) {
super(desc, targetType, null, null);
this.compoundType = compoundType;
this.typeConverter = typeConverter;
}
DeployBeanEmbedded deployEmbedded;
public BeanPropertyCompoundRoot getFlatProperties(BeanDescriptorMap owner, BeanDescriptor<?> descriptor) {
// get a 'flat' list of all the scalar types, their relative property names
// and also set their matching dbColumn
// represents the root property
BeanPropertyCompoundRoot rootProperty = new BeanPropertyCompoundRoot(this);
// Walk the tree of a compound type collecting the
// scalar types and non-scalar properties
CtCompoundTypeScalarList ctMeta = new CtCompoundTypeScalarList();
compoundType.accumulateScalarTypes(null, ctMeta);
List<BeanProperty> beanPropertyList = new ArrayList<BeanProperty>();
// for each of the scalar types inside a compound value object
// build a BeanPropertyCompoundScalar with appropriate deployment
// information.
for (Entry<String, ScalarType<?>> entry : ctMeta.entries()) {
/**
* Create the property.
*/
public DeployBeanPropertyCompound(DeployBeanDescriptor<?> desc, Class<?> targetType,
CtCompoundType<?> compoundType, ScalarTypeConverter<?, ?> typeConverter) {
String relativePropertyName = entry.getKey();
ScalarType<?> scalarType = entry.getValue();
CtCompoundProperty ctProp = ctMeta.getCompoundType(relativePropertyName);
String dbColumn = relativePropertyName.replace(".", "_");
dbColumn = getDbColumn(relativePropertyName, dbColumn);
DeployBeanProperty deploy = new DeployBeanProperty(null, scalarType.getType(), scalarType, null);
deploy.setScalarType(scalarType);
deploy.setDbColumn(dbColumn);
deploy.setName(relativePropertyName);
deploy.setDbInsertable(true);
deploy.setDbUpdateable(true);
deploy.setDbRead(true);
BeanPropertyCompoundScalar bp = new BeanPropertyCompoundScalar(rootProperty, deploy, ctProp, typeConverter);
beanPropertyList.add(bp);
rootProperty.register(bp);
}
rootProperty.setNonScalarProperties(ctMeta.getNonScalarProperties());
return rootProperty;
}
private String getDbColumn(String propName, String defaultDbColumn){
if (deployEmbedded == null){
return defaultDbColumn;
}
String dbColumn = deployEmbedded.getPropertyColumnMap().get(propName);
return dbColumn == null ? defaultDbColumn : dbColumn;
}
/**
* Return the deploy information specifically for the deployment
* of Embedded beans.
*/
public DeployBeanEmbedded getDeployEmbedded() {
// deployment should be single threaded
if (deployEmbedded == null){
deployEmbedded = new DeployBeanEmbedded();
}
return deployEmbedded;
}
super(desc, targetType, null, null);
this.compoundType = compoundType;
this.typeConverter = typeConverter;
}
public ScalarTypeConverter<?, ?> getTypeConverter() {
return typeConverter;
public BeanPropertyCompoundRoot getFlatProperties(BeanDescriptorMap owner, BeanDescriptor<?> descriptor) {
// get a 'flat' list of all the scalar types, their relative property names
// and also set their matching dbColumn
// represents the root property
BeanPropertyCompoundRoot rootProperty = new BeanPropertyCompoundRoot(this);
// Walk the tree of a compound type collecting the
// scalar types and non-scalar properties
CtCompoundTypeScalarList ctMeta = new CtCompoundTypeScalarList();
compoundType.accumulateScalarTypes(null, ctMeta);
List<BeanProperty> beanPropertyList = new ArrayList<BeanProperty>();
// for each of the scalar types inside a compound value object
// build a BeanPropertyCompoundScalar with appropriate deployment
// information.
for (Entry<String, ScalarType<?>> entry : ctMeta.entries()) {
String relativePropertyName = entry.getKey();
ScalarType<?> scalarType = entry.getValue();
CtCompoundProperty ctProp = ctMeta.getCompoundType(relativePropertyName);
String dbColumn = (getName() + "." + relativePropertyName).replace(".", "_");
dbColumn = getDbColumn(relativePropertyName, dbColumn);
DeployBeanProperty deploy = new DeployBeanProperty(null, scalarType.getType(), scalarType, null);
deploy.setScalarType(scalarType);
deploy.setDbColumn(dbColumn);
deploy.setName(relativePropertyName);
deploy.setDbInsertable(true);
deploy.setDbUpdateable(true);
deploy.setDbRead(true);
BeanPropertyCompoundScalar bp = new BeanPropertyCompoundScalar(rootProperty, deploy, ctProp, typeConverter);
beanPropertyList.add(bp);
rootProperty.register(bp);
}
public CtCompoundType<?> getCompoundType() {
return compoundType;
rootProperty.setNonScalarProperties(ctMeta.getNonScalarProperties());
return rootProperty;
}
private String getDbColumn(String propName, String defaultDbColumn) {
if (deployEmbedded == null) {
return defaultDbColumn;
}
String dbColumn = deployEmbedded.getPropertyColumnMap().get(propName);
return dbColumn == null ? defaultDbColumn : dbColumn;
}
/**
* Return the deploy information specifically for the deployment
* of Embedded beans.
*/
public DeployBeanEmbedded getDeployEmbedded() {
// deployment should be single threaded
if (deployEmbedded == null) {
deployEmbedded = new DeployBeanEmbedded();
}
return deployEmbedded;
}
public ScalarTypeConverter<?, ?> getTypeConverter() {
return typeConverter;
}
public CtCompoundType<?> getCompoundType() {
return compoundType;
}
}
@@ -93,7 +93,7 @@ public class DeployCreateProperties {
}
/**
* reflect the bean properties from Class. Some of these properties may not map to database
* properties the bean properties from Class. Some of these properties may not map to database
* columns.
*/
private void createProperties(DeployBeanDescriptor<?> desc, Class<?> beanType, int level) {