initial add of EbeanORM server based on v2.8.1

This commit is contained in:
rbygrave committed 2012-09-14 00:40:39 +12:00
1 parent 2b74d0f9d9
commit 96ce4c0ddf
1188 files changed
+135034

No files matched your search

@@ -0,0 +1,192 @@
package com.avaje.ebeaninternal.server.deploy.id;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.DbReadContext;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import com.avaje.ebeaninternal.server.type.DataBind;
/**
* Binds id values to prepared statements.
*/
public interface IdBinder {
/**
* Initialise the binder.
*/
public void initialise();
/**
* Convert the Id value as a Lucene string term.
*/
public String writeTerm(Object idValue);
/**
* Convert the Lucene string term into an Id value.
*/
public Object readTerm(String idTermValue);
/**
* Write the Id value to binary DataOuput.
*/
public void writeData(DataOutput dataOutput, Object idValue) throws IOException;
/**
* Read the Id value from the binary DataInput.
*/
public Object readData(DataInput dataInput) throws IOException;
/**
* Adds RDN's to the LdapName using the id value.
*/
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException;
/**
* Adds RDN's to the LdapName using the id value from the bean.
*/
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException;
/**
* Return the name(s) of the Id property(s).
* Comma delimited if there is more than one.
* <p>
* This can be used to include in a query.
* </p>
*/
public String getIdProperty();
/**
* Find a BeanProperty that is mapped to the database column.
*/
public BeanProperty findBeanProperty(String dbColumnName);
/**
* Return the number of scalar properties for this id.
*/
public int getPropertyCount();
/**
* Return false if the id is a simple scalar and false if it is embedded or concatenated.
*/
public boolean isComplexId();
/**
* Return the default order by that may need to be used if the query includes a many property.
*/
public String getDefaultOrderBy();
public String getOrderBy(String pathPrefix, boolean ascending);
/**
* Return the values as an array of scalar bindable values.
* <p>
* For concatenated keys that use an Embedded bean or multiple id properties
* this determines the field values are returns them as an Object array.
* </p>
* <p>
* Added primarily for Query.addWhere().add(Expr.idEq()) support.
* </p>
*/
public Object[] getBindValues(Object idValue);
/**
* Return the id values for a given bean.
*/
public Object[] getIdValues(Object bean);
/**
* Build a string of the logical expressions.
* <p>
* Typically used to build a id = ? string.
* </p>
*/
public String getAssocOneIdExpr(String prefix, String operator);
/**
* Return the logical id in expression taking into account embedded id's.
*/
public String getAssocIdInExpr(String prefix);
/**
* Binds an id value to a prepared statement.
*/
public void bindId(DataBind dataBind, Object value) throws SQLException;
/**
* Bind the id value to a SqlUpdate statement.
*/
public void bindId(DefaultSqlUpdate sqlUpdate, Object value);
public void addIdInBindValue(SpiExpressionRequest request, Object value);
/**
* Return the sql for binding the id using an IN clause.
*/
public String getBindIdInSql(String baseTableAlias);
/**
* Return the binding expression (like "?" or "(?,?)")for the Id.
*/
public String getIdInValueExpr(int size);
/**
* Same as getIdInValueExpr but for delete by id.
*/
public String getIdInValueExprDelete(int size);
public void buildSelectExpressionChain(String prefix, List<String> selectChain);
/**
* Read the id value from the result set and set it to the bean also returning it.
*/
public Object readSet(DbReadContext ctx, Object bean) throws SQLException;
/**
* Ignore the appropriate number of scalar properties for this id.
*/
public void loadIgnore(DbReadContext ctx);
/**
* Read the id value from the result set and return it.
*/
public Object read(DbReadContext ctx) throws SQLException;
/**
* Append to the select clause.
*/
public void appendSelect(DbSqlContext ctx, boolean subQuery);
/**
* Return the sql for binding the id to. This includes table alias and columns that make up the id.
*/
public String getBindIdSql(String baseTableAlias);
/**
* Return the id properties in flat form.
*/
public BeanProperty[] getProperties();
/**
* Cast or convert the Id value if necessary and optionally set it.
* <p>
* The Id value is not assumed to be the correct type so it is converted to
* the correct type. Typically this is because we could get a Integer, Long
* or BigDecimal depending on the JDBC driver and situation.
* </p>
* <p>
* If the bean is not null, then the value is set to the bean.
* </p>
*/
public Object convertSetId(Object idValue, Object bean);
}
@@ -0,0 +1,455 @@
package com.avaje.ebeaninternal.server.deploy.id;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
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.deploy.DbReadContext;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import com.avaje.ebeaninternal.server.query.SplitName;
import com.avaje.ebeaninternal.server.type.DataBind;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import javax.persistence.PersistenceException;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
/**
* Bind an Id that is an Embedded bean.
*/
public final class IdBinderEmbedded implements IdBinder {
private final BeanPropertyAssocOne<?> embIdProperty;
private final boolean idInExpandedForm;
private BeanProperty[] props;
private BeanDescriptor<?> idDesc;
private String idInValueSql;
public IdBinderEmbedded(boolean idInExpandedForm, BeanPropertyAssocOne<?> embIdProperty) {
this.idInExpandedForm = idInExpandedForm;
this.embIdProperty = embIdProperty;
}
public void initialise() {
this.idDesc = embIdProperty.getTargetDescriptor();
this.props = embIdProperty.getProperties();
this.idInValueSql = idInExpandedForm ? idInExpanded() : idInCompressed();
}
private String idInExpanded() {
StringBuilder sb = new StringBuilder();
sb.append("(");
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(" and ");
}
sb.append(embIdProperty.getName());
sb.append(".");
sb.append(props[i].getName());
sb.append("=?");
}
sb.append(")");
return sb.toString();
}
private String idInCompressed() {
StringBuilder sb = new StringBuilder();
sb.append("(");
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(",");
}
sb.append("?");
}
sb.append(")");
return sb.toString();
}
public String getOrderBy(String pathPrefix, boolean ascending){
StringBuilder sb = new StringBuilder();
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(", ");
}
if (pathPrefix != null){
sb.append(pathPrefix).append(".");
}
sb.append(embIdProperty.getName()).append(".");
sb.append(props[i].getName());
if (!ascending){
sb.append(" desc");
}
}
return sb.toString();
}
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
for (int i = 0; i < props.length; i++) {
Object v = props[i].getValue(id);
Rdn rdn = new Rdn(props[i].getDbColumn(), v);
name.add(rdn);
}
}
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
Object id = embIdProperty.getValue(bean);
createLdapNameById(name, id);
}
public BeanDescriptor<?> getIdBeanDescriptor() {
return idDesc;
}
public int getPropertyCount() {
return props.length;
}
public String getIdProperty() {
return embIdProperty.getName();
}
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
prefix = SplitName.add(prefix, embIdProperty.getName());
for (int i = 0; i < props.length; i++) {
props[i].buildSelectExpressionChain(prefix, selectChain);
}
}
public BeanProperty findBeanProperty(String dbColumnName) {
for (int i = 0; i < props.length; i++) {
if (dbColumnName.equalsIgnoreCase(props[i].getDbColumn())) {
return props[i];
}
}
return null;
}
public boolean isComplexId() {
return true;
}
public String getDefaultOrderBy() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(",");
}
sb.append(embIdProperty.getName());
sb.append(".");
sb.append(props[i].getName());
}
return sb.toString();
}
public BeanProperty[] getProperties() {
return props;
}
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
for (int i = 0; i < props.length; i++) {
request.addBindValue(props[i].getValue(value));
}
}
public String getIdInValueExprDelete(int size) {
if (!idInExpandedForm){
return getIdInValueExpr(size);
}
StringBuilder sb = new StringBuilder();
sb.append("(");
for (int j = 0; j < size; j++) {
if (j > 0){
sb.append(" or ");
}
sb.append("(");
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(" and ");
}
sb.append(props[i].getDbColumn());
sb.append("=?");
}
sb.append(")");
}
sb.append(") ");
return sb.toString();
}
public String getIdInValueExpr(int size) {
StringBuilder sb = new StringBuilder();
if (!idInExpandedForm){
sb.append(" in");
}
sb.append(" (");
for (int i = 0; i < size; i++) {
if (i > 0){
if (idInExpandedForm) {
sb.append(" or ");
} else {
sb.append(",");
}
}
sb.append(idInValueSql);
}
sb.append(") ");
return sb.toString();
}
public String getIdInValueExpr() {
return idInValueSql;
}
/**
* Convert the lucene string term value into embedded id.
*/
public Object readTerm(String idTermValue) {
String[] split = idTermValue.split("|");
if (split.length != props.length){
String msg = "Failed to split ["+idTermValue+"] using | for id.";
throw new PersistenceException(msg);
}
Object embId = idDesc.createVanillaBean();
for (int i = 0; i < props.length; i++) {
Object v = props[i].getScalarType().parse(split[i]);
props[i].setValue(embId, v);
}
return embId;
}
/**
* Write the embedded id as a Lucene string term value.
*/
public String writeTerm(Object idValue) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < props.length; i++) {
Object v = props[i].getValue(idValue);
String formatValue = props[i].getScalarType().format(v);
if (i > 0){
sb.append("|");
}
sb.append(formatValue);
}
return sb.toString();
}
public Object[] getIdValues(Object bean) {
bean = embIdProperty.getValue(bean);
Object[] bindvalues = new Object[props.length];
for (int i = 0; i < props.length; i++) {
bindvalues[i] = props[i].getValue(bean);
}
return bindvalues;
}
public Object[] getBindValues(Object value) {
Object[] bindvalues = new Object[props.length];
for (int i = 0; i < props.length; i++) {
bindvalues[i] = props[i].getValue(value);
}
return bindvalues;
}
public void bindId(DefaultSqlUpdate sqlUpdate, Object value) {
for (int i = 0; i < props.length; i++) {
Object embFieldValue = props[i].getValue(value);
sqlUpdate.addParameter(embFieldValue);
}
}
public void bindId(DataBind dataBind, Object value) throws SQLException {
for (int i = 0; i < props.length; i++) {
Object embFieldValue = props[i].getValue(value);
props[i].bind(dataBind, embFieldValue);
}
}
public Object readData(DataInput dataInput) throws IOException {
Object embId = idDesc.createVanillaBean();
boolean notNull = true;
for (int i = 0; i < props.length; i++) {
Object value = props[i].readData(dataInput);
props[i].setValue(embId, value);
if (value == null) {
notNull = false;
}
}
if (notNull) {
return embId;
} else {
return null;
}
}
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
for (int i = 0; i < props.length; i++) {
Object embFieldValue = props[i].getValue(idValue);
props[i].writeData(dataOutput, embFieldValue);
}
}
public void loadIgnore(DbReadContext ctx) {
for (int i = 0; i < props.length; i++) {
props[i].loadIgnore(ctx);
}
}
public Object read(DbReadContext ctx) throws SQLException {
Object embId = idDesc.createVanillaBean();
boolean notNull = true;
for (int i = 0; i < props.length; i++) {
Object value = props[i].readSet(ctx, embId, null);
if (value == null) {
notNull = false;
}
}
if (notNull) {
return embId;
} else {
return null;
}
}
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
Object embId = read(ctx);
if (embId != null) {
embIdProperty.setValue(bean, embId);
return embId;
} else {
return null;
}
}
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
for (int i = 0; i < props.length; i++) {
props[i].appendSelect(ctx, subQuery);
}
}
public String getAssocIdInExpr(String prefix) {
StringBuilder sb = new StringBuilder();
sb.append("(");
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(",");
}
if (prefix != null) {
sb.append(prefix);
sb.append(".");
}
sb.append(props[i].getName());
}
sb.append(")");
return sb.toString();
}
public String getAssocOneIdExpr(String prefix, String operator) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(" and ");
}
if (prefix != null) {
sb.append(prefix);
sb.append(".");
}
sb.append(embIdProperty.getName());
sb.append(".");
sb.append(props[i].getName());
sb.append(operator);
}
return sb.toString();
}
public String getBindIdSql(String baseTableAlias) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(" and ");
}
if (baseTableAlias != null) {
sb.append(baseTableAlias);
sb.append(".");
}
sb.append(props[i].getDbColumn());
sb.append(" = ? ");
}
return sb.toString();
}
public String getBindIdInSql(String baseTableAlias) {
if (idInExpandedForm){
return "";
}
StringBuilder sb = new StringBuilder();
sb.append("(");
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(",");
}
if (baseTableAlias != null){
sb.append(baseTableAlias);
sb.append(".");
}
sb.append(props[i].getDbColumn());
}
sb.append(")");
return sb.toString();
}
public Object convertSetId(Object idValue, Object bean) {
// can not cast/convert if it is embedded
if (bean != null) {
// support PropertyChangeSupport
embIdProperty.setValueIntercept(bean, idValue);
}
return idValue;
}
}
@@ -0,0 +1,152 @@
package com.avaje.ebeaninternal.server.deploy.id;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.DbReadContext;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import com.avaje.ebeaninternal.server.type.DataBind;
/**
* For beans with no id properties AKA report type beans.
*/
public final class IdBinderEmpty implements IdBinder {
private static final String bindIdSql = "";
private static final BeanProperty[] properties = new BeanProperty[0];
public IdBinderEmpty() {
}
public void initialise(){
}
public Object readTerm(String idTermValue) {
return null;
}
public String writeTerm(Object idValue) {
return null;
}
public String getOrderBy(String pathPrefix, boolean ascending){
return pathPrefix;
}
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
}
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
}
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
}
public int getPropertyCount() {
return 0;
}
public String getIdProperty() {
return null;
}
public BeanProperty findBeanProperty(String dbColumnName) {
return null;
}
public boolean isComplexId(){
return true;
}
public String getDefaultOrderBy() {
// this should never happen?
return "";
}
public BeanProperty[] getProperties() {
return properties;
}
public String getBindIdSql(String baseTableAlias) {
return bindIdSql;
}
public String getAssocOneIdExpr(String prefix, String operator){
return null;
}
public String getAssocIdInExpr(String prefix) {
return null;
}
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
}
public String getIdInValueExprDelete(int size) {
return getIdInValueExpr(size);
}
public String getIdInValueExpr(int size) {
return "";
}
public String getBindIdInSql(String baseTableAlias) {
return null;
}
public Object[] getIdValues(Object bean){
return null;
}
public Object[] getBindValues(Object idValue){
return new Object[]{idValue};
}
public void bindId(DefaultSqlUpdate sqlUpdate, Object value) {
}
public void bindId(DataBind dataBind, Object value) throws SQLException {
}
public void loadIgnore(DbReadContext ctx) {
}
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
return null;
}
public Object read(DbReadContext ctx) throws SQLException {
return null;
}
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
}
public Object convertSetId(Object idValue, Object bean){
return idValue;
}
public Object readData(DataInput dataOutput) throws IOException {
return null;
}
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
}
}
@@ -0,0 +1,59 @@
/**
* Copyright (C) 2006 Robin Bygrave
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.ebeaninternal.server.deploy.id;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
/**
* Creates the appropriate IdConvertSet depending on the type of Id property(s).
*/
public class IdBinderFactory {
private static final IdBinderEmpty EMPTY = new IdBinderEmpty();
private final boolean idInExpandedForm;
public IdBinderFactory(boolean idInExpandedForm) {
this.idInExpandedForm = idInExpandedForm;
}
/**
* Create the IdConvertSet for the given type of Id properties.
*/
public IdBinder createIdBinder(BeanProperty[] uids) {
if (uids.length == 0){
// for report type beans that don't need an id
return EMPTY;
} else if (uids.length == 1){
if (uids[0].isEmbedded()){
return new IdBinderEmbedded(idInExpandedForm, (BeanPropertyAssocOne<?>)uids[0]);
} else {
return new IdBinderSimple(uids[0]);
}
} else {
return new IdBinderMultiple(uids);
}
}
}
@@ -0,0 +1,461 @@
package com.avaje.ebeaninternal.server.deploy.id;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
import com.avaje.ebeaninternal.server.core.InternString;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.DbReadContext;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import com.avaje.ebeaninternal.server.lib.util.MapFromString;
import com.avaje.ebeaninternal.server.type.DataBind;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import javax.persistence.PersistenceException;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Bind an Id that is made up of multiple separate properties.
* <p>
* The id passed in for binding is expected to be a map with the key being the
* String name of the property and the value being that properties bind value.
* </p>
*/
public final class IdBinderMultiple implements IdBinder {
private final BeanProperty[] props;
private final String idProperties;
private final String idInValueSql;
public IdBinderMultiple(BeanProperty[] idProps) {
this.props = idProps;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < idProps.length; i++) {
if (i > 0){
sb.append(",");
}
sb.append(idProps[i].getName());
}
idProperties = InternString.intern(sb.toString());
sb = new StringBuilder();
sb.append("(");
for (int i = 0; i < props.length; i++) {
if (i > 0){
sb.append(",");
}
sb.append("?");
}
sb.append(")");
idInValueSql = sb.toString();
}
public void initialise(){
// do nothing
}
public String getOrderBy(String pathPrefix, boolean ascending){
StringBuilder sb = new StringBuilder();
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(" ");
}
if (pathPrefix != null){
sb.append(pathPrefix).append(".");
}
sb.append(props[i].getName());
if (!ascending){
sb.append(" desc");
}
}
return sb.toString();
}
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
if (id instanceof Map<?,?> == false){
throw new RuntimeException("Expecting a Map for concatinated key");
}
Map<?,?> mapId = (Map<?,?>)id;
for (int i = 0; i < props.length; i++) {
Object v = mapId.get(props[i].getName());
if (v == null){
throw new RuntimeException("No value in Map for key "+props[i].getName());
}
Rdn rdn = new Rdn(props[i].getDbColumn(), v);
name.add(rdn);
}
}
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
for (int i = 0; i < props.length; i++) {
props[i].buildSelectExpressionChain(prefix, selectChain);
}
}
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
for (int i = 0; i < props.length; i++) {
Object v = props[i].getValue(bean);
Rdn rdn = new Rdn(props[i].getDbColumn(), v);
name.add(rdn);
}
}
public int getPropertyCount() {
return props.length;
}
public String getIdProperty() {
return idProperties;
}
public BeanProperty findBeanProperty(String dbColumnName) {
for (int i = 0; i < props.length; i++) {
if (dbColumnName.equalsIgnoreCase(props[i].getDbColumn())){
return props[i];
}
}
return null;
}
public boolean isComplexId(){
return true;
}
public String getDefaultOrderBy() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < props.length; i++) {
if (i > 0){
sb.append(",");
}
sb.append(props[i].getName());
}
return sb.toString();
}
public BeanProperty[] getProperties() {
return props;
}
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
for (int i = 0; i < props.length; i++) {
request.addBindValue(props[i].getValue(value));
}
}
public String getIdInValueExprDelete(int size) {
return getIdInValueExpr(size);
}
public String getIdInValueExpr(int size) {
StringBuilder sb = new StringBuilder();
sb.append(" in");
sb.append(" (");
sb.append(idInValueSql);
for (int i = 1; i < size; i++) {
sb.append(",").append(idInValueSql);
}
sb.append(") ");
return sb.toString();
}
public String getBindIdInSql(String baseTableAlias) {
StringBuilder sb = new StringBuilder();
sb.append("(");
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(",");
}
if (baseTableAlias != null){
sb.append(baseTableAlias);
sb.append(".");
}
sb.append(props[i].getDbColumn());
}
sb.append(")");
return sb.toString();
}
public Object[] getIdValues(Object bean){
Object[] bindvalues = new Object[props.length];
for (int i = 0; i < props.length; i++) {
bindvalues[i] = props[i].getValue(bean);
}
return bindvalues;
}
@SuppressWarnings("unchecked")
public Object[] getBindValues(Object idValue){
Object[] bindvalues = new Object[props.length];
// concatenated id as a Map
try {
Map<String, ?> uidMap = (Map<String, ?>) idValue;
for (int i = 0; i < props.length; i++) {
Object value = uidMap.get(props[i].getName());
bindvalues[i] = value;
}
return bindvalues;
} catch (ClassCastException e) {
String msg = "Expecting concatinated idValue to be a Map";
throw new PersistenceException(msg, e);
}
}
public Object readTerm(String idTermValue) {
String[] split = idTermValue.split("|");
if (split.length != props.length){
String msg = "Failed to split ["+idTermValue+"] using | for id.";
throw new PersistenceException(msg);
}
Map<String, Object> uidMap = new LinkedHashMap<String, Object>();
for (int i = 0; i < props.length; i++) {
Object v = props[i].getScalarType().parse(split[i]);
uidMap.put(props[i].getName(), v);
}
return uidMap;
}
@SuppressWarnings("unchecked")
public String writeTerm(Object idValue) {
Map<String, ?> uidMap = (Map<String, ?>) idValue;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < props.length; i++) {
Object v = uidMap.get(props[i].getName());
String formatValue = props[i].getScalarType().format(v);
if (i > 0){
sb.append("|");
}
sb.append(formatValue);
}
return sb.toString();
}
public Object readData(DataInput dataInput) throws IOException {
LinkedHashMap<String,Object> map = new LinkedHashMap<String, Object>();
boolean notNull = true;
for (int i = 0; i < props.length; i++) {
Object value = props[i].readData(dataInput);
map.put(props[i].getName(), value);
if (value == null) {
notNull = false;
}
}
if (notNull) {
return map;
} else {
return null;
}
}
@SuppressWarnings("unchecked")
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
Map<String,Object> map = (Map<String,Object>)idValue;
for (int i = 0; i < props.length; i++) {
Object embFieldValue = map.get(props[i].getName());
//Object embFieldValue = props[i].getValue(idValue);
props[i].writeData(dataOutput, embFieldValue);
}
}
public void loadIgnore(DbReadContext ctx) {
for (int i = 0; i < props.length; i++) {
props[i].loadIgnore(ctx);
}
}
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
boolean notNull = false;
for (int i = 0; i < props.length; i++) {
Object value = props[i].readSet(ctx, bean, null);
if (value != null){
map.put(props[i].getName(), value);
notNull = true;
}
}
if (notNull){
return map;
} else {
return null;
}
}
public Object read(DbReadContext ctx) throws SQLException {
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
boolean notNull = false;
for (int i = 0; i < props.length; i++) {
Object value = props[i].read(ctx);
if (value != null){
map.put(props[i].getName(), value);
notNull = true;
}
}
if (notNull){
return map;
} else {
return null;
}
}
@SuppressWarnings("unchecked")
public void bindId(DefaultSqlUpdate sqlUpdate, Object idValue) {
// concatenated id as a Map
try {
Map<String, ?> uidMap = (Map<String, ?>) idValue;
for (int i = 0; i < props.length; i++) {
Object value = uidMap.get(props[i].getName());
sqlUpdate.addParameter(value);
}
} catch (ClassCastException e) {
String msg = "Expecting concatinated idValue to be a Map";
throw new PersistenceException(msg, e);
}
}
@SuppressWarnings("unchecked")
public void bindId(DataBind bind, Object idValue) throws SQLException {
// concatenated id as a Map
try {
Map<String, ?> uidMap = (Map<String, ?>) idValue;
for (int i = 0; i < props.length; i++) {
Object value = uidMap.get(props[i].getName());
props[i].bind(bind, value);
}
} catch (ClassCastException e) {
String msg = "Expecting concatinated idValue to be a Map";
throw new PersistenceException(msg, e);
}
}
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
for (int i = 0; i < props.length; i++) {
props[i].appendSelect(ctx, subQuery);
}
}
public String getAssocIdInExpr(String prefix) {
StringBuilder sb = new StringBuilder();
sb.append("(");
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(",");
}
if (prefix != null) {
sb.append(prefix);
sb.append(".");
}
sb.append(props[i].getName());
}
sb.append(")");
return sb.toString();
}
public String getAssocOneIdExpr(String prefix, String operator){
StringBuilder sb = new StringBuilder();
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(" and ");
}
if (prefix != null){
sb.append(prefix);
sb.append(".");
}
sb.append(props[i].getName());
sb.append(operator);
}
return sb.toString();
}
public String getBindIdSql(String baseTableAlias) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < props.length; i++) {
if (i > 0) {
sb.append(" and ");
}
if (baseTableAlias != null){
sb.append(baseTableAlias);
sb.append(".");
}
sb.append(props[i].getDbColumn());
sb.append(" = ? ");
}
return sb.toString();
}
public Object convertSetId(Object idValue, Object bean) {
// allow Map or String for concatenated id
Map<?,?> mapVal = null;
if (idValue instanceof Map<?,?>) {
mapVal = (Map<?,?>) idValue;
} else {
mapVal = MapFromString.parse(idValue.toString());
}
// Use a new LinkedHashMap to control the order
LinkedHashMap<String,Object> newMap = new LinkedHashMap<String, Object>();
for (int i = 0; i < props.length; i++) {
BeanProperty prop = props[i];
Object value = mapVal.get(prop.getName());
// Convert the property type if required
value = props[i].getScalarType().toBeanType(value);
newMap.put(prop.getName(), value);
if (bean != null) {
// support PropertyChangeSupport
prop.setValueIntercept(bean, value);
}
}
return newMap;
}
}
@@ -0,0 +1,233 @@
package com.avaje.ebeaninternal.server.deploy.id;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
import com.avaje.ebeaninternal.server.core.InternString;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.DbReadContext;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import com.avaje.ebeaninternal.server.type.DataBind;
import com.avaje.ebeaninternal.server.type.ScalarType;
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
/**
* Bind an Id where the Id is made of a single property (not embedded).
*/
public final class IdBinderSimple implements IdBinder {
private final BeanProperty idProperty;
private final String bindIdSql;
private final BeanProperty[] properties;
private final Class<?> expectedType;
@SuppressWarnings("rawtypes")
private final ScalarType scalarType;
public IdBinderSimple(BeanProperty idProperty) {
this.idProperty = idProperty;
this.scalarType = idProperty.getScalarType();
this.expectedType = idProperty.getPropertyType();
this.properties = new BeanProperty[1];
properties[0] = idProperty;
bindIdSql = InternString.intern(idProperty.getDbColumn()+" = ? ");
}
public void initialise(){
// do nothing
}
public Object readTerm(String idTermValue) {
return scalarType.parse(idTermValue);
}
public String writeTerm(Object idValue) {
return scalarType.format(idValue);
}
public String getOrderBy(String pathPrefix, boolean ascending){
StringBuilder sb = new StringBuilder();
if (pathPrefix != null){
sb.append(pathPrefix).append(".");
}
sb.append(idProperty.getName());
if (!ascending){
sb.append(" desc");
}
return sb.toString();
}
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
idProperty.buildSelectExpressionChain(prefix, selectChain);
}
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
Rdn rdn = new Rdn(idProperty.getDbColumn(), id);
name.add(rdn);
}
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
Object id = idProperty.getValue(bean);
createLdapNameById(name, id);
}
/**
* Returns 1.
*/
public int getPropertyCount() {
return 1;
}
public String getIdProperty() {
return idProperty.getName();
}
public BeanProperty findBeanProperty(String dbColumnName) {
if (dbColumnName.equalsIgnoreCase(idProperty.getDbColumn())){
return idProperty;
}
return null;
}
public boolean isComplexId(){
return false;
}
public String getDefaultOrderBy() {
return idProperty.getName();
}
public BeanProperty[] getProperties() {
return properties;
}
public String getBindIdInSql(String baseTableAlias) {
if (baseTableAlias == null){
return idProperty.getDbColumn();
} else {
return baseTableAlias+"."+idProperty.getDbColumn();
}
}
public String getBindIdSql(String baseTableAlias) {
if (baseTableAlias == null){
return bindIdSql;
} else {
return baseTableAlias+"."+bindIdSql;
}
}
public Object[] getIdValues(Object bean){
return new Object[]{idProperty.getValue(bean)};
}
public Object[] getBindValues(Object idValue){
return new Object[]{idValue};
}
public String getIdInValueExprDelete(int size) {
return getIdInValueExpr(size);
}
public String getIdInValueExpr(int size) {
StringBuilder sb = new StringBuilder(2*size+10);
sb.append(" in");
sb.append(" (?");
for (int i = 1; i < size; i++) {
sb.append(",?");
}
sb.append(") ");
return sb.toString();
}
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
value = convertSetId(value, null);
request.addBindValue(value);
}
public void bindId(DefaultSqlUpdate sqlUpdate, Object value) {
sqlUpdate.addParameter(value);
}
public void bindId(DataBind dataBind, Object value) throws SQLException {
value = idProperty.toBeanType(value);
idProperty.bind(dataBind, value);
}
public void writeData(DataOutput os, Object value) throws IOException {
idProperty.writeData(os, value);
}
public Object readData(DataInput is) throws IOException {
return idProperty.readData(is);
}
public void loadIgnore(DbReadContext ctx) {
idProperty.loadIgnore(ctx);
}
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
Object id = idProperty.read(ctx);
if (id != null){
idProperty.setValue(bean, id);
}
return id;
}
public Object read(DbReadContext ctx) throws SQLException {
return idProperty.read(ctx);
}
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
idProperty.appendSelect(ctx, subQuery);
}
public String getAssocOneIdExpr(String prefix, String operator){
StringBuilder sb = new StringBuilder();
if (prefix != null){
sb.append(prefix);
sb.append(".");
}
sb.append(idProperty.getName());
sb.append(operator);
return sb.toString();
}
public String getAssocIdInExpr(String prefix) {
StringBuilder sb = new StringBuilder();
if (prefix != null) {
sb.append(prefix);
sb.append(".");
}
sb.append(idProperty.getName());
return sb.toString();
}
public Object convertSetId(Object idValue, Object bean) {
if (!idValue.getClass().equals(expectedType)){
idValue = scalarType.toBeanType(idValue);
}
if (bean != null) {
// support PropertyChangeSupport
idProperty.setValueIntercept(bean, idValue);
}
return idValue;
}
}
@@ -0,0 +1,72 @@
package com.avaje.ebeaninternal.server.deploy.id;
import java.sql.SQLException;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import com.avaje.ebeaninternal.server.deploy.IntersectionRow;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
/**
* Represents a imported property.
*/
public interface ImportedId {
public void addFkeys(String name);
/**
* Return true if this id is a simple single scalar value. False if it is a
* compound id (embedded or multiple).
*/
public boolean isScalar();
/**
* Return the logical property name.
*/
public String getLogicalName();
/**
* For scalar id return the related single db column.
* <p>
* This is essentially the imported foreign key column (where there is only
* one).
* </p>
*/
public String getDbColumn();
/**
* Append the the SQL query statement.
*/
public void sqlAppend(DbSqlContext ctx);
/**
* Append to the DML statement.
*/
public void dmlAppend(GenerateDmlRequest request);
/**
* Append to the DML statement to the where clause.
*/
public void dmlWhere(GenerateDmlRequest request, Object bean);
/**
* Return true if the id value has changed.
*/
public boolean hasChanged(Object bean, Object oldValues);
/**
* Bind the value from the bean.
*/
public Object bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException;
/**
* For inserting into ManyToMany intersection.
*/
public void buildImport(IntersectionRow row, Object other);
/**
* Used to derive a missing concatenated key from multiple imported keys.
*/
public BeanProperty findMatchImport(String matchDbColumn);
}
@@ -0,0 +1,164 @@
package com.avaje.ebeaninternal.server.deploy.id;
import java.sql.SQLException;
import javax.persistence.PersistenceException;
import com.avaje.ebeaninternal.server.deploy.BeanFkeyProperty;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import com.avaje.ebeaninternal.server.deploy.IntersectionRow;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
import com.avaje.ebeaninternal.util.ValueUtil;
/**
* Imported Embedded id.
*/
public class ImportedIdEmbedded implements ImportedId {
final BeanPropertyAssoc<?> owner;
final BeanPropertyAssocOne<?> foreignAssocOne;
final ImportedIdSimple[] imported;
public ImportedIdEmbedded(BeanPropertyAssoc<?> owner, BeanPropertyAssocOne<?> foreignAssocOne, ImportedIdSimple[] imported) {
this.owner = owner;
this.foreignAssocOne = foreignAssocOne;
this.imported = imported;
}
public void addFkeys(String name) {
BeanProperty[] embeddedProps = foreignAssocOne.getProperties();
for (int i = 0; i < imported.length; i++) {
String n = name+"."+foreignAssocOne.getName()+"."+embeddedProps[i].getName();
BeanFkeyProperty fkey = new BeanFkeyProperty(null, n, imported[i].localDbColumn, foreignAssocOne.getDeployOrder());
owner.getBeanDescriptor().add(fkey);
}
}
public boolean isScalar(){
return false;
}
public String getLogicalName() {
return owner.getName()+"."+foreignAssocOne.getName();
}
public String getDbColumn(){
return null;
}
public void sqlAppend(DbSqlContext ctx) {
for (int i = 0; i < imported.length; i++) {
ctx.appendColumn(imported[i].localDbColumn);
}
}
public void dmlAppend(GenerateDmlRequest request) {
for (int i = 0; i < imported.length; i++) {
request.appendColumn(imported[i].localDbColumn);
}
}
public void dmlWhere(GenerateDmlRequest request, Object bean){
Object embeddedId = null;
if (bean != null) {
embeddedId = foreignAssocOne.getValue(bean);
}
if (embeddedId == null){
for (int i = 0; i < imported.length; i++) {
if (imported[i].owner.isDbUpdatable()) {
request.appendColumnIsNull(imported[i].localDbColumn);
}
}
} else {
for (int i = 0; i < imported.length; i++) {
if (imported[i].owner.isDbUpdatable()) {
Object value = imported[i].foreignProperty.getValue(embeddedId);
if (value == null){
request.appendColumnIsNull(imported[i].localDbColumn);
} else {
request.appendColumn(imported[i].localDbColumn);
}
}
}
}
}
public boolean hasChanged(Object bean, Object oldValues) {
Object id = foreignAssocOne.getValue(bean);
Object oldId = foreignAssocOne.getValue(oldValues);
return !ValueUtil.areEqual(id, oldId);
}
public Object bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {
Object embeddedId = null;
if (bean != null) {
embeddedId = foreignAssocOne.getValue(bean);
}
if (embeddedId == null){
for (int i = 0; i < imported.length; i++) {
if (imported[i].owner.isUpdateable()) {
request.bind(null, imported[i].foreignProperty, imported[i].localDbColumn, true);
}
}
} else {
for (int i = 0; i < imported.length; i++) {
if (imported[i].owner.isUpdateable()) {
Object scalarValue = imported[i].foreignProperty.getValue(embeddedId);
request.bind(scalarValue, imported[i].foreignProperty, imported[i].localDbColumn, true);
}
}
}
// hmmm, not worrying about this just yet
return null;
}
public void buildImport(IntersectionRow row, Object other){
Object embeddedId = foreignAssocOne.getValue(other);
if (embeddedId == null){
String msg = "Foreign Key value null?";
throw new PersistenceException(msg);
}
for (int i = 0; i < imported.length; i++) {
Object scalarValue = imported[i].foreignProperty.getValue(embeddedId);
row.put(imported[i].localDbColumn, scalarValue);
}
}
/**
* Not supported for embedded id.
*/
public BeanProperty findMatchImport(String matchDbColumn) {
BeanProperty p = null;
for (int i = 0; i < imported.length; i++) {
p = imported[i].findMatchImport(matchDbColumn);
if (p != null){
return p;
}
}
return p;
}
}
@@ -0,0 +1,123 @@
package com.avaje.ebeaninternal.server.deploy.id;
import java.sql.SQLException;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import com.avaje.ebeaninternal.server.deploy.IntersectionRow;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
import com.avaje.ebeaninternal.util.ValueUtil;
/**
* Imported concatenated id that is not embedded.
*/
public class ImportedIdMultiple implements ImportedId {
final BeanPropertyAssoc<?> owner;
final ImportedIdSimple[] imported;
public ImportedIdMultiple(BeanPropertyAssoc<?> owner, ImportedIdSimple[] imported) {
this.owner = owner;
this.imported = imported;
}
public void addFkeys(String name) {
// not supporting addFkeys for ImportedIdMultiple
}
public String getLogicalName() {
return null;
}
public boolean isScalar(){
return false;
}
public String getDbColumn(){
return null;
}
public void sqlAppend(DbSqlContext ctx) {
for (int i = 0; i < imported.length; i++) {
ctx.appendColumn(imported[i].localDbColumn);
}
}
public void dmlAppend(GenerateDmlRequest request) {
for (int i = 0; i < imported.length; i++) {
request.appendColumn(imported[i].localDbColumn);
}
}
public void dmlWhere(GenerateDmlRequest request, Object bean){
if (bean == null){
for (int i = 0; i < imported.length; i++) {
request.appendColumnIsNull(imported[i].localDbColumn);
}
} else {
for (int i = 0; i < imported.length; i++) {
Object value = imported[i].foreignProperty.getValue(bean);
if (value == null){
request.appendColumnIsNull(imported[i].localDbColumn);
} else {
request.appendColumn(imported[i].localDbColumn);
}
}
}
}
public boolean hasChanged(Object bean, Object oldValues) {
for (int i = 0; i < imported.length; i++) {
Object id = imported[i].foreignProperty.getValue(bean);
Object oldId = imported[i].foreignProperty.getValue(oldValues);
if (!ValueUtil.areEqual(id, oldId)) {
return true;
}
}
return false;
}
public Object bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {
for (int i = 0; i < imported.length; i++) {
if (imported[i].owner.isUpdateable()) {
Object scalarValue = imported[i].foreignProperty.getValue(bean);
request.bind(scalarValue, imported[i].foreignProperty, imported[i].localDbColumn, true);
}
}
// hmmm, not worrying about this just yet
return null;
}
public void buildImport(IntersectionRow row, Object other){
for (int i = 0; i < imported.length; i++) {
Object scalarValue = imported[i].foreignProperty.getValue(other);
row.put(imported[i].localDbColumn, scalarValue);
}
}
/**
* Not supported for concatenated id.
*/
public BeanProperty findMatchImport(String matchDbColumn) {
BeanProperty p = null;
for (int i = 0; i < imported.length; i++) {
p = imported[i].findMatchImport(matchDbColumn);
if (p != null){
return p;
}
}
return p;
}
}
@@ -0,0 +1,161 @@
package com.avaje.ebeaninternal.server.deploy.id;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebeaninternal.server.core.InternString;
import com.avaje.ebeaninternal.server.deploy.BeanFkeyProperty;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import com.avaje.ebeaninternal.server.deploy.IntersectionRow;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
import com.avaje.ebeaninternal.util.ValueUtil;
/**
* Single scalar imported id.
*/
public final class ImportedIdSimple implements ImportedId, Comparable<ImportedIdSimple> {
/**
* Helper class to sort ImportedIdSimple.
*/
private final static class EntryComparator implements Comparator<ImportedIdSimple> {
public int compare(ImportedIdSimple o1, ImportedIdSimple o2) {
return o1.compareTo(o2);
}
}
private static final EntryComparator COMPARATOR = new EntryComparator();
protected final BeanPropertyAssoc<?> owner;
protected final String localDbColumn;
protected final String logicalName;
protected final BeanProperty foreignProperty;
protected final int position;
public ImportedIdSimple(BeanPropertyAssoc<?> owner, String localDbColumn, BeanProperty foreignProperty, int position) {
this.owner = owner;
this.localDbColumn = InternString.intern(localDbColumn);
this.foreignProperty = foreignProperty;
this.position = position;
this.logicalName = InternString.intern(owner.getName()+"."+foreignProperty.getName());
}
/**
* Return the list as an array sorted into the same order as the Bean Properties.
*/
public static ImportedIdSimple[] sort(List<ImportedIdSimple> list) {
ImportedIdSimple[] importedIds = (ImportedIdSimple[]) list.toArray(new ImportedIdSimple[list.size()]);
// sort into the same order as the BeanProperties
Arrays.sort(importedIds, COMPARATOR);
return importedIds;
}
@Override
public boolean equals(Object obj) {
// remove FindBugs warning
return obj == this;
}
public int compareTo(ImportedIdSimple other) {
return (position < other.position ? -1 : (position == other.position ? 0 : 1));
}
public void addFkeys(String name) {
BeanFkeyProperty fkey = new BeanFkeyProperty(null, name+"."+foreignProperty.getName(), localDbColumn, owner.getDeployOrder());
owner.getBeanDescriptor().add(fkey);
}
public boolean isScalar(){
return true;
}
public String getLogicalName() {
return logicalName;
}
public String getDbColumn(){
return localDbColumn;
}
private Object getIdValue(Object bean) {
return foreignProperty.getValueWithInheritance(bean);
}
public void buildImport(IntersectionRow row, Object other){
Object value = getIdValue(other);
if (value == null){
String msg = "Foreign Key value null?";
throw new PersistenceException(msg);
}
row.put(localDbColumn, value);
}
public void sqlAppend(DbSqlContext ctx) {
ctx.appendColumn(localDbColumn);
}
public void dmlAppend(GenerateDmlRequest request) {
request.appendColumn(localDbColumn);
}
public void dmlWhere(GenerateDmlRequest request, Object bean){
if (owner.isDbUpdatable()){
Object value = null;
if (bean != null){
value = getIdValue(bean);
}
if (value == null){
request.appendColumnIsNull(localDbColumn);
} else {
request.appendColumn(localDbColumn);
}
}
}
public boolean hasChanged(Object bean, Object oldValues) {
Object id = getIdValue(bean);
if (oldValues != null){
Object oldId = getIdValue(oldValues);
return !ValueUtil.areEqual(id, oldId);
}
return true;
}
public Object bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {
Object value = null;
if (bean != null){
value = getIdValue(bean);
}
request.bind(value, foreignProperty, localDbColumn, bindNull);
return value;
}
public BeanProperty findMatchImport(String matchDbColumn) {
if (matchDbColumn.equals(localDbColumn)) {
return foreignProperty;
}
return null;
}
}
@@ -0,0 +1,10 @@
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
<TITLE>Helpers for Id property conversion</TITLE>
</HEAD>
<Body BGCOLOR="#ffffff">
Helpers for Id property conversion
</Body>
</HTML>