mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
No effective change - format only
This commit is contained in:
@@ -78,7 +78,7 @@ public final class IdBinderEmbedded implements IdBinder {
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BeanProperty getBeanProperty() {
|
||||
return embIdProperty;
|
||||
|
||||
@@ -99,7 +99,7 @@ public final class IdBinderEmpty implements IdBinder {
|
||||
}
|
||||
|
||||
public Object[] getBindValues(Object idValue) {
|
||||
return new Object[] { idValue };
|
||||
return new Object[]{idValue};
|
||||
}
|
||||
|
||||
public void bindId(DefaultSqlUpdate sqlUpdate, Object value) {
|
||||
@@ -133,6 +133,6 @@ public final class IdBinderEmpty implements IdBinder {
|
||||
}
|
||||
|
||||
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,29 +8,29 @@ import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
*/
|
||||
public class IdBinderFactory {
|
||||
|
||||
private static final IdBinderEmpty EMPTY = new IdBinderEmpty();
|
||||
|
||||
private final boolean idInExpandedForm;
|
||||
|
||||
public IdBinderFactory(boolean idInExpandedForm) {
|
||||
this.idInExpandedForm = idInExpandedForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the IdConvertSet for the given type of Id properties.
|
||||
*/
|
||||
public IdBinder createIdBinder(BeanProperty id) {
|
||||
|
||||
if (id == null){
|
||||
// for report type beans that don't need an id
|
||||
return EMPTY;
|
||||
|
||||
}
|
||||
if (id.isEmbedded()){
|
||||
return new IdBinderEmbedded(idInExpandedForm, (BeanPropertyAssocOne<?>)id);
|
||||
} else {
|
||||
return new IdBinderSimple(id);
|
||||
}
|
||||
}
|
||||
|
||||
private static final IdBinderEmpty EMPTY = new IdBinderEmpty();
|
||||
|
||||
private final boolean idInExpandedForm;
|
||||
|
||||
public IdBinderFactory(boolean idInExpandedForm) {
|
||||
this.idInExpandedForm = idInExpandedForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the IdConvertSet for the given type of Id properties.
|
||||
*/
|
||||
public IdBinder createIdBinder(BeanProperty id) {
|
||||
|
||||
if (id == null) {
|
||||
// for report type beans that don't need an id
|
||||
return EMPTY;
|
||||
|
||||
}
|
||||
if (id.isEmbedded()) {
|
||||
return new IdBinderEmbedded(idInExpandedForm, (BeanPropertyAssocOne<?>) id);
|
||||
} else {
|
||||
return new IdBinderSimple(id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,25 +21,25 @@ import java.util.List;
|
||||
*/
|
||||
public final class IdBinderSimple implements IdBinder {
|
||||
|
||||
private final BeanProperty idProperty;
|
||||
private final BeanProperty idProperty;
|
||||
|
||||
private final String bindIdSql;
|
||||
|
||||
private final Class<?> expectedType;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final ScalarType scalarType;
|
||||
|
||||
public IdBinderSimple(BeanProperty idProperty) {
|
||||
this.idProperty = idProperty;
|
||||
this.scalarType = idProperty.getScalarType();
|
||||
this.expectedType = idProperty.getPropertyType();
|
||||
bindIdSql = InternString.intern(idProperty.getDbColumn()+" = ? ");
|
||||
}
|
||||
|
||||
public void initialise(){
|
||||
// do nothing
|
||||
}
|
||||
private final String bindIdSql;
|
||||
|
||||
private final Class<?> expectedType;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final ScalarType scalarType;
|
||||
|
||||
public IdBinderSimple(BeanProperty idProperty) {
|
||||
this.idProperty = idProperty;
|
||||
this.scalarType = idProperty.getScalarType();
|
||||
this.expectedType = idProperty.getPropertyType();
|
||||
bindIdSql = InternString.intern(idProperty.getDbColumn() + " = ? ");
|
||||
}
|
||||
|
||||
public void initialise() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public boolean isIdInExpandedForm() {
|
||||
return false;
|
||||
@@ -57,9 +57,9 @@ public final class IdBinderSimple implements IdBinder {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public void buildRawSqlSelectChain(String prefix, List<String> selectChain) {
|
||||
|
||||
|
||||
idProperty.buildRawSqlSelectChain(prefix, selectChain);
|
||||
}
|
||||
|
||||
@@ -69,30 +69,30 @@ public final class IdBinderSimple implements IdBinder {
|
||||
public int getPropertyCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public BeanProperty getBeanProperty() {
|
||||
return idProperty;
|
||||
}
|
||||
|
||||
public String getIdProperty() {
|
||||
return idProperty.getName();
|
||||
}
|
||||
return idProperty.getName();
|
||||
}
|
||||
|
||||
public BeanProperty findBeanProperty(String dbColumnName) {
|
||||
if (dbColumnName.equalsIgnoreCase(idProperty.getDbColumn())){
|
||||
return idProperty;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public BeanProperty findBeanProperty(String dbColumnName) {
|
||||
if (dbColumnName.equalsIgnoreCase(idProperty.getDbColumn())) {
|
||||
return idProperty;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isComplexId(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDefaultOrderBy() {
|
||||
return idProperty.getName();
|
||||
}
|
||||
public boolean isComplexId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDefaultOrderBy() {
|
||||
return idProperty.getName();
|
||||
}
|
||||
|
||||
public String getBindIdInSql(String baseTableAlias) {
|
||||
if (baseTableAlias == null) {
|
||||
@@ -111,11 +111,11 @@ public final class IdBinderSimple implements IdBinder {
|
||||
}
|
||||
|
||||
public Object[] getIdValues(EntityBean bean) {
|
||||
return new Object[] { idProperty.getValue(bean) };
|
||||
return new Object[]{idProperty.getValue(bean)};
|
||||
}
|
||||
|
||||
public Object[] getBindValues(Object idValue) {
|
||||
return new Object[] { idValue };
|
||||
return new Object[]{idValue};
|
||||
}
|
||||
|
||||
public String getIdInValueExprDelete(int size) {
|
||||
|
||||
@@ -14,55 +14,55 @@ import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
|
||||
*/
|
||||
public interface ImportedId {
|
||||
|
||||
void addFkeys(String name);
|
||||
|
||||
/**
|
||||
* Return true if this id is a simple single scalar value. False if it is a
|
||||
* compound id (embedded or multiple).
|
||||
*/
|
||||
boolean isScalar();
|
||||
void addFkeys(String name);
|
||||
|
||||
/**
|
||||
* Return the logical property name.
|
||||
*/
|
||||
String getLogicalName();
|
||||
/**
|
||||
* Return true if this id is a simple single scalar value. False if it is a
|
||||
* compound id (embedded or multiple).
|
||||
*/
|
||||
boolean isScalar();
|
||||
|
||||
/**
|
||||
* For scalar id return the related single db column.
|
||||
* <p>
|
||||
* This is essentially the imported foreign key column (where there is only
|
||||
* one).
|
||||
* </p>
|
||||
*/
|
||||
String getDbColumn();
|
||||
/**
|
||||
* Return the logical property name.
|
||||
*/
|
||||
String getLogicalName();
|
||||
|
||||
/**
|
||||
* Append the the SQL query statement.
|
||||
*/
|
||||
void sqlAppend(DbSqlContext ctx);
|
||||
/**
|
||||
* For scalar id return the related single db column.
|
||||
* <p>
|
||||
* This is essentially the imported foreign key column (where there is only
|
||||
* one).
|
||||
* </p>
|
||||
*/
|
||||
String getDbColumn();
|
||||
|
||||
/**
|
||||
* Append to the DML statement.
|
||||
*/
|
||||
void dmlAppend(GenerateDmlRequest request);
|
||||
/**
|
||||
* Append the the SQL query statement.
|
||||
*/
|
||||
void sqlAppend(DbSqlContext ctx);
|
||||
|
||||
/**
|
||||
* Append to the DML statement to the where clause.
|
||||
*/
|
||||
void dmlWhere(GenerateDmlRequest request, EntityBean bean);
|
||||
|
||||
/**
|
||||
* Bind the value from the bean.
|
||||
*/
|
||||
Object bind(BindableRequest request, EntityBean bean) throws SQLException;
|
||||
/**
|
||||
* Append to the DML statement.
|
||||
*/
|
||||
void dmlAppend(GenerateDmlRequest request);
|
||||
|
||||
/**
|
||||
* For inserting into ManyToMany intersection.
|
||||
*/
|
||||
void buildImport(IntersectionRow row, EntityBean other);
|
||||
/**
|
||||
* Append to the DML statement to the where clause.
|
||||
*/
|
||||
void dmlWhere(GenerateDmlRequest request, EntityBean bean);
|
||||
|
||||
/**
|
||||
* Used to derive a missing concatenated key from multiple imported keys.
|
||||
*/
|
||||
BeanProperty findMatchImport(String matchDbColumn);
|
||||
/**
|
||||
* Bind the value from the bean.
|
||||
*/
|
||||
Object bind(BindableRequest request, EntityBean bean) throws SQLException;
|
||||
|
||||
/**
|
||||
* For inserting into ManyToMany intersection.
|
||||
*/
|
||||
void buildImport(IntersectionRow row, EntityBean other);
|
||||
|
||||
/**
|
||||
* Used to derive a missing concatenated key from multiple imported keys.
|
||||
*/
|
||||
BeanProperty findMatchImport(String matchDbColumn);
|
||||
}
|
||||
@@ -18,141 +18,141 @@ import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
|
||||
* Imported Embedded id.
|
||||
*/
|
||||
public class ImportedIdEmbedded implements ImportedId {
|
||||
|
||||
private final BeanPropertyAssoc<?> owner;
|
||||
|
||||
private final BeanPropertyAssocOne<?> foreignAssocOne;
|
||||
private final BeanPropertyAssoc<?> owner;
|
||||
|
||||
private final ImportedIdSimple[] imported;
|
||||
|
||||
public ImportedIdEmbedded(BeanPropertyAssoc<?> owner, BeanPropertyAssocOne<?> foreignAssocOne, ImportedIdSimple[] imported) {
|
||||
this.owner = owner;
|
||||
this.foreignAssocOne = foreignAssocOne;
|
||||
this.imported = imported;
|
||||
}
|
||||
|
||||
public void addFkeys(String name) {
|
||||
|
||||
BeanProperty[] embeddedProps = foreignAssocOne.getProperties();
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
String n = name+"."+foreignAssocOne.getName()+"."+embeddedProps[i].getName();
|
||||
BeanFkeyProperty fkey = new BeanFkeyProperty(n, imported[i].localDbColumn, foreignAssocOne.getDeployOrder());
|
||||
owner.getBeanDescriptor().add(fkey);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isScalar(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getLogicalName() {
|
||||
return owner.getName()+"."+foreignAssocOne.getName();
|
||||
}
|
||||
private final BeanPropertyAssocOne<?> foreignAssocOne;
|
||||
|
||||
|
||||
public String getDbColumn(){
|
||||
return null;
|
||||
}
|
||||
private final ImportedIdSimple[] imported;
|
||||
|
||||
public void sqlAppend(DbSqlContext ctx) {
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
ctx.appendColumn(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
request.appendColumn(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
public ImportedIdEmbedded(BeanPropertyAssoc<?> owner, BeanPropertyAssocOne<?> foreignAssocOne, ImportedIdSimple[] imported) {
|
||||
this.owner = owner;
|
||||
this.foreignAssocOne = foreignAssocOne;
|
||||
this.imported = imported;
|
||||
}
|
||||
|
||||
public void dmlWhere(GenerateDmlRequest request, EntityBean bean){
|
||||
public void addFkeys(String name) {
|
||||
|
||||
Object embeddedId = null;
|
||||
if (bean != null) {
|
||||
embeddedId = foreignAssocOne.getValue(bean);
|
||||
}
|
||||
|
||||
if (embeddedId == null){
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isDbUpdatable()) {
|
||||
request.appendColumnIsNull(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
EntityBean embedded = (EntityBean)embeddedId;
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isDbUpdatable()) {
|
||||
Object value = imported[i].foreignProperty.getValue(embedded);
|
||||
if (value == null){
|
||||
request.appendColumnIsNull(imported[i].localDbColumn);
|
||||
} else {
|
||||
request.appendColumn(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object bind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
BeanProperty[] embeddedProps = foreignAssocOne.getProperties();
|
||||
|
||||
Object embeddedId = null;
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
String n = name + "." + foreignAssocOne.getName() + "." + embeddedProps[i].getName();
|
||||
BeanFkeyProperty fkey = new BeanFkeyProperty(n, imported[i].localDbColumn, foreignAssocOne.getDeployOrder());
|
||||
owner.getBeanDescriptor().add(fkey);
|
||||
}
|
||||
}
|
||||
|
||||
if (bean != null) {
|
||||
embeddedId = foreignAssocOne.getValue(bean);
|
||||
public boolean isScalar() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getLogicalName() {
|
||||
return owner.getName() + "." + foreignAssocOne.getName();
|
||||
}
|
||||
|
||||
|
||||
public String getDbColumn() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void sqlAppend(DbSqlContext ctx) {
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
ctx.appendColumn(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
request.appendColumn(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlWhere(GenerateDmlRequest request, EntityBean bean) {
|
||||
|
||||
Object embeddedId = null;
|
||||
if (bean != null) {
|
||||
embeddedId = foreignAssocOne.getValue(bean);
|
||||
}
|
||||
|
||||
if (embeddedId == null) {
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isDbUpdatable()) {
|
||||
request.appendColumnIsNull(imported[i].localDbColumn);
|
||||
}
|
||||
|
||||
if (embeddedId == null){
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isUpdateable()) {
|
||||
request.bind(null, imported[i].foreignProperty);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
EntityBean embedded = (EntityBean)embeddedId;
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isUpdateable()) {
|
||||
Object scalarValue = imported[i].foreignProperty.getValue(embedded);
|
||||
request.bind(scalarValue, imported[i].foreignProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
// hmmm, not worrying about this just yet
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
EntityBean embedded = (EntityBean) embeddedId;
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isDbUpdatable()) {
|
||||
Object value = imported[i].foreignProperty.getValue(embedded);
|
||||
if (value == null) {
|
||||
request.appendColumnIsNull(imported[i].localDbColumn);
|
||||
} else {
|
||||
request.appendColumn(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void buildImport(IntersectionRow row, EntityBean other){
|
||||
|
||||
EntityBean embeddedId = (EntityBean)foreignAssocOne.getValue(other);
|
||||
if (embeddedId == null){
|
||||
String msg = "Foreign Key value null?";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
Object scalarValue = imported[i].foreignProperty.getValue(embeddedId);
|
||||
row.put(imported[i].localDbColumn, scalarValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported for embedded id.
|
||||
*/
|
||||
public BeanProperty findMatchImport(String matchDbColumn) {
|
||||
|
||||
BeanProperty p = null;
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
p = imported[i].findMatchImport(matchDbColumn);
|
||||
if (p != null){
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
public Object bind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
Object embeddedId = null;
|
||||
|
||||
if (bean != null) {
|
||||
embeddedId = foreignAssocOne.getValue(bean);
|
||||
}
|
||||
|
||||
if (embeddedId == null) {
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isUpdateable()) {
|
||||
request.bind(null, imported[i].foreignProperty);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
EntityBean embedded = (EntityBean) embeddedId;
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isUpdateable()) {
|
||||
Object scalarValue = imported[i].foreignProperty.getValue(embedded);
|
||||
request.bind(scalarValue, imported[i].foreignProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
// hmmm, not worrying about this just yet
|
||||
return null;
|
||||
}
|
||||
|
||||
public void buildImport(IntersectionRow row, EntityBean other) {
|
||||
|
||||
EntityBean embeddedId = (EntityBean) foreignAssocOne.getValue(other);
|
||||
if (embeddedId == null) {
|
||||
String msg = "Foreign Key value null?";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
Object scalarValue = imported[i].foreignProperty.getValue(embeddedId);
|
||||
row.put(imported[i].localDbColumn, scalarValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported for embedded id.
|
||||
*/
|
||||
public BeanProperty findMatchImport(String matchDbColumn) {
|
||||
|
||||
BeanProperty p = null;
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
p = imported[i].findMatchImport(matchDbColumn);
|
||||
if (p != null) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,97 +14,97 @@ import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
|
||||
* Imported concatenated id that is not embedded.
|
||||
*/
|
||||
public class ImportedIdMultiple implements ImportedId {
|
||||
|
||||
final BeanPropertyAssoc<?> owner;
|
||||
|
||||
final ImportedIdSimple[] imported;
|
||||
|
||||
public ImportedIdMultiple(BeanPropertyAssoc<?> owner, ImportedIdSimple[] imported) {
|
||||
this.owner = owner;
|
||||
this.imported = imported;
|
||||
}
|
||||
final BeanPropertyAssoc<?> owner;
|
||||
|
||||
public void addFkeys(String name) {
|
||||
final ImportedIdSimple[] imported;
|
||||
|
||||
// not supporting addFkeys for ImportedIdMultiple
|
||||
}
|
||||
|
||||
public String getLogicalName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isScalar(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDbColumn(){
|
||||
return null;
|
||||
}
|
||||
public ImportedIdMultiple(BeanPropertyAssoc<?> owner, ImportedIdSimple[] imported) {
|
||||
this.owner = owner;
|
||||
this.imported = imported;
|
||||
}
|
||||
|
||||
public void addFkeys(String name) {
|
||||
|
||||
// not supporting addFkeys for ImportedIdMultiple
|
||||
}
|
||||
|
||||
public String getLogicalName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isScalar() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDbColumn() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void sqlAppend(DbSqlContext ctx) {
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
ctx.appendColumn(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
request.appendColumn(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
public void sqlAppend(DbSqlContext ctx) {
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
ctx.appendColumn(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlWhere(GenerateDmlRequest request, EntityBean bean){
|
||||
if (bean == null){
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
request.appendColumnIsNull(imported[i].localDbColumn);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
Object value = imported[i].foreignProperty.getValue(bean);
|
||||
if (value == null){
|
||||
request.appendColumnIsNull(imported[i].localDbColumn);
|
||||
} else {
|
||||
request.appendColumn(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object bind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isUpdateable()) {
|
||||
Object scalarValue = imported[i].foreignProperty.getValue(bean);
|
||||
request.bind(scalarValue, imported[i].foreignProperty);
|
||||
}
|
||||
}
|
||||
// hmmm, not worrying about this just yet
|
||||
return null;
|
||||
}
|
||||
|
||||
public void buildImport(IntersectionRow row, EntityBean other){
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
Object scalarValue = imported[i].foreignProperty.getValue(other);
|
||||
row.put(imported[i].localDbColumn, scalarValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported for concatenated id.
|
||||
*/
|
||||
public BeanProperty findMatchImport(String matchDbColumn) {
|
||||
|
||||
BeanProperty p = null;
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
p = imported[i].findMatchImport(matchDbColumn);
|
||||
if (p != null){
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
request.appendColumn(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlWhere(GenerateDmlRequest request, EntityBean bean) {
|
||||
if (bean == null) {
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
request.appendColumnIsNull(imported[i].localDbColumn);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
Object value = imported[i].foreignProperty.getValue(bean);
|
||||
if (value == null) {
|
||||
request.appendColumnIsNull(imported[i].localDbColumn);
|
||||
} else {
|
||||
request.appendColumn(imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object bind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isUpdateable()) {
|
||||
Object scalarValue = imported[i].foreignProperty.getValue(bean);
|
||||
request.bind(scalarValue, imported[i].foreignProperty);
|
||||
}
|
||||
}
|
||||
// hmmm, not worrying about this just yet
|
||||
return null;
|
||||
}
|
||||
|
||||
public void buildImport(IntersectionRow row, EntityBean other) {
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
Object scalarValue = imported[i].foreignProperty.getValue(other);
|
||||
row.put(imported[i].localDbColumn, scalarValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported for concatenated id.
|
||||
*/
|
||||
public BeanProperty findMatchImport(String matchDbColumn) {
|
||||
|
||||
BeanProperty p = null;
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
p = imported[i].findMatchImport(matchDbColumn);
|
||||
if (p != null) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,128 +22,128 @@ import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
|
||||
*/
|
||||
public final class ImportedIdSimple implements ImportedId, Comparable<ImportedIdSimple> {
|
||||
|
||||
/**
|
||||
* Helper class to sort ImportedIdSimple.
|
||||
*/
|
||||
private final static class EntryComparator implements Comparator<ImportedIdSimple> {
|
||||
public int compare(ImportedIdSimple o1, ImportedIdSimple o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
/**
|
||||
* Helper class to sort ImportedIdSimple.
|
||||
*/
|
||||
private final static class EntryComparator implements Comparator<ImportedIdSimple> {
|
||||
public int compare(ImportedIdSimple o1, ImportedIdSimple o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
|
||||
private static final EntryComparator COMPARATOR = new EntryComparator();
|
||||
|
||||
protected final BeanPropertyAssoc<?> owner;
|
||||
}
|
||||
|
||||
protected final String localDbColumn;
|
||||
private static final EntryComparator COMPARATOR = new EntryComparator();
|
||||
|
||||
protected final String logicalName;
|
||||
protected final BeanPropertyAssoc<?> owner;
|
||||
|
||||
protected final BeanProperty foreignProperty;
|
||||
|
||||
protected final int position;
|
||||
protected final String localDbColumn;
|
||||
|
||||
public ImportedIdSimple(BeanPropertyAssoc<?> owner, String localDbColumn, BeanProperty foreignProperty, int position) {
|
||||
this.owner = owner;
|
||||
this.localDbColumn = InternString.intern(localDbColumn);
|
||||
this.foreignProperty = foreignProperty;
|
||||
this.position = position;
|
||||
this.logicalName = InternString.intern(owner.getName()+"."+foreignProperty.getName());
|
||||
}
|
||||
protected final String logicalName;
|
||||
|
||||
/**
|
||||
* Return the list as an array sorted into the same order as the Bean Properties.
|
||||
*/
|
||||
public static ImportedIdSimple[] sort(List<ImportedIdSimple> list) {
|
||||
|
||||
ImportedIdSimple[] importedIds = list.toArray(new ImportedIdSimple[list.size()]);
|
||||
|
||||
// sort into the same order as the BeanProperties
|
||||
Arrays.sort(importedIds, COMPARATOR);
|
||||
return importedIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
// remove FindBugs warning
|
||||
return obj == this;
|
||||
}
|
||||
protected final BeanProperty foreignProperty;
|
||||
|
||||
public int compareTo(ImportedIdSimple other) {
|
||||
return (position < other.position ? -1 : (position == other.position ? 0 : 1));
|
||||
}
|
||||
protected final int position;
|
||||
|
||||
public void addFkeys(String name) {
|
||||
BeanFkeyProperty fkey = new BeanFkeyProperty(name+"."+foreignProperty.getName(), localDbColumn, owner.getDeployOrder());
|
||||
owner.getBeanDescriptor().add(fkey);
|
||||
}
|
||||
public ImportedIdSimple(BeanPropertyAssoc<?> owner, String localDbColumn, BeanProperty foreignProperty, int position) {
|
||||
this.owner = owner;
|
||||
this.localDbColumn = InternString.intern(localDbColumn);
|
||||
this.foreignProperty = foreignProperty;
|
||||
this.position = position;
|
||||
this.logicalName = InternString.intern(owner.getName() + "." + foreignProperty.getName());
|
||||
}
|
||||
|
||||
public boolean isScalar(){
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Return the list as an array sorted into the same order as the Bean Properties.
|
||||
*/
|
||||
public static ImportedIdSimple[] sort(List<ImportedIdSimple> list) {
|
||||
|
||||
public String getLogicalName() {
|
||||
return logicalName;
|
||||
}
|
||||
ImportedIdSimple[] importedIds = list.toArray(new ImportedIdSimple[list.size()]);
|
||||
|
||||
// sort into the same order as the BeanProperties
|
||||
Arrays.sort(importedIds, COMPARATOR);
|
||||
return importedIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
// remove FindBugs warning
|
||||
return obj == this;
|
||||
}
|
||||
|
||||
public int compareTo(ImportedIdSimple other) {
|
||||
return (position < other.position ? -1 : (position == other.position ? 0 : 1));
|
||||
}
|
||||
|
||||
public void addFkeys(String name) {
|
||||
BeanFkeyProperty fkey = new BeanFkeyProperty(name + "." + foreignProperty.getName(), localDbColumn, owner.getDeployOrder());
|
||||
owner.getBeanDescriptor().add(fkey);
|
||||
}
|
||||
|
||||
public boolean isScalar() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getLogicalName() {
|
||||
return logicalName;
|
||||
}
|
||||
|
||||
public String getDbColumn() {
|
||||
return localDbColumn;
|
||||
}
|
||||
|
||||
public String getDbColumn(){
|
||||
return localDbColumn;
|
||||
}
|
||||
|
||||
private Object getIdValue(EntityBean bean) {
|
||||
return foreignProperty.getValue(bean);
|
||||
}
|
||||
|
||||
public void buildImport(IntersectionRow row, EntityBean other){
|
||||
public void buildImport(IntersectionRow row, EntityBean other) {
|
||||
|
||||
Object value = getIdValue(other);
|
||||
if (value == null){
|
||||
String msg = "Foreign Key value null?";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
Object value = getIdValue(other);
|
||||
if (value == null) {
|
||||
String msg = "Foreign Key value null?";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
|
||||
row.put(localDbColumn, value);
|
||||
}
|
||||
row.put(localDbColumn, value);
|
||||
}
|
||||
|
||||
public void sqlAppend(DbSqlContext ctx) {
|
||||
ctx.appendColumn(localDbColumn);
|
||||
}
|
||||
public void sqlAppend(DbSqlContext ctx) {
|
||||
ctx.appendColumn(localDbColumn);
|
||||
}
|
||||
|
||||
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
request.appendColumn(localDbColumn);
|
||||
}
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
request.appendColumn(localDbColumn);
|
||||
}
|
||||
|
||||
public void dmlWhere(GenerateDmlRequest request, EntityBean bean){
|
||||
public void dmlWhere(GenerateDmlRequest request, EntityBean bean) {
|
||||
|
||||
if (owner.isDbUpdatable()){
|
||||
Object value = null;
|
||||
if (bean != null){
|
||||
value = getIdValue(bean);
|
||||
}
|
||||
if (value == null){
|
||||
request.appendColumnIsNull(localDbColumn);
|
||||
} else {
|
||||
request.appendColumn(localDbColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (owner.isDbUpdatable()) {
|
||||
Object value = null;
|
||||
if (bean != null) {
|
||||
value = getIdValue(bean);
|
||||
}
|
||||
if (value == null) {
|
||||
request.appendColumnIsNull(localDbColumn);
|
||||
} else {
|
||||
request.appendColumn(localDbColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object bind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
public Object bind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
Object value = null;
|
||||
if (bean != null){
|
||||
value = getIdValue(bean);
|
||||
}
|
||||
request.bind(value, foreignProperty);
|
||||
return value;
|
||||
}
|
||||
Object value = null;
|
||||
if (bean != null) {
|
||||
value = getIdValue(bean);
|
||||
}
|
||||
request.bind(value, foreignProperty);
|
||||
return value;
|
||||
}
|
||||
|
||||
public BeanProperty findMatchImport(String matchDbColumn) {
|
||||
public BeanProperty findMatchImport(String matchDbColumn) {
|
||||
|
||||
if (matchDbColumn.equals(localDbColumn)) {
|
||||
return foreignProperty;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (matchDbColumn.equals(localDbColumn)) {
|
||||
return foreignProperty;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user