Merge in v4 code changes

This commit is contained in:
Rob Bygrave committed 2014-04-03 03:47:55 +13:00
commit 96e4b4640f
171 files changed
+2747 -3848

No files matched your search

@@ -6,6 +6,8 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
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;
@@ -168,6 +170,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,6 +6,9 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
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;
@@ -150,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));
}
}
@@ -206,11 +209,11 @@ public final class IdBinderEmbedded implements IdBinder {
return idInValueSql;
}
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;
}
@@ -219,14 +222,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);
}
}
@@ -234,14 +237,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++) {
@@ -261,7 +264,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);
}
}
@@ -274,7 +277,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++) {
@@ -291,7 +294,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) {
@@ -385,7 +388,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,6 +6,8 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
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;
@@ -131,5 +133,4 @@ public final class IdBinderEmpty implements IdBinder {
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
}
}
@@ -10,6 +10,7 @@ import java.util.Map;
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;
@@ -89,7 +90,6 @@ public final class IdBinderMultiple implements IdBinder {
}
public int getPropertyCount() {
return props.length;
}
@@ -134,7 +134,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));
}
}
@@ -171,7 +171,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);
@@ -238,7 +238,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;
@@ -367,7 +367,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,6 +6,8 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
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;
@@ -44,6 +46,7 @@ public final class IdBinderSimple implements IdBinder {
// do nothing
}
public String getOrderBy(String pathPrefix, boolean ascending){
StringBuilder sb = new StringBuilder();
@@ -108,7 +111,7 @@ public final class IdBinderSimple implements IdBinder {
}
}
public Object[] getIdValues(Object bean){
public Object[] getIdValues(EntityBean bean){
return new Object[]{idProperty.getValue(bean)};
}
@@ -159,7 +162,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);
@@ -198,7 +201,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;
}