diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfiguration.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfiguration.java
index 931af86c5..ef067e405 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfiguration.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfiguration.java
@@ -628,5 +628,25 @@ public interface JDBCConfiguration
* @param util instance of the identifier utility
*/
public void setIdentifierUtil(DBIdentifierUtil util);
+
+ /**
+ * Affirms if select statements are aggressively cached.
+ * An aggressive select cache assumes that {@link FetchConfiguration fetch plan}
+ * does not change between execution.
+ *
+ * @return false by default.
+ *
+ * @since 2.2.0
+ */
+ public boolean getSelectCacheEnabled();
+
+ /**
+ * Sets if select statements are aggressively cached.
+ * An aggressive select cache assumes that {@link FetchConfiguration fetch plan}
+ * does not change between execution.
+ *
+ * @since 2.2.0
+ */
+ public void setSelectCacheEnabled(boolean enable);
}
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java
index f511705cb..1a6c68078 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java
@@ -43,6 +43,8 @@ import org.apache.openjpa.jdbc.sql.MaxDBDictionary;
import org.apache.openjpa.jdbc.sql.SQLFactory;
import org.apache.openjpa.kernel.BrokerImpl;
import org.apache.openjpa.kernel.StoreContext;
+import org.apache.openjpa.lib.conf.BooleanValue;
+import org.apache.openjpa.lib.conf.ImmutableBooleanValue;
import org.apache.openjpa.lib.conf.IntValue;
import org.apache.openjpa.lib.conf.ObjectValue;
import org.apache.openjpa.lib.conf.PluginValue;
@@ -87,6 +89,7 @@ public class JDBCConfigurationImpl
public PluginValue driverDataSourcePlugin;
public MappingFactoryValue mappingFactoryPlugin;
public ObjectValue identifierUtilPlugin;
+ public ImmutableBooleanValue cacheSelect;
// used internally
private String firstUser = null;
@@ -350,6 +353,9 @@ public class JDBCConfigurationImpl
identifierUtilPlugin.setString(aliases[0]);
identifierUtilPlugin.setInstantiatingGetter("getIdentifierUtilInstance");
+ cacheSelect = new ImmutableBooleanValue("jdbc.CachesSelect");
+ addValue(cacheSelect);
+ cacheSelect.setDefault("false");
// this static initializer is to get past a weird
// ClassCircularityError that happens only under IBM's
@@ -996,5 +1002,13 @@ public class JDBCConfigurationImpl
public void setIdentifierUtil(DBIdentifierUtil util) {
identifierUtilPlugin.set(util);
}
+
+ public boolean getSelectCacheEnabled() {
+ return cacheSelect.get();
+ }
+ public void setSelectCacheEnabled(boolean enable) {
+ cacheSelect.set(enable);
+ }
+
}
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
index 75ed1a8e0..e4f230980 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
@@ -260,9 +260,9 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
private boolean exists(ClassMapping mapping, Object oid, Object context) {
// add where conditions on base class to avoid joins if subclass
// doesn't use oid as identifier
- Select sel = _sql.newSelect();
while (mapping.getJoinablePCSuperclassMapping() != null)
mapping = mapping.getJoinablePCSuperclassMapping();
+ Select sel = mapping.getSelect();
sel.wherePrimaryKey(oid, mapping, this);
if (_log.isTraceEnabled()) {
@@ -301,8 +301,7 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
FetchConfiguration fetch, Object context) {
ConnectionInfo info = (ConnectionInfo) context;
try {
- return initializeState(sm, state, (JDBCFetchConfiguration) fetch,
- info);
+ return initializeState(sm, state, (JDBCFetchConfiguration) fetch, info);
} catch (ClassNotFoundException cnfe) {
throw new UserException(cnfe);
} catch (SQLException se) {
@@ -332,27 +331,24 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
Boolean custom = customLoad(sm, mapping, state, fetch);
if (custom != null)
return custom.booleanValue();
- res = getInitializeStateResult(sm, mapping, fetch,
- Select.SUBS_EXACT);
+ res = getInitializeStateResult(sm, mapping, fetch, Select.SUBS_EXACT);
if (res == null && !selectPrimaryKey(sm, mapping, fetch))
return false;
if (isEmptyResult(res))
return false;
} else {
- ClassMapping[] mappings = mapping.
- getIndependentAssignableMappings();
+ ClassMapping[] mappings = mapping.getIndependentAssignableMappings();
if (mappings.length == 1) {
mapping = mappings[0];
Boolean custom = customLoad(sm, mapping, state, fetch);
if (custom != null)
return custom.booleanValue();
- res = getInitializeStateResult(sm, mapping, fetch,
- Select.SUBS_ANY_JOINABLE);
+ res = getInitializeStateResult(sm, mapping, fetch, Select.SUBS_ANY_JOINABLE);
if (res == null && !selectPrimaryKey(sm, mapping, fetch))
return false;
- } else
- res = getInitializeStateUnionResult(sm, mapping, mappings,
- fetch);
+ } else {
+ res = getInitializeStateUnionResult(sm, mapping, mappings, fetch);
+ }
if (isEmptyResult(res))
return false;
}
@@ -365,8 +361,7 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
mapping = res.getBaseMapping();
res.startDataRequest(mapping.getDiscriminator());
try {
- type = mapping.getDiscriminator().getClass(this, mapping,
- res);
+ type = mapping.getDiscriminator().getClass(this, mapping, res);
} finally {
res.endDataRequest();
}
@@ -378,19 +373,15 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
sm.initialize(type, state);
if (info != null && info.result != null) {
- FieldMapping mappedByFieldMapping = info.result.
- getMappedByFieldMapping();
+ FieldMapping mappedByFieldMapping = info.result.getMappedByFieldMapping();
Object mappedByObject = info.result.getMappedByValue();
if (mappedByFieldMapping != null && mappedByObject != null)
if (mappedByObject instanceof OpenJPAId &&
mapping.getExtraFieldDataIndex(mappedByFieldMapping.getIndex()) != -1) {
- // The inverse relation can not be set since
- // we are eagerly loading this sm for
- // a sm owner that is still in the process of
- // initializing itself.
+ // The inverse relation can not be set since we are eagerly loading this sm for
+ // an owner that is still in the process of initializing itself.
// Remember owner oid by setIntermediate().
- // The inverse relation is set later by
- // setInverseRelation() when the sm owner is fully
+ // The inverse relation is set later by setInverseRelation() when the owner is fully
// initialized.
int index = mappedByFieldMapping.getIndex();
if (sm.getLoaded().get(index)) {
@@ -535,7 +526,7 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
FinderQueryImpl fq = getFinder(mapping, fetch);
if (fq != null)
return fq.execute(sm, this, fetch);
- Select sel = _sql.newSelect();
+ Select sel = mapping.getSelect();
if (!select(sel, mapping, subs, sm, null, fetch,
JDBCFetchConfiguration.EAGER_JOIN, true, false))
return null;
@@ -563,7 +554,7 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
final int eager = Math.min(fetch.getEagerFetchMode(),
JDBCFetchConfiguration.EAGER_JOIN);
- Union union = _sql.newUnion(mappings.length);
+ Union union = mapping.getUnion(mappings.length);
union.setExpectedResultCount(1, false);
if (fetch.getSubclassFetchMode(mapping) != EagerFetchModes.EAGER_JOIN)
union.abortUnion();
@@ -592,7 +583,7 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
while (base.getJoinablePCSuperclassMapping() != null)
base = base.getJoinablePCSuperclassMapping();
- Select sel = _sql.newSelect();
+ Select sel = mapping.getSelect();
sel.select(base.getPrimaryKeyColumns());
sel.wherePrimaryKey(sm.getObjectId(), base, this);
if (_log.isTraceEnabled()) {
@@ -645,7 +636,7 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
//### use it... would it be worth it to have a small shell select
//### object that only creates a real select when actually used?
- Select sel = _sql.newSelect();
+ Select sel = mapping.getSelect();
if (select(sel, mapping, Select.SUBS_EXACT, sm, fields, jfetch,
EagerFetchModes.EAGER_JOIN, true, false)) {
sel.wherePrimaryKey(sm.getObjectId(), mapping, this);
@@ -818,7 +809,7 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
if (rops[i] != null)
continue;
- Select sel = _sql.newSelect();
+ Select sel = mapping.getSelect();
sel.setLRS(true);
if (_log.isTraceEnabled()) {
_log.trace("executeExtent: "+mappings[i].getDescribedType());
@@ -839,13 +830,12 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
}
// perform a union on all independent classes
- Union union = _sql.newUnion(mappings.length);
+ Union union = mapping.getUnion(mappings.length);
union.setLRS(true);
final BitSet[] paged = new BitSet[mappings.length];
union.select(new Union.Selector() {
public void select(Select sel, int idx) {
- paged[idx] = selectExtent(sel, mappings[idx], jfetch,
- subclasses);
+ paged[idx] = selectExtent(sel, mappings[idx], jfetch, subclasses);
}
});
@@ -1124,6 +1114,8 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
public boolean select(Select sel, ClassMapping mapping, int subs,
OpenJPAStateManager sm, BitSet fields, JDBCFetchConfiguration fetch,
int eager, boolean ident, boolean outer) {
+ if (sel.isReadOnly())
+ return true;
// add class conditions so that they're cloned for any batched selects
boolean joinedSupers = false;
if(needClassCondition(mapping, subs, sm)) {
@@ -1134,8 +1126,7 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
// and cannot be reused during the actual eager select process,
// preventing infinite recursion
eager = Math.min(eager, fetch.getEagerFetchMode());
- FieldMapping eagerToMany = createEagerSelects(sel, mapping, sm, fields,
- fetch, eager);
+ FieldMapping eagerToMany = createEagerSelects(sel, mapping, sm, fields, fetch, eager);
// select all base class mappings; do this after batching so that
// the joins needed by these selects don't get in the WHERE clause
@@ -1145,10 +1136,9 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
// select eager to-many relations last because during load they
// advance the result set and could exhaust it, so no other mappings
- // can load afterwords
+ // can load afterwards
if (eagerToMany != null)
- eagerToMany.selectEagerJoin(sel, sm, this,
- fetch.traverseJDBC(eagerToMany), eager);
+ eagerToMany.selectEagerJoin(sel, sm, this, fetch.traverseJDBC(eagerToMany), eager);
// optionally select subclass mappings
if (subs == Select.SUBS_JOINABLE || subs == Select.SUBS_ANY_JOINABLE)
@@ -1164,8 +1154,7 @@ public class JDBCStoreManager implements StoreManager, JDBCStore {
return mapping.getDiscriminator().addClassConditions(sel, subs == Select.SUBS_JOINABLE, joins);
}
- private boolean needClassCondition(ClassMapping mapping, int subs,
- OpenJPAStateManager sm) {
+ private boolean needClassCondition(ClassMapping mapping, int subs, OpenJPAStateManager sm) {
boolean retVal = false;
if(sm == null || sm.getPCState() == PCState.TRANSIENT) {
if(subs == Select.SUBS_JOINABLE || subs == Select.SUBS_NONE) {
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
index f565fab8f..c59c632bb 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
@@ -31,6 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.openjpa.enhance.PersistenceCapable;
import org.apache.openjpa.enhance.Reflection;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
import org.apache.openjpa.jdbc.kernel.JDBCStore;
import org.apache.openjpa.jdbc.meta.strats.NoneClassStrategy;
@@ -44,6 +45,8 @@ import org.apache.openjpa.jdbc.sql.Joins;
import org.apache.openjpa.jdbc.sql.Result;
import org.apache.openjpa.jdbc.sql.RowManager;
import org.apache.openjpa.jdbc.sql.Select;
+import org.apache.openjpa.jdbc.sql.SelectExecutor;
+import org.apache.openjpa.jdbc.sql.Union;
import org.apache.openjpa.kernel.FetchConfiguration;
import org.apache.openjpa.kernel.OpenJPAStateManager;
import org.apache.openjpa.kernel.PCState;
@@ -60,17 +63,22 @@ import org.apache.openjpa.util.OpenJPAId;
/**
* Specialization of metadata for relational databases.
+ *
+ * The mapping may reuse the same {@link SelectExecutor select} if the
+ * {@link JDBCConfiguration#getSelectCacheEnabled() configuration option}
+ * instructs to do so.
*
* @author Abe White
+ * @author Pinaki Poddar (select caching)
*/
+@SuppressWarnings("serial")
public class ClassMapping
extends ClassMetaData
implements ClassStrategy {
public static final ClassMapping[] EMPTY_MAPPINGS = new ClassMapping[0];
- private static final Localizer _loc = Localizer.forPackage
- (ClassMapping.class);
+ private static final Localizer _loc = Localizer.forPackage(ClassMapping.class);
private final ClassMappingInfo _info;
private final Discriminator _discrim;
@@ -88,6 +96,9 @@ public class ClassMapping
// maps columns to joinables
private final Map _joinables = new ConcurrentHashMap();
+
+ private Select _select;
+ private Union _union;
/**
* Constructor. Supply described type and owning repository.
@@ -1109,4 +1120,48 @@ public class ClassMapping
return true;
return false;
}
+
+ /**
+ * Gets the {@link Select select} used for selecting instances of this mapping.
+ * If {@link JDBCConfiguration#getSelectCacheEnabled() aggressive caching} of
+ * select statements is enabled, then a select is generated for the first call,
+ * cached in this mapping and subsequently returned. A cached select becomes
+ * {@link Select#isReadOnly() immutable} i.e. no structural modification is
+ * allowed after its corresponding SQL has been executed on the database.
+ *
+ * @return a new or cached select to select instances of this mapping.
+ */
+ public Select getSelect() {
+ Select result = _select;
+ if (result == null) {
+ JDBCConfiguration conf = (JDBCConfiguration)getMappingRepository().getConfiguration();
+ result = conf.getSQLFactoryInstance().newSelect();
+ if (conf.getSelectCacheEnabled()) {
+ _select = result;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Gets the {@link Union union} used for selecting instances of this mapping.
+ * If {@link JDBCConfiguration#getSelectCacheEnabled() aggressive caching} of
+ * union statements is enabled, then a union is generated for the first call,
+ * cached in this mapping and subsequently returned. A cached union becomes
+ * {@link Select#isReadOnly() immutable} i.e. no structural modification is
+ * allowed after its corresponding SQL has been executed on the database.
+ *
+ * @return a new or cached union to select instances of this mapping.
+ */
+ public Union getUnion(int selects) {
+ Union result = _union;
+ if (result == null) {
+ JDBCConfiguration conf = (JDBCConfiguration)getMappingRepository().getConfiguration();
+ result = conf.getSQLFactoryInstance().newUnion(selects);
+ if (conf.getSelectCacheEnabled()) {
+ _union = result;
+ }
+ }
+ return result;
+ }
}
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
index 68cf48392..1cdc9f44a 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
@@ -81,19 +81,19 @@ public class FieldMapping
private boolean _outer = false;
private int _fetchMode = Integer.MAX_VALUE;
private Unique[] _joinTableUniques; // Unique constraints on JoinTable
- private Boolean _bidirectionalJoinTableOwner = null;
- private Boolean _bidirectionalJoinTableNonOwner = null;
+ private Boolean _bidirectionalJoinTableOwner;
+ private Boolean _bidirectionalJoinTableNonOwner;
- private Boolean _bi_MTo1_JT = null;
- private Boolean _uni_1ToM_FK = null;
- private Boolean _uni_MTo1_JT = null;
- private Boolean _uni_1To1_JT = null;
- private Boolean _bi_1To1_JT = null;
+ private Boolean _bidirectionalManyToOneJoinTable;
+ private Boolean _unidirectionalOneToManyForeignKey;
+ private Boolean _unidirectionalManyToOneJoinTable;
+ private Boolean _unidirectionalOneToOneJoinTable;
+ private Boolean _bidirectionalOneToOneJoinTable;
- private FieldMapping _bi_1ToM_JT_Field = null;
- private FieldMapping _bi_MTo1_JT_Field = null;
- private ForeignKey _bi_1ToM_Join_FK = null;
- private ForeignKey _bi_1ToM_Elem_FK = null;
+ private FieldMapping _bidirectionalOneToManyJoinTableField;
+ private FieldMapping _bidirectionalManyToOneJoinTableField;
+ private ForeignKey _bidirectionalOneToManyJoinForeignKey;
+ private ForeignKey _bidirectionalOneToManyElementForeignKey;
private boolean _hasMapsIdCols = false;
@@ -1271,85 +1271,90 @@ public class FieldMapping
return _bidirectionalJoinTableNonOwner.booleanValue();
}
- public boolean isBiMTo1JT() {
- if (_bi_MTo1_JT == null) {
- _bi_MTo1_JT = getMappingRepository().isBiMTo1JT(this);
+ public boolean isBidirectionalManyToOneJoinTable() {
+ if (_bidirectionalManyToOneJoinTable == null) {
+ _bidirectionalManyToOneJoinTable = getMappingRepository().isBidirectionalManyToOneJoinTable(this);
}
- return _bi_MTo1_JT;
+ return _bidirectionalManyToOneJoinTable;
}
- public boolean isUni1ToMFK() {
- if (_uni_1ToM_FK == null)
- _uni_1ToM_FK = getMappingRepository().isUni1ToMFK(this);
- return _uni_1ToM_FK;
+ public boolean isUnidirectionalOneToManyForeignKey() {
+ if (_unidirectionalOneToManyForeignKey == null)
+ _unidirectionalOneToManyForeignKey = getMappingRepository().isUnidirectionalOneToManyForeignKey(this);
+ return _unidirectionalOneToManyForeignKey;
}
- public boolean isUniMTo1JT() {
- if (_uni_MTo1_JT == null)
- _uni_MTo1_JT = getMappingRepository().isUniMTo1JT(this);
- return _uni_MTo1_JT;
+ public boolean isUnidirectionalManyToOneJoinTable() {
+ if (_unidirectionalManyToOneJoinTable == null)
+ _unidirectionalManyToOneJoinTable = getMappingRepository().isUnidirectionalManyToOneJoinTable(this);
+ return _unidirectionalManyToOneJoinTable;
}
- public boolean isUni1To1JT() {
- if (_uni_1To1_JT == null)
- _uni_1To1_JT = getMappingRepository().isUni1To1JT(this);
- return _uni_1To1_JT;
+ public boolean isUnidirectionalOneToOneJoinTable() {
+ if (_unidirectionalOneToOneJoinTable == null)
+ _unidirectionalOneToOneJoinTable = getMappingRepository().isUnidirectionalOneToOneJoinTable(this);
+ return _unidirectionalOneToOneJoinTable;
}
- public boolean isBi1To1JT() {
- if (_bi_1To1_JT == null)
- _bi_1To1_JT = getMappingRepository().isBi1To1JT(this);
- return _bi_1To1_JT;
+ public boolean isBidirectionalOneToOneJoinTable() {
+ if (_bidirectionalOneToOneJoinTable == null)
+ _bidirectionalOneToOneJoinTable = getMappingRepository().isBidirectionalOneToOneJoinTable(this);
+ return _bidirectionalOneToOneJoinTable;
}
- public FieldMapping getBi_1ToM_JTField() {
- if (_bi_1ToM_JT_Field == null) {
- _bi_1ToM_JT_Field = getMappingRepository().getBi_1ToM_JoinTableField(this);
+ public FieldMapping getBidirectionalOneToManyJoinTableField() {
+ if (_bidirectionalOneToManyJoinTableField == null) {
+ _bidirectionalOneToManyJoinTableField =
+ getMappingRepository().getBidirectionalOneToManyJoinTableField(this);
}
- return _bi_1ToM_JT_Field;
+ return _bidirectionalOneToManyJoinTableField;
}
- public FieldMapping getBi_MTo1_JTField() {
- if (_bi_MTo1_JT_Field == null) {
- _bi_MTo1_JT_Field = getMappingRepository().getBi_MTo1_JoinTableField(this);
+ public FieldMapping getBidirectionalManyToOneJoinTableField() {
+ if (_bidirectionalManyToOneJoinTableField == null) {
+ _bidirectionalManyToOneJoinTableField =
+ getMappingRepository().getBidirectionalManyToOneJoinTableField(this);
}
- return _bi_MTo1_JT_Field;
+ return _bidirectionalManyToOneJoinTableField;
}
- public ForeignKey getBi1ToMJoinFK() {
- if (_bi_1ToM_Join_FK == null) {
- getBi_1ToM_JTField();
- if (_bi_1ToM_JT_Field != null)
- _bi_1ToM_Join_FK = _bi_1ToM_JT_Field.getJoinForeignKey();
+ public ForeignKey getBidirectionalOneToManyJoinForeignKey() {
+ if (_bidirectionalOneToManyJoinForeignKey == null) {
+ getBidirectionalOneToManyJoinTableField();
+ if (_bidirectionalOneToManyJoinTableField != null)
+ _bidirectionalOneToManyJoinForeignKey = _bidirectionalOneToManyJoinTableField.getJoinForeignKey();
}
- return _bi_1ToM_Join_FK;
+ return _bidirectionalOneToManyJoinForeignKey;
}
- public ForeignKey getBi1ToMElemFK() {
- if (_bi_1ToM_Elem_FK == null) {
- getBi_1ToM_JTField();
- if (_bi_1ToM_JT_Field != null)
- _bi_1ToM_Elem_FK = _bi_1ToM_JT_Field.getElementMapping().getForeignKey();
+ public ForeignKey getBidirectionalOneToManyElementForeignKey() {
+ if (_bidirectionalOneToManyElementForeignKey == null) {
+ getBidirectionalOneToManyJoinTableField();
+ if (_bidirectionalOneToManyJoinTableField != null)
+ _bidirectionalOneToManyElementForeignKey =
+ _bidirectionalOneToManyJoinTableField.getElementMapping().getForeignKey();
}
- return _bi_1ToM_Elem_FK;
+ return _bidirectionalOneToManyElementForeignKey;
}
- public void setBi1MJoinTableInfo() {
+ public void setBidirectionalOneToManyJoinTableInfo() {
if (getAssociationType() == FieldMetaData.ONE_TO_MANY) {
- FieldMapping mapped = getBi_MTo1_JTField();
+ FieldMapping mapped = getBidirectionalManyToOneJoinTableField();
if (mapped != null) {
FieldMappingInfo info = getMappingInfo();
FieldMappingInfo mappedInfo = mapped.getMappingInfo();
info.setTableIdentifier(mappedInfo.getTableIdentifier());
info.setColumns(mapped.getElementMapping().getValueInfo().getColumns());
- getElementMapping().getValueInfo().setColumns(
- mappedInfo.getColumns());
+ getElementMapping().getValueInfo().setColumns(mappedInfo.getColumns());
}
}
}
public boolean isNonDefaultMappingUsingJoinTableStrategy() {
- return isBi1To1JT() || isUni1To1JT() || isUniMTo1JT() || isBiMTo1JT();
+ return isBidirectionalOneToOneJoinTable()
+ || isUnidirectionalOneToOneJoinTable()
+ || isUnidirectionalManyToOneJoinTable()
+ || isBidirectionalManyToOneJoinTable();
}
public void setMapsIdCols(boolean hasMapsIdCols) {
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java
index ced9c7c0a..63a3637a2 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java
@@ -165,7 +165,7 @@ public class FieldMappingInfo
public ForeignKey getJoinForeignKey (final FieldMapping field, Table table,
boolean adapt) {
- if (field.isUni1ToMFK()) {
+ if (field.isUnidirectionalOneToManyForeignKey()) {
List cols = field.getElementMapping().getValueInfo().getColumns();
return getJoin(field, table, adapt, cols);
}
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
index 64dc05340..2b8685e46 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
@@ -105,15 +105,14 @@ import org.apache.openjpa.util.UserException;
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class MappingRepository extends MetaDataRepository {
- private static final Localizer _loc = Localizer.forPackage
- (MappingRepository.class);
+ private static final Localizer _loc = Localizer.forPackage(MappingRepository.class);
private transient DBDictionary _dict = null;
private transient MappingDefaults _defaults = null;
- // object->queryresultmapping
private Map