No effective change - format only

This commit is contained in:
Robin Bygrave
2015-07-31 23:03:17 +12:00
parent 99cecd6756
commit 498f567e37
19 changed files with 419 additions and 419 deletions
@@ -22,21 +22,21 @@ import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
*/
public interface Bindable {
/**
* For Updates including only changed properties add the Bindable to the
* list if it should be included in the 'update set'.
*/
void addToUpdate(PersistRequestBean<?> request, List<Bindable> list);
/**
* For Updates including only changed properties add the Bindable to the
* list if it should be included in the 'update set'.
*/
void addToUpdate(PersistRequestBean<?> request, List<Bindable> list);
/**
* append sql to the buffer with prefix and suffix options.
*/
void dmlAppend(GenerateDmlRequest request);
/**
* append sql to the buffer with prefix and suffix options.
*/
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.
*/
void dmlBind(BindableRequest request, EntityBean bean) throws SQLException;
/**
* 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.
*/
void dmlBind(BindableRequest request, EntityBean bean) throws SQLException;
}
@@ -40,7 +40,7 @@ public class BindableAssocOne implements Bindable {
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
EntityBean assocBean = (EntityBean)assocOne.getValue(bean);
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
@@ -15,31 +15,31 @@ import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
*/
public class BindableDiscriminator implements Bindable {
private final String columnName;
private final Object discValue;
private final int sqlType;
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 BindableDiscriminator(InheritInfo inheritInfo) {
this.columnName = inheritInfo.getDiscriminatorColumn();
this.discValue = inheritInfo.getDiscriminatorValue();
this.sqlType = inheritInfo.getDiscriminatorType();
}
public String toString() {
return columnName + " = " + discValue;
}
public String toString() {
return columnName + " = " + discValue;
}
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
throw new PersistenceException("Never called (only for inserts)");
}
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 dmlAppend(GenerateDmlRequest request) {
request.appendColumn(columnName);
}
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
bindRequest.bind(columnName, discValue, sqlType);
}
bindRequest.bind(columnName, discValue, sqlType);
}
}
@@ -14,47 +14,47 @@ import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
*/
public class BindableEmbedded implements Bindable {
private final Bindable[] items;
private final Bindable[] items;
private final BeanPropertyAssocOne<?> embProp;
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 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 String toString() {
return "BindableEmbedded " + embProp + " items:" + Arrays.toString(items);
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (request.isAddToUpdate(embProp)) {
list.add(this);
}
}
public void dmlAppend(GenerateDmlRequest request) {
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
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);
//}
}
// 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);
//}
}
}
}
}
@@ -14,56 +14,56 @@ import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
*/
public class BindableEncryptedProperty implements Bindable {
private final BeanProperty prop;
private final boolean bindEncryptDataFirst;
private final BeanProperty prop;
public BindableEncryptedProperty(BeanProperty prop, boolean bindEncryptDataFirst) {
this.prop = prop;
this.bindEncryptDataFirst = bindEncryptDataFirst;
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);
}
public String toString() {
return prop.toString();
// 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);
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (request.isAddToUpdate(prop)) {
list.add(this);
}
if (bindEncryptDataFirst) {
// MySql, Postgres, Oracle
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
}
}
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() + "=****");
}
}
}
@@ -19,24 +19,24 @@ public interface BindableId extends Bindable {
* Return true if there is no Id properties at all.
*/
boolean isEmpty();
/**
* Return true if this is a concatenated key.
*/
boolean isConcatenated();
/**
* Return the DB Column to use with genGeneratedKeys.
*/
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>
*/
boolean deriveConcatenatedId(PersistRequestBean<?> persist);
/**
* Return true if this is a concatenated key.
*/
boolean isConcatenated();
/**
* Return the DB Column to use with genGeneratedKeys.
*/
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>
*/
boolean deriveConcatenatedId(PersistRequestBean<?> persist);
}
@@ -57,7 +57,7 @@ public final class BindableIdEmbedded implements BindableId {
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
EntityBean idValue = (EntityBean)embId.getValue(bean);
EntityBean idValue = (EntityBean) embId.getValue(bean);
for (int i = 0; i < props.length; i++) {
@@ -86,7 +86,7 @@ public final class BindableIdEmbedded implements BindableId {
EntityBean bean = persist.getEntityBean();
// create the new id
EntityBean newId = (EntityBean)embId.createEmbeddedId();
EntityBean newId = (EntityBean) embId.createEmbeddedId();
// populate it from the assoc one id values...
for (int i = 0; i < matches.length; i++) {
@@ -8,7 +8,7 @@ import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
public class BindableIdEmpty implements BindableId {
public boolean isEmpty() {
return true;
}
@@ -57,7 +57,7 @@ public final class BindableIdScalar implements BindableId {
request.appendColumn(uidProp.getDbColumn());
}
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
Object value = uidProp.getValue(bean);
@@ -12,37 +12,37 @@ import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
*/
public class BindableList implements Bindable {
private final Bindable[] items;
private final Bindable[] items;
public BindableList(List<Bindable> list) {
items = list.toArray(new Bindable[list.size()]);
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 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 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 dmlAppend(GenerateDmlRequest request) {
public void dmlBind(BindableRequest bindRequest, EntityBean bean)
throws SQLException {
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);
}
for (int i = 0; i < items.length; i++) {
items[i].dmlBind(bindRequest, bean);
}
}
}
@@ -14,33 +14,33 @@ import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
* </p>
*/
public class BindablePropertyInsertGenerated extends BindableProperty {
private final GeneratedProperty gen;
public BindablePropertyInsertGenerated(BeanProperty prop, GeneratedProperty gen) {
super(prop);
this.gen = gen;
}
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);
}
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());
}
/**
* Always bind on Insert SET.
*/
@Override
public void dmlAppend(GenerateDmlRequest request) {
request.appendColumn(prop.getDbColumn());
}
}
@@ -16,17 +16,17 @@ import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
* </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.
*/
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);
@@ -37,28 +37,28 @@ public class BindablePropertyUpdateGenerated extends BindableProperty {
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);
}
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());
}
}
/**
* Always bind on Insert SET.
*/
@Override
public void dmlAppend(GenerateDmlRequest request) {
request.appendColumn(prop.getDbColumn());
}
}
@@ -21,48 +21,48 @@ import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
*/
public class BindableUnidirectional implements Bindable {
private final BeanPropertyAssocOne<?> unidirectional;
private final BeanPropertyAssocOne<?> unidirectional;
private final ImportedId importedId;
private final ImportedId importedId;
private final BeanDescriptor<?> desc;
private final BeanDescriptor<?> desc;
public BindableUnidirectional(BeanDescriptor<?> desc, BeanPropertyAssocOne<?> unidirectional) {
this.desc = desc;
this.unidirectional = unidirectional;
this.importedId = unidirectional.getImportedId();
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);
}
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);
}
importedId.bind(request, (EntityBean) parentBean);
}
}
@@ -10,33 +10,33 @@ 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 void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode) {
BeanPropertyAssocOne<?>[] ones = desc.propertiesOneImported();
public FactoryAssocOnes() {
}
for (int i = 0; i < ones.length; i++) {
/**
* Add foreign key columns from associated one beans.
*/
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode) {
BeanPropertyAssocOne<?>[] ones = desc.propertiesOneImported();
for (int i = 0; i < ones.length; i++) {
if (!ones[i].isImportedPrimaryKey()) {
switch (mode) {
case INSERT:
if (!ones[i].isInsertable()) {
continue;
}
break;
case UPDATE:
if (!ones[i].isUpdateable()) {
continue;
}
break;
case INSERT:
if (!ones[i].isInsertable()) {
continue;
}
break;
case UPDATE:
if (!ones[i].isUpdateable()) {
continue;
}
break;
}
list.add(new BindableAssocOne(ones[i]));
}
}
}
}
}
@@ -13,35 +13,35 @@ import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
*/
public class FactoryEmbedded {
private final FactoryProperty factoryProperty;
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));
}
}
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));
}
}
}
@@ -21,7 +21,7 @@ public class FactoryId {
if (id == null) {
return new BindableIdEmpty();
}
}
if (!id.isEmbedded()) {
return new BindableIdScalar(id);
@@ -13,53 +13,53 @@ import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
*/
public class FactoryProperty {
private final boolean bindEncryptDataFirst;
public FactoryProperty(boolean bindEncryptDataFirst) {
this.bindEncryptDataFirst = bindEncryptDataFirst;
}
private final boolean bindEncryptDataFirst;
/**
* Create a Bindable for the property given the mode and withLobs flag.
*/
public Bindable create(BeanProperty prop, DmlMode mode, boolean withLobs) {
public FactoryProperty(boolean bindEncryptDataFirst) {
this.bindEncryptDataFirst = bindEncryptDataFirst;
}
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);
}
}
/**
* Create a Bindable for the property given the mode and withLobs flag.
*/
public Bindable create(BeanProperty prop, DmlMode mode, boolean withLobs) {
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;
}
}
}
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);
}
}
@@ -8,20 +8,20 @@ import com.avaje.ebeaninternal.server.deploy.BeanProperty;
*/
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);
}
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);
}
}
@@ -18,69 +18,69 @@ import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
*/
class MatchedImportedProperty {
private final BeanPropertyAssocOne<?> assocOne;
private final BeanPropertyAssocOne<?> assocOne;
private final BeanProperty foreignProp;
private final BeanProperty foreignProp;
private final BeanProperty localProp;
private final BeanProperty localProp;
protected MatchedImportedProperty(BeanPropertyAssocOne<?> assocOne, BeanProperty foreignProp,
BeanProperty localProp) {
this.assocOne = assocOne;
this.foreignProp = foreignProp;
this.localProp = 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);
}
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);
}
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) {
/**
* 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];
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) {
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;
}
// find matching against the local database column
String dbColumn = prop.getDbColumn();
private static MatchedImportedProperty findMatch(BeanProperty prop, BeanDescriptor<?> desc) {
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);
// find matching against the local database column
String dbColumn = prop.getDbColumn();
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;
}
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;
}
}