This patch will take the insertable/updatable flag on JoinColumn into account.
With this patch it is possible to have associations in your entity which are not persisted.
Index: ../ebean/src/com/avaje/ebean/server/deploy/parse/JoinDefineManualInfo.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/deploy/parse/JoinDefineManualInfo.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/deploy/parse/JoinDefineManualInfo.java Sat Feb 14 16:25:31 CET 2009
@@ -152,7 +152,7 @@
String localColumn = nullEmptyString(joinColumn.name());
String refColumn = nullEmptyString(joinColumn.referencedColumnName());
- add(new DeployTableJoinColumn(localColumn, refColumn));
+ add(new DeployTableJoinColumn(localColumn, refColumn, joinColumn.insertable(), joinColumn.updatable()));
}
private String nullEmptyString(String s){
Index: ../ebean/src/com/avaje/ebean/server/deploy/BeanPropertyAssoc.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/deploy/BeanPropertyAssoc.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/deploy/BeanPropertyAssoc.java Sat Feb 14 16:35:14 CET 2009
@@ -217,6 +217,23 @@
return tableJoin;
}
+ public boolean isUpdateable() {
+ if (tableJoin.columns().length > 0) {
+ return tableJoin.columns()[0].isUpdatable();
+ }
+
+ return true;
+ }
+
+ public boolean isInsertable() {
+ if (tableJoin.columns().length > 0) {
+ return tableJoin.columns()[0].isInsertable();
+ }
+
+ return true;
+ }
+
+
/**
* Return the BeanTable for this association.
*
@@ -264,6 +281,11 @@
} else {
// embedded id
BeanPropertyAssocOne embProp = (BeanPropertyAssocOne)props[0];
+ if (embProp.getTargetDescriptor() == null)
+ {
+ // I'll consider this as a hack ...
+ embProp.initialise();
+ }
BeanProperty[] embBaseProps = embProp.getTargetDescriptor().propertiesBaseScalar();
ImportedIdSimple[] scalars = createImportedList(owner, cols, embBaseProps);
Index: ../ebean/src/com/avaje/ebean/server/persist/dmlbind/FactoryAssocOnes.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/persist/dmlbind/FactoryAssocOnes.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/persist/dmlbind/FactoryAssocOnes.java Sat Feb 14 16:37:08 CET 2009
@@ -23,6 +23,7 @@
import com.avaje.ebean.server.deploy.BeanDescriptor;
import com.avaje.ebean.server.deploy.BeanPropertyAssocOne;
+import com.avaje.ebean.server.persist.dml.Modes;
/**
* A factory that builds Bindable for BeanPropertyAssocOne properties.
@@ -35,7 +36,7 @@
/**
* Add foreign key columns from associated one beans.
*/
- public List create(List list, BeanDescriptor desc) {
+ public List create(List list, BeanDescriptor desc, int mode) {
BeanPropertyAssocOne[] ones = desc.propertiesOneImported();
@@ -47,8 +48,21 @@
// excluded as its the 'non-owning' side of OneToOne
} else {
+ switch(mode)
+ {
+ case Modes.MODE_INSERT:
+ if (!ones[i].isInsertable()) {
+ continue;
+ }
+ break;
+ case Modes.MODE_UPDATE:
+ if (!ones[i].isUpdateable()) {
+ continue;
+ }
+ break;
+ }
- Bindable item = new BindableAssocOne(ones[i]);
- list.add(item);
+ Bindable item = new BindableAssocOne(ones[i]);
+ list.add(item);
}
}
Index: ../ebean/src/com/avaje/ebean/server/deploy/TableJoinColumn.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/deploy/TableJoinColumn.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/deploy/TableJoinColumn.java Sat Feb 14 16:08:47 CET 2009
@@ -36,17 +36,24 @@
*/
private final String foreignDbColumn;
+ private final boolean updatable;
+
+ private final boolean insertable;
/**
* Create the pair.
*/
public TableJoinColumn(DeployTableJoinColumn deploy) {
this.localDbColumn = deploy.getLocalDbColumn();
this.foreignDbColumn = deploy.getForeignDbColumn();
+ this.updatable = deploy.isUpdatable();
+ this.insertable = deploy.isInsertable();
}
public TableJoinColumn(String localDbColumn, String foreignDbColumn) {
this.localDbColumn = localDbColumn;
this.foreignDbColumn = foreignDbColumn;
+ this.updatable = true;
+ this.insertable = true;
}
// /**
@@ -75,4 +82,11 @@
return localDbColumn;
}
+ public boolean isUpdatable() {
+ return updatable;
-}
+ }
+
+ public boolean isInsertable() {
+ return insertable;
+ }
+}
Index: ../ebean/src/com/avaje/ebean/server/persist/dml/MetaFactory.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/persist/dml/MetaFactory.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/persist/dml/MetaFactory.java Sat Feb 14 16:18:28 CET 2009
@@ -71,7 +71,7 @@
baseFact.create(setList, desc, MODE_UPDATE, includeLobs);
embeddedFact.create(setList, desc, MODE_UPDATE, includeLobs);
- assocOneFact.create(setList, desc);
+ assocOneFact.create(setList, desc, MODE_UPDATE);
Bindable id = idFact.createId(desc);
@@ -82,7 +82,7 @@
baseFact.create(allList, desc, MODE_WHERE, false);
embeddedFact.create(allList, desc, MODE_WHERE, false);
- assocOneFact.create(allList, desc);
+ assocOneFact.create(allList, desc, MODE_WHERE);
Bindable setBindable = new BindableList(setList);
@@ -104,7 +104,7 @@
baseFact.create(allList, desc, MODE_WHERE, false);
embeddedFact.create(allList, desc, MODE_WHERE, false);
- assocOneFact.create(allList, desc);
+ assocOneFact.create(allList, desc, MODE_WHERE);
Bindable allBindable = new BindableList(allList);
@@ -122,7 +122,7 @@
baseFact.create(allList, desc, MODE_INSERT, includeLobs);
embeddedFact.create(allList, desc, MODE_INSERT, includeLobs);
- assocOneFact.create(allList, desc);
+ assocOneFact.create(allList, desc, MODE_INSERT);
Bindable allBindable = new BindableList(allList);
Index: ../ebean/src/com/avaje/ebean/server/deploy/meta/DeployTableJoinColumn.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/deploy/meta/DeployTableJoinColumn.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/deploy/meta/DeployTableJoinColumn.java Sat Feb 14 16:08:47 CET 2009
@@ -34,6 +34,9 @@
*/
String foreignDbColumn;
+ boolean insertable;
+ boolean updatable;
+
// /**
// * Create the pair.
// */
@@ -41,16 +44,19 @@
//
// }
- public DeployTableJoinColumn(String localDbColumn, String foreignDbColumn) {
+ public DeployTableJoinColumn(String localDbColumn, String foreignDbColumn, boolean insertable, boolean updatable) {
this.localDbColumn = localDbColumn;
this.foreignDbColumn = foreignDbColumn;
+ this.insertable = insertable;
+ this.updatable = updatable;
}
/**
* Create a TableJoinColumn with the local and foreign columns swapped.
*/
public DeployTableJoinColumn createInverse() {
- return new DeployTableJoinColumn(foreignDbColumn, localDbColumn);
+ // TODO: do we really know that the inverse join is has the same insertable/updatable state?
+ return new DeployTableJoinColumn(foreignDbColumn, localDbColumn, insertable, updatable);
}
public String toString() {
@@ -120,4 +126,11 @@
this.localDbColumn = localDbColumn;
}
+ public boolean isInsertable() {
+ return insertable;
-}
+ }
+
+ public boolean isUpdatable() {
+ return updatable;
+ }
+}
Index: ../ebean/src/com/avaje/ebean/server/deploy/meta/DeployTableJoin.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/deploy/meta/DeployTableJoin.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/deploy/meta/DeployTableJoin.java Sat Feb 14 16:07:37 CET 2009
@@ -131,9 +131,9 @@
DeployTableJoinColumn joinColumn;
if (exported) {
// its around the other way...
- joinColumn = new DeployTableJoinColumn(col.getPkColumnName(), col.getFkColumnName());
+ joinColumn = new DeployTableJoinColumn(col.getPkColumnName(), col.getFkColumnName(), true, true);
} else {
- joinColumn = new DeployTableJoinColumn(col.getFkColumnName(), col.getPkColumnName());
+ joinColumn = new DeployTableJoinColumn(col.getFkColumnName(), col.getPkColumnName(), true, true);
}
addTableJoinColumn(joinColumn);
Index: ../ebean/src/com/avaje/ebean/server/deploy/BeanPropertyAssocMany.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/deploy/BeanPropertyAssocMany.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/deploy/BeanPropertyAssocMany.java Sat Feb 14 10:37:23 CET 2009
@@ -310,6 +310,11 @@
if (uids.length == 1 && uids[0].isEmbedded()) {
BeanPropertyAssocOne one = (BeanPropertyAssocOne) uids[0];
+ if (one.getTargetDescriptor() == null)
+ {
+ // I'll consider this as a hack ...
+ one.initialise();
+ }
BeanDescriptor targetDesc = one.getTargetDescriptor();
BeanProperty[] emIds = targetDesc.propertiesBaseScalar();
for (int i = 0; i < emIds.length; i++) {