mirror of https://github.com/apache/openjpa.git
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:
parent
963e541fd2
commit
f65c4aebcd
|
@ -139,12 +139,19 @@ public class HandlerRelationMapTableFieldStrategy
|
||||||
if (val.getTypeCode() != JavaTypes.PC || val.isEmbeddedPC())
|
if (val.getTypeCode() != JavaTypes.PC || val.isEmbeddedPC())
|
||||||
throw new MetaDataException(_loc.get("not-relation", val));
|
throw new MetaDataException(_loc.get("not-relation", val));
|
||||||
FieldMapping mapped = field.getMappedByMapping();
|
FieldMapping mapped = field.getMappedByMapping();
|
||||||
|
String keyName = null;
|
||||||
if (mapped != null) // map to the owner table
|
_kio = new ColumnIO();
|
||||||
|
if (mapped != null) { // map to the owner table
|
||||||
|
keyName = field.getName() + "_KEY";
|
||||||
|
_kcols = HandlerStrategies.map(key, keyName, _kio, adapt);
|
||||||
handleMappedBy(adapt);
|
handleMappedBy(adapt);
|
||||||
else {
|
} else {
|
||||||
// map to a separate table
|
// map to a separate table
|
||||||
field.mapJoin(adapt, true);
|
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()) {
|
if (val.getTypeMapping().isMapped()) {
|
||||||
ValueMappingInfo vinfo = val.getValueInfo();
|
ValueMappingInfo vinfo = val.getValueInfo();
|
||||||
ForeignKey fk = vinfo.getTypeJoin(val, "value", false, adapt);
|
ForeignKey fk = vinfo.getTypeJoin(val, "value", false, adapt);
|
||||||
|
@ -155,10 +162,6 @@ public class HandlerRelationMapTableFieldStrategy
|
||||||
|
|
||||||
val.mapConstraints("value", adapt);
|
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);
|
field.mapPrimaryKey(adapt);
|
||||||
}
|
}
|
||||||
|
@ -347,4 +350,11 @@ public class HandlerRelationMapTableFieldStrategy
|
||||||
return HandlerStrategies.toDataStoreValue(field.getKeyMapping(), val,
|
return HandlerStrategies.toDataStoreValue(field.getKeyMapping(), val,
|
||||||
_kcols, store);
|
_kcols, store);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delete(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
|
||||||
|
throws SQLException {
|
||||||
|
if (field.getMappedBy() != null)
|
||||||
|
return;
|
||||||
|
super.delete(sm, store, rm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.openjpa.enhance.PersistenceCapable;
|
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.JDBCFetchConfiguration;
|
||||||
import org.apache.openjpa.jdbc.kernel.JDBCStore;
|
import org.apache.openjpa.jdbc.kernel.JDBCStore;
|
||||||
import org.apache.openjpa.jdbc.meta.ClassMapping;
|
import org.apache.openjpa.jdbc.meta.ClassMapping;
|
||||||
|
@ -265,7 +266,10 @@ public abstract class MapTableFieldStrategy
|
||||||
Collection<Map.Entry> entrySets = mapObj.entrySet();
|
Collection<Map.Entry> entrySets = mapObj.entrySet();
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (Map.Entry entry : entrySets) {
|
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();
|
Row newRow = (Row) ((RowImpl)row).clone();
|
||||||
Object keyObj = entry.getKey();
|
Object keyObj = entry.getKey();
|
||||||
Strategy strat = fm.getStrategy();
|
Strategy strat = fm.getStrategy();
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.openjpa.enhance.PersistenceCapable;
|
import org.apache.openjpa.enhance.PersistenceCapable;
|
||||||
|
import org.apache.openjpa.enhance.ReflectingPersistenceCapable;
|
||||||
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
||||||
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
|
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
|
||||||
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfigurationImpl;
|
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfigurationImpl;
|
||||||
|
@ -276,6 +277,8 @@ public class RelationFieldStrategy
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getMapKeyObj(Map mapObj, Object value) {
|
private Object getMapKeyObj(Map mapObj, Object value) {
|
||||||
|
if (value instanceof ReflectingPersistenceCapable)
|
||||||
|
value = ((ReflectingPersistenceCapable)value).getManagedInstance();
|
||||||
Set keySet = mapObj.keySet();
|
Set keySet = mapObj.keySet();
|
||||||
for (Object key : keySet) {
|
for (Object key : keySet) {
|
||||||
if (mapObj.get(key) == value)
|
if (mapObj.get(key) == value)
|
||||||
|
|
Loading…
Reference in New Issue