Change license to Apache2 and reformat

This commit is contained in:
rbygrave committed 2012-09-15 00:00:08 +12:00
1 parent 96ce4c0ddf
commit 7aae897def
560 files changed
+73292 -85907

No files matched your search

@@ -1,75 +1,56 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Item held by Meta objects used to generate and bind bean insert update and
* delete statements.
* <p>
* An implementation is expected to be immutable and thread safe.
* </p>
* <p>
* The design is to take a bean structure with embedded and associated objects
* etc and flatten that into lists of Bindable objects. These are put into
* InsertMeta UpdateMeta and DeleteMeta objects to support the generation of DML
* and binding of statements in a fast and painless manor.
* </p>
*/
public interface Bindable {
/**
* For Updates including only changed properties add the Bindable to the
* list if it should be included in the 'update set'.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list);
/**
* append sql to the buffer with prefix and suffix options.
*/
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes);
/**
* append sql to the buffer with prefix and suffix options.
*/
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes);
/**
* For WHERE clauses append sql to the buffer with prefix and suffix
* options. These need to take into account binding of null values.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean);
/**
* Bind given the request and bean. The bean could be the oldValues bean
* when binding a update or delete where clause with ALL concurrency mode.
*/
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean)
throws SQLException;
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean)
throws SQLException;
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Item held by Meta objects used to generate and bind bean insert update and
* delete statements.
* <p>
* An implementation is expected to be immutable and thread safe.
* </p>
* <p>
* The design is to take a bean structure with embedded and associated objects
* etc and flatten that into lists of Bindable objects. These are put into
* InsertMeta UpdateMeta and DeleteMeta objects to support the generation of DML
* and binding of statements in a fast and painless manor.
* </p>
*/
public interface Bindable {
/**
* For Updates including only changed properties add the Bindable to the
* list if it should be included in the 'update set'.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list);
/**
* append sql to the buffer with prefix and suffix options.
*/
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes);
/**
* append sql to the buffer with prefix and suffix options.
*/
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes);
/**
* For WHERE clauses append sql to the buffer with prefix and suffix
* options. These need to take into account binding of null values.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean);
/**
* Bind given the request and bean. The bean could be the oldValues bean
* when binding a update or delete where clause with ALL concurrency mode.
*/
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean)
throws SQLException;
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean)
throws SQLException;
}
@@ -1,107 +1,88 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebeaninternal.api.DerivedRelationshipData;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.deploy.id.ImportedId;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for an ManyToOne or OneToOne associated bean.
*/
public class BindableAssocOne implements Bindable {
private final BeanPropertyAssocOne<?> assocOne;
private final ImportedId importedId;
public BindableAssocOne(BeanPropertyAssocOne<?> assocOne) {
this.assocOne = assocOne;
this.importedId = assocOne.getImportedId();
}
public String toString() {
return "BindableAssocOne " + assocOne;
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(assocOne)) {
list.add(this);
}
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(assocOne)) {
return;
}
importedId.dmlAppend(request);
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
if (checkIncludes && !request.isIncludedWhere(assocOne)) {
return;
}
Object assocBean = assocOne.getValue(bean);
importedId.dmlWhere(request, assocBean);
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncluded(assocOne)) {
return;
}
dmlBind(request, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncludedWhere(assocOne)) {
return;
}
dmlBind(request, bean, false);
}
private void dmlBind(BindableRequest request, Object bean, boolean bindNull)
throws SQLException {
Object assocBean = assocOne.getValue(bean);
Object boundValue = importedId.bind(request, assocBean, bindNull);
if (bindNull && boundValue == null && assocBean != null){
// this is the scenario for a derived foreign key
// which will require an additional update
// register for post insert of assocBean
// update of bean set ... importedId.getLogicalName();
// value of assocBean.getId
DerivedRelationshipData d = new DerivedRelationshipData(assocBean, assocOne.getName(), bean);
request.registerDerivedRelationship(d);
}
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebeaninternal.api.DerivedRelationshipData;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.deploy.id.ImportedId;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for an ManyToOne or OneToOne associated bean.
*/
public class BindableAssocOne implements Bindable {
private final BeanPropertyAssocOne<?> assocOne;
private final ImportedId importedId;
public BindableAssocOne(BeanPropertyAssocOne<?> assocOne) {
this.assocOne = assocOne;
this.importedId = assocOne.getImportedId();
}
public String toString() {
return "BindableAssocOne " + assocOne;
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(assocOne)) {
list.add(this);
}
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(assocOne)) {
return;
}
importedId.dmlAppend(request);
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
if (checkIncludes && !request.isIncludedWhere(assocOne)) {
return;
}
Object assocBean = assocOne.getValue(bean);
importedId.dmlWhere(request, assocBean);
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncluded(assocOne)) {
return;
}
dmlBind(request, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncludedWhere(assocOne)) {
return;
}
dmlBind(request, bean, false);
}
private void dmlBind(BindableRequest request, Object bean, boolean bindNull)
throws SQLException {
Object assocBean = assocOne.getValue(bean);
Object boundValue = importedId.bind(request, assocBean, bindNull);
if (bindNull && boundValue == null && assocBean != null){
// this is the scenario for a derived foreign key
// which will require an additional update
// register for post insert of assocBean
// update of bean set ... importedId.getLogicalName();
// value of assocBean.getId
DerivedRelationshipData d = new DerivedRelationshipData(assocBean, assocOne.getName(), bean);
request.registerDerivedRelationship(d);
}
}
}
@@ -1,106 +1,87 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyCompound;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a Immutable Compound value object.
*/
public class BindableCompound implements Bindable {
private final Bindable[] items;
private final BeanPropertyCompound compound;
public BindableCompound(BeanPropertyCompound embProp, List<Bindable> list) {
this.compound = embProp;
this.items = list.toArray(new Bindable[list.size()]);
}
public String toString() {
return "BindableCompound " + compound + " items:" + Arrays.toString(items);
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(compound)) {
return;
}
for (int i = 0; i < items.length; i++) {
items[i].dmlAppend(request, false);
}
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object origBean) {
if (checkIncludes && !request.isIncludedWhere(compound)) {
return;
}
Object valueObject = compound.getValue(origBean);
for (int i = 0; i < items.length; i++) {
items[i].dmlWhere(request, false, valueObject);
}
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(compound)) {
list.add(this);
}
}
public void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !bindRequest.isIncluded(compound)) {
return;
}
Object valueObject = compound.getValue(bean);
for (int i = 0; i < items.length; i++) {
items[i].dmlBind(bindRequest, false, valueObject);
}
}
public void dmlBindWhere(BindableRequest bindRequest, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !bindRequest.isIncludedWhere(compound)) {
return;
}
Object valueObject = compound.getValue(bean);
for (int i = 0; i < items.length; i++) {
items[i].dmlBindWhere(bindRequest, false, valueObject);
}
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyCompound;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a Immutable Compound value object.
*/
public class BindableCompound implements Bindable {
private final Bindable[] items;
private final BeanPropertyCompound compound;
public BindableCompound(BeanPropertyCompound embProp, List<Bindable> list) {
this.compound = embProp;
this.items = list.toArray(new Bindable[list.size()]);
}
public String toString() {
return "BindableCompound " + compound + " items:" + Arrays.toString(items);
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(compound)) {
return;
}
for (int i = 0; i < items.length; i++) {
items[i].dmlAppend(request, false);
}
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object origBean) {
if (checkIncludes && !request.isIncludedWhere(compound)) {
return;
}
Object valueObject = compound.getValue(origBean);
for (int i = 0; i < items.length; i++) {
items[i].dmlWhere(request, false, valueObject);
}
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(compound)) {
list.add(this);
}
}
public void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !bindRequest.isIncluded(compound)) {
return;
}
Object valueObject = compound.getValue(bean);
for (int i = 0; i < items.length; i++) {
items[i].dmlBind(bindRequest, false, valueObject);
}
}
public void dmlBindWhere(BindableRequest bindRequest, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !bindRequest.isIncludedWhere(compound)) {
return;
}
Object valueObject = compound.getValue(bean);
for (int i = 0; i < items.length; i++) {
items[i].dmlBindWhere(bindRequest, false, valueObject);
}
}
}
@@ -1,79 +1,60 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.InheritInfo;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for inserting a discriminator value.
*/
public class BindableDiscriminator implements Bindable {
private final String columnName;
private final Object discValue;
private final int sqlType;
public BindableDiscriminator(InheritInfo inheritInfo) {
this.columnName = inheritInfo.getDiscriminatorColumn();
this.discValue = inheritInfo.getDiscriminatorValue();
this.sqlType = inheritInfo.getDiscriminatorType();
}
public String toString() {
return columnName + " = " + discValue;
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
throw new PersistenceException("Never called (only for inserts)");
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
/**
* Never used in where clause.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// never used in where
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
request.appendColumn(columnName);
}
public void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean) throws SQLException {
bindRequest.bind(columnName, discValue, sqlType);
}
public void dmlBindWhere(BindableRequest bindRequest, boolean checkIncludes, Object bean) throws SQLException {
bindRequest.bind(columnName, discValue, sqlType);
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.InheritInfo;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for inserting a discriminator value.
*/
public class BindableDiscriminator implements Bindable {
private final String columnName;
private final Object discValue;
private final int sqlType;
public BindableDiscriminator(InheritInfo inheritInfo) {
this.columnName = inheritInfo.getDiscriminatorColumn();
this.discValue = inheritInfo.getDiscriminatorValue();
this.sqlType = inheritInfo.getDiscriminatorType();
}
public String toString() {
return columnName + " = " + discValue;
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
throw new PersistenceException("Never called (only for inserts)");
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
/**
* Never used in where clause.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// never used in where
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
request.appendColumn(columnName);
}
public void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean) throws SQLException {
bindRequest.bind(columnName, discValue, sqlType);
}
public void dmlBindWhere(BindableRequest bindRequest, boolean checkIncludes, Object bean) throws SQLException {
bindRequest.bind(columnName, discValue, sqlType);
}
}
@@ -1,139 +1,120 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a Embedded bean.
*/
public class BindableEmbedded implements Bindable {
private final Bindable[] items;
private final BeanPropertyAssocOne<?> embProp;
public BindableEmbedded(BeanPropertyAssocOne<?> embProp, List<Bindable> list) {
this.embProp = embProp;
this.items = list.toArray(new Bindable[list.size()]);
}
public String toString() {
return "BindableEmbedded " + embProp + " items:" + Arrays.toString(items);
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(embProp)) {
return;
}
for (int i = 0; i < items.length; i++) {
items[i].dmlAppend(request, false);
}
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object origBean) {
if (checkIncludes && !request.isIncludedWhere(embProp)) {
return;
}
Object embBean = embProp.getValue(origBean);
Object oldValues = getOldValue(embBean);
for (int i = 0; i < items.length; i++) {
items[i].dmlWhere(request, false, oldValues);
}
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(embProp)) {
list.add(this);
}
}
public void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean)
throws SQLException {
if (checkIncludes && !bindRequest.isIncluded(embProp)) {
return;
}
// get the embedded bean
Object embBean = embProp.getValue(bean);
for (int i = 0; i < items.length; i++) {
items[i].dmlBind(bindRequest, false, embBean);
}
}
public void dmlBindWhere(BindableRequest bindRequest, boolean checkIncludes, Object bean)
throws SQLException {
if (checkIncludes && !bindRequest.isIncludedWhere(embProp)) {
return;
}
// get the embedded bean
Object embBean = embProp.getValue(bean);
Object oldEmbBean = getOldValue(embBean);
for (int i = 0; i < items.length; i++) {
items[i].dmlBindWhere(bindRequest, false, oldEmbBean);
}
}
/**
* Get the old bean which will have the original values.
* <p>
* These are bound to the WHERE clause for updates.
* </p>
*/
private Object getOldValue(Object embBean) {
Object oldValues = null;
if (embBean instanceof EntityBean) {
// get the old embedded bean (with the original values)
oldValues = ((EntityBean) embBean)._ebean_getIntercept().getOldValues();
}
if (oldValues == null) {
// this embedded bean was not modified
// (or not an EntityBean)
oldValues = embBean;
}
return oldValues;
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a Embedded bean.
*/
public class BindableEmbedded implements Bindable {
private final Bindable[] items;
private final BeanPropertyAssocOne<?> embProp;
public BindableEmbedded(BeanPropertyAssocOne<?> embProp, List<Bindable> list) {
this.embProp = embProp;
this.items = list.toArray(new Bindable[list.size()]);
}
public String toString() {
return "BindableEmbedded " + embProp + " items:" + Arrays.toString(items);
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(embProp)) {
return;
}
for (int i = 0; i < items.length; i++) {
items[i].dmlAppend(request, false);
}
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object origBean) {
if (checkIncludes && !request.isIncludedWhere(embProp)) {
return;
}
Object embBean = embProp.getValue(origBean);
Object oldValues = getOldValue(embBean);
for (int i = 0; i < items.length; i++) {
items[i].dmlWhere(request, false, oldValues);
}
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(embProp)) {
list.add(this);
}
}
public void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean)
throws SQLException {
if (checkIncludes && !bindRequest.isIncluded(embProp)) {
return;
}
// get the embedded bean
Object embBean = embProp.getValue(bean);
for (int i = 0; i < items.length; i++) {
items[i].dmlBind(bindRequest, false, embBean);
}
}
public void dmlBindWhere(BindableRequest bindRequest, boolean checkIncludes, Object bean)
throws SQLException {
if (checkIncludes && !bindRequest.isIncludedWhere(embProp)) {
return;
}
// get the embedded bean
Object embBean = embProp.getValue(bean);
Object oldEmbBean = getOldValue(embBean);
for (int i = 0; i < items.length; i++) {
items[i].dmlBindWhere(bindRequest, false, oldEmbBean);
}
}
/**
* Get the old bean which will have the original values.
* <p>
* These are bound to the WHERE clause for updates.
* </p>
*/
private Object getOldValue(Object embBean) {
Object oldValues = null;
if (embBean instanceof EntityBean) {
// get the old embedded bean (with the original values)
oldValues = ((EntityBean) embBean)._ebean_getIntercept().getOldValues();
}
if (oldValues == null) {
// this embedded bean was not modified
// (or not an EntityBean)
oldValues = embBean;
}
return oldValues;
}
}
@@ -1,144 +1,125 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a DB encrypted BeanProperty.
*/
public class BindableEncryptedProperty implements Bindable {
private final BeanProperty prop;
private final boolean bindEncryptDataFirst;
public BindableEncryptedProperty(BeanProperty prop, boolean bindEncryptDataFirst) {
this.prop = prop;
this.bindEncryptDataFirst = bindEncryptDataFirst;
}
public String toString() {
return prop.toString();
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(prop)) {
list.add(this);
}
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
// columnName
// AES_ENCRYPT(?,?)
request.appendColumn(prop.getDbColumn(), prop.getDbBind());
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
// columnName = AES_ENCRYPT(?,?)
request.appendColumn(prop.getDbColumn(), "=", prop.getDbBind());
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// only include encrypted property in where when it is included
// in the update as well (so not using isIncludedWhere)
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
if (bean == null || request.isDbNull(prop.getValue(bean))) {
request.appendColumnIsNull(prop.getDbColumn());
} else {
// ? = AES_DECRYPT(columnName,?)
request.appendColumn("? = ", prop.getDecryptSql());
}
}
/**
* Bind a value in a Insert SET clause.
*/
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean)
throws SQLException {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
Object value = null;
if (bean != null) {
value = prop.getValue(bean);
}
// get Encrypt key
String encryptKeyValue = prop.getEncryptKey().getStringValue();
if (!bindEncryptDataFirst){
// H2 encrypt function ... different parameter order
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
}
request.bindNoLog(value, prop, prop.getName(), true);
if (bindEncryptDataFirst){
// MySql, Postgres, Oracle
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
}
}
/**
* Bind a value in a Insert SET clause.
*/
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean)
throws SQLException {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
Object value = null;
if (bean != null) {
value = prop.getValue(bean);
}
// get Encrypt key
String encryptKeyValue = prop.getEncryptKey().getStringValue();
request.bind(value, prop, prop.getName(), false);
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a DB encrypted BeanProperty.
*/
public class BindableEncryptedProperty implements Bindable {
private final BeanProperty prop;
private final boolean bindEncryptDataFirst;
public BindableEncryptedProperty(BeanProperty prop, boolean bindEncryptDataFirst) {
this.prop = prop;
this.bindEncryptDataFirst = bindEncryptDataFirst;
}
public String toString() {
return prop.toString();
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(prop)) {
list.add(this);
}
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
// columnName
// AES_ENCRYPT(?,?)
request.appendColumn(prop.getDbColumn(), prop.getDbBind());
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
// columnName = AES_ENCRYPT(?,?)
request.appendColumn(prop.getDbColumn(), "=", prop.getDbBind());
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// only include encrypted property in where when it is included
// in the update as well (so not using isIncludedWhere)
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
if (bean == null || request.isDbNull(prop.getValue(bean))) {
request.appendColumnIsNull(prop.getDbColumn());
} else {
// ? = AES_DECRYPT(columnName,?)
request.appendColumn("? = ", prop.getDecryptSql());
}
}
/**
* Bind a value in a Insert SET clause.
*/
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean)
throws SQLException {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
Object value = null;
if (bean != null) {
value = prop.getValue(bean);
}
// get Encrypt key
String encryptKeyValue = prop.getEncryptKey().getStringValue();
if (!bindEncryptDataFirst){
// H2 encrypt function ... different parameter order
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
}
request.bindNoLog(value, prop, prop.getName(), true);
if (bindEncryptDataFirst){
// MySql, Postgres, Oracle
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
}
}
/**
* Bind a value in a Insert SET clause.
*/
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean)
throws SQLException {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
Object value = null;
if (bean != null) {
value = prop.getValue(bean);
}
// get Encrypt key
String encryptKeyValue = prop.getEncryptKey().getStringValue();
request.bind(value, prop, prop.getName(), false);
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.getName() + "=****");
}
}
@@ -1,61 +1,42 @@
/**
* 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.persist.dmlbind;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
/**
* Adds support for id creation for concatenated ids on intersection tables.
* <p>
* Specifically if the concatenated id object is null on insert this can be
* built from the matching ManyToOne associated beans. For example RoleUserId
* embeddedId object could be built from the associated Role and User beans.
* </p>
* <p>
* This is only attempted if the id is null when it gets to the insert.
* </p>
*/
public interface BindableId extends Bindable {
/**
* Return true if there is no Id properties at all.
*/
public boolean isEmpty();
/**
* Return true if this is a concatenated key.
*/
public boolean isConcatenated();
/**
* Return the DB Column to use with genGeneratedKeys.
*/
public String getIdentityColumn();
/**
* Create the concatenated id for inserts with PFK relationships.
* <p>
* Really only where there are ManyToOne assoc beans that make up the
* primary key and the values can be got from those.
* </p>
*/
public boolean deriveConcatenatedId(PersistRequestBean<?> persist);
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
/**
* Adds support for id creation for concatenated ids on intersection tables.
* <p>
* Specifically if the concatenated id object is null on insert this can be
* built from the matching ManyToOne associated beans. For example RoleUserId
* embeddedId object could be built from the associated Role and User beans.
* </p>
* <p>
* This is only attempted if the id is null when it gets to the insert.
* </p>
*/
public interface BindableId extends Bindable {
/**
* Return true if there is no Id properties at all.
*/
public boolean isEmpty();
/**
* Return true if this is a concatenated key.
*/
public boolean isConcatenated();
/**
* Return the DB Column to use with genGeneratedKeys.
*/
public String getIdentityColumn();
/**
* Create the concatenated id for inserts with PFK relationships.
* <p>
* Really only where there are ManyToOne assoc beans that make up the
* primary key and the values can be got from those.
* </p>
*/
public boolean deriveConcatenatedId(PersistRequestBean<?> persist);
}
@@ -1,148 +1,129 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a EmbeddedId.
*/
public final class BindableIdEmbedded implements BindableId {
private final BeanPropertyAssocOne<?> embId;
private final BeanProperty[] props;
private final MatchedImportedProperty[] matches;
public BindableIdEmbedded(BeanPropertyAssocOne<?> embId, BeanDescriptor<?> desc) {
this.embId = embId;
this.props = embId.getTargetDescriptor().propertiesBaseScalar();
matches = MatchedImportedProperty.build(props, desc);
}
public boolean isEmpty() {
return false;
}
public boolean isConcatenated() {
return true;
}
public String getIdentityColumn() {
// return null for concatenated keys
return null;
}
@Override
public String toString() {
return embId + " props:" + Arrays.toString(props);
}
/**
* Does nothing for BindableId.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
// do nothing (id not changing)
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
private void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean, boolean bindNull) throws SQLException {
if (checkIncludes && !bindRequest.isIncluded(embId)) {
return;
}
Object idValue = embId.getValue(bean);
for (int i = 0; i < props.length; i++) {
Object value = props[i].getValue(idValue);
bindRequest.bind(value, props[i], props[i].getDbColumn(), bindNull);
}
bindRequest.setIdValue(idValue);
}
/**
* Id values are never null in where clause.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
if (checkIncludes && !request.isIncluded(embId)) {
return;
}
dmlAppend(request, false);
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(embId)) {
return;
}
for (int i = 0; i < props.length; i++) {
request.appendColumn(props[i].getDbColumn());
}
}
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
if (matches == null) {
String m = "Matches for the concatinated key columns where not found?"
+ " I expect that the concatinated key was null, and this bean does"
+ " not have ManyToOne assoc beans matching the primary key columns?";
throw new PersistenceException(m);
}
Object bean = persist.getBean();
// create the new id
Object newId = embId.createEmbeddedId();
// populate it from the assoc one id values...
for (int i = 0; i < matches.length; i++) {
matches[i].populate(bean, newId);
}
// support PropertyChangeSupport
embId.setValueIntercept(bean, newId);
return true;
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a EmbeddedId.
*/
public final class BindableIdEmbedded implements BindableId {
private final BeanPropertyAssocOne<?> embId;
private final BeanProperty[] props;
private final MatchedImportedProperty[] matches;
public BindableIdEmbedded(BeanPropertyAssocOne<?> embId, BeanDescriptor<?> desc) {
this.embId = embId;
this.props = embId.getTargetDescriptor().propertiesBaseScalar();
matches = MatchedImportedProperty.build(props, desc);
}
public boolean isEmpty() {
return false;
}
public boolean isConcatenated() {
return true;
}
public String getIdentityColumn() {
// return null for concatenated keys
return null;
}
@Override
public String toString() {
return embId + " props:" + Arrays.toString(props);
}
/**
* Does nothing for BindableId.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
// do nothing (id not changing)
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
private void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean, boolean bindNull) throws SQLException {
if (checkIncludes && !bindRequest.isIncluded(embId)) {
return;
}
Object idValue = embId.getValue(bean);
for (int i = 0; i < props.length; i++) {
Object value = props[i].getValue(idValue);
bindRequest.bind(value, props[i], props[i].getDbColumn(), bindNull);
}
bindRequest.setIdValue(idValue);
}
/**
* Id values are never null in where clause.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
if (checkIncludes && !request.isIncluded(embId)) {
return;
}
dmlAppend(request, false);
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(embId)) {
return;
}
for (int i = 0; i < props.length; i++) {
request.appendColumn(props[i].getDbColumn());
}
}
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
if (matches == null) {
String m = "Matches for the concatinated key columns where not found?"
+ " I expect that the concatinated key was null, and this bean does"
+ " not have ManyToOne assoc beans matching the primary key columns?";
throw new PersistenceException(m);
}
Object bean = persist.getBean();
// create the new id
Object newId = embId.createEmbeddedId();
// populate it from the assoc one id values...
for (int i = 0; i < matches.length; i++) {
matches[i].populate(bean, newId);
}
// support PropertyChangeSupport
embId.setValueIntercept(bean, newId);
return true;
}
}
@@ -1,133 +1,114 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a concatenated id that is not embedded.
*/
public final class BindableIdMap implements BindableId {
private final BeanProperty[] uids;
private final MatchedImportedProperty[] matches;
public BindableIdMap(BeanProperty[] uids, BeanDescriptor<?> desc) {
this.uids = uids;
matches = MatchedImportedProperty.build(uids, desc);
}
public boolean isEmpty() {
return false;
}
public boolean isConcatenated() {
return true;
}
public String getIdentityColumn() {
// return null for concatenated keys
return null;
}
@Override
public String toString() {
return Arrays.toString(uids);
}
/**
* Does nothing for BindableId.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
// do nothing (id not changing)
}
/**
* Id values are never null in where clause.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// id values are never null in where clause
dmlAppend(request, false);
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
for (int i = 0; i < uids.length; i++) {
request.appendColumn(uids[i].getDbColumn());
}
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
private void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean, boolean bindNull) throws SQLException {
LinkedHashMap<String, Object> mapId = new LinkedHashMap<String, Object>();
for (int i = 0; i < uids.length; i++) {
Object value = uids[i].getValue(bean);
bindRequest.bind(value, uids[i], uids[i].getName(), bindNull);
// putting logicalType into map rather than
// the dbType (which may have been converted).
mapId.put(uids[i].getName(), value);
}
bindRequest.setIdValue(mapId);
}
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
if (matches == null) {
String m = "Matches for the concatinated key columns where not found?"
+ " I expect that the concatinated key was null, and this bean does"
+ " not have ManyToOne assoc beans matching the primary key columns?";
throw new PersistenceException(m);
}
Object bean = persist.getBean();
// populate it from the assoc one id values...
for (int i = 0; i < matches.length; i++) {
matches[i].populate(bean, bean);
}
return true;
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a concatenated id that is not embedded.
*/
public final class BindableIdMap implements BindableId {
private final BeanProperty[] uids;
private final MatchedImportedProperty[] matches;
public BindableIdMap(BeanProperty[] uids, BeanDescriptor<?> desc) {
this.uids = uids;
matches = MatchedImportedProperty.build(uids, desc);
}
public boolean isEmpty() {
return false;
}
public boolean isConcatenated() {
return true;
}
public String getIdentityColumn() {
// return null for concatenated keys
return null;
}
@Override
public String toString() {
return Arrays.toString(uids);
}
/**
* Does nothing for BindableId.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
// do nothing (id not changing)
}
/**
* Id values are never null in where clause.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// id values are never null in where clause
dmlAppend(request, false);
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
for (int i = 0; i < uids.length; i++) {
request.appendColumn(uids[i].getDbColumn());
}
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
private void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean, boolean bindNull) throws SQLException {
LinkedHashMap<String, Object> mapId = new LinkedHashMap<String, Object>();
for (int i = 0; i < uids.length; i++) {
Object value = uids[i].getValue(bean);
bindRequest.bind(value, uids[i], uids[i].getName(), bindNull);
// putting logicalType into map rather than
// the dbType (which may have been converted).
mapId.put(uids[i].getName(), value);
}
bindRequest.setIdValue(mapId);
}
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
if (matches == null) {
String m = "Matches for the concatinated key columns where not found?"
+ " I expect that the concatinated key was null, and this bean does"
+ " not have ManyToOne assoc beans matching the primary key columns?";
throw new PersistenceException(m);
}
Object bean = persist.getBean();
// populate it from the assoc one id values...
for (int i = 0; i < matches.length; i++) {
matches[i].populate(bean, bean);
}
return true;
}
}
@@ -1,108 +1,89 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a single scalar id property.
*/
public final class BindableIdScalar implements BindableId {
private final BeanProperty uidProp;
public BindableIdScalar(BeanProperty uidProp) {
this.uidProp = uidProp;
}
public boolean isEmpty() {
return false;
}
public boolean isConcatenated() {
return false;
}
public String getIdentityColumn() {
return uidProp.getDbColumn();
}
@Override
public String toString() {
return uidProp.toString();
}
/**
* Does nothing for BindableId.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
// do nothing (id not changing)
}
/**
* Should not be called as this is really only for concatenated keys.
*/
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
throw new PersistenceException("Should not be called? only for concatinated keys");
}
/**
* Id values are never null in where clause.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// id values are never null in where clause
request.appendColumn(uidProp.getDbColumn());
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
request.appendColumn(uidProp.getDbColumn());
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
private void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean, boolean bindNull) throws SQLException {
Object value = uidProp.getValue(bean);
bindRequest.bind(value, uidProp, uidProp.getName(), bindNull);
// used for summary logging
bindRequest.setIdValue(value);
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a single scalar id property.
*/
public final class BindableIdScalar implements BindableId {
private final BeanProperty uidProp;
public BindableIdScalar(BeanProperty uidProp) {
this.uidProp = uidProp;
}
public boolean isEmpty() {
return false;
}
public boolean isConcatenated() {
return false;
}
public String getIdentityColumn() {
return uidProp.getDbColumn();
}
@Override
public String toString() {
return uidProp.toString();
}
/**
* Does nothing for BindableId.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
// do nothing (id not changing)
}
/**
* Should not be called as this is really only for concatenated keys.
*/
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
throw new PersistenceException("Should not be called? only for concatinated keys");
}
/**
* Id values are never null in where clause.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
// id values are never null in where clause
request.appendColumn(uidProp.getDbColumn());
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
request.appendColumn(uidProp.getDbColumn());
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
private void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean, boolean bindNull) throws SQLException {
Object value = uidProp.getValue(bean);
bindRequest.bind(value, uidProp, uidProp.getName(), bindNull);
// used for summary logging
bindRequest.setIdValue(value);
}
}
@@ -1,80 +1,61 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* List of Bindable items.
*/
public class BindableList implements Bindable {
private final Bindable[] items;
public BindableList(List<Bindable> list) {
items = list.toArray(new Bindable[list.size()]);
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
for (int i = 0; i < items.length; i++) {
items[i].addChanged(request, list);
}
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
for (int i = 0; i < items.length; i++) {
items[i].dmlInsert(request, checkIncludes);
}
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
for (int i = 0; i < items.length; i++) {
items[i].dmlAppend(request, checkIncludes);
}
}
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
for (int i = 0; i < items.length; i++) {
items[i].dmlWhere(request, checkIncludes, bean);
}
}
public void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean)
throws SQLException {
for (int i = 0; i < items.length; i++) {
items[i].dmlBind(bindRequest, checkIncludes, bean);
}
}
public void dmlBindWhere(BindableRequest bindRequest, boolean checkIncludes, Object bean)
throws SQLException {
for (int i = 0; i < items.length; i++) {
items[i].dmlBindWhere(bindRequest, checkIncludes, bean);
}
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* List of Bindable items.
*/
public class BindableList implements Bindable {
private final Bindable[] items;
public BindableList(List<Bindable> list) {
items = list.toArray(new Bindable[list.size()]);
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
for (int i = 0; i < items.length; i++) {
items[i].addChanged(request, list);
}
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
for (int i = 0; i < items.length; i++) {
items[i].dmlInsert(request, checkIncludes);
}
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
for (int i = 0; i < items.length; i++) {
items[i].dmlAppend(request, checkIncludes);
}
}
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
for (int i = 0; i < items.length; i++) {
items[i].dmlWhere(request, checkIncludes, bean);
}
}
public void dmlBind(BindableRequest bindRequest, boolean checkIncludes, Object bean)
throws SQLException {
for (int i = 0; i < items.length; i++) {
items[i].dmlBind(bindRequest, checkIncludes, bean);
}
}
public void dmlBindWhere(BindableRequest bindRequest, boolean checkIncludes, Object bean)
throws SQLException {
for (int i = 0; i < items.length; i++) {
items[i].dmlBindWhere(bindRequest, checkIncludes, bean);
}
}
}
@@ -1,102 +1,83 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a single BeanProperty.
*/
public class BindableProperty implements Bindable {
protected final BeanProperty prop;
public BindableProperty(BeanProperty prop) {
this.prop = prop;
}
public String toString() {
return prop.toString();
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(prop)) {
list.add(this);
}
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
request.appendColumn(prop.getDbColumn());
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
if (checkIncludes && !request.isIncludedWhere(prop)) {
return;
}
if (bean == null || request.isDbNull(prop.getValue(bean))) {
request.appendColumnIsNull(prop.getDbColumn());
} else {
request.appendColumn(prop.getDbColumn());
}
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
dmlBind(request, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncludedWhere(prop)) {
return;
}
dmlBind(request, bean, false);
}
private void dmlBind(BindableRequest request, Object bean, boolean bindNull)
throws SQLException {
Object value = null;
if (bean != null) {
value = prop.getValue(bean);
}
// value = prop.getDefaultValue();
request.bind(value, prop, prop.getName(), bindNull);
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a single BeanProperty.
*/
public class BindableProperty implements Bindable {
protected final BeanProperty prop;
public BindableProperty(BeanProperty prop) {
this.prop = prop;
}
public String toString() {
return prop.toString();
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
if (request.hasChanged(prop)) {
list.add(this);
}
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
request.appendColumn(prop.getDbColumn());
}
/**
* Used for dynamic where clause generation.
*/
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
if (checkIncludes && !request.isIncludedWhere(prop)) {
return;
}
if (bean == null || request.isDbNull(prop.getValue(bean))) {
request.appendColumnIsNull(prop.getDbColumn());
} else {
request.appendColumn(prop.getDbColumn());
}
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncluded(prop)) {
return;
}
dmlBind(request, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncludedWhere(prop)) {
return;
}
dmlBind(request, bean, false);
}
private void dmlBind(BindableRequest request, Object bean, boolean bindNull)
throws SQLException {
Object value = null;
if (bean != null) {
value = prop.getValue(bean);
}
// value = prop.getDefaultValue();
request.bind(value, prop, prop.getName(), bindNull);
}
}
@@ -1,76 +1,57 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for insert on a property with a GeneratedProperty.
* <p>
* This is typically a 'insert timestamp', 'update timestamp' or 'counter'.
* </p>
*/
public class BindablePropertyInsertGenerated extends BindableProperty {
private final GeneratedProperty gen;
public BindablePropertyInsertGenerated(BeanProperty prop, GeneratedProperty gen) {
super(prop);
this.gen = gen;
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
/**
* Bind a value in a Insert SET clause.
*/
private void dmlBind(BindableRequest request, boolean checkIncludes, Object bean, boolean bindNull) throws SQLException {
Object value = gen.getInsertValue(prop, bean);
// generated value should be the correct type
if (bean != null){
// support PropertyChangeSupport
prop.setValueIntercept(bean, value);
request.registerAdditionalProperty(prop.getName());
}
//value = prop.getDefaultValue();
request.bind(value, prop, prop.getName(), bindNull);
}
/**
* Always bind on Insert SET.
*/
@Override
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes){
request.appendColumn(prop.getDbColumn());
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for insert on a property with a GeneratedProperty.
* <p>
* This is typically a 'insert timestamp', 'update timestamp' or 'counter'.
* </p>
*/
public class BindablePropertyInsertGenerated extends BindableProperty {
private final GeneratedProperty gen;
public BindablePropertyInsertGenerated(BeanProperty prop, GeneratedProperty gen) {
super(prop);
this.gen = gen;
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
/**
* Bind a value in a Insert SET clause.
*/
private void dmlBind(BindableRequest request, boolean checkIncludes, Object bean, boolean bindNull) throws SQLException {
Object value = gen.getInsertValue(prop, bean);
// generated value should be the correct type
if (bean != null){
// support PropertyChangeSupport
prop.setValueIntercept(bean, value);
request.registerAdditionalProperty(prop.getName());
}
//value = prop.getDefaultValue();
request.bind(value, prop, prop.getName(), bindNull);
}
/**
* Always bind on Insert SET.
*/
@Override
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes){
request.appendColumn(prop.getDbColumn());
}
}
@@ -1,95 +1,76 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for update on a property with a GeneratedProperty.
* <p>
* This is typically a 'update timestamp' or 'counter'.
* </p>
*/
public class BindablePropertyUpdateGenerated extends BindableProperty {
private final GeneratedProperty gen;
public BindablePropertyUpdateGenerated(BeanProperty prop, GeneratedProperty gen) {
super(prop);
this.gen = gen;
}
/**
* Always add BindablePropertyUpdateGenerated properties.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
list.add(this);
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncluded(prop)){
return;
}
dmlBind(request, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncludedWhere(prop)){
return;
}
dmlBind(request, bean, false);
}
private void dmlBind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {
Object value = gen.getUpdateValue(prop, bean);
// generated value should be the correct type
request.bind(value, prop, prop.getName(), bindNull);
// only register the update value if it was included
// in the bean in the first place
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, boolean checkIncludes){
if (checkIncludes && !request.isIncluded(prop)){
return;
}
request.appendColumn(prop.getDbColumn());
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for update on a property with a GeneratedProperty.
* <p>
* This is typically a 'update timestamp' or 'counter'.
* </p>
*/
public class BindablePropertyUpdateGenerated extends BindableProperty {
private final GeneratedProperty gen;
public BindablePropertyUpdateGenerated(BeanProperty prop, GeneratedProperty gen) {
super(prop);
this.gen = gen;
}
/**
* Always add BindablePropertyUpdateGenerated properties.
*/
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
list.add(this);
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncluded(prop)){
return;
}
dmlBind(request, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
if (checkIncludes && !request.isIncludedWhere(prop)){
return;
}
dmlBind(request, bean, false);
}
private void dmlBind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {
Object value = gen.getUpdateValue(prop, bean);
// generated value should be the correct type
request.bind(value, prop, prop.getName(), bindNull);
// only register the update value if it was included
// in the bean in the first place
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, boolean checkIncludes){
if (checkIncludes && !request.isIncluded(prop)){
return;
}
request.appendColumn(prop.getDbColumn());
}
}
@@ -1,98 +1,79 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import com.avaje.ebeaninternal.api.DerivedRelationshipData;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
/**
* Request object passed to bindables.
*/
public interface BindableRequest {
/**
* Set the id for use with summary level logging.
*/
public void setIdValue(Object idValue);
/**
* Bind the value to a PreparedStatement.
* <p>
* Takes into account logicalType to dbType conversion if required.
* </p>
* <p>
* Returns the value that was bound (and was potentially converted from
* logicalType to dbType.
* </p>
*
* @param value
* the value of a property
* @param bindNull
* if true bind null values, if false use IS NULL.
*/
public Object bind(Object value, BeanProperty prop, String propName, boolean bindNull) throws SQLException;
/**
* Bind a raw value. Used to bind the discriminator column.
*/
public Object bind(String propName, Object value, int sqlType) throws SQLException;
/**
* Bind a raw value with a placeHolder to put into the transaction log.
*/
public Object bindNoLog(Object value, int sqlType, String logPlaceHolder) throws SQLException;
/**
* Bind the value to the preparedStatement without logging.
*/
public Object bindNoLog(Object value, BeanProperty prop, String propName, boolean bindNull) throws SQLException;
/**
* Return true if the property is included in this request.
*/
public boolean isIncluded(BeanProperty prop);
/**
* Return true if the property is included in the WHERE clause for this
* request.
*/
public boolean isIncludedWhere(BeanProperty prop);
/**
* Register the value from a update GeneratedValue. This can only be set to
* the bean property after the where clause has bean built.
*/
public void registerUpdateGenValue(BeanProperty prop, Object bean, Object value);
/**
* Register a property into loadedProperties if required.
*/
public void registerAdditionalProperty(String propertyName);
/**
* Return the original PersistRequest.
*/
public PersistRequestBean<?> getPersistRequest();
public void registerDerivedRelationship(DerivedRelationshipData assocBean);
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import com.avaje.ebeaninternal.api.DerivedRelationshipData;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
/**
* Request object passed to bindables.
*/
public interface BindableRequest {
/**
* Set the id for use with summary level logging.
*/
public void setIdValue(Object idValue);
/**
* Bind the value to a PreparedStatement.
* <p>
* Takes into account logicalType to dbType conversion if required.
* </p>
* <p>
* Returns the value that was bound (and was potentially converted from
* logicalType to dbType.
* </p>
*
* @param value
* the value of a property
* @param bindNull
* if true bind null values, if false use IS NULL.
*/
public Object bind(Object value, BeanProperty prop, String propName, boolean bindNull) throws SQLException;
/**
* Bind a raw value. Used to bind the discriminator column.
*/
public Object bind(String propName, Object value, int sqlType) throws SQLException;
/**
* Bind a raw value with a placeHolder to put into the transaction log.
*/
public Object bindNoLog(Object value, int sqlType, String logPlaceHolder) throws SQLException;
/**
* Bind the value to the preparedStatement without logging.
*/
public Object bindNoLog(Object value, BeanProperty prop, String propName, boolean bindNull) throws SQLException;
/**
* Return true if the property is included in this request.
*/
public boolean isIncluded(BeanProperty prop);
/**
* Return true if the property is included in the WHERE clause for this
* request.
*/
public boolean isIncludedWhere(BeanProperty prop);
/**
* Register the value from a update GeneratedValue. This can only be set to
* the bean property after the where clause has bean built.
*/
public void registerUpdateGenValue(BeanProperty prop, Object bean, Object value);
/**
* Register a property into loadedProperties if required.
*/
public void registerAdditionalProperty(String propertyName);
/**
* Return the original PersistRequest.
*/
public PersistRequestBean<?> getPersistRequest();
public void registerDerivedRelationship(DerivedRelationshipData assocBean);
}
@@ -1,102 +1,83 @@
/**
* 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.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.deploy.id.ImportedId;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a unidirectional relationship.
* <p>
* This inserts the foreign key value that is retrieved from the id of the
* parentBean.
* </p>
*/
public class BindableUnidirectional implements Bindable {
private final BeanPropertyAssocOne<?> unidirectional;
private final ImportedId importedId;
private final BeanDescriptor<?> desc;
public BindableUnidirectional(BeanDescriptor<?> desc, BeanPropertyAssocOne<?> unidirectional) {
this.desc = desc;
this.unidirectional = unidirectional;
this.importedId = unidirectional.getImportedId();
}
public String toString() {
return "BindableShadowFKey " + unidirectional;
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
throw new PersistenceException("Never called (for insert only)");
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
// always included (in insert)
importedId.dmlAppend(request);
}
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
throw new RuntimeException("Never called");
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
private void dmlBind(BindableRequest request, boolean checkIncludes, Object bean, boolean bindNull)
throws SQLException {
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, parentBean, bindNull);
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.deploy.id.ImportedId;
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
/**
* Bindable for a unidirectional relationship.
* <p>
* This inserts the foreign key value that is retrieved from the id of the
* parentBean.
* </p>
*/
public class BindableUnidirectional implements Bindable {
private final BeanPropertyAssocOne<?> unidirectional;
private final ImportedId importedId;
private final BeanDescriptor<?> desc;
public BindableUnidirectional(BeanDescriptor<?> desc, BeanPropertyAssocOne<?> unidirectional) {
this.desc = desc;
this.unidirectional = unidirectional;
this.importedId = unidirectional.getImportedId();
}
public String toString() {
return "BindableShadowFKey " + unidirectional;
}
public void addChanged(PersistRequestBean<?> request, List<Bindable> list) {
throw new PersistenceException("Never called (for insert only)");
}
public void dmlInsert(GenerateDmlRequest request, boolean checkIncludes) {
dmlAppend(request, checkIncludes);
}
public void dmlAppend(GenerateDmlRequest request, boolean checkIncludes) {
// always included (in insert)
importedId.dmlAppend(request);
}
public void dmlWhere(GenerateDmlRequest request, boolean checkIncludes, Object bean) {
throw new RuntimeException("Never called");
}
public void dmlBind(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, true);
}
public void dmlBindWhere(BindableRequest request, boolean checkIncludes, Object bean) throws SQLException {
dmlBind(request, checkIncludes, bean, false);
}
private void dmlBind(BindableRequest request, boolean checkIncludes, Object bean, boolean bindNull)
throws SQLException {
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, parentBean, bindNull);
}
}
@@ -1,68 +1,49 @@
/**
* 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.persist.dmlbind;
import java.util.List;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
/**
* A factory that builds Bindable for BeanPropertyAssocOne properties.
*/
public class FactoryAssocOnes {
public FactoryAssocOnes() {
}
/**
* Add foreign key columns from associated one beans.
*/
public List<Bindable> create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode) {
BeanPropertyAssocOne<?>[] ones = desc.propertiesOneImported();
for (int i = 0; i < ones.length; i++) {
if (ones[i].isImportedPrimaryKey()){
// excluded as already part of the primary key
} else {
switch (mode) {
case WHERE:
break;
case INSERT:
if (!ones[i].isInsertable()) {
continue;
}
break;
case UPDATE:
if (!ones[i].isUpdateable()) {
continue;
}
break;
}
list.add(new BindableAssocOne(ones[i]));
}
}
return list;
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.util.List;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
/**
* A factory that builds Bindable for BeanPropertyAssocOne properties.
*/
public class FactoryAssocOnes {
public FactoryAssocOnes() {
}
/**
* Add foreign key columns from associated one beans.
*/
public List<Bindable> create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode) {
BeanPropertyAssocOne<?>[] ones = desc.propertiesOneImported();
for (int i = 0; i < ones.length; i++) {
if (ones[i].isImportedPrimaryKey()){
// excluded as already part of the primary key
} else {
switch (mode) {
case WHERE:
break;
case INSERT:
if (!ones[i].isInsertable()) {
continue;
}
break;
case UPDATE:
if (!ones[i].isUpdateable()) {
continue;
}
break;
}
list.add(new BindableAssocOne(ones[i]));
}
}
return list;
}
}
@@ -1,79 +1,60 @@
/**
* 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.persist.dmlbind;
import java.util.ArrayList;
import java.util.List;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyCompound;
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
/**
* Add base properties to the BindableList for a bean type.
* <p>
* This excludes unique embedded and associated properties.
* </p>
*/
public class FactoryBaseProperties {
private final FactoryProperty factoryProperty;
public FactoryBaseProperties(boolean bindEncryptDataFirst) {
factoryProperty = new FactoryProperty(bindEncryptDataFirst);
}
/**
* Add Bindable for the base properties to the list.
*/
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
add(desc.propertiesBaseScalar(), list, desc, mode, withLobs);
BeanPropertyCompound[] compoundProps = desc.propertiesBaseCompound();
for (int i = 0; i < compoundProps.length; i++) {
BeanProperty[] props = compoundProps[i].getScalarProperties();
ArrayList<Bindable> newList = new ArrayList<Bindable>(props.length);
add(props, newList, desc, mode, withLobs);
BindableCompound compoundBindable = new BindableCompound(compoundProps[i], newList);
list.add(compoundBindable);
}
}
private void add(BeanProperty[] props, List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
for (int i = 0; i < props.length; i++) {
Bindable item = factoryProperty.create(props[i], mode, withLobs);
if (item != null) {
list.add(item);
} else {
// null where readOnly (Secondary tables) or Lob exclusion
}
}
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.util.ArrayList;
import java.util.List;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyCompound;
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
/**
* Add base properties to the BindableList for a bean type.
* <p>
* This excludes unique embedded and associated properties.
* </p>
*/
public class FactoryBaseProperties {
private final FactoryProperty factoryProperty;
public FactoryBaseProperties(boolean bindEncryptDataFirst) {
factoryProperty = new FactoryProperty(bindEncryptDataFirst);
}
/**
* Add Bindable for the base properties to the list.
*/
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
add(desc.propertiesBaseScalar(), list, desc, mode, withLobs);
BeanPropertyCompound[] compoundProps = desc.propertiesBaseCompound();
for (int i = 0; i < compoundProps.length; i++) {
BeanProperty[] props = compoundProps[i].getScalarProperties();
ArrayList<Bindable> newList = new ArrayList<Bindable>(props.length);
add(props, newList, desc, mode, withLobs);
BindableCompound compoundBindable = new BindableCompound(compoundProps[i], newList);
list.add(compoundBindable);
}
}
private void add(BeanProperty[] props, List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
for (int i = 0; i < props.length; i++) {
Bindable item = factoryProperty.create(props[i], mode, withLobs);
if (item != null) {
list.add(item);
} else {
// null where readOnly (Secondary tables) or Lob exclusion
}
}
}
}
@@ -1,65 +1,46 @@
/**
* 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.persist.dmlbind;
import java.util.ArrayList;
import java.util.List;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
/**
* A factory that builds Bindable for embedded bean properties.
*/
public class FactoryEmbedded {
private final FactoryProperty factoryProperty;
public FactoryEmbedded(boolean bindEncryptDataFirst) {
factoryProperty = new FactoryProperty(bindEncryptDataFirst);
}
/**
* Add bindable for the embedded properties to the list.
*/
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
BeanPropertyAssocOne<?>[] embedded = desc.propertiesEmbedded();
for (int j = 0; j < embedded.length; j++) {
List<Bindable> bindList = new ArrayList<Bindable>();
BeanProperty[] props = embedded[j].getProperties();
for (int i = 0; i < props.length; i++) {
Bindable item = factoryProperty.create(props[i], mode, withLobs);
if (item != null){
bindList.add(item);
}
}
list.add(new BindableEmbedded(embedded[j], bindList));
}
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.util.ArrayList;
import java.util.List;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
/**
* A factory that builds Bindable for embedded bean properties.
*/
public class FactoryEmbedded {
private final FactoryProperty factoryProperty;
public FactoryEmbedded(boolean bindEncryptDataFirst) {
factoryProperty = new FactoryProperty(bindEncryptDataFirst);
}
/**
* Add bindable for the embedded properties to the list.
*/
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
BeanPropertyAssocOne<?>[] embedded = desc.propertiesEmbedded();
for (int j = 0; j < embedded.length; j++) {
List<Bindable> bindList = new ArrayList<Bindable>();
BeanProperty[] props = embedded[j].getProperties();
for (int i = 0; i < props.length; i++) {
Bindable item = factoryProperty.create(props[i], mode, withLobs);
if (item != null){
bindList.add(item);
}
}
list.add(new BindableEmbedded(embedded[j], bindList));
}
}
}
@@ -1,55 +1,36 @@
/**
* 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.persist.dmlbind;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
/**
* Create a Bindable for the ids of a bean type.
*/
public class FactoryId {
public FactoryId() {
}
/**
* Add uniqueId properties.
*/
public BindableId createId(BeanDescriptor<?> desc) {
BeanProperty[] uids = desc.propertiesId();
if (uids.length == 0) {
return new BindableIdEmpty();
} else if (uids.length == 1) {
if (!uids[0].isEmbedded()) {
return new BindableIdScalar(uids[0]);
} else {
BeanPropertyAssocOne<?> embId = (BeanPropertyAssocOne<?>) uids[0];
return new BindableIdEmbedded(embId, desc);
}
} else {
return new BindableIdMap(uids, desc);
}
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
/**
* Create a Bindable for the ids of a bean type.
*/
public class FactoryId {
public FactoryId() {
}
/**
* Add uniqueId properties.
*/
public BindableId createId(BeanDescriptor<?> desc) {
BeanProperty[] uids = desc.propertiesId();
if (uids.length == 0) {
return new BindableIdEmpty();
} else if (uids.length == 1) {
if (!uids[0].isEmbedded()) {
return new BindableIdScalar(uids[0]);
} else {
BeanPropertyAssocOne<?> embId = (BeanPropertyAssocOne<?>) uids[0];
return new BindableIdEmbedded(embId, desc);
}
} else {
return new BindableIdMap(uids, desc);
}
}
}
@@ -1,84 +1,65 @@
/**
* 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.persist.dmlbind;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
/**
* Creates the appropriate Bindable for a BeanProperty.
* <p>
* Lob properties can be excluded and it creates BindablePropertyInsertGenerated
* and BindablePropertyUpdateGenerated as required.
* </p>
*/
public class FactoryProperty {
private final boolean bindEncryptDataFirst;
public FactoryProperty(boolean bindEncryptDataFirst) {
this.bindEncryptDataFirst = bindEncryptDataFirst;
}
/**
* Create a Bindable for the property given the mode and withLobs flag.
*/
public Bindable create(BeanProperty prop, DmlMode mode, boolean withLobs) {
if (DmlMode.INSERT.equals(mode) && !prop.isDbInsertable()){
return null;
}
if (DmlMode.UPDATE.equals(mode) && !prop.isDbUpdatable()){
return null;
}
if (prop.isLob()) {
if (DmlMode.WHERE.equals(mode) || !withLobs) {
// Lob exclusion
return null;
} else {
return prop.isDbEncrypted() ? new BindableEncryptedProperty(prop, bindEncryptDataFirst) : new BindableProperty(prop);
}
}
GeneratedProperty gen = prop.getGeneratedProperty();
if (gen != null) {
if (DmlMode.INSERT.equals(mode)) {
if (gen.includeInInsert()) {
return new BindablePropertyInsertGenerated(prop, gen);
} else {
return null;
}
}
if (DmlMode.UPDATE.equals(mode)) {
if (gen.includeInUpdate()) {
return new BindablePropertyUpdateGenerated(prop, gen);
} else {
// An 'Insert Timestamp' is never updated
return null;
}
}
}
return prop.isDbEncrypted() ? new BindableEncryptedProperty(prop, bindEncryptDataFirst) : new BindableProperty(prop);
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
/**
* Creates the appropriate Bindable for a BeanProperty.
* <p>
* Lob properties can be excluded and it creates BindablePropertyInsertGenerated
* and BindablePropertyUpdateGenerated as required.
* </p>
*/
public class FactoryProperty {
private final boolean bindEncryptDataFirst;
public FactoryProperty(boolean bindEncryptDataFirst) {
this.bindEncryptDataFirst = bindEncryptDataFirst;
}
/**
* Create a Bindable for the property given the mode and withLobs flag.
*/
public Bindable create(BeanProperty prop, DmlMode mode, boolean withLobs) {
if (DmlMode.INSERT.equals(mode) && !prop.isDbInsertable()){
return null;
}
if (DmlMode.UPDATE.equals(mode) && !prop.isDbUpdatable()){
return null;
}
if (prop.isLob()) {
if (DmlMode.WHERE.equals(mode) || !withLobs) {
// Lob exclusion
return null;
} else {
return prop.isDbEncrypted() ? new BindableEncryptedProperty(prop, bindEncryptDataFirst) : new BindableProperty(prop);
}
}
GeneratedProperty gen = prop.getGeneratedProperty();
if (gen != null) {
if (DmlMode.INSERT.equals(mode)) {
if (gen.includeInInsert()) {
return new BindablePropertyInsertGenerated(prop, gen);
} else {
return null;
}
}
if (DmlMode.UPDATE.equals(mode)) {
if (gen.includeInUpdate()) {
return new BindablePropertyUpdateGenerated(prop, gen);
} else {
// An 'Insert Timestamp' is never updated
return null;
}
}
}
return prop.isDbEncrypted() ? new BindableEncryptedProperty(prop, bindEncryptDataFirst) : new BindableProperty(prop);
}
}
@@ -1,79 +1,60 @@
/**
* 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.persist.dmlbind;
import java.util.ArrayList;
import java.util.List;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
/**
* Creates a Bindable to support version concurrency where clauses.
*/
public class FactoryVersion {
public FactoryVersion() {
}
/**
* Create a Bindable for the version property(s) for a bean type.
*/
public Bindable create(BeanDescriptor<?> desc) {
List<Bindable> verList = new ArrayList<Bindable>();
BeanProperty[] vers = desc.propertiesVersion();
for (int i = 0; i < vers.length; i++) {
verList.add(new BindableProperty(vers[i]));
}
// version columns on embedded beans?
BeanPropertyAssocOne<?>[] embedded = desc.propertiesEmbedded();
for (int j = 0; j < embedded.length; j++) {
if (embedded[j].isEmbeddedVersion()) {
List<Bindable> bindList = new ArrayList<Bindable>();
BeanProperty[] embProps = embedded[j].getProperties();
for (int i = 0; i < embProps.length; i++) {
if (embProps[i].isVersion()){
bindList.add(new BindableProperty(embProps[i]));
}
}
verList.add(new BindableEmbedded(embedded[j], bindList));
}
}
if (verList.size() == 0){
return null;
}
if (verList.size() == 1){
return verList.get(0);
}
return new BindableList(verList);
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.util.ArrayList;
import java.util.List;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
/**
* Creates a Bindable to support version concurrency where clauses.
*/
public class FactoryVersion {
public FactoryVersion() {
}
/**
* Create a Bindable for the version property(s) for a bean type.
*/
public Bindable create(BeanDescriptor<?> desc) {
List<Bindable> verList = new ArrayList<Bindable>();
BeanProperty[] vers = desc.propertiesVersion();
for (int i = 0; i < vers.length; i++) {
verList.add(new BindableProperty(vers[i]));
}
// version columns on embedded beans?
BeanPropertyAssocOne<?>[] embedded = desc.propertiesEmbedded();
for (int j = 0; j < embedded.length; j++) {
if (embedded[j].isEmbeddedVersion()) {
List<Bindable> bindList = new ArrayList<Bindable>();
BeanProperty[] embProps = embedded[j].getProperties();
for (int i = 0; i < embProps.length; i++) {
if (embProps[i].isVersion()){
bindList.add(new BindableProperty(embProps[i]));
}
}
verList.add(new BindableEmbedded(embedded[j], bindList));
}
}
if (verList.size() == 0){
return null;
}
if (verList.size() == 1){
return verList.get(0);
}
return new BindableList(verList);
}
}
@@ -1,104 +1,85 @@
/**
* 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.persist.dmlbind;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
/**
* Matches local embedded id properties to 'matching' properties from a
* ManyToOne associated bean that is a 'imported primary key'.
* <p>
* This object is designed to help BindableIdEmbedded and BindableIdMap to
* create a concatenated id from the id values from ManyToOne associated beans.
* This can be done when those ManyToOne associated beans make up the primary
* key. This typically means the BindableIdEmbedded is for a intersection table
* of a Many to Many relationship.
* </p>
*/
class MatchedImportedProperty {
private final BeanPropertyAssocOne<?> assocOne;
private final BeanProperty foreignProp;
private final BeanProperty localProp;
protected MatchedImportedProperty(BeanPropertyAssocOne<?> assocOne, BeanProperty foreignProp,
BeanProperty localProp) {
this.assocOne = assocOne;
this.foreignProp = foreignProp;
this.localProp = localProp;
}
protected void populate(Object sourceBean, Object destBean) {
Object assocBean = assocOne.getValue(sourceBean);
if (assocBean == null) {
String msg = "The assoc bean for " + assocOne + " is null?";
throw new NullPointerException(msg);
}
Object value = foreignProp.getValue(assocBean);
localProp.setValue(destBean, value);
}
/**
* Create the array of matchedImportedProperty based on the properties and descriptor.
*/
protected static MatchedImportedProperty[] build(BeanProperty[] props, BeanDescriptor<?> desc) {
MatchedImportedProperty[] matches = new MatchedImportedProperty[props.length];
for (int i = 0; i < props.length; i++) {
// find matching assoc one property for dbColumn
matches[i] = MatchedImportedProperty.findMatch(props[i], desc);
if (matches[i] == null) {
// ok, the assoc ones are not on the bean?
return null;
}
}
return matches;
}
private static MatchedImportedProperty findMatch(BeanProperty prop, BeanDescriptor<?> desc) {
// find matching against the local database column
String dbColumn = prop.getDbColumn();
BeanPropertyAssocOne<?>[] assocOnes = desc.propertiesOne();
for (int i = 0; i < assocOnes.length; i++) {
if (assocOnes[i].isImportedPrimaryKey()) {
// search using the ImportedId from the assoc one
BeanProperty foreignMatch = assocOnes[i].getImportedId().findMatchImport(dbColumn);
if (foreignMatch != null) {
return new MatchedImportedProperty(assocOnes[i], foreignMatch, prop);
}
}
}
// there was no matching assoc one property.
// example UserRole bean missing assoc one to User?
return null;
}
}
package com.avaje.ebeaninternal.server.persist.dmlbind;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
/**
* Matches local embedded id properties to 'matching' properties from a
* ManyToOne associated bean that is a 'imported primary key'.
* <p>
* This object is designed to help BindableIdEmbedded and BindableIdMap to
* create a concatenated id from the id values from ManyToOne associated beans.
* This can be done when those ManyToOne associated beans make up the primary
* key. This typically means the BindableIdEmbedded is for a intersection table
* of a Many to Many relationship.
* </p>
*/
class MatchedImportedProperty {
private final BeanPropertyAssocOne<?> assocOne;
private final BeanProperty foreignProp;
private final BeanProperty localProp;
protected MatchedImportedProperty(BeanPropertyAssocOne<?> assocOne, BeanProperty foreignProp,
BeanProperty localProp) {
this.assocOne = assocOne;
this.foreignProp = foreignProp;
this.localProp = localProp;
}
protected void populate(Object sourceBean, Object destBean) {
Object assocBean = assocOne.getValue(sourceBean);
if (assocBean == null) {
String msg = "The assoc bean for " + assocOne + " is null?";
throw new NullPointerException(msg);
}
Object value = foreignProp.getValue(assocBean);
localProp.setValue(destBean, value);
}
/**
* Create the array of matchedImportedProperty based on the properties and descriptor.
*/
protected static MatchedImportedProperty[] build(BeanProperty[] props, BeanDescriptor<?> desc) {
MatchedImportedProperty[] matches = new MatchedImportedProperty[props.length];
for (int i = 0; i < props.length; i++) {
// find matching assoc one property for dbColumn
matches[i] = MatchedImportedProperty.findMatch(props[i], desc);
if (matches[i] == null) {
// ok, the assoc ones are not on the bean?
return null;
}
}
return matches;
}
private static MatchedImportedProperty findMatch(BeanProperty prop, BeanDescriptor<?> desc) {
// find matching against the local database column
String dbColumn = prop.getDbColumn();
BeanPropertyAssocOne<?>[] assocOnes = desc.propertiesOne();
for (int i = 0; i < assocOnes.length; i++) {
if (assocOnes[i].isImportedPrimaryKey()) {
// search using the ImportedId from the assoc one
BeanProperty foreignMatch = assocOnes[i].getImportedId().findMatchImport(dbColumn);
if (foreignMatch != null) {
return new MatchedImportedProperty(assocOnes[i], foreignMatch, prop);
}
}
}
// there was no matching assoc one property.
// example UserRole bean missing assoc one to User?
return null;
}
}