initial rework for new enhancement

This commit is contained in:
Robin Bygrave committed 2013-06-19 20:36:24 +12:00
1 parent eb1eafe98c
commit 4ec62a5772
193 files changed
+2737 -5285

No files matched your search

@@ -34,8 +34,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
private final boolean oneToOneExported;
private final boolean embeddedVersion;
private final boolean importedPrimaryKey;
private final LocalHelp localHelp;
@@ -78,11 +76,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
// Overriding of the columns and use table alias of owning BeanDescriptor
BeanEmbeddedMeta overrideMeta = BeanEmbeddedMetaFactory.create(owner, deploy, descriptor);
embeddedProps = overrideMeta.getProperties();
if (id) {
embeddedVersion = false;
} else {
embeddedVersion = overrideMeta.isEmbeddedVersion();
}
embeddedPropsMap = new HashMap<String, BeanProperty>();
for (int i = 0; i < embeddedProps.length; i++) {
embeddedPropsMap.put(embeddedProps[i].getName(), embeddedProps[i]);
@@ -91,7 +84,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
} else {
embeddedProps = null;
embeddedPropsMap = null;
embeddedVersion = false;
}
localHelp = createHelp(embedded, oneToOneExported);
}
@@ -130,11 +122,11 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
}
}
public void cacheDelete(boolean clearOnNull, Object bean) {
public void cacheDelete(boolean clearOnNull, EntityBean bean) {
if (targetDescriptor.isBeanCaching() && relationshipProperty != null) {
Object assocBean = getValue(bean);
if (assocBean != null) {
Object parentId = targetDescriptor.getId(assocBean);
Object parentId = targetDescriptor.getId((EntityBean)assocBean);
if (parentId != null) {
targetDescriptor.cacheRemoveCachedManyIds(parentId, relationshipProperty.getName());
return;
@@ -249,8 +241,9 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
} else {
int pos = 1;
EntityBean parent = (EntityBean)parentId;
for (int i = 0; i < exportedProperties.length; i++) {
Object embVal = exportedProperties[i].getValue(parentId);
Object embVal = exportedProperties[i].getValue(parent);
q.setParameter(pos++, embVal);
}
}
@@ -270,41 +263,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
return true;
}
private boolean hasChangedEmbedded(Object bean, Object oldValues) {
Object embValue = getValue(oldValues);
if (embValue instanceof EntityBean) {
// the embedded bean .. has its own old values
return ((EntityBean) embValue)._ebean_getIntercept().isNewOrDirty();
}
if (embValue == null) {
return getValue(bean) != null;
} else {
return false;
}
}
@Override
public boolean hasChanged(Object bean, Object oldValues) {
if (embedded) {
return hasChangedEmbedded(bean, oldValues);
}
Object value = getValue(bean);
Object oldVal = getValue(oldValues);
if (oneToOneExported) {
// FKey on other side
return false;
} else {
if (value == null) {
return oldVal != null;
} else if (oldValues == null) {
return true;
}
return importedId.hasChanged(value, oldVal);
}
}
/**
* Return meta data for the deployment of the embedded bean specific to this
* property.
@@ -342,13 +300,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
return oneToOneExported;
}
/**
* Returns true if the associated bean has version properties.
*/
public boolean isEmbeddedVersion() {
return embeddedVersion;
}
/**
* If true this bean maps to the primary key.
*/
@@ -364,7 +315,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
return getPropertyType();
}
public Object getCacheDataValue(Object bean){
public Object getCacheDataValue(EntityBean bean){
if (embedded) {
throw new RuntimeException();
} else {
@@ -372,24 +323,19 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
if (ap == null){
return null;
} else {
return targetDescriptor.getId(ap);
return targetDescriptor.getId((EntityBean)ap);
}
}
}
public void setCacheDataValue(Object bean, Object cacheData, Object oldValues, boolean readOnly){
@Override
public void setCacheDataValue(EntityBean bean, Object cacheData){
if (cacheData != null) {
if (embedded){
throw new RuntimeException();
} else {
T ref = targetDescriptor.createReference(Boolean.FALSE, cacheData, null);
T ref = targetDescriptor.createReference(Boolean.FALSE, cacheData);
setValue(bean, ref);
if (oldValues != null){
setValue(oldValues, ref);
}
if (readOnly){
((EntityBean)ref)._ebean_intercept().setReadOnly(true);
}
}
}
}
@@ -398,7 +344,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
* Return the Id values from the given bean.
*/
@Override
public Object[] getAssocOneIdValues(Object bean) {
public Object[] getAssocOneIdValues(EntityBean bean) {
return targetDescriptor.getIdBinder().getIdValues(bean);
}
@@ -451,7 +397,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
return targetDescriptor.createEntityBean();
}
public void elSetReference(Object bean) {
public void elSetReference(EntityBean bean) {
Object value = getValueIntercept(bean);
if (value != null) {
((EntityBean) value)._ebean_getIntercept().setReference();
@@ -459,7 +405,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
}
@Override
public Object elGetReference(Object bean) {
public Object elGetReference(EntityBean bean) {
Object value = getValueIntercept(bean);
if (value == null) {
value = targetDescriptor.createEntityBean();
@@ -565,7 +511,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
}
@Override
public Object readSet(DbReadContext ctx, Object bean, Class<?> type) throws SQLException {
public Object readSet(DbReadContext ctx, EntityBean bean, Class<?> type) throws SQLException {
boolean assignable = (type == null || owningType.isAssignableFrom(type));
return localHelp.readSet(ctx, bean, assignable);
}
@@ -579,6 +525,24 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
// pass in null for the bean so any data read is ignored
return localHelp.read(ctx);
}
@Override
public void setValue(EntityBean bean, Object value) {
super.setValue(bean, value);
if (value instanceof EntityBean) {
EntityBean embedded = (EntityBean)value;
embedded._ebean_getIntercept().setEmbeddedOwner(bean, propertyIndex);
}
}
@Override
public void setValueIntercept(EntityBean bean, Object value) {
super.setValueIntercept(bean, value);
if (value instanceof EntityBean) {
EntityBean embedded = (EntityBean)value;
embedded._ebean_getIntercept().setEmbeddedOwner(bean, propertyIndex);
}
}
@Override
public void loadIgnore(DbReadContext ctx) {
@@ -615,7 +579,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
abstract Object read(DbReadContext ctx) throws SQLException;
abstract Object readSet(DbReadContext ctx, Object bean, boolean assignAble) throws SQLException;
abstract Object readSet(DbReadContext ctx, EntityBean bean, boolean assignAble) throws SQLException;
abstract void appendSelect(DbSqlContext ctx, boolean subQuery);
@@ -632,7 +596,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
}
@Override
Object readSet(DbReadContext ctx, Object bean, boolean assignable) throws SQLException {
Object readSet(DbReadContext ctx, EntityBean bean, boolean assignable) throws SQLException {
Object dbVal = read(ctx);
if (bean != null && assignable) {
// set back to the parent bean
@@ -694,7 +658,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
}
}
Object readSet(DbReadContext ctx, Object bean, boolean assignable) throws SQLException {
Object readSet(DbReadContext ctx, EntityBean bean, boolean assignable) throws SQLException {
Object val = read(ctx);
if (bean != null && assignable) {
setValue(bean, val);
@@ -733,16 +697,13 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
return existing;
}
// parent always null for this case (but here to document)
Object parent = null;
Boolean readOnly = ctx.isReadOnly();
Object ref;
if (targetInheritInfo != null) {
// for inheritance hierarchy create the correct type for this row...
ref = rowDescriptor.createReference(readOnly, id, parent);
// for inheritance hierarchy create the correct type for this row...
ref = rowDescriptor.createReference(readOnly, id);
} else {
ref = targetDescriptor.createReference(readOnly, id, parent);
ref = targetDescriptor.createReference(readOnly, id);
}
Object existingBean = ctx.getPersistenceContext().putIfAbsent(id, ref);
@@ -802,7 +763,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
* Read and set a Reference bean.
*/
@Override
Object readSet(DbReadContext ctx, Object bean, boolean assignable) throws SQLException {
Object readSet(DbReadContext ctx, EntityBean bean, boolean assignable) throws SQLException {
Object dbVal = read(ctx);
if (bean != null && assignable) {
@@ -828,8 +789,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
if (existing != null) {
return existing;
}
Object parent = null;
Object ref = targetDescriptor.createReference(ctx.isReadOnly(), id, parent);
Object ref = targetDescriptor.createReference(ctx.isReadOnly(), id);
EntityBeanIntercept ebi = ((EntityBean) ref)._ebean_getIntercept();
if (Boolean.TRUE.equals(ctx.isReadOnly())) {
@@ -867,7 +827,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
}
@Override
public void jsonWrite(WriteJsonContext ctx, Object bean) {
public void jsonWrite(WriteJsonContext ctx, EntityBean bean) {
Object value = getValueIntercept(bean);
if (value == null){
@@ -881,7 +841,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
ctx.pushParentBean(bean);
ctx.beginAssocOne(name);
BeanDescriptor<?> refDesc = descriptor.getBeanDescriptor(value.getClass());
refDesc.jsonWrite(ctx, value);
refDesc.jsonWrite(ctx, (EntityBean)value);
ctx.endAssocOne();
ctx.popParentBean();
}
@@ -889,7 +849,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
}
@Override
public void jsonRead(ReadJsonContext ctx, Object bean){
public void jsonRead(ReadJsonContext ctx, EntityBean bean){
T assocBean = targetDescriptor.jsonReadBean(ctx, name);
setValue(bean, assocBean);