mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
Fix for #91 Stateless Update API Change, #90 Removed BeanState.setReference(), #89 Remove support for multiple @Id properties
This commit is contained in:
1 parent
5e2d592c2a
commit
0d1c9e2883
66 files changed
+1045
-1768
No files matched your search
@@ -44,6 +44,11 @@ public interface IdBinder {
|
||||
*/
|
||||
public String getIdProperty();
|
||||
|
||||
/**
|
||||
* Return the Id BeanProperty.
|
||||
*/
|
||||
public BeanProperty getBeanProperty();
|
||||
|
||||
/**
|
||||
* Find a BeanProperty that is mapped to the database column.
|
||||
*/
|
||||
@@ -154,11 +159,6 @@ public interface IdBinder {
|
||||
*/
|
||||
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>
|
||||
|
||||
@@ -6,8 +6,6 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
@@ -24,378 +22,382 @@ import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
*/
|
||||
public final class IdBinderEmbedded implements IdBinder {
|
||||
|
||||
private final BeanPropertyAssocOne<?> embIdProperty;
|
||||
private final BeanPropertyAssocOne<?> embIdProperty;
|
||||
|
||||
private final boolean idInExpandedForm;
|
||||
|
||||
private BeanProperty[] props;
|
||||
private final boolean idInExpandedForm;
|
||||
|
||||
private BeanDescriptor<?> idDesc;
|
||||
private BeanProperty[] props;
|
||||
|
||||
private String idInValueSql;
|
||||
|
||||
|
||||
public IdBinderEmbedded(boolean idInExpandedForm, BeanPropertyAssocOne<?> embIdProperty) {
|
||||
this.idInExpandedForm = idInExpandedForm;
|
||||
this.embIdProperty = embIdProperty;
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BeanProperty getBeanProperty() {
|
||||
return embIdProperty;
|
||||
}
|
||||
|
||||
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 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());
|
||||
}
|
||||
|
||||
public void initialise() {
|
||||
this.idDesc = embIdProperty.getTargetDescriptor();
|
||||
this.props = embIdProperty.getProperties();
|
||||
this.idInValueSql = idInExpandedForm ? idInExpanded() : idInCompressed();
|
||||
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((EntityBean) value));
|
||||
}
|
||||
}
|
||||
|
||||
public String getIdInValueExprDelete(int size) {
|
||||
if (!idInExpandedForm) {
|
||||
return getIdInValueExpr(size);
|
||||
}
|
||||
|
||||
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("=?");
|
||||
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(")");
|
||||
|
||||
return sb.toString();
|
||||
sb.append(props[i].getDbColumn());
|
||||
sb.append("=?");
|
||||
}
|
||||
sb.append(")");
|
||||
}
|
||||
|
||||
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(")");
|
||||
sb.append(") ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
public String getIdInValueExpr(int size) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (!idInExpandedForm) {
|
||||
sb.append(" in");
|
||||
}
|
||||
|
||||
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 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((EntityBean)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;
|
||||
}
|
||||
|
||||
public Object[] getIdValues(EntityBean bean) {
|
||||
Object val = embIdProperty.getValue(bean);
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
bindvalues[i] = props[i].getValue((EntityBean)val);
|
||||
}
|
||||
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((EntityBean)value);
|
||||
}
|
||||
return bindvalues;
|
||||
}
|
||||
|
||||
public void bindId(DefaultSqlUpdate sqlUpdate, Object value) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = props[i].getValue((EntityBean)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((EntityBean)value);
|
||||
props[i].bind(dataBind, embFieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public Object readData(DataInput dataInput) throws IOException {
|
||||
|
||||
EntityBean embId = idDesc.createBean();
|
||||
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;
|
||||
sb.append(" (");
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (i > 0) {
|
||||
if (idInExpandedForm) {
|
||||
sb.append(" or ");
|
||||
} else {
|
||||
return null;
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append(idInValueSql);
|
||||
}
|
||||
sb.append(") ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getIdInValueExpr() {
|
||||
return idInValueSql;
|
||||
}
|
||||
|
||||
public Object[] getIdValues(EntityBean bean) {
|
||||
Object val = embIdProperty.getValue(bean);
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
bindvalues[i] = props[i].getValue((EntityBean) val);
|
||||
}
|
||||
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((EntityBean) value);
|
||||
}
|
||||
return bindvalues;
|
||||
}
|
||||
|
||||
public void bindId(DefaultSqlUpdate sqlUpdate, Object value) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = props[i].getValue((EntityBean) 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((EntityBean) value);
|
||||
props[i].bind(dataBind, embFieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public Object readData(DataInput dataInput) throws IOException {
|
||||
|
||||
EntityBean embId = idDesc.createBean();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = props[i].getValue((EntityBean)idValue);
|
||||
props[i].writeData(dataOutput, embFieldValue);
|
||||
}
|
||||
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((EntityBean) 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 {
|
||||
|
||||
EntityBean embId = idDesc.createBean();
|
||||
boolean notNull = true;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = props[i].readSet(ctx, embId, null);
|
||||
if (value == null) {
|
||||
notNull = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void loadIgnore(DbReadContext ctx) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].loadIgnore(ctx);
|
||||
}
|
||||
if (notNull) {
|
||||
return embId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, EntityBean 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 "";
|
||||
}
|
||||
|
||||
public Object read(DbReadContext ctx) throws SQLException {
|
||||
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();
|
||||
}
|
||||
|
||||
EntityBean embId = idDesc.createBean();
|
||||
boolean notNull = true;
|
||||
public Object convertSetId(Object idValue, EntityBean bean) {
|
||||
|
||||
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;
|
||||
}
|
||||
// can not cast/convert if it is embedded
|
||||
if (bean != null) {
|
||||
// support PropertyChangeSupport
|
||||
embIdProperty.setValueIntercept(bean, idValue);
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, EntityBean 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, EntityBean bean) {
|
||||
|
||||
// can not cast/convert if it is embedded
|
||||
if (bean != null) {
|
||||
// support PropertyChangeSupport
|
||||
embIdProperty.setValueIntercept(bean, idValue);
|
||||
}
|
||||
|
||||
return idValue;
|
||||
}
|
||||
return idValue;
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,6 @@ public final class IdBinderEmpty implements IdBinder {
|
||||
|
||||
private static final String bindIdSql = "";
|
||||
|
||||
private static final BeanProperty[] properties = new BeanProperty[0];
|
||||
|
||||
public IdBinderEmpty() {
|
||||
|
||||
}
|
||||
@@ -43,6 +41,11 @@ public final class IdBinderEmpty implements IdBinder {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BeanProperty getBeanProperty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getIdProperty() {
|
||||
return null;
|
||||
}
|
||||
@@ -60,10 +63,6 @@ public final class IdBinderEmpty implements IdBinder {
|
||||
return "";
|
||||
}
|
||||
|
||||
public BeanProperty[] getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public String getBindIdSql(String baseTableAlias) {
|
||||
return bindIdSql;
|
||||
}
|
||||
|
||||
@@ -19,21 +19,17 @@ public class IdBinderFactory {
|
||||
/**
|
||||
* Create the IdConvertSet for the given type of Id properties.
|
||||
*/
|
||||
public IdBinder createIdBinder(BeanProperty[] uids) {
|
||||
public IdBinder createIdBinder(BeanProperty id) {
|
||||
|
||||
if (uids.length == 0){
|
||||
if (id == null){
|
||||
// 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]);
|
||||
}
|
||||
|
||||
}
|
||||
if (id.isEmbedded()){
|
||||
return new IdBinderEmbedded(idInExpandedForm, (BeanPropertyAssocOne<?>)id);
|
||||
} else {
|
||||
return new IdBinderMultiple(uids);
|
||||
return new IdBinderSimple(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,399 +0,0 @@
|
||||
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.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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 buildSelectExpressionChain(String prefix, List<String> selectChain) {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].buildSelectExpressionChain(prefix, selectChain);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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((EntityBean)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(EntityBean 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 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, EntityBean 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, EntityBean 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;
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,6 @@ public final class IdBinderSimple implements IdBinder {
|
||||
|
||||
private final String bindIdSql;
|
||||
|
||||
private final BeanProperty[] properties;
|
||||
|
||||
private final Class<?> expectedType;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -37,8 +35,6 @@ public final class IdBinderSimple implements IdBinder {
|
||||
this.idProperty = idProperty;
|
||||
this.scalarType = idProperty.getScalarType();
|
||||
this.expectedType = idProperty.getPropertyType();
|
||||
this.properties = new BeanProperty[1];
|
||||
properties[0] = idProperty;
|
||||
bindIdSql = InternString.intern(idProperty.getDbColumn()+" = ? ");
|
||||
}
|
||||
|
||||
@@ -46,33 +42,37 @@ public final class IdBinderSimple implements IdBinder {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public String getOrderBy(String pathPrefix, boolean ascending) {
|
||||
|
||||
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();
|
||||
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) {
|
||||
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
|
||||
|
||||
idProperty.buildSelectExpressionChain(prefix, selectChain);
|
||||
}
|
||||
|
||||
idProperty.buildSelectExpressionChain(prefix, selectChain);
|
||||
}
|
||||
/**
|
||||
* Returns 1.
|
||||
*/
|
||||
public int getPropertyCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BeanProperty getBeanProperty() {
|
||||
return idProperty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 1.
|
||||
*/
|
||||
public int getPropertyCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String getIdProperty() {
|
||||
public String getIdProperty() {
|
||||
return idProperty.getName();
|
||||
}
|
||||
|
||||
@@ -90,128 +90,124 @@ public final class IdBinderSimple implements IdBinder {
|
||||
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 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 String getBindIdSql(String baseTableAlias) {
|
||||
if (baseTableAlias == null) {
|
||||
return bindIdSql;
|
||||
} else {
|
||||
return baseTableAlias + "." + bindIdSql;
|
||||
}
|
||||
}
|
||||
|
||||
public Object[] getIdValues(EntityBean bean){
|
||||
return new Object[]{idProperty.getValue(bean)};
|
||||
}
|
||||
|
||||
public Object[] getBindValues(Object idValue){
|
||||
return new Object[]{idValue};
|
||||
}
|
||||
public Object[] getIdValues(EntityBean bean) {
|
||||
return new Object[] { idProperty.getValue(bean) };
|
||||
}
|
||||
|
||||
public String getIdInValueExprDelete(int size) {
|
||||
return getIdInValueExpr(size);
|
||||
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 {
|
||||
if (!value.getClass().equals(expectedType)) {
|
||||
value = scalarType.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, EntityBean 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, EntityBean bean) {
|
||||
|
||||
if (!idValue.getClass().equals(expectedType)) {
|
||||
idValue = scalarType.toBeanType(idValue);
|
||||
}
|
||||
|
||||
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();
|
||||
if (bean != null) {
|
||||
// support PropertyChangeSupport
|
||||
idProperty.setValueIntercept(bean, idValue);
|
||||
}
|
||||
|
||||
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 {
|
||||
if( !value.getClass().equals(expectedType) ){
|
||||
value = scalarType.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, EntityBean 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, EntityBean bean) {
|
||||
|
||||
if (!idValue.getClass().equals(expectedType)){
|
||||
idValue = scalarType.toBeanType(idValue);
|
||||
}
|
||||
|
||||
if (bean != null) {
|
||||
// support PropertyChangeSupport
|
||||
idProperty.setValueIntercept(bean, idValue);
|
||||
}
|
||||
|
||||
return idValue;
|
||||
}
|
||||
return idValue;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user