OPENJPA-870: orphanRemoval support

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@738933 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Fay Wang 2009-01-29 17:35:45 +00:00
parent 963e541fd2
commit f65c4aebcd
3 changed files with 25 additions and 8 deletions

View File

@ -139,12 +139,19 @@ public class HandlerRelationMapTableFieldStrategy
if (val.getTypeCode() != JavaTypes.PC || val.isEmbeddedPC())
throw new MetaDataException(_loc.get("not-relation", val));
FieldMapping mapped = field.getMappedByMapping();
if (mapped != null) // map to the owner table
String keyName = null;
_kio = new ColumnIO();
if (mapped != null) { // map to the owner table
keyName = field.getName() + "_KEY";
_kcols = HandlerStrategies.map(key, keyName, _kio, adapt);
handleMappedBy(adapt);
else {
} else {
// map to a separate table
field.mapJoin(adapt, true);
DBDictionary dict = field.getMappingRepository().getDBDictionary();
keyName = dict.getValidColumnName("key", field.getTable());
_kcols = HandlerStrategies.map(key, keyName, _kio, adapt);
if (val.getTypeMapping().isMapped()) {
ValueMappingInfo vinfo = val.getValueInfo();
ForeignKey fk = vinfo.getTypeJoin(val, "value", false, adapt);
@ -155,10 +162,6 @@ public class HandlerRelationMapTableFieldStrategy
val.mapConstraints("value", adapt);
}
_kio = new ColumnIO();
DBDictionary dict = field.getMappingRepository().getDBDictionary();
_kcols = HandlerStrategies.map(key,
dict.getValidColumnName("key", field.getTable()), _kio, adapt);
field.mapPrimaryKey(adapt);
}
@ -347,4 +350,11 @@ public class HandlerRelationMapTableFieldStrategy
return HandlerStrategies.toDataStoreValue(field.getKeyMapping(), val,
_kcols, store);
}
public void delete(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
throws SQLException {
if (field.getMappedBy() != null)
return;
super.delete(sm, store, rm);
}
}

View File

@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.Map;
import org.apache.openjpa.enhance.PersistenceCapable;
import org.apache.openjpa.enhance.ReflectingPersistenceCapable;
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
import org.apache.openjpa.jdbc.kernel.JDBCStore;
import org.apache.openjpa.jdbc.meta.ClassMapping;
@ -265,7 +266,10 @@ public abstract class MapTableFieldStrategy
Collection<Map.Entry> entrySets = mapObj.entrySet();
boolean found = false;
for (Map.Entry entry : entrySets) {
if (entry.getValue() == obj) {
Object value = entry.getValue();
if (obj instanceof ReflectingPersistenceCapable)
obj = ((ReflectingPersistenceCapable)obj).getManagedInstance();
if (value == obj) {
Row newRow = (Row) ((RowImpl)row).clone();
Object keyObj = entry.getKey();
Strategy strat = fm.getStrategy();

View File

@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Set;
import org.apache.openjpa.enhance.PersistenceCapable;
import org.apache.openjpa.enhance.ReflectingPersistenceCapable;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfigurationImpl;
@ -276,6 +277,8 @@ public class RelationFieldStrategy
}
private Object getMapKeyObj(Map mapObj, Object value) {
if (value instanceof ReflectingPersistenceCapable)
value = ((ReflectingPersistenceCapable)value).getManagedInstance();
Set keySet = mapObj.keySet();
for (Object key : keySet) {
if (mapObj.get(key) == value)