mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
No effective change - change newline char
This commit is contained in:
1 parent
4143c0de26
commit
4eaa6adf08
58 files changed
+7127
-7127
No files matched your search
@@ -1,42 +1,42 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Item held by Meta objects used to generate and bind bean insert update and
|
||||
* delete statements.
|
||||
* <p>
|
||||
* An implementation is expected to be immutable and thread safe.
|
||||
* </p>
|
||||
* <p>
|
||||
* The design is to take a bean structure with embedded and associated objects
|
||||
* etc and flatten that into lists of Bindable objects. These are put into
|
||||
* InsertMeta UpdateMeta and DeleteMeta objects to support the generation of DML
|
||||
* and binding of statements in a fast and painless manor.
|
||||
* </p>
|
||||
*/
|
||||
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 addToUpdate(PersistRequestBean<?> request, List<Bindable> list);
|
||||
|
||||
/**
|
||||
* append sql to the buffer with prefix and suffix options.
|
||||
*/
|
||||
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, EntityBean bean) throws SQLException;
|
||||
|
||||
}
|
||||
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;
|
||||
|
||||
/**
|
||||
* Item held by Meta objects used to generate and bind bean insert update and
|
||||
* delete statements.
|
||||
* <p>
|
||||
* An implementation is expected to be immutable and thread safe.
|
||||
* </p>
|
||||
* <p>
|
||||
* The design is to take a bean structure with embedded and associated objects
|
||||
* etc and flatten that into lists of Bindable objects. These are put into
|
||||
* InsertMeta UpdateMeta and DeleteMeta objects to support the generation of DML
|
||||
* and binding of statements in a fast and painless manor.
|
||||
* </p>
|
||||
*/
|
||||
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 addToUpdate(PersistRequestBean<?> request, List<Bindable> list);
|
||||
|
||||
/**
|
||||
* append sql to the buffer with prefix and suffix options.
|
||||
*/
|
||||
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, EntityBean bean) throws SQLException;
|
||||
|
||||
}
|
||||
+56
-56
@@ -1,56 +1,56 @@
|
||||
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;
|
||||
import com.avaje.ebeaninternal.server.deploy.id.ImportedId;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
/**
|
||||
* Bindable for an ManyToOne or OneToOne associated bean.
|
||||
*/
|
||||
public class BindableAssocOne implements Bindable {
|
||||
|
||||
private final BeanPropertyAssocOne<?> assocOne;
|
||||
|
||||
private final ImportedId importedId;
|
||||
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
import com.avaje.ebeaninternal.server.deploy.id.ImportedId;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
/**
|
||||
* Bindable for an ManyToOne or OneToOne associated bean.
|
||||
*/
|
||||
public class BindableAssocOne implements Bindable {
|
||||
|
||||
private final BeanPropertyAssocOne<?> assocOne;
|
||||
|
||||
private final ImportedId importedId;
|
||||
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+54
-54
@@ -1,54 +1,54 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bindable for a Immutable Compound value object.
|
||||
*/
|
||||
public class BindableCompound implements Bindable {
|
||||
|
||||
private final BindableProperty[] items;
|
||||
|
||||
private final BeanPropertyCompound compound;
|
||||
|
||||
public BindableCompound(BeanPropertyCompound embProp, List<BindableProperty> list) {
|
||||
this.compound = embProp;
|
||||
this.items = list.toArray(new BindableProperty[list.size()]);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "BindableCompound " + compound + " items:" + Arrays.toString(items);
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
if (request.isAddToUpdate(compound)) {
|
||||
list.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
|
||||
|
||||
// get the compound type value
|
||||
Object valueObject = compound.getValue(bean);
|
||||
|
||||
// bind each of the underlying scalar values for this compound type
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].dmlBindObject(bindRequest, valueObject);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bindable for a Immutable Compound value object.
|
||||
*/
|
||||
public class BindableCompound implements Bindable {
|
||||
|
||||
private final BindableProperty[] items;
|
||||
|
||||
private final BeanPropertyCompound compound;
|
||||
|
||||
public BindableCompound(BeanPropertyCompound embProp, List<BindableProperty> list) {
|
||||
this.compound = embProp;
|
||||
this.items = list.toArray(new BindableProperty[list.size()]);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "BindableCompound " + compound + " items:" + Arrays.toString(items);
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
if (request.isAddToUpdate(compound)) {
|
||||
list.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
|
||||
|
||||
// get the compound type value
|
||||
Object valueObject = compound.getValue(bean);
|
||||
|
||||
// bind each of the underlying scalar values for this compound type
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].dmlBindObject(bindRequest, valueObject);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+45
-45
@@ -1,45 +1,45 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import java.sql.SQLException;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bindable for inserting a discriminator value.
|
||||
*/
|
||||
public class BindableDiscriminator implements Bindable {
|
||||
|
||||
private final String columnName;
|
||||
private final Object discValue;
|
||||
private final int sqlType;
|
||||
|
||||
public BindableDiscriminator(InheritInfo inheritInfo) {
|
||||
this.columnName = inheritInfo.getDiscriminatorColumn();
|
||||
this.discValue = inheritInfo.getDiscriminatorValue();
|
||||
this.sqlType = inheritInfo.getDiscriminatorType();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return columnName + " = " + discValue;
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
throw new PersistenceException("Never called (only for inserts)");
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
request.appendColumn(columnName);
|
||||
}
|
||||
|
||||
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
|
||||
|
||||
bindRequest.bind(columnName, discValue, sqlType);
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import java.sql.SQLException;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bindable for inserting a discriminator value.
|
||||
*/
|
||||
public class BindableDiscriminator implements Bindable {
|
||||
|
||||
private final String columnName;
|
||||
private final Object discValue;
|
||||
private final int sqlType;
|
||||
|
||||
public BindableDiscriminator(InheritInfo inheritInfo) {
|
||||
this.columnName = inheritInfo.getDiscriminatorColumn();
|
||||
this.discValue = inheritInfo.getDiscriminatorValue();
|
||||
this.sqlType = inheritInfo.getDiscriminatorType();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return columnName + " = " + discValue;
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
throw new PersistenceException("Never called (only for inserts)");
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
request.appendColumn(columnName);
|
||||
}
|
||||
|
||||
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
|
||||
|
||||
bindRequest.bind(columnName, discValue, sqlType);
|
||||
}
|
||||
|
||||
}
|
||||
+60
-60
@@ -1,60 +1,60 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
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.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
/**
|
||||
* Bindable for a Embedded bean.
|
||||
*/
|
||||
public class BindableEmbedded implements Bindable {
|
||||
|
||||
private final Bindable[] items;
|
||||
|
||||
private final BeanPropertyAssocOne<?> embProp;
|
||||
|
||||
public BindableEmbedded(BeanPropertyAssocOne<?> embProp, List<Bindable> bindList) {
|
||||
this.embProp = embProp;
|
||||
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 dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
if (request.isAddToUpdate(embProp)) {
|
||||
list.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
|
||||
|
||||
// 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, null);
|
||||
}
|
||||
} else {
|
||||
//EntityBeanIntercept ebi = embBean._ebean_getIntercept();
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
//if (ebi.isLoadedProperty(props[i].getPropertyIndex())) {
|
||||
items[i].dmlBind(bindRequest, embBean);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
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.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
/**
|
||||
* Bindable for a Embedded bean.
|
||||
*/
|
||||
public class BindableEmbedded implements Bindable {
|
||||
|
||||
private final Bindable[] items;
|
||||
|
||||
private final BeanPropertyAssocOne<?> embProp;
|
||||
|
||||
public BindableEmbedded(BeanPropertyAssocOne<?> embProp, List<Bindable> bindList) {
|
||||
this.embProp = embProp;
|
||||
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 dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
if (request.isAddToUpdate(embProp)) {
|
||||
list.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
|
||||
|
||||
// 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, null);
|
||||
}
|
||||
} else {
|
||||
//EntityBeanIntercept ebi = embBean._ebean_getIntercept();
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
//if (ebi.isLoadedProperty(props[i].getPropertyIndex())) {
|
||||
items[i].dmlBind(bindRequest, embBean);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+69
-69
@@ -1,69 +1,69 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bindable for a DB encrypted BeanProperty.
|
||||
*/
|
||||
public class BindableEncryptedProperty implements Bindable {
|
||||
|
||||
private final BeanProperty prop;
|
||||
|
||||
private final boolean bindEncryptDataFirst;
|
||||
|
||||
public BindableEncryptedProperty(BeanProperty prop, boolean bindEncryptDataFirst) {
|
||||
this.prop = prop;
|
||||
this.bindEncryptDataFirst = bindEncryptDataFirst;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return prop.toString();
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
if (request.isAddToUpdate(prop)) {
|
||||
list.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
// columnName = AES_ENCRYPT(?,?)
|
||||
request.appendColumn(prop.getDbColumn(), prop.getDbBind());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Bind a value in a Insert SET clause.
|
||||
*/
|
||||
public void dmlBind(BindableRequest request, EntityBean bean)
|
||||
throws SQLException {
|
||||
|
||||
Object value = null;
|
||||
if (bean != null) {
|
||||
value = prop.getValue(bean);
|
||||
}
|
||||
|
||||
// get Encrypt key
|
||||
String encryptKeyValue = prop.getEncryptKey().getStringValue();
|
||||
|
||||
if (!bindEncryptDataFirst){
|
||||
// H2 encrypt function ... different parameter order
|
||||
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
|
||||
}
|
||||
request.bindNoLog(value, prop);
|
||||
|
||||
if (bindEncryptDataFirst){
|
||||
// MySql, Postgres, Oracle
|
||||
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bindable for a DB encrypted BeanProperty.
|
||||
*/
|
||||
public class BindableEncryptedProperty implements Bindable {
|
||||
|
||||
private final BeanProperty prop;
|
||||
|
||||
private final boolean bindEncryptDataFirst;
|
||||
|
||||
public BindableEncryptedProperty(BeanProperty prop, boolean bindEncryptDataFirst) {
|
||||
this.prop = prop;
|
||||
this.bindEncryptDataFirst = bindEncryptDataFirst;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return prop.toString();
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
if (request.isAddToUpdate(prop)) {
|
||||
list.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
// columnName = AES_ENCRYPT(?,?)
|
||||
request.appendColumn(prop.getDbColumn(), prop.getDbBind());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Bind a value in a Insert SET clause.
|
||||
*/
|
||||
public void dmlBind(BindableRequest request, EntityBean bean)
|
||||
throws SQLException {
|
||||
|
||||
Object value = null;
|
||||
if (bean != null) {
|
||||
value = prop.getValue(bean);
|
||||
}
|
||||
|
||||
// get Encrypt key
|
||||
String encryptKeyValue = prop.getEncryptKey().getStringValue();
|
||||
|
||||
if (!bindEncryptDataFirst){
|
||||
// H2 encrypt function ... different parameter order
|
||||
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
|
||||
}
|
||||
request.bindNoLog(value, prop);
|
||||
|
||||
if (bindEncryptDataFirst){
|
||||
// MySql, Postgres, Oracle
|
||||
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +1,42 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
|
||||
|
||||
/**
|
||||
* Adds support for id creation for concatenated ids on intersection tables.
|
||||
* <p>
|
||||
* Specifically if the concatenated id object is null on insert this can be
|
||||
* built from the matching ManyToOne associated beans. For example RoleUserId
|
||||
* embeddedId object could be built from the associated Role and User beans.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is only attempted if the id is null when it gets to the insert.
|
||||
* </p>
|
||||
*/
|
||||
public interface BindableId extends Bindable {
|
||||
|
||||
/**
|
||||
* Return true if there is no Id properties at all.
|
||||
*/
|
||||
public boolean isEmpty();
|
||||
|
||||
/**
|
||||
* Return true if this is a concatenated key.
|
||||
*/
|
||||
public boolean isConcatenated();
|
||||
|
||||
/**
|
||||
* Return the DB Column to use with genGeneratedKeys.
|
||||
*/
|
||||
public String getIdentityColumn();
|
||||
|
||||
/**
|
||||
* Create the concatenated id for inserts with PFK relationships.
|
||||
* <p>
|
||||
* Really only where there are ManyToOne assoc beans that make up the
|
||||
* primary key and the values can be got from those.
|
||||
* </p>
|
||||
*/
|
||||
public boolean deriveConcatenatedId(PersistRequestBean<?> persist);
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
|
||||
|
||||
/**
|
||||
* Adds support for id creation for concatenated ids on intersection tables.
|
||||
* <p>
|
||||
* Specifically if the concatenated id object is null on insert this can be
|
||||
* built from the matching ManyToOne associated beans. For example RoleUserId
|
||||
* embeddedId object could be built from the associated Role and User beans.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is only attempted if the id is null when it gets to the insert.
|
||||
* </p>
|
||||
*/
|
||||
public interface BindableId extends Bindable {
|
||||
|
||||
/**
|
||||
* Return true if there is no Id properties at all.
|
||||
*/
|
||||
public boolean isEmpty();
|
||||
|
||||
/**
|
||||
* Return true if this is a concatenated key.
|
||||
*/
|
||||
public boolean isConcatenated();
|
||||
|
||||
/**
|
||||
* Return the DB Column to use with genGeneratedKeys.
|
||||
*/
|
||||
public String getIdentityColumn();
|
||||
|
||||
/**
|
||||
* Create the concatenated id for inserts with PFK relationships.
|
||||
* <p>
|
||||
* Really only where there are ManyToOne assoc beans that make up the
|
||||
* primary key and the values can be got from those.
|
||||
* </p>
|
||||
*/
|
||||
public boolean deriveConcatenatedId(PersistRequestBean<?> persist);
|
||||
|
||||
}
|
||||
+101
-101
@@ -1,101 +1,101 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
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;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
/**
|
||||
* Bindable for a EmbeddedId.
|
||||
*/
|
||||
public final class BindableIdEmbedded implements BindableId {
|
||||
|
||||
private final BeanPropertyAssocOne<?> embId;
|
||||
|
||||
private final BeanProperty[] props;
|
||||
|
||||
private final MatchedImportedProperty[] matches;
|
||||
|
||||
public BindableIdEmbedded(BeanPropertyAssocOne<?> embId, BeanDescriptor<?> desc) {
|
||||
this.embId = embId;
|
||||
this.props = embId.getProperties();
|
||||
matches = MatchedImportedProperty.build(props, desc);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isConcatenated() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getIdentityColumn() {
|
||||
// return null for concatenated keys
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return embId + " props:" + Arrays.toString(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing for BindableId.
|
||||
*/
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
// do nothing (id not changing)
|
||||
}
|
||||
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
EntityBean idValue = (EntityBean)embId.getValue(bean);
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
|
||||
Object value = props[i].getValue(idValue);
|
||||
request.bind(value, props[i]);
|
||||
}
|
||||
|
||||
request.setIdValue(idValue);
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
request.appendColumn(props[i].getDbColumn());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
|
||||
|
||||
if (matches == null) {
|
||||
String m = "Matches for the concatinated key columns where not found?"
|
||||
+ " I expect that the concatinated key was null, and this bean does"
|
||||
+ " not have ManyToOne assoc beans matching the primary key columns?";
|
||||
throw new PersistenceException(m);
|
||||
}
|
||||
|
||||
EntityBean bean = persist.getEntityBean();
|
||||
|
||||
// create the new id
|
||||
EntityBean newId = (EntityBean)embId.createEmbeddedId();
|
||||
|
||||
// populate it from the assoc one id values...
|
||||
for (int i = 0; i < matches.length; i++) {
|
||||
matches[i].populate(bean, newId);
|
||||
}
|
||||
|
||||
// support PropertyChangeSupport
|
||||
embId.setValueIntercept(bean, newId);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
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;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
/**
|
||||
* Bindable for a EmbeddedId.
|
||||
*/
|
||||
public final class BindableIdEmbedded implements BindableId {
|
||||
|
||||
private final BeanPropertyAssocOne<?> embId;
|
||||
|
||||
private final BeanProperty[] props;
|
||||
|
||||
private final MatchedImportedProperty[] matches;
|
||||
|
||||
public BindableIdEmbedded(BeanPropertyAssocOne<?> embId, BeanDescriptor<?> desc) {
|
||||
this.embId = embId;
|
||||
this.props = embId.getProperties();
|
||||
matches = MatchedImportedProperty.build(props, desc);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isConcatenated() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getIdentityColumn() {
|
||||
// return null for concatenated keys
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return embId + " props:" + Arrays.toString(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing for BindableId.
|
||||
*/
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
// do nothing (id not changing)
|
||||
}
|
||||
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
EntityBean idValue = (EntityBean)embId.getValue(bean);
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
|
||||
Object value = props[i].getValue(idValue);
|
||||
request.bind(value, props[i]);
|
||||
}
|
||||
|
||||
request.setIdValue(idValue);
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
request.appendColumn(props[i].getDbColumn());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
|
||||
|
||||
if (matches == null) {
|
||||
String m = "Matches for the concatinated key columns where not found?"
|
||||
+ " I expect that the concatinated key was null, and this bean does"
|
||||
+ " not have ManyToOne assoc beans matching the primary key columns?";
|
||||
throw new PersistenceException(m);
|
||||
}
|
||||
|
||||
EntityBean bean = persist.getEntityBean();
|
||||
|
||||
// create the new id
|
||||
EntityBean newId = (EntityBean)embId.createEmbeddedId();
|
||||
|
||||
// populate it from the assoc one id values...
|
||||
for (int i = 0; i < matches.length; i++) {
|
||||
matches[i].populate(bean, newId);
|
||||
}
|
||||
|
||||
// support PropertyChangeSupport
|
||||
embId.setValueIntercept(bean, newId);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +1,95 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
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;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
/**
|
||||
* Bindable for a concatenated id that is not embedded.
|
||||
*/
|
||||
public final class BindableIdMap implements BindableId {
|
||||
|
||||
private final BeanProperty[] uids;
|
||||
|
||||
private final MatchedImportedProperty[] matches;
|
||||
|
||||
public BindableIdMap(BeanProperty[] uids, BeanDescriptor<?> desc) {
|
||||
this.uids = uids;
|
||||
matches = MatchedImportedProperty.build(uids, desc);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isConcatenated() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getIdentityColumn() {
|
||||
// return null for concatenated keys
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Arrays.toString(uids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing for BindableId.
|
||||
*/
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
// do nothing (id not changing)
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
for (int i = 0; i < uids.length; i++) {
|
||||
request.appendColumn(uids[i].getDbColumn());
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
request.bind(value, uids[i]);
|
||||
|
||||
// putting logicalType into map rather than
|
||||
// the dbType (which may have been converted).
|
||||
mapId.put(uids[i].getName(), value);
|
||||
}
|
||||
request.setIdValue(mapId);
|
||||
}
|
||||
|
||||
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
|
||||
|
||||
if (matches == null) {
|
||||
String m = "Matches for the concatinated key columns where not found?"
|
||||
+ " I expect that the concatinated key was null, and this bean does"
|
||||
+ " not have ManyToOne assoc beans matching the primary key columns?";
|
||||
throw new PersistenceException(m);
|
||||
}
|
||||
|
||||
EntityBean bean = persist.getEntityBean();
|
||||
|
||||
// populate it from the assoc one id values...
|
||||
for (int i = 0; i < matches.length; i++) {
|
||||
matches[i].populate(bean, bean);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
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;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
/**
|
||||
* Bindable for a concatenated id that is not embedded.
|
||||
*/
|
||||
public final class BindableIdMap implements BindableId {
|
||||
|
||||
private final BeanProperty[] uids;
|
||||
|
||||
private final MatchedImportedProperty[] matches;
|
||||
|
||||
public BindableIdMap(BeanProperty[] uids, BeanDescriptor<?> desc) {
|
||||
this.uids = uids;
|
||||
matches = MatchedImportedProperty.build(uids, desc);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isConcatenated() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getIdentityColumn() {
|
||||
// return null for concatenated keys
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Arrays.toString(uids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing for BindableId.
|
||||
*/
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
// do nothing (id not changing)
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
for (int i = 0; i < uids.length; i++) {
|
||||
request.appendColumn(uids[i].getDbColumn());
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
request.bind(value, uids[i]);
|
||||
|
||||
// putting logicalType into map rather than
|
||||
// the dbType (which may have been converted).
|
||||
mapId.put(uids[i].getName(), value);
|
||||
}
|
||||
request.setIdValue(mapId);
|
||||
}
|
||||
|
||||
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
|
||||
|
||||
if (matches == null) {
|
||||
String m = "Matches for the concatinated key columns where not found?"
|
||||
+ " I expect that the concatinated key was null, and this bean does"
|
||||
+ " not have ManyToOne assoc beans matching the primary key columns?";
|
||||
throw new PersistenceException(m);
|
||||
}
|
||||
|
||||
EntityBean bean = persist.getEntityBean();
|
||||
|
||||
// populate it from the assoc one id values...
|
||||
for (int i = 0; i < matches.length; i++) {
|
||||
matches[i].populate(bean, bean);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+70
-70
@@ -1,70 +1,70 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import java.sql.SQLException;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bindable for a single scalar id property.
|
||||
*/
|
||||
public final class BindableIdScalar implements BindableId {
|
||||
|
||||
private final BeanProperty uidProp;
|
||||
|
||||
public BindableIdScalar(BeanProperty uidProp) {
|
||||
this.uidProp = uidProp;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isConcatenated() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getIdentityColumn() {
|
||||
return uidProp.getDbColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return uidProp.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing for BindableId.
|
||||
*/
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
// do nothing (id not changing)
|
||||
}
|
||||
|
||||
/**
|
||||
* Should not be called as this is really only for concatenated keys.
|
||||
*/
|
||||
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
|
||||
throw new PersistenceException("Should not be called? only for concatinated keys");
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
request.appendColumn(uidProp.getDbColumn());
|
||||
}
|
||||
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
Object value = uidProp.getValue(bean);
|
||||
|
||||
request.bind(value, uidProp);
|
||||
|
||||
// used for summary logging
|
||||
request.setIdValue(value);
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import java.sql.SQLException;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bindable for a single scalar id property.
|
||||
*/
|
||||
public final class BindableIdScalar implements BindableId {
|
||||
|
||||
private final BeanProperty uidProp;
|
||||
|
||||
public BindableIdScalar(BeanProperty uidProp) {
|
||||
this.uidProp = uidProp;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isConcatenated() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getIdentityColumn() {
|
||||
return uidProp.getDbColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return uidProp.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing for BindableId.
|
||||
*/
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
// do nothing (id not changing)
|
||||
}
|
||||
|
||||
/**
|
||||
* Should not be called as this is really only for concatenated keys.
|
||||
*/
|
||||
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
|
||||
throw new PersistenceException("Should not be called? only for concatinated keys");
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
request.appendColumn(uidProp.getDbColumn());
|
||||
}
|
||||
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
Object value = uidProp.getValue(bean);
|
||||
|
||||
request.bind(value, uidProp);
|
||||
|
||||
// used for summary logging
|
||||
request.setIdValue(value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +1,48 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* List of Bindable items.
|
||||
*/
|
||||
public class BindableList implements Bindable {
|
||||
|
||||
private final Bindable[] items;
|
||||
|
||||
public BindableList(List<Bindable> list) {
|
||||
items = list.toArray(new Bindable[list.size()]);
|
||||
}
|
||||
|
||||
public void addAll(List<Bindable> list) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
list.add(items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].addToUpdate(request, list);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlBind(BindableRequest bindRequest, EntityBean bean)
|
||||
throws SQLException {
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].dmlBind(bindRequest, bean);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
|
||||
/**
|
||||
* List of Bindable items.
|
||||
*/
|
||||
public class BindableList implements Bindable {
|
||||
|
||||
private final Bindable[] items;
|
||||
|
||||
public BindableList(List<Bindable> list) {
|
||||
items = list.toArray(new Bindable[list.size()]);
|
||||
}
|
||||
|
||||
public void addAll(List<Bindable> list) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
list.add(items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].addToUpdate(request, list);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlBind(BindableRequest bindRequest, EntityBean bean)
|
||||
throws SQLException {
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].dmlBind(bindRequest, bean);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+59
-59
@@ -1,59 +1,59 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bindable for a single BeanProperty.
|
||||
*/
|
||||
public class BindableProperty implements Bindable {
|
||||
|
||||
protected final BeanProperty prop;
|
||||
|
||||
public BindableProperty(BeanProperty prop) {
|
||||
this.prop = prop;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return prop.toString();
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
if (request.isAddToUpdate(prop)) {
|
||||
list.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
request.appendColumn(prop.getDbColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal binding of a property value from the bean.
|
||||
*/
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
Object value = null;
|
||||
if (bean != null) {
|
||||
value = prop.getValue(bean);
|
||||
}
|
||||
request.bind(value, prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* For compound types bind one of the underlying scalar values for a compound type.
|
||||
*/
|
||||
public void dmlBindObject(BindableRequest request, Object bean) throws SQLException {
|
||||
|
||||
Object value = null;
|
||||
if (bean != null) {
|
||||
value = prop.getValueObject(bean);
|
||||
}
|
||||
request.bind(value, prop);
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bindable for a single BeanProperty.
|
||||
*/
|
||||
public class BindableProperty implements Bindable {
|
||||
|
||||
protected final BeanProperty prop;
|
||||
|
||||
public BindableProperty(BeanProperty prop) {
|
||||
this.prop = prop;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return prop.toString();
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
if (request.isAddToUpdate(prop)) {
|
||||
list.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
request.appendColumn(prop.getDbColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal binding of a property value from the bean.
|
||||
*/
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
Object value = null;
|
||||
if (bean != null) {
|
||||
value = prop.getValue(bean);
|
||||
}
|
||||
request.bind(value, prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* For compound types bind one of the underlying scalar values for a compound type.
|
||||
*/
|
||||
public void dmlBindObject(BindableRequest request, Object bean) throws SQLException {
|
||||
|
||||
Object value = null;
|
||||
if (bean != null) {
|
||||
value = prop.getValueObject(bean);
|
||||
}
|
||||
request.bind(value, prop);
|
||||
}
|
||||
}
|
||||
+46
-46
@@ -1,46 +1,46 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bindable for insert on a property with a GeneratedProperty.
|
||||
* <p>
|
||||
* This is typically a 'insert timestamp', 'update timestamp' or 'counter'.
|
||||
* </p>
|
||||
*/
|
||||
public class BindablePropertyInsertGenerated extends BindableProperty {
|
||||
|
||||
private final GeneratedProperty gen;
|
||||
|
||||
public BindablePropertyInsertGenerated(BeanProperty prop, GeneratedProperty gen) {
|
||||
super(prop);
|
||||
this.gen = gen;
|
||||
}
|
||||
|
||||
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);
|
||||
prop.setValue(bean, value);
|
||||
}
|
||||
request.bind(value, prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Always bind on Insert SET.
|
||||
*/
|
||||
@Override
|
||||
public void dmlAppend(GenerateDmlRequest request){
|
||||
request.appendColumn(prop.getDbColumn());
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bindable for insert on a property with a GeneratedProperty.
|
||||
* <p>
|
||||
* This is typically a 'insert timestamp', 'update timestamp' or 'counter'.
|
||||
* </p>
|
||||
*/
|
||||
public class BindablePropertyInsertGenerated extends BindableProperty {
|
||||
|
||||
private final GeneratedProperty gen;
|
||||
|
||||
public BindablePropertyInsertGenerated(BeanProperty prop, GeneratedProperty gen) {
|
||||
super(prop);
|
||||
this.gen = gen;
|
||||
}
|
||||
|
||||
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);
|
||||
prop.setValue(bean, value);
|
||||
}
|
||||
request.bind(value, prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Always bind on Insert SET.
|
||||
*/
|
||||
@Override
|
||||
public void dmlAppend(GenerateDmlRequest request){
|
||||
request.appendColumn(prop.getDbColumn());
|
||||
}
|
||||
|
||||
}
|
||||
+64
-64
@@ -1,64 +1,64 @@
|
||||
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;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
/**
|
||||
* Bindable for update on a property with a GeneratedProperty.
|
||||
* <p>
|
||||
* This is typically a 'update timestamp' or 'counter'.
|
||||
* </p>
|
||||
*/
|
||||
public class BindablePropertyUpdateGenerated extends BindableProperty {
|
||||
|
||||
private final GeneratedProperty gen;
|
||||
|
||||
public BindablePropertyUpdateGenerated(BeanProperty prop, GeneratedProperty gen) {
|
||||
super(prop);
|
||||
this.gen = gen;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
Object value = gen.getUpdateValue(prop, bean);
|
||||
|
||||
// generated value should be the correct type
|
||||
request.bind(value, prop);
|
||||
|
||||
// only register the update value if it was included
|
||||
// in the bean in the first place
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Always bind on Insert SET.
|
||||
*/
|
||||
@Override
|
||||
public void dmlAppend(GenerateDmlRequest request){
|
||||
request.appendColumn(prop.getDbColumn());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
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;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
/**
|
||||
* Bindable for update on a property with a GeneratedProperty.
|
||||
* <p>
|
||||
* This is typically a 'update timestamp' or 'counter'.
|
||||
* </p>
|
||||
*/
|
||||
public class BindablePropertyUpdateGenerated extends BindableProperty {
|
||||
|
||||
private final GeneratedProperty gen;
|
||||
|
||||
public BindablePropertyUpdateGenerated(BeanProperty prop, GeneratedProperty gen) {
|
||||
super(prop);
|
||||
this.gen = gen;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
Object value = gen.getUpdateValue(prop, bean);
|
||||
|
||||
// generated value should be the correct type
|
||||
request.bind(value, prop);
|
||||
|
||||
// only register the update value if it was included
|
||||
// in the bean in the first place
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Always bind on Insert SET.
|
||||
*/
|
||||
@Override
|
||||
public void dmlAppend(GenerateDmlRequest request){
|
||||
request.appendColumn(prop.getDbColumn());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,60 +1,60 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Request object passed to bindables.
|
||||
*/
|
||||
public interface BindableRequest {
|
||||
|
||||
/**
|
||||
* Set the id for use with summary level logging.
|
||||
*/
|
||||
public void setIdValue(Object idValue);
|
||||
|
||||
/**
|
||||
* Bind the value to a PreparedStatement.
|
||||
* <p>
|
||||
* Takes into account logicalType to dbType conversion if required.
|
||||
* </p>
|
||||
* <p>
|
||||
* Returns the value that was bound (and was potentially converted from
|
||||
* logicalType to dbType.
|
||||
* </p>
|
||||
*/
|
||||
public Object bind(Object value, BeanProperty prop) throws SQLException;
|
||||
|
||||
/**
|
||||
* Bind a raw value. Used to bind the discriminator column.
|
||||
*/
|
||||
public Object bind(String propName, Object value, int sqlType) throws SQLException;
|
||||
|
||||
/**
|
||||
* Bind a raw value with a placeHolder to put into the transaction log.
|
||||
*/
|
||||
public Object bindNoLog(Object value, int sqlType, String logPlaceHolder) throws SQLException;
|
||||
|
||||
/**
|
||||
* Bind the value to the preparedStatement without logging.
|
||||
*/
|
||||
public Object bindNoLog(Object value, BeanProperty prop) throws SQLException;
|
||||
|
||||
|
||||
/**
|
||||
* 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, EntityBean bean, Object value);
|
||||
|
||||
/**
|
||||
* Return the original PersistRequest.
|
||||
*/
|
||||
public PersistRequestBean<?> getPersistRequest();
|
||||
|
||||
public void registerDerivedRelationship(DerivedRelationshipData assocBean);
|
||||
}
|
||||
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;
|
||||
|
||||
/**
|
||||
* Request object passed to bindables.
|
||||
*/
|
||||
public interface BindableRequest {
|
||||
|
||||
/**
|
||||
* Set the id for use with summary level logging.
|
||||
*/
|
||||
public void setIdValue(Object idValue);
|
||||
|
||||
/**
|
||||
* Bind the value to a PreparedStatement.
|
||||
* <p>
|
||||
* Takes into account logicalType to dbType conversion if required.
|
||||
* </p>
|
||||
* <p>
|
||||
* Returns the value that was bound (and was potentially converted from
|
||||
* logicalType to dbType.
|
||||
* </p>
|
||||
*/
|
||||
public Object bind(Object value, BeanProperty prop) throws SQLException;
|
||||
|
||||
/**
|
||||
* Bind a raw value. Used to bind the discriminator column.
|
||||
*/
|
||||
public Object bind(String propName, Object value, int sqlType) throws SQLException;
|
||||
|
||||
/**
|
||||
* Bind a raw value with a placeHolder to put into the transaction log.
|
||||
*/
|
||||
public Object bindNoLog(Object value, int sqlType, String logPlaceHolder) throws SQLException;
|
||||
|
||||
/**
|
||||
* Bind the value to the preparedStatement without logging.
|
||||
*/
|
||||
public Object bindNoLog(Object value, BeanProperty prop) throws SQLException;
|
||||
|
||||
|
||||
/**
|
||||
* 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, EntityBean bean, Object value);
|
||||
|
||||
/**
|
||||
* Return the original PersistRequest.
|
||||
*/
|
||||
public PersistRequestBean<?> getPersistRequest();
|
||||
|
||||
public void registerDerivedRelationship(DerivedRelationshipData assocBean);
|
||||
}
|
||||
+68
-68
@@ -1,68 +1,68 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import java.sql.SQLException;
|
||||
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;
|
||||
import com.avaje.ebeaninternal.server.deploy.id.ImportedId;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
/**
|
||||
* Bindable for a unidirectional relationship.
|
||||
* <p>
|
||||
* This inserts the foreign key value that is retrieved from the id of the
|
||||
* parentBean.
|
||||
* </p>
|
||||
*/
|
||||
public class BindableUnidirectional implements Bindable {
|
||||
|
||||
private final BeanPropertyAssocOne<?> unidirectional;
|
||||
|
||||
private final ImportedId importedId;
|
||||
|
||||
private final BeanDescriptor<?> desc;
|
||||
|
||||
public BindableUnidirectional(BeanDescriptor<?> desc, BeanPropertyAssocOne<?> unidirectional) {
|
||||
this.desc = desc;
|
||||
this.unidirectional = unidirectional;
|
||||
this.importedId = unidirectional.getImportedId();
|
||||
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "BindableShadowFKey " + unidirectional;
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
throw new PersistenceException("Never called (for insert only)");
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
// always included (in insert)
|
||||
importedId.dmlAppend(request);
|
||||
}
|
||||
|
||||
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
PersistRequestBean<?> persistRequest = request.getPersistRequest();
|
||||
Object parentBean = persistRequest.getParentBean();
|
||||
|
||||
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, (EntityBean)parentBean);
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import java.sql.SQLException;
|
||||
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;
|
||||
import com.avaje.ebeaninternal.server.deploy.id.ImportedId;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
/**
|
||||
* Bindable for a unidirectional relationship.
|
||||
* <p>
|
||||
* This inserts the foreign key value that is retrieved from the id of the
|
||||
* parentBean.
|
||||
* </p>
|
||||
*/
|
||||
public class BindableUnidirectional implements Bindable {
|
||||
|
||||
private final BeanPropertyAssocOne<?> unidirectional;
|
||||
|
||||
private final ImportedId importedId;
|
||||
|
||||
private final BeanDescriptor<?> desc;
|
||||
|
||||
public BindableUnidirectional(BeanDescriptor<?> desc, BeanPropertyAssocOne<?> unidirectional) {
|
||||
this.desc = desc;
|
||||
this.unidirectional = unidirectional;
|
||||
this.importedId = unidirectional.getImportedId();
|
||||
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "BindableShadowFKey " + unidirectional;
|
||||
}
|
||||
|
||||
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
|
||||
throw new PersistenceException("Never called (for insert only)");
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
// always included (in insert)
|
||||
importedId.dmlAppend(request);
|
||||
}
|
||||
|
||||
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
PersistRequestBean<?> persistRequest = request.getPersistRequest();
|
||||
Object parentBean = persistRequest.getParentBean();
|
||||
|
||||
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, (EntityBean)parentBean);
|
||||
}
|
||||
|
||||
}
|
||||
+47
-47
@@ -1,47 +1,47 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
|
||||
|
||||
/**
|
||||
* A factory that builds Bindable for BeanPropertyAssocOne properties.
|
||||
*/
|
||||
public class FactoryAssocOnes {
|
||||
|
||||
public FactoryAssocOnes() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add foreign key columns from associated one beans.
|
||||
*/
|
||||
public List<Bindable> create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode) {
|
||||
|
||||
BeanPropertyAssocOne<?>[] ones = desc.propertiesOneImported();
|
||||
|
||||
for (int i = 0; i < ones.length; i++) {
|
||||
if (ones[i].isImportedPrimaryKey()){
|
||||
// excluded as already part of the primary key
|
||||
|
||||
} else {
|
||||
switch (mode) {
|
||||
case INSERT:
|
||||
if (!ones[i].isInsertable()) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case UPDATE:
|
||||
if (!ones[i].isUpdateable()) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
list.add(new BindableAssocOne(ones[i]));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
|
||||
|
||||
/**
|
||||
* A factory that builds Bindable for BeanPropertyAssocOne properties.
|
||||
*/
|
||||
public class FactoryAssocOnes {
|
||||
|
||||
public FactoryAssocOnes() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add foreign key columns from associated one beans.
|
||||
*/
|
||||
public List<Bindable> create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode) {
|
||||
|
||||
BeanPropertyAssocOne<?>[] ones = desc.propertiesOneImported();
|
||||
|
||||
for (int i = 0; i < ones.length; i++) {
|
||||
if (ones[i].isImportedPrimaryKey()){
|
||||
// excluded as already part of the primary key
|
||||
|
||||
} else {
|
||||
switch (mode) {
|
||||
case INSERT:
|
||||
if (!ones[i].isInsertable()) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case UPDATE:
|
||||
if (!ones[i].isUpdateable()) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
list.add(new BindableAssocOne(ones[i]));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
+67
-67
@@ -1,67 +1,67 @@
|
||||
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.BeanPropertyCompound;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
|
||||
|
||||
/**
|
||||
* Add base properties to the BindableList for a bean type.
|
||||
* <p>
|
||||
* This excludes unique embedded and associated properties.
|
||||
* </p>
|
||||
*/
|
||||
public class FactoryBaseProperties {
|
||||
|
||||
private final FactoryProperty factoryProperty;
|
||||
|
||||
|
||||
public FactoryBaseProperties(boolean bindEncryptDataFirst) {
|
||||
factoryProperty = new FactoryProperty(bindEncryptDataFirst);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Bindable for the base properties to the list.
|
||||
*/
|
||||
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
|
||||
|
||||
add(desc.propertiesBaseScalar(), list, desc, mode, withLobs);
|
||||
|
||||
BeanPropertyCompound[] compoundProps = desc.propertiesBaseCompound();
|
||||
for (int i = 0; i < compoundProps.length; i++) {
|
||||
BeanProperty[] props = compoundProps[i].getScalarProperties();
|
||||
|
||||
List<BindableProperty> newList = new ArrayList<BindableProperty>(props.length);
|
||||
addCompound(props, newList, desc, mode, withLobs);
|
||||
|
||||
BindableCompound compoundBindable = new BindableCompound(compoundProps[i], newList);
|
||||
|
||||
list.add(compoundBindable);
|
||||
}
|
||||
}
|
||||
|
||||
private void add(BeanProperty[] props, List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Bindable item = factoryProperty.create(props[i], mode, withLobs);
|
||||
if (item != null) {
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addCompound(BeanProperty[] props, List<BindableProperty> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
BindableProperty item = (BindableProperty) factoryProperty.create(props[i], mode, withLobs);
|
||||
if (item != null) {
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
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.BeanPropertyCompound;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
|
||||
|
||||
/**
|
||||
* Add base properties to the BindableList for a bean type.
|
||||
* <p>
|
||||
* This excludes unique embedded and associated properties.
|
||||
* </p>
|
||||
*/
|
||||
public class FactoryBaseProperties {
|
||||
|
||||
private final FactoryProperty factoryProperty;
|
||||
|
||||
|
||||
public FactoryBaseProperties(boolean bindEncryptDataFirst) {
|
||||
factoryProperty = new FactoryProperty(bindEncryptDataFirst);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Bindable for the base properties to the list.
|
||||
*/
|
||||
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
|
||||
|
||||
add(desc.propertiesBaseScalar(), list, desc, mode, withLobs);
|
||||
|
||||
BeanPropertyCompound[] compoundProps = desc.propertiesBaseCompound();
|
||||
for (int i = 0; i < compoundProps.length; i++) {
|
||||
BeanProperty[] props = compoundProps[i].getScalarProperties();
|
||||
|
||||
List<BindableProperty> newList = new ArrayList<BindableProperty>(props.length);
|
||||
addCompound(props, newList, desc, mode, withLobs);
|
||||
|
||||
BindableCompound compoundBindable = new BindableCompound(compoundProps[i], newList);
|
||||
|
||||
list.add(compoundBindable);
|
||||
}
|
||||
}
|
||||
|
||||
private void add(BeanProperty[] props, List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Bindable item = factoryProperty.create(props[i], mode, withLobs);
|
||||
if (item != null) {
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addCompound(BeanProperty[] props, List<BindableProperty> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
BindableProperty item = (BindableProperty) factoryProperty.create(props[i], mode, withLobs);
|
||||
if (item != null) {
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +1,47 @@
|
||||
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;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
|
||||
|
||||
/**
|
||||
* A factory that builds Bindable for embedded bean properties.
|
||||
*/
|
||||
public class FactoryEmbedded {
|
||||
|
||||
private final FactoryProperty factoryProperty;
|
||||
|
||||
public FactoryEmbedded(boolean bindEncryptDataFirst) {
|
||||
factoryProperty = new FactoryProperty(bindEncryptDataFirst);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add bindable for the embedded properties to the list.
|
||||
*/
|
||||
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
|
||||
|
||||
BeanPropertyAssocOne<?>[] embedded = desc.propertiesEmbedded();
|
||||
|
||||
for (int j = 0; j < embedded.length; j++) {
|
||||
|
||||
BeanProperty[] props = embedded[j].getProperties();
|
||||
|
||||
List<Bindable> bindList = new ArrayList<Bindable>(props.length);
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Bindable item = factoryProperty.create(props[i], mode, withLobs);
|
||||
if (item != null){
|
||||
bindList.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
list.add(new BindableEmbedded(embedded[j], bindList));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
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;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
|
||||
|
||||
/**
|
||||
* A factory that builds Bindable for embedded bean properties.
|
||||
*/
|
||||
public class FactoryEmbedded {
|
||||
|
||||
private final FactoryProperty factoryProperty;
|
||||
|
||||
public FactoryEmbedded(boolean bindEncryptDataFirst) {
|
||||
factoryProperty = new FactoryProperty(bindEncryptDataFirst);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add bindable for the embedded properties to the list.
|
||||
*/
|
||||
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
|
||||
|
||||
BeanPropertyAssocOne<?>[] embedded = desc.propertiesEmbedded();
|
||||
|
||||
for (int j = 0; j < embedded.length; j++) {
|
||||
|
||||
BeanProperty[] props = embedded[j].getProperties();
|
||||
|
||||
List<Bindable> bindList = new ArrayList<Bindable>(props.length);
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Bindable item = factoryProperty.create(props[i], mode, withLobs);
|
||||
if (item != null){
|
||||
bindList.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
list.add(new BindableEmbedded(embedded[j], bindList));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,33 +1,33 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
|
||||
/**
|
||||
* Create a Bindable for the ids of a bean type.
|
||||
*/
|
||||
public class FactoryId {
|
||||
|
||||
public FactoryId() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add uniqueId properties.
|
||||
*/
|
||||
public BindableId createId(BeanDescriptor<?> desc) {
|
||||
|
||||
BeanProperty id = desc.getIdProperty();
|
||||
if (id == null) {
|
||||
return new BindableIdEmpty();
|
||||
|
||||
}
|
||||
if (!id.isEmbedded()) {
|
||||
return new BindableIdScalar(id);
|
||||
|
||||
} else {
|
||||
BeanPropertyAssocOne<?> embId = (BeanPropertyAssocOne<?>) id;
|
||||
return new BindableIdEmbedded(embId, desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
|
||||
/**
|
||||
* Create a Bindable for the ids of a bean type.
|
||||
*/
|
||||
public class FactoryId {
|
||||
|
||||
public FactoryId() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add uniqueId properties.
|
||||
*/
|
||||
public BindableId createId(BeanDescriptor<?> desc) {
|
||||
|
||||
BeanProperty id = desc.getIdProperty();
|
||||
if (id == null) {
|
||||
return new BindableIdEmpty();
|
||||
|
||||
}
|
||||
if (!id.isEmbedded()) {
|
||||
return new BindableIdScalar(id);
|
||||
|
||||
} else {
|
||||
BeanPropertyAssocOne<?> embId = (BeanPropertyAssocOne<?>) id;
|
||||
return new BindableIdEmbedded(embId, desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +1,65 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
|
||||
|
||||
/**
|
||||
* Creates the appropriate Bindable for a BeanProperty.
|
||||
* <p>
|
||||
* Lob properties can be excluded and it creates BindablePropertyInsertGenerated
|
||||
* and BindablePropertyUpdateGenerated as required.
|
||||
* </p>
|
||||
*/
|
||||
public class FactoryProperty {
|
||||
|
||||
private final boolean bindEncryptDataFirst;
|
||||
|
||||
public FactoryProperty(boolean bindEncryptDataFirst) {
|
||||
this.bindEncryptDataFirst = bindEncryptDataFirst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Bindable for the property given the mode and withLobs flag.
|
||||
*/
|
||||
public Bindable create(BeanProperty prop, DmlMode mode, boolean withLobs) {
|
||||
|
||||
if (DmlMode.INSERT.equals(mode) && !prop.isDbInsertable()){
|
||||
return null;
|
||||
}
|
||||
if (DmlMode.UPDATE.equals(mode) && !prop.isDbUpdatable()){
|
||||
return null;
|
||||
}
|
||||
|
||||
if (prop.isLob()) {
|
||||
if (!withLobs) {
|
||||
// Lob exclusion
|
||||
return null;
|
||||
} else {
|
||||
return prop.isDbEncrypted() ? new BindableEncryptedProperty(prop, bindEncryptDataFirst) : new BindableProperty(prop);
|
||||
}
|
||||
}
|
||||
|
||||
GeneratedProperty gen = prop.getGeneratedProperty();
|
||||
if (gen != null) {
|
||||
if (DmlMode.INSERT.equals(mode)) {
|
||||
if (gen.includeInInsert()) {
|
||||
return new BindablePropertyInsertGenerated(prop, gen);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
if (DmlMode.UPDATE.equals(mode)) {
|
||||
if (gen.includeInUpdate()) {
|
||||
return new BindablePropertyUpdateGenerated(prop, gen);
|
||||
} else {
|
||||
// An 'Insert Timestamp' is never updated
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return prop.isDbEncrypted() ? new BindableEncryptedProperty(prop, bindEncryptDataFirst) : new BindableProperty(prop);
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
|
||||
|
||||
/**
|
||||
* Creates the appropriate Bindable for a BeanProperty.
|
||||
* <p>
|
||||
* Lob properties can be excluded and it creates BindablePropertyInsertGenerated
|
||||
* and BindablePropertyUpdateGenerated as required.
|
||||
* </p>
|
||||
*/
|
||||
public class FactoryProperty {
|
||||
|
||||
private final boolean bindEncryptDataFirst;
|
||||
|
||||
public FactoryProperty(boolean bindEncryptDataFirst) {
|
||||
this.bindEncryptDataFirst = bindEncryptDataFirst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Bindable for the property given the mode and withLobs flag.
|
||||
*/
|
||||
public Bindable create(BeanProperty prop, DmlMode mode, boolean withLobs) {
|
||||
|
||||
if (DmlMode.INSERT.equals(mode) && !prop.isDbInsertable()){
|
||||
return null;
|
||||
}
|
||||
if (DmlMode.UPDATE.equals(mode) && !prop.isDbUpdatable()){
|
||||
return null;
|
||||
}
|
||||
|
||||
if (prop.isLob()) {
|
||||
if (!withLobs) {
|
||||
// Lob exclusion
|
||||
return null;
|
||||
} else {
|
||||
return prop.isDbEncrypted() ? new BindableEncryptedProperty(prop, bindEncryptDataFirst) : new BindableProperty(prop);
|
||||
}
|
||||
}
|
||||
|
||||
GeneratedProperty gen = prop.getGeneratedProperty();
|
||||
if (gen != null) {
|
||||
if (DmlMode.INSERT.equals(mode)) {
|
||||
if (gen.includeInInsert()) {
|
||||
return new BindablePropertyInsertGenerated(prop, gen);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
if (DmlMode.UPDATE.equals(mode)) {
|
||||
if (gen.includeInUpdate()) {
|
||||
return new BindablePropertyUpdateGenerated(prop, gen);
|
||||
} else {
|
||||
// An 'Insert Timestamp' is never updated
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return prop.isDbEncrypted() ? new BindableEncryptedProperty(prop, bindEncryptDataFirst) : new BindableProperty(prop);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,27 @@
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
* Creates a Bindable to support version concurrency where clauses.
|
||||
*/
|
||||
public class FactoryVersion {
|
||||
|
||||
|
||||
public FactoryVersion() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Bindable for the version property(s) for a bean type.
|
||||
*/
|
||||
public Bindable create(BeanDescriptor<?> desc) {
|
||||
|
||||
BeanProperty versionProperty = desc.getVersionProperty();
|
||||
if (versionProperty == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BindableProperty(versionProperty);
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist.dmlbind;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
* Creates a Bindable to support version concurrency where clauses.
|
||||
*/
|
||||
public class FactoryVersion {
|
||||
|
||||
|
||||
public FactoryVersion() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Bindable for the version property(s) for a bean type.
|
||||
*/
|
||||
public Bindable create(BeanDescriptor<?> desc) {
|
||||
|
||||
BeanProperty versionProperty = desc.getVersionProperty();
|
||||
if (versionProperty == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BindableProperty(versionProperty);
|
||||
}
|
||||
}
|
||||
+86
-86
@@ -1,86 +1,86 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* Matches local embedded id properties to 'matching' properties from a
|
||||
* ManyToOne associated bean that is a 'imported primary key'.
|
||||
* <p>
|
||||
* This object is designed to help BindableIdEmbedded and BindableIdMap to
|
||||
* create a concatenated id from the id values from ManyToOne associated beans.
|
||||
* This can be done when those ManyToOne associated beans make up the primary
|
||||
* key. This typically means the BindableIdEmbedded is for a intersection table
|
||||
* of a Many to Many relationship.
|
||||
* </p>
|
||||
*/
|
||||
class MatchedImportedProperty {
|
||||
|
||||
private final BeanPropertyAssocOne<?> assocOne;
|
||||
|
||||
private final BeanProperty foreignProp;
|
||||
|
||||
private final BeanProperty localProp;
|
||||
|
||||
protected MatchedImportedProperty(BeanPropertyAssocOne<?> assocOne, BeanProperty foreignProp,
|
||||
BeanProperty localProp) {
|
||||
this.assocOne = assocOne;
|
||||
this.foreignProp = foreignProp;
|
||||
this.localProp = localProp;
|
||||
}
|
||||
|
||||
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((EntityBean)assocBean);
|
||||
localProp.setValue(destBean, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the array of matchedImportedProperty based on the properties and descriptor.
|
||||
*/
|
||||
protected static MatchedImportedProperty[] build(BeanProperty[] props, BeanDescriptor<?> desc) {
|
||||
|
||||
MatchedImportedProperty[] matches = new MatchedImportedProperty[props.length];
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
// find matching assoc one property for dbColumn
|
||||
matches[i] = MatchedImportedProperty.findMatch(props[i], desc);
|
||||
if (matches[i] == null) {
|
||||
// ok, the assoc ones are not on the bean?
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
private static MatchedImportedProperty findMatch(BeanProperty prop, BeanDescriptor<?> desc) {
|
||||
|
||||
// find matching against the local database column
|
||||
String dbColumn = prop.getDbColumn();
|
||||
|
||||
BeanPropertyAssocOne<?>[] assocOnes = desc.propertiesOne();
|
||||
for (int i = 0; i < assocOnes.length; i++) {
|
||||
if (assocOnes[i].isImportedPrimaryKey()) {
|
||||
|
||||
// search using the ImportedId from the assoc one
|
||||
BeanProperty foreignMatch = assocOnes[i].getImportedId().findMatchImport(dbColumn);
|
||||
|
||||
if (foreignMatch != null) {
|
||||
return new MatchedImportedProperty(assocOnes[i], foreignMatch, prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// there was no matching assoc one property.
|
||||
// example UserRole bean missing assoc one to User?
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
|
||||
/**
|
||||
* Matches local embedded id properties to 'matching' properties from a
|
||||
* ManyToOne associated bean that is a 'imported primary key'.
|
||||
* <p>
|
||||
* This object is designed to help BindableIdEmbedded and BindableIdMap to
|
||||
* create a concatenated id from the id values from ManyToOne associated beans.
|
||||
* This can be done when those ManyToOne associated beans make up the primary
|
||||
* key. This typically means the BindableIdEmbedded is for a intersection table
|
||||
* of a Many to Many relationship.
|
||||
* </p>
|
||||
*/
|
||||
class MatchedImportedProperty {
|
||||
|
||||
private final BeanPropertyAssocOne<?> assocOne;
|
||||
|
||||
private final BeanProperty foreignProp;
|
||||
|
||||
private final BeanProperty localProp;
|
||||
|
||||
protected MatchedImportedProperty(BeanPropertyAssocOne<?> assocOne, BeanProperty foreignProp,
|
||||
BeanProperty localProp) {
|
||||
this.assocOne = assocOne;
|
||||
this.foreignProp = foreignProp;
|
||||
this.localProp = localProp;
|
||||
}
|
||||
|
||||
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((EntityBean)assocBean);
|
||||
localProp.setValue(destBean, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the array of matchedImportedProperty based on the properties and descriptor.
|
||||
*/
|
||||
protected static MatchedImportedProperty[] build(BeanProperty[] props, BeanDescriptor<?> desc) {
|
||||
|
||||
MatchedImportedProperty[] matches = new MatchedImportedProperty[props.length];
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
// find matching assoc one property for dbColumn
|
||||
matches[i] = MatchedImportedProperty.findMatch(props[i], desc);
|
||||
if (matches[i] == null) {
|
||||
// ok, the assoc ones are not on the bean?
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
private static MatchedImportedProperty findMatch(BeanProperty prop, BeanDescriptor<?> desc) {
|
||||
|
||||
// find matching against the local database column
|
||||
String dbColumn = prop.getDbColumn();
|
||||
|
||||
BeanPropertyAssocOne<?>[] assocOnes = desc.propertiesOne();
|
||||
for (int i = 0; i < assocOnes.length; i++) {
|
||||
if (assocOnes[i].isImportedPrimaryKey()) {
|
||||
|
||||
// search using the ImportedId from the assoc one
|
||||
BeanProperty foreignMatch = assocOnes[i].getImportedId().findMatchImport(dbColumn);
|
||||
|
||||
if (foreignMatch != null) {
|
||||
return new MatchedImportedProperty(assocOnes[i], foreignMatch, prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// there was no matching assoc one property.
|
||||
// example UserRole bean missing assoc one to User?
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user