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

@@ -6,9 +6,7 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
@@ -47,16 +45,6 @@ public interface IdBinder {
public Object readData(DataInput dataInput) throws IOException;
/**
* Adds RDN's to the LdapName using the id value.
*/
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException;
/**
* Adds RDN's to the LdapName using the id value from the bean.
*/
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException;
/**
* Return the name(s) of the Id property(s).
* Comma delimited if there is more than one.
* <p>
@@ -102,7 +90,7 @@ public interface IdBinder {
/**
* Return the id values for a given bean.
*/
public Object[] getIdValues(Object bean);
public Object[] getIdValues(EntityBean bean);
/**
* Build a string of the logical expressions.
@@ -149,7 +137,7 @@ public interface IdBinder {
/**
* Read the id value from the result set and set it to the bean also returning it.
*/
public Object readSet(DbReadContext ctx, Object bean) throws SQLException;
public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException;
/**
* Ignore the appropriate number of scalar properties for this id.
@@ -187,6 +175,6 @@ public interface IdBinder {
* If the bean is not null, then the value is set to the bean.
* </p>
*/
public Object convertSetId(Object idValue, Object bean);
public Object convertSetId(Object idValue, EntityBean bean);
}
@@ -6,11 +6,9 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import javax.persistence.PersistenceException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
@@ -99,23 +97,6 @@ public final class IdBinderEmbedded implements IdBinder {
return sb.toString();
}
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
for (int i = 0; i < props.length; i++) {
Object v = props[i].getValue(id);
Rdn rdn = new Rdn(props[i].getDbColumn(), v);
name.add(rdn);
}
}
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
Object id = embIdProperty.getValue(bean);
createLdapNameById(name, id);
}
public BeanDescriptor<?> getIdBeanDescriptor() {
return idDesc;
}
@@ -172,7 +153,7 @@ public final class IdBinderEmbedded implements IdBinder {
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
for (int i = 0; i < props.length; i++) {
request.addBindValue(props[i].getValue(value));
request.addBindValue(props[i].getValue((EntityBean)value));
}
}
@@ -238,7 +219,7 @@ public final class IdBinderEmbedded implements IdBinder {
String msg = "Failed to split ["+idTermValue+"] using | for id.";
throw new PersistenceException(msg);
}
Object embId = idDesc.createBean();
EntityBean embId = idDesc.createBean();
for (int i = 0; i < props.length; i++) {
Object v = props[i].getScalarType().parse(split[i]);
props[i].setValue(embId, v);
@@ -254,7 +235,7 @@ public final class IdBinderEmbedded implements IdBinder {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < props.length; i++) {
Object v = props[i].getValue(idValue);
Object v = props[i].getValue((EntityBean)idValue);
String formatValue = props[i].getScalarType().format(v);
if (i > 0){
sb.append("|");
@@ -264,11 +245,11 @@ public final class IdBinderEmbedded implements IdBinder {
return sb.toString();
}
public Object[] getIdValues(Object bean) {
bean = embIdProperty.getValue(bean);
public Object[] getIdValues(EntityBean bean) {
Object val = embIdProperty.getValue(bean);
Object[] bindvalues = new Object[props.length];
for (int i = 0; i < props.length; i++) {
bindvalues[i] = props[i].getValue(bean);
bindvalues[i] = props[i].getValue((EntityBean)val);
}
return bindvalues;
}
@@ -277,14 +258,14 @@ public final class IdBinderEmbedded implements IdBinder {
Object[] bindvalues = new Object[props.length];
for (int i = 0; i < props.length; i++) {
bindvalues[i] = props[i].getValue(value);
bindvalues[i] = props[i].getValue((EntityBean)value);
}
return bindvalues;
}
public void bindId(DefaultSqlUpdate sqlUpdate, Object value) {
for (int i = 0; i < props.length; i++) {
Object embFieldValue = props[i].getValue(value);
Object embFieldValue = props[i].getValue((EntityBean)value);
sqlUpdate.addParameter(embFieldValue);
}
}
@@ -292,14 +273,14 @@ public final class IdBinderEmbedded implements IdBinder {
public void bindId(DataBind dataBind, Object value) throws SQLException {
for (int i = 0; i < props.length; i++) {
Object embFieldValue = props[i].getValue(value);
Object embFieldValue = props[i].getValue((EntityBean)value);
props[i].bind(dataBind, embFieldValue);
}
}
public Object readData(DataInput dataInput) throws IOException {
Object embId = idDesc.createBean();
EntityBean embId = idDesc.createBean();
boolean notNull = true;
for (int i = 0; i < props.length; i++) {
@@ -319,7 +300,7 @@ public final class IdBinderEmbedded implements IdBinder {
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
for (int i = 0; i < props.length; i++) {
Object embFieldValue = props[i].getValue(idValue);
Object embFieldValue = props[i].getValue((EntityBean)idValue);
props[i].writeData(dataOutput, embFieldValue);
}
}
@@ -332,7 +313,7 @@ public final class IdBinderEmbedded implements IdBinder {
public Object read(DbReadContext ctx) throws SQLException {
Object embId = idDesc.createBean();
EntityBean embId = idDesc.createBean();
boolean notNull = true;
for (int i = 0; i < props.length; i++) {
@@ -349,7 +330,7 @@ public final class IdBinderEmbedded implements IdBinder {
}
}
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException {
Object embId = read(ctx);
if (embId != null) {
@@ -443,7 +424,7 @@ public final class IdBinderEmbedded implements IdBinder {
return sb.toString();
}
public Object convertSetId(Object idValue, Object bean) {
public Object convertSetId(Object idValue, EntityBean bean) {
// can not cast/convert if it is embedded
if (bean != null) {
@@ -6,9 +6,7 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
@@ -47,11 +45,6 @@ public final class IdBinderEmpty implements IdBinder {
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
}
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
}
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
}
public int getPropertyCount() {
return 0;
@@ -107,7 +100,7 @@ public final class IdBinderEmpty implements IdBinder {
return null;
}
public Object[] getIdValues(Object bean){
public Object[] getIdValues(EntityBean bean){
return null;
}
@@ -126,7 +119,7 @@ public final class IdBinderEmpty implements IdBinder {
public void loadIgnore(DbReadContext ctx) {
}
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException {
return null;
}
@@ -137,7 +130,7 @@ public final class IdBinderEmpty implements IdBinder {
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
}
public Object convertSetId(Object idValue, Object bean){
public Object convertSetId(Object idValue, EntityBean bean){
return idValue;
}
@@ -8,11 +8,9 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import javax.persistence.PersistenceException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
import com.avaje.ebeaninternal.server.core.InternString;
@@ -83,24 +81,6 @@ public final class IdBinderMultiple implements IdBinder {
return sb.toString();
}
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
if (id instanceof Map<?,?> == false){
throw new RuntimeException("Expecting a Map for concatinated key");
}
Map<?,?> mapId = (Map<?,?>)id;
for (int i = 0; i < props.length; i++) {
Object v = mapId.get(props[i].getName());
if (v == null){
throw new RuntimeException("No value in Map for key "+props[i].getName());
}
Rdn rdn = new Rdn(props[i].getDbColumn(), v);
name.add(rdn);
}
}
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
@@ -109,16 +89,6 @@ public final class IdBinderMultiple implements IdBinder {
}
}
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
for (int i = 0; i < props.length; i++) {
Object v = props[i].getValue(bean);
Rdn rdn = new Rdn(props[i].getDbColumn(), v);
name.add(rdn);
}
}
public int getPropertyCount() {
return props.length;
}
@@ -163,7 +133,7 @@ public final class IdBinderMultiple implements IdBinder {
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
for (int i = 0; i < props.length; i++) {
request.addBindValue(props[i].getValue(value));
request.addBindValue(props[i].getValue((EntityBean)value));
}
}
@@ -200,7 +170,7 @@ public final class IdBinderMultiple implements IdBinder {
return sb.toString();
}
public Object[] getIdValues(Object bean){
public Object[] getIdValues(EntityBean bean){
Object[] bindvalues = new Object[props.length];
for (int i = 0; i < props.length; i++) {
bindvalues[i] = props[i].getValue(bean);
@@ -301,7 +271,7 @@ public final class IdBinderMultiple implements IdBinder {
}
}
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException {
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
boolean notNull = false;
@@ -430,7 +400,7 @@ public final class IdBinderMultiple implements IdBinder {
return sb.toString();
}
public Object convertSetId(Object idValue, Object bean) {
public Object convertSetId(Object idValue, EntityBean bean) {
// allow Map or String for concatenated id
Map<?,?> mapVal = null;
@@ -6,10 +6,7 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
import com.avaje.ebeaninternal.server.core.InternString;
@@ -74,16 +71,6 @@ public final class IdBinderSimple implements IdBinder {
idProperty.buildSelectExpressionChain(prefix, selectChain);
}
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
Rdn rdn = new Rdn(idProperty.getDbColumn(), id);
name.add(rdn);
}
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
Object id = idProperty.getValue(bean);
createLdapNameById(name, id);
}
/**
* Returns 1.
*/
@@ -130,7 +117,7 @@ public final class IdBinderSimple implements IdBinder {
}
}
public Object[] getIdValues(Object bean){
public Object[] getIdValues(EntityBean bean){
return new Object[]{idProperty.getValue(bean)};
}
@@ -181,7 +168,7 @@ public final class IdBinderSimple implements IdBinder {
idProperty.loadIgnore(ctx);
}
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException {
Object id = idProperty.read(ctx);
if (id != null){
idProperty.setValue(bean, id);
@@ -220,7 +207,7 @@ public final class IdBinderSimple implements IdBinder {
return sb.toString();
}
public Object convertSetId(Object idValue, Object bean) {
public Object convertSetId(Object idValue, EntityBean bean) {
if (!idValue.getClass().equals(expectedType)){
idValue = scalarType.toBeanType(idValue);
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.deploy.id;
import java.sql.SQLException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import com.avaje.ebeaninternal.server.deploy.IntersectionRow;
@@ -48,22 +49,17 @@ public interface ImportedId {
/**
* Append to the DML statement to the where clause.
*/
public void dmlWhere(GenerateDmlRequest request, Object bean);
/**
* Return true if the id value has changed.
*/
public boolean hasChanged(Object bean, Object oldValues);
public void dmlWhere(GenerateDmlRequest request, EntityBean bean);
/**
* Bind the value from the bean.
*/
public Object bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException;
public Object bind(BindableRequest request, EntityBean bean) throws SQLException;
/**
* For inserting into ManyToMany intersection.
*/
public void buildImport(IntersectionRow row, Object other);
public void buildImport(IntersectionRow row, EntityBean other);
/**
* Used to derive a missing concatenated key from multiple imported keys.
@@ -4,6 +4,7 @@ import java.sql.SQLException;
import javax.persistence.PersistenceException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.deploy.BeanFkeyProperty;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
@@ -68,7 +69,7 @@ public class ImportedIdEmbedded implements ImportedId {
}
}
public void dmlWhere(GenerateDmlRequest request, Object bean){
public void dmlWhere(GenerateDmlRequest request, EntityBean bean){
Object embeddedId = null;
if (bean != null) {
@@ -82,10 +83,10 @@ public class ImportedIdEmbedded implements ImportedId {
}
}
} else {
EntityBean embedded = (EntityBean)embeddedId;
for (int i = 0; i < imported.length; i++) {
if (imported[i].owner.isDbUpdatable()) {
Object value = imported[i].foreignProperty.getValue(embeddedId);
Object value = imported[i].foreignProperty.getValue(embedded);
if (value == null){
request.appendColumnIsNull(imported[i].localDbColumn);
} else {
@@ -96,14 +97,7 @@ public class ImportedIdEmbedded implements ImportedId {
}
}
public boolean hasChanged(Object bean, Object oldValues) {
Object id = foreignAssocOne.getValue(bean);
Object oldId = foreignAssocOne.getValue(oldValues);
return !ValueUtil.areEqual(id, oldId);
}
public Object bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {
public Object bind(BindableRequest request, EntityBean bean) throws SQLException {
Object embeddedId = null;
@@ -114,15 +108,16 @@ public class ImportedIdEmbedded implements ImportedId {
if (embeddedId == null){
for (int i = 0; i < imported.length; i++) {
if (imported[i].owner.isUpdateable()) {
request.bind(null, imported[i].foreignProperty, imported[i].localDbColumn, true);
request.bind(null, imported[i].foreignProperty, imported[i].localDbColumn);
}
}
} else {
EntityBean embedded = (EntityBean)embeddedId;
for (int i = 0; i < imported.length; i++) {
if (imported[i].owner.isUpdateable()) {
Object scalarValue = imported[i].foreignProperty.getValue(embeddedId);
request.bind(scalarValue, imported[i].foreignProperty, imported[i].localDbColumn, true);
Object scalarValue = imported[i].foreignProperty.getValue(embedded);
request.bind(scalarValue, imported[i].foreignProperty, imported[i].localDbColumn);
}
}
}
@@ -130,9 +125,9 @@ public class ImportedIdEmbedded implements ImportedId {
return null;
}
public void buildImport(IntersectionRow row, Object other){
public void buildImport(IntersectionRow row, EntityBean other){
Object embeddedId = foreignAssocOne.getValue(other);
EntityBean embeddedId = (EntityBean)foreignAssocOne.getValue(other);
if (embeddedId == null){
String msg = "Foreign Key value null?";
throw new PersistenceException(msg);
@@ -2,13 +2,13 @@ package com.avaje.ebeaninternal.server.deploy.id;
import java.sql.SQLException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import com.avaje.ebeaninternal.server.deploy.IntersectionRow;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
import com.avaje.ebeaninternal.util.ValueUtil;
/**
* Imported concatenated id that is not embedded.
@@ -55,7 +55,7 @@ public class ImportedIdMultiple implements ImportedId {
}
}
public void dmlWhere(GenerateDmlRequest request, Object bean){
public void dmlWhere(GenerateDmlRequest request, EntityBean bean){
if (bean == null){
for (int i = 0; i < imported.length; i++) {
request.appendColumnIsNull(imported[i].localDbColumn);
@@ -72,32 +72,19 @@ public class ImportedIdMultiple implements ImportedId {
}
}
public boolean hasChanged(Object bean, Object oldValues) {
for (int i = 0; i < imported.length; i++) {
Object id = imported[i].foreignProperty.getValue(bean);
Object oldId = imported[i].foreignProperty.getValue(oldValues);
if (!ValueUtil.areEqual(id, oldId)) {
return true;
}
}
return false;
}
public Object bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {
public Object bind(BindableRequest request, EntityBean bean) throws SQLException {
for (int i = 0; i < imported.length; i++) {
if (imported[i].owner.isUpdateable()) {
Object scalarValue = imported[i].foreignProperty.getValue(bean);
request.bind(scalarValue, imported[i].foreignProperty, imported[i].localDbColumn, true);
request.bind(scalarValue, imported[i].foreignProperty, imported[i].localDbColumn);
}
}
// hmmm, not worrying about this just yet
return null;
}
public void buildImport(IntersectionRow row, Object other){
public void buildImport(IntersectionRow row, EntityBean other){
for (int i = 0; i < imported.length; i++) {
Object scalarValue = imported[i].foreignProperty.getValue(other);
@@ -7,6 +7,7 @@ import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.InternString;
import com.avaje.ebeaninternal.server.deploy.BeanFkeyProperty;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
@@ -15,7 +16,6 @@ import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import com.avaje.ebeaninternal.server.deploy.IntersectionRow;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
import com.avaje.ebeaninternal.util.ValueUtil;
/**
* Single scalar imported id.
@@ -90,11 +90,11 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
return localDbColumn;
}
private Object getIdValue(Object bean) {
return foreignProperty.getValueWithInheritance(bean);
}
private Object getIdValue(EntityBean bean) {
return foreignProperty.getValue(bean);
}
public void buildImport(IntersectionRow row, Object other){
public void buildImport(IntersectionRow row, EntityBean other){
Object value = getIdValue(other);
if (value == null){
@@ -114,7 +114,7 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
request.appendColumn(localDbColumn);
}
public void dmlWhere(GenerateDmlRequest request, Object bean){
public void dmlWhere(GenerateDmlRequest request, EntityBean bean){
if (owner.isDbUpdatable()){
Object value = null;
@@ -129,25 +129,13 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
}
}
public boolean hasChanged(Object bean, Object oldValues) {
Object id = getIdValue(bean);
if (oldValues != null){
Object oldId = getIdValue(oldValues);
return !ValueUtil.areEqual(id, oldId);
}
return true;
}
public Object bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {
public Object bind(BindableRequest request, EntityBean bean) throws SQLException {
Object value = null;
if (bean != null){
value = getIdValue(bean);
}
request.bind(value, foreignProperty, localDbColumn, bindNull);
request.bind(value, foreignProperty, localDbColumn);
return value;
}