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

@@ -3,6 +3,7 @@ package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
@@ -25,32 +26,17 @@ public interface Bindable {
* For Updates including only changed properties add the Bindable to the
* list if it should be included in the 'update set'.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list);
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list);
/**
* append sql to the buffer with prefix and suffix options.
*/
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes);
/**
* append sql to the buffer with prefix and suffix options.
*/
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes);
/**
* For WHERE clauses append sql to the buffer with prefix and suffix
* options. These need to take into account binding of null values.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean);
public void dmlAppend(GenerateDmlRequest request);
/**
* Bind given the request and bean. The bean could be the oldValues bean
* when binding a update or delete where clause with ALL concurrency mode.
*/
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean)
throws SQLException;
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean)
throws SQLException;
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException;
}
@@ -3,6 +3,7 @@ package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.api.DerivedRelationshipData;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
@@ -14,75 +15,42 @@ import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
*/
public class BindableAssocOne implements Bindable {
private final BeanPropertyAssocOne<?> assocOne;
private final BeanPropertyAssocOne<?> assocOne;
private final ImportedId importedId;
private final ImportedId importedId;
public BindableAssocOne(BeanPropertyAssocOne<?> assocOne) {
this.assocOne = assocOne;
this.importedId = assocOne.getImportedId();
public BindableAssocOne(BeanPropertyAssocOne<?> assocOne) {
this.assocOne = assocOne;
this.importedId = assocOne.getImportedId();
}
public String toString() {
return "BindableAssocOne " + assocOne;
}
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (request.isAddToUpdate(assocOne)) {
list.add(this);
}
}
public String toString() {
return "BindableAssocOne " + assocOne;
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(assocOne)) {
list.add(this);
}
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(assocOne)) {
return;
}
importedId.dmlAppend(request);
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
if (checkIncludes && !request.isIncludedWhere(assocOne)) {
return;
}
Object assocBean = assocOne.getValue(bean);
importedId.dmlWhere(request, assocBean);
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncluded(assocOne)) {
return;
}
dmlBind(request, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncludedWhere(assocOne)) {
return;
}
dmlBind(request, bean, false);
}
private void dmlBind(BindableRequest request, Object bean, boolean bindNull)
throws SQLException {
Object assocBean = assocOne.getValue(bean);
Object boundValue = importedId.bind(request, assocBean, bindNull);
if (bindNull && boundValue == null && assocBean != null){
// this is the scenario for a derived foreign key
// which will require an additional update
// register for post insert of assocBean
// update of bean set ... importedId.getLogicalName();
// value of assocBean.getId
DerivedRelationshipData d = new DerivedRelationshipData(assocBean, assocOne.getName(), bean);
request.registerDerivedRelationship(d);
}
public void dmlAppend(GenerateDmlRequest request) {
importedId.dmlAppend(request);
}
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
EntityBean assocBean = (EntityBean)assocOne.getValue(bean);
Object boundValue = importedId.bind(request, assocBean);
if (boundValue == null && assocBean != null) {
// this is the scenario for a derived foreign key
// which will require an additional update
// register for post insert of assocBean
// update of bean set ... importedId.getLogicalName();
// value of assocBean.getId
DerivedRelationshipData d = new DerivedRelationshipData(assocBean, assocOne.getName(), bean);
request.registerDerivedRelationship(d);
}
}
}
@@ -4,6 +4,7 @@ import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyCompound;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
@@ -26,62 +27,27 @@ public class BindableCompound implements Bindable {
return "BindableCompound " + compound + " items:" + Arrays.toString(items);
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(compound)) {
return;
}
public void dmlAppend(GenerateDmlRequest request) {
for (int i = 0; i < items.length; i++) {
items[i].dmlAppend(request, false);
items[i].dmlAppend(request);
}
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object origBean) {
if (checkIncludes && !request.isIncludedWhere(compound)) {
return;
}
Object valueObject = compound.getValue(origBean);
for (int i = 0; i < items.length; i++) {
items[i].dmlWhere(request, false, valueObject);
}
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(compound)) {
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (request.isAddToUpdate(compound)) {
list.add(this);
}
}
public void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !bindRequest.isIncluded(compound)) {
return;
}
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
Object valueObject = compound.getValue(bean);
for (int i = 0; i < items.length; i++) {
items[i].dmlBind(bindRequest, false, valueObject);
}
throw new RuntimeException("This is broken, need to break out the scalar values!!");
//Object valueObject = compound.getValue(bean);
//for (int i = 0; i < items.length; i++) {
// items[i].dmlBind(bindRequest, valueObject);
//}
}
public void dmlBindWhere(BindableRequest bindRequest, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !bindRequest.isIncludedWhere(compound)) {
return;
}
Object valueObject = compound.getValue(bean);
for (int i = 0; i < items.length; i++) {
items[i].dmlBindWhere(bindRequest, false, valueObject);
}
}
}
@@ -5,6 +5,7 @@ import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.InheritInfo;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
@@ -28,31 +29,15 @@ public class BindableDiscriminator implements Bindable {
return columnName + " = " + discValue;
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
throw new PersistenceException("Never called (only for inserts)");
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
/**
* Never used in where clause.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// never used in where
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
public void dmlAppend(GenerateDmlRequest request) {
request.appendColumn(columnName);
}
public void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean) throws SQLException {
bindRequest.bind(columnName, discValue, sqlType);
}
public void dmlBindWhere(BindableRequest bindRequest, boolean checkIncludes, Object bean) throws SQLException {
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
bindRequest.bind(columnName, discValue, sqlType);
}
@@ -18,103 +18,43 @@ public class BindableEmbedded implements Bindable {
private final BeanPropertyAssocOne<?> embProp;
public BindableEmbedded(BeanPropertyAssocOne<?> embProp, List<Bindable> list) {
public BindableEmbedded(BeanPropertyAssocOne<?> embProp, List<Bindable> bindList) {
this.embProp = embProp;
this.items = list.toArray(new Bindable[list.size()]);
this.items = bindList.toArray(new Bindable[bindList.size()]); //this.props = propList.toArray(new BeanProperty[propList.size()]);
}
public String toString() {
return "BindableEmbedded " + embProp + " items:" + Arrays.toString(items);
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(embProp)) {
return;
}
public void dmlAppend(GenerateDmlRequest request) {
for (int i = 0; i < items.length; i++) {
items[i].dmlAppend(request, false);
items[i].dmlAppend(request);
}
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object origBean) {
if (checkIncludes && !request.isIncludedWhere(embProp)) {
return;
}
Object embBean = embProp.getValue(origBean);
Object oldValues = getOldValue(embBean);
for (int i = 0; i < items.length; i++) {
items[i].dmlWhere(request, false, oldValues);
}
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(embProp)) {
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (request.isAddToUpdate(embProp)) {
list.add(this);
}
}
public void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean)
throws SQLException {
if (checkIncludes && !bindRequest.isIncluded(embProp)) {
return;
}
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
// get the embedded bean
Object embBean = embProp.getValue(bean);
// get the embedded bean
EntityBean embBean = (EntityBean)embProp.getValue(bean);
if (embBean == null) {
for (int i = 0; i < items.length; i++) {
items[i].dmlBind(bindRequest, false, embBean);
items[i].dmlBind(bindRequest, null);
}
}
public void dmlBindWhere(BindableRequest bindRequest, boolean checkIncludes, Object bean)
throws SQLException {
if (checkIncludes && !bindRequest.isIncludedWhere(embProp)) {
return;
}
// get the embedded bean
Object embBean = embProp.getValue(bean);
Object oldEmbBean = getOldValue(embBean);
} else {
//EntityBeanIntercept ebi = embBean._ebean_getIntercept();
for (int i = 0; i < items.length; i++) {
items[i].dmlBindWhere(bindRequest, false, oldEmbBean);
//if (ebi.isLoadedProperty(props[i].getPropertyIndex())) {
items[i].dmlBind(bindRequest, embBean);
//}
}
}
}
/**
* Get the old bean which will have the original values.
* <p>
* These are bound to the WHERE clause for updates.
* </p>
*/
private Object getOldValue(Object embBean) {
Object oldValues = null;
if (embBean instanceof EntityBean) {
// get the old embedded bean (with the original values)
oldValues = ((EntityBean) embBean)._ebean_getIntercept().getOldValues();
}
if (oldValues == null) {
// this embedded bean was not modified
// (or not an EntityBean)
oldValues = embBean;
}
return oldValues;
}
}
@@ -4,6 +4,7 @@ import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
@@ -26,59 +27,25 @@ public class BindableEncryptedProperty implements Bindable {
return prop.toString();
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(prop)) {
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (request.isAddToUpdate(prop)) {
list.add(this);
}
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
public void dmlAppend(GenerateDmlRequest request) {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
// columnName
// AES_ENCRYPT(?,?)
// columnName = AES_ENCRYPT(?,?)
request.appendColumn(prop.getDbColumn(), prop.getDbBind());
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
// columnName = AES_ENCRYPT(?,?)
request.appendColumn(prop.getDbColumn(), "=", prop.getDbBind());
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// only include encrypted property in where when it is included
// in the update as well (so not using isIncludedWhere)
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
if (bean == null || request.isDbNull(prop.getValue(bean))) {
request.appendColumnIsNull(prop.getDbColumn());
} else {
// ? = AES_DECRYPT(columnName,?)
request.appendColumn("? = ", prop.getDecryptSql());
}
}
/**
* Bind a value in a Insert SET clause.
*/
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean)
public void dmlBind(BindableRequest request, EntityBean bean)
throws SQLException {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
Object value = null;
if (bean != null) {
value = prop.getValue(bean);
@@ -91,35 +58,12 @@ public class BindableEncryptedProperty implements Bindable {
// H2 encrypt function ... different parameter order
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
}
request.bindNoLog(value, prop, prop.getName(), true);
request.bindNoLog(value, prop, prop.getName());
if (bindEncryptDataFirst){
// MySql, Postgres, Oracle
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
}
}
/**
* Bind a value in a Insert SET clause.
*/
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean)
throws SQLException {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
Object value = null;
if (bean != null) {
value = prop.getValue(bean);
}
// get Encrypt key
String encryptKeyValue = prop.getEncryptKey().getStringValue();
request.bind(value, prop, prop.getName(), false);
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
}
}
@@ -6,6 +6,7 @@ import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
@@ -50,53 +51,24 @@ public final class BindableIdEmbedded implements BindableId {
/**
* Does nothing for BindableId.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
// do nothing (id not changing)
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
private void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean, boolean bindNull) throws SQLException {
if (checkIncludes && !bindRequest.isIncluded(embId)) {
return;
}
Object idValue = embId.getValue(bean);
EntityBean idValue = (EntityBean)embId.getValue(bean);
for (int i = 0; i < props.length; i++) {
Object value = props[i].getValue(idValue);
bindRequest.bind(value, props[i], props[i].getDbColumn(), bindNull);
request.bind(value, props[i], props[i].getDbColumn());
}
bindRequest.setIdValue(idValue);
request.setIdValue(idValue);
}
/**
* Id values are never null in where clause.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
if (checkIncludes && !request.isIncluded(embId)) {
return;
}
dmlAppend(request, false);
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(embId)) {
return;
}
public void dmlAppend(GenerateDmlRequest request) {
for (int i = 0; i < props.length; i++) {
request.appendColumn(props[i].getDbColumn());
}
@@ -111,10 +83,10 @@ public final class BindableIdEmbedded implements BindableId {
throw new PersistenceException(m);
}
Object bean = persist.getBean();
EntityBean bean = persist.getEntityBean();
// create the new id
Object newId = embId.createEmbeddedId();
EntityBean newId = (EntityBean)embId.createEmbeddedId();
// populate it from the assoc one id values...
for (int i = 0; i < matches.length; i++) {
@@ -3,6 +3,7 @@ package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
@@ -12,27 +13,15 @@ public class BindableIdEmpty implements BindableId {
return true;
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
// nothing
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
public void dmlAppend(GenerateDmlRequest request) {
// nothing
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
// nothing
}
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// nothing
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
// nothing
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
// nothing
}
@@ -7,6 +7,7 @@ import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
@@ -47,49 +48,29 @@ public final class BindableIdMap implements BindableId {
/**
* Does nothing for BindableId.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
// do nothing (id not changing)
}
/**
* Id values are never null in where clause.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// id values are never null in where clause
dmlAppend(request, false);
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
public void dmlAppend(GenerateDmlRequest request) {
for (int i = 0; i < uids.length; i++) {
request.appendColumn(uids[i].getDbColumn());
}
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
private void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean, boolean bindNull) throws SQLException {
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
LinkedHashMap<String, Object> mapId = new LinkedHashMap<String, Object>();
for (int i = 0; i < uids.length; i++) {
Object value = uids[i].getValue(bean);
bindRequest.bind(value, uids[i], uids[i].getName(), bindNull);
request.bind(value, uids[i], uids[i].getName());
// putting logicalType into map rather than
// the dbType (which may have been converted).
mapId.put(uids[i].getName(), value);
}
bindRequest.setIdValue(mapId);
request.setIdValue(mapId);
}
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
@@ -101,7 +82,7 @@ public final class BindableIdMap implements BindableId {
throw new PersistenceException(m);
}
Object bean = persist.getBean();
EntityBean bean = persist.getEntityBean();
// populate it from the assoc one id values...
for (int i = 0; i < matches.length; i++) {
@@ -5,6 +5,7 @@ import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
@@ -40,7 +41,7 @@ public final class BindableIdScalar implements BindableId {
/**
* Does nothing for BindableId.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
// do nothing (id not changing)
}
@@ -51,39 +52,19 @@ public final class BindableIdScalar implements BindableId {
throw new PersistenceException("Should not be called? only for concatinated keys");
}
/**
* Id values are never null in where clause.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// id values are never null in where clause
request.appendColumn(uidProp.getDbColumn());
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
public void dmlAppend(GenerateDmlRequest request) {
request.appendColumn(uidProp.getDbColumn());
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
private void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean, boolean bindNull) throws SQLException {
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
Object value = uidProp.getValue(bean);
bindRequest.bind(value, uidProp, uidProp.getName(), bindNull);
request.bind(value, uidProp, uidProp.getName());
// used for summary logging
bindRequest.setIdValue(value);
request.setIdValue(value);
}
}
@@ -3,6 +3,7 @@ package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
@@ -23,45 +24,25 @@ public class BindableList implements Bindable {
}
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
for (int i = 0; i < items.length; i++) {
items[i].addChanged(request, list);
items[i].addToUpdate(request, list);
}
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
public void dmlAppend(GenerateDmlRequest request) {
for (int i = 0; i < items.length; i++) {
items[i].dmlInsert(request, checkIncludes);
items[i].dmlAppend(request);
}
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
for (int i = 0; i < items.length; i++) {
items[i].dmlAppend(request, checkIncludes);
}
}
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
for (int i = 0; i < items.length; i++) {
items[i].dmlWhere(request, checkIncludes, bean);
}
}
public void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean)
public void dmlBind(BindableRequest bindRequest, EntityBean bean)
throws SQLException {
for (int i = 0; i < items.length; i++) {
items[i].dmlBind(bindRequest, checkIncludes, bean);
items[i].dmlBind(bindRequest, bean);
}
}
public void dmlBindWhere(BindableRequest bindRequest, boolean checkIncludes, Object bean)
throws SQLException {
for (int i = 0; i < items.length; i++) {
items[i].dmlBindWhere(bindRequest, checkIncludes, bean);
}
}
}
@@ -3,6 +3,7 @@ package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
@@ -22,62 +23,23 @@ public class BindableProperty implements Bindable {
return prop.toString();
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(prop)) {
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (request.isAddToUpdate(prop)) {
list.add(this);
}
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
public void dmlAppend(GenerateDmlRequest request) {
request.appendColumn(prop.getDbColumn());
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
if (checkIncludes && !request.isIncludedWhere(prop)) {
return;
}
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
if (bean == null || request.isDbNull(prop.getValue(bean))) {
request.appendColumnIsNull(prop.getDbColumn());
} else {
request.appendColumn(prop.getDbColumn());
}
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
dmlBind(request, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncludedWhere(prop)) {
return;
}
dmlBind(request, bean, false);
}
private void dmlBind(BindableRequest request, Object bean, boolean bindNull)
throws SQLException {
Object value = null;
if (bean != null) {
value = prop.getValue(bean);
}
// value = prop.getDefaultValue();
request.bind(value, prop, prop.getName(), bindNull);
request.bind(value, prop, prop.getName());
}
}
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
@@ -21,36 +22,24 @@ public class BindablePropertyInsertGenerated extends BindableProperty {
this.gen = gen;
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
/**
* Bind a value in a Insert SET clause.
*/
private void dmlBind(BindableRequest request, boolean checkIncludes, Object bean, boolean bindNull) throws SQLException {
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
Object value = gen.getInsertValue(prop, bean);
// generated value should be the correct type
if (bean != null){
// support PropertyChangeSupport
prop.setValueIntercept(bean, value);
request.registerAdditionalProperty(prop.getName());
//prop.setValueIntercept(bean, value);
prop.setValue(bean, value);
}
//value = prop.getDefaultValue();
request.bind(value, prop, prop.getName(), bindNull);
}
request.bind(value, prop, prop.getName());
}
/**
* Always bind on Insert SET.
*/
@Override
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes){
public void dmlAppend(GenerateDmlRequest request){
request.appendColumn(prop.getDbColumn());
}
@@ -3,6 +3,7 @@ package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
@@ -24,37 +25,27 @@ public class BindablePropertyUpdateGenerated extends BindableProperty {
}
/**
* Always add BindablePropertyUpdateGenerated properties.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
list.add(this);
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncluded(prop)){
return;
}
dmlBind(request, bean, true);
* Add BindablePropertyUpdateGenerated if the property is loaded.
*/
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (gen.includeInAllUpdates()) {
list.add(this);
} else if (request.isLoadedProperty(prop)) {
list.add(this);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncludedWhere(prop)){
return;
}
dmlBind(request, bean, false);
}
private void dmlBind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {
}
Object value = gen.getUpdateValue(prop, bean);
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
Object value = gen.getUpdateValue(prop, bean);
// generated value should be the correct type
request.bind(value, prop, prop.getName(), bindNull);
// generated value should be the correct type
request.bind(value, prop, prop.getName());
// only register the update value if it was included
// in the bean in the first place
if (request.isIncluded(prop)) {
if (request.getPersistRequest().isLoadedProperty(prop)) {
//if (request.isIncluded(prop)) {
// need to set the generated value to the bean later
// after the where clause has been generated
request.registerUpdateGenValue(prop, bean, value);
@@ -65,10 +56,7 @@ public class BindablePropertyUpdateGenerated extends BindableProperty {
* Always bind on Insert SET.
*/
@Override
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes){
if (checkIncludes && !request.isIncluded(prop)){
return;
}
public void dmlAppend(GenerateDmlRequest request){
request.appendColumn(prop.getDbColumn());
}
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.api.DerivedRelationshipData;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
@@ -31,7 +32,7 @@ public interface BindableRequest {
* @param bindNull
* if true bind null values, if false use IS NULL.
*/
public Object bind(Object value, BeanProperty prop, String propName, boolean bindNull) throws SQLException;
public Object bind(Object value, BeanProperty prop, String propName) throws SQLException;
/**
* Bind a raw value. Used to bind the discriminator column.
@@ -46,29 +47,14 @@ public interface BindableRequest {
/**
* Bind the value to the preparedStatement without logging.
*/
public Object bindNoLog(Object value, BeanProperty prop, String propName, boolean bindNull) throws SQLException;
public Object bindNoLog(Object value, BeanProperty prop, String propName) throws SQLException;
/**
* Return true if the property is included in this request.
*/
public boolean isIncluded(BeanProperty prop);
/**
* Return true if the property is included in the WHERE clause for this
* request.
*/
public boolean isIncludedWhere(BeanProperty prop);
/**
* Register the value from a update GeneratedValue. This can only be set to
* the bean property after the where clause has bean built.
*/
public void registerUpdateGenValue(BeanProperty prop, Object bean, Object value);
/**
* Register a property into loadedProperties if required.
*/
public void registerAdditionalProperty(String propertyName);
public void registerUpdateGenValue(BeanProperty prop, EntityBean bean, Object value);
/**
* Return the original PersistRequest.
@@ -5,6 +5,7 @@ import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
@@ -37,33 +38,17 @@ public class BindableUnidirectional implements Bindable {
return "BindableShadowFKey " + unidirectional;
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
throw new PersistenceException("Never called (for insert only)");
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
public void dmlAppend(GenerateDmlRequest request) {
// always included (in insert)
importedId.dmlAppend(request);
}
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
throw new RuntimeException("Never called");
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
private void dmlBind(BindableRequest request, boolean checkIncludes, Object bean, boolean bindNull)
throws SQLException {
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
PersistRequestBean<?> persistRequest = request.getPersistRequest();
Object parentBean = persistRequest.getParentBean();
@@ -71,13 +56,13 @@ public class BindableUnidirectional implements Bindable {
if (parentBean == null) {
Class<?> localType = desc.getBeanType();
Class<?> targetType = unidirectional.getTargetType();
;
String msg = "Error inserting bean [" + localType + "] with unidirectional relationship. ";
msg += "For inserts you must use cascade save on the master bean [" + targetType + "].";
throw new PersistenceException(msg);
}
importedId.bind(request, parentBean, bindNull);
importedId.bind(request, (EntityBean)parentBean);
}
}
@@ -27,8 +27,6 @@ public class FactoryAssocOnes {
} else {
switch (mode) {
case WHERE:
break;
case INSERT:
if (!ones[i].isInsertable()) {
continue;
@@ -28,9 +28,10 @@ public class FactoryEmbedded {
for (int j = 0; j < embedded.length; j++) {
List<Bindable> bindList = new ArrayList<Bindable>();
BeanProperty[] props = embedded[j].getProperties();
List<Bindable> bindList = new ArrayList<Bindable>(props.length);
BeanProperty[] props = embedded[j].getProperties();
for (int i = 0; i < props.length; i++) {
Bindable item = factoryProperty.create(props[i], mode, withLobs);
if (item != null){
@@ -32,11 +32,11 @@ public class FactoryProperty {
}
if (prop.isLob()) {
if (DmlMode.WHERE.equals(mode) || !withLobs) {
if (!withLobs) {
// Lob exclusion
return null;
} else {
return prop.isDbEncrypted() ? new BindableEncryptedProperty(prop, bindEncryptDataFirst) : new BindableProperty(prop);
return prop.isDbEncrypted() ? new BindableEncryptedProperty(prop, bindEncryptDataFirst) : new BindableProperty(prop);
}
}
@@ -1,11 +1,7 @@
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.util.ArrayList;
import java.util.List;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
/**
* Creates a Bindable to support version concurrency where clauses.
@@ -21,40 +17,11 @@ public class FactoryVersion {
*/
public Bindable create(BeanDescriptor<?> desc) {
List<Bindable> verList = new ArrayList<Bindable>();
BeanProperty[] vers = desc.propertiesVersion();
for (int i = 0; i < vers.length; i++) {
verList.add(new BindableProperty(vers[i]));
}
// version columns on embedded beans?
BeanPropertyAssocOne<?>[] embedded = desc.propertiesEmbedded();
for (int j = 0; j < embedded.length; j++) {
if (embedded[j].isEmbeddedVersion()) {
List<Bindable> bindList = new ArrayList<Bindable>();
BeanProperty[] embProps = embedded[j].getProperties();
for (int i = 0; i < embProps.length; i++) {
if (embProps[i].isVersion()){
bindList.add(new BindableProperty(embProps[i]));
}
}
verList.add(new BindableEmbedded(embedded[j], bindList));
}
}
if (verList.size() == 0){
return null;
}
if (verList.size() == 1){
return verList.get(0);
}
return new BindableList(verList);
BeanProperty versionProperty = desc.getVersionProperty();
if (versionProperty == null) {
return null;
}
return new BindableProperty(versionProperty);
}
}
@@ -1,5 +1,6 @@
package com.avaje.ebeaninternal.server.persist.dmlbind;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
@@ -30,14 +31,14 @@ class MatchedImportedProperty {
this.localProp = localProp;
}
protected void populate(Object sourceBean, Object destBean) {
protected void populate(EntityBean sourceBean, EntityBean destBean) {
Object assocBean = assocOne.getValue(sourceBean);
if (assocBean == null) {
String msg = "The assoc bean for " + assocOne + " is null?";
throw new NullPointerException(msg);
}
Object value = foreignProp.getValue(assocBean);
Object value = foreignProp.getValue((EntityBean)assocBean);
localProp.setValue(destBean, value);
}