You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2012/01/17 15:04:07 UTC
svn commit: r1232415 [2/2] - in /openjpa/trunk:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/
openjpa-jdbc/src/main/java/org/...
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationRelationMapTableFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationRelationMapTableFieldStrategy.java?rev=1232415&r1=1232414&r2=1232415&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationRelationMapTableFieldStrategy.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationRelationMapTableFieldStrategy.java Tue Jan 17 14:04:07 2012
@@ -82,7 +82,7 @@ public class RelationRelationMapTableFie
kunion.select(new Union.Selector() {
public void select(Select sel, int idx) {
ForeignKey joinFK = null;
- if (field.isUni1ToMFK()) {
+ if (field.isUnidirectionalOneToManyForeignKey()) {
ValueMapping val = field.getElementMapping();
ValueMappingInfo vinfo = val.getValueInfo();
Table table = vinfo.getTable(val);
@@ -117,7 +117,7 @@ public class RelationRelationMapTableFie
vunion.setLRS(lrs);
vunion.select(new Union.Selector() {
public void select(Select sel, int idx) {
- if (field.isUni1ToMFK()) {
+ if (field.isUnidirectionalOneToManyForeignKey()) {
sel.orderBy(field.getKeyMapping().getColumns(), true, true);
sel.select(vals[idx], field.getElementMapping().
getSelectSubclasses(), store, fetch, eagerMode, null);
@@ -203,10 +203,11 @@ public class RelationRelationMapTableFie
FieldMapping mapped = field.getMappedByMapping();
DBDictionary dict = field.getMappingRepository().getDBDictionary();
DBIdentifier keyName = null;
- if (field.isUni1ToMFK() || (!field.isBiMTo1JT() && mapped != null)) {
+ if (field.isUnidirectionalOneToManyForeignKey()
+ || (!field.isBidirectionalManyToOneJoinTable() && mapped != null)) {
handleMappedByForeignKey(adapt);
keyName = dict.getValidColumnName(DBIdentifier.newColumn("vkey"), field.getTable());
- } else if (field.isBiMTo1JT() || mapped == null) {
+ } else if (field.isBidirectionalManyToOneJoinTable() || mapped == null) {
field.mapJoin(adapt, true);
mapTypeJoin(val, DBIdentifier.newColumn("value"), adapt);
keyName = dict.getValidColumnName(DBIdentifier.newColumn("key"), field.getTable());
@@ -245,11 +246,11 @@ public class RelationRelationMapTableFie
if (map == null || map.isEmpty())
return;
- if (!field.isBiMTo1JT() && field.getMappedBy() != null)
+ if (!field.isBidirectionalManyToOneJoinTable() && field.getMappedBy() != null)
return;
Row row = null;
- if (!field.isUni1ToMFK()) {
+ if (!field.isUnidirectionalOneToManyForeignKey()) {
row = rm.getSecondaryRow(field.getTable(), Row.ACTION_INSERT);
row.setForeignKey(field.getJoinForeignKey(), field.getJoinColumnIO(),
sm);
@@ -263,7 +264,7 @@ public class RelationRelationMapTableFie
entry = (Map.Entry) itr.next();
keysm = RelationStrategies.getStateManager(entry.getKey(), ctx);
valsm = RelationStrategies.getStateManager(entry.getValue(), ctx);
- if (field.isUni1ToMFK()){
+ if (field.isUnidirectionalOneToManyForeignKey()){
row = rm.getRow(field.getElementMapping().getDeclaredTypeMapping().getTable(),
Row.ACTION_UPDATE, valsm, true);
row.wherePrimaryKey(valsm);
@@ -281,14 +282,14 @@ public class RelationRelationMapTableFie
// from the view point of the owned side
PersistenceCapable obj = sm.getPersistenceCapable();
if (!populateKey(row, valsm, obj, ctx, rm, store))
- if (!field.isUni1ToMFK())
+ if (!field.isUnidirectionalOneToManyForeignKey())
rm.flushSecondaryRow(row);
}
}
public void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
throws SQLException {
- if (field.getMappedBy() != null && !field.isBiMTo1JT())
+ if (field.getMappedBy() != null && !field.isBidirectionalManyToOneJoinTable())
return;
Map map = (Map) sm.fetchObject(field.getIndex());
@@ -319,7 +320,7 @@ public class RelationRelationMapTableFie
Object mkey;
if (canChange && !change.isEmpty()) {
Row changeRow = null;
- if (!field.isUni1ToMFK()) {
+ if (!field.isUnidirectionalOneToManyForeignKey()) {
changeRow = rm.getSecondaryRow(field.getTable(),
Row.ACTION_UPDATE);
changeRow.whereForeignKey(field.getJoinForeignKey(), sm);
@@ -339,7 +340,7 @@ public class RelationRelationMapTableFie
keysm = RelationStrategies.getStateManager(mkey, ctx);
valsm = RelationStrategies.getStateManager(mval, ctx);
key.whereForeignKey(changeRow, keysm);
- if (field.isUni1ToMFK()){
+ if (field.isUnidirectionalOneToManyForeignKey()){
changeRow = rm.getRow(field.getElementMapping().getDeclaredTypeMapping().getTable(),
Row.ACTION_UPDATE, valsm, true);
changeRow.wherePrimaryKey(valsm);
@@ -355,7 +356,7 @@ public class RelationRelationMapTableFie
Collection rem = ct.getRemoved();
if (!rem.isEmpty() || (!canChange && !change.isEmpty())) {
Row delRow = null;
- if (!field.isUni1ToMFK()) {
+ if (!field.isUnidirectionalOneToManyForeignKey()) {
delRow = rm.getSecondaryRow(field.getTable(),
Row.ACTION_DELETE);
delRow.whereForeignKey(field.getJoinForeignKey(), sm);
@@ -363,7 +364,7 @@ public class RelationRelationMapTableFie
for (Iterator itr = rem.iterator(); itr.hasNext();) {
Object pc = itr.next();
- if (field.isUni1ToMFK()){
+ if (field.isUnidirectionalOneToManyForeignKey()){
updateSetNull(sm, rm, pc);
} else {
keysm = RelationStrategies.getStateManager(pc, ctx);
@@ -374,7 +375,7 @@ public class RelationRelationMapTableFie
if (!canChange && !change.isEmpty()) {
for (Iterator itr = change.iterator(); itr.hasNext();) {
Object pc = itr.next();
- if (field.isUni1ToMFK()){
+ if (field.isUnidirectionalOneToManyForeignKey()){
updateSetNull(sm, rm, pc);
} else {
keysm = RelationStrategies.getStateManager(pc, ctx);
@@ -389,7 +390,7 @@ public class RelationRelationMapTableFie
Collection add = ct.getAdded();
if (!add.isEmpty() || (!canChange && !change.isEmpty())) {
Row addRow = null;
- if (!field.isUni1ToMFK()) {
+ if (!field.isUnidirectionalOneToManyForeignKey()) {
addRow = rm.getSecondaryRow(field.getTable(),
Row.ACTION_INSERT);
addRow.setForeignKey(field.getJoinForeignKey(),
@@ -409,7 +410,7 @@ public class RelationRelationMapTableFie
continue;
keysm = RelationStrategies.getStateManager(mkey, ctx);
valsm = RelationStrategies.getStateManager(mval, ctx);
- if (field.isUni1ToMFK()){
+ if (field.isUnidirectionalOneToManyForeignKey()){
addRow = rm.getRow(field.getElementMapping().getDeclaredTypeMapping().getTable(),
Row.ACTION_UPDATE, valsm, true);
addRow.wherePrimaryKey(valsm);
@@ -436,7 +437,7 @@ public class RelationRelationMapTableFie
continue;
keysm = RelationStrategies.getStateManager(mkey, ctx);
valsm = RelationStrategies.getStateManager(mval, ctx);
- if (field.isUni1ToMFK()){
+ if (field.isUnidirectionalOneToManyForeignKey()){
addRow = rm.getRow(field.getElementMapping().getDeclaredTypeMapping().getTable(),
Row.ACTION_UPDATE, valsm, true);
addRow.wherePrimaryKey(valsm);
@@ -503,7 +504,7 @@ public class RelationRelationMapTableFie
public void delete(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
throws SQLException {
- if (field.isUni1ToMFK()) {
+ if (field.isUnidirectionalOneToManyForeignKey()) {
Map mapObj = (Map)sm.fetchObject(field.getIndex());
updateSetNull(sm, store, rm, mapObj.keySet());
return;
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java?rev=1232415&r1=1232414&r2=1232415&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java Tue Jan 17 14:04:07 2012
@@ -113,7 +113,7 @@ public abstract class RelationToManyTabl
// Bi-directional oneToMany relation with join table strategy
// ==> should not mapped in the owner's table
if (mapped != null) {
- if (!field.isBiMTo1JT()) {
+ if (!field.isBidirectionalManyToOneJoinTable()) {
if (mapped.getElement().getTypeCode() != JavaTypes.PC) {
throw new MetaDataException(_loc.get("not-inv-relation-coll",
field, mapped));
@@ -134,9 +134,9 @@ public abstract class RelationToManyTabl
}
}
- if (mapped == null || field.isBiMTo1JT()) {
- if (field.isBiMTo1JT())
- field.setBi1MJoinTableInfo();
+ if (mapped == null || field.isBidirectionalManyToOneJoinTable()) {
+ if (field.isBidirectionalManyToOneJoinTable())
+ field.setBidirectionalOneToManyJoinTableInfo();
field.mapJoin(adapt, true);
if (elem.getTypeMapping().isMapped()) {
ForeignKey fk = vinfo.getTypeJoin(elem, "element", false, adapt);
@@ -157,7 +157,7 @@ public abstract class RelationToManyTabl
public void insert(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
throws SQLException {
- if (field.getMappedBy() == null || field.isBiMTo1JT())
+ if (field.getMappedBy() == null || field.isBidirectionalManyToOneJoinTable())
insert(sm, rm, sm.fetchObject(field.getIndex()));
}
@@ -188,7 +188,7 @@ public abstract class RelationToManyTabl
public void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
throws SQLException {
- if (field.getMappedBy() != null && !field.isBiMTo1JT())
+ if (field.getMappedBy() != null && !field.isBidirectionalManyToOneJoinTable())
return;
Object obj = sm.fetchObject(field.getIndex());
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java?rev=1232415&r1=1232414&r2=1232415&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java Tue Jan 17 14:04:07 2012
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Map;
import org.apache.openjpa.enhance.PersistenceCapable;
+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.ClassMapping;
@@ -57,8 +58,13 @@ import org.apache.openjpa.util.Proxy;
* insert/update/delete behavior as well as overriding
* {@link FieldStrategy#toDataStoreValue}, {@link FieldStrategy#join}, and
* {@link FieldStrategy#joinRelation} if necessary.
+ * <br>
+ * The strategy 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 abstract class StoreCollectionFieldStrategy
@@ -194,6 +200,7 @@ public abstract class StoreCollectionFie
private void selectEager(Select sel, ClassMapping elem,
OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch,
int eagerMode, boolean selectOid, boolean outer) {
+ if (sel.isReadOnly()) return;
// force distinct if there was a to-many join to avoid duplicates, but
// if this is a parallel select don't make distinct based on the
// eager joins alone if the original wasn't distinct
@@ -523,7 +530,9 @@ public abstract class StoreCollectionFie
Union union;
if (_executor == null) {
union = store.getSQLFactory().newUnion(Math.max(1, elems.length));
- _executor = union;
+ if (store.getConfiguration().getSelectCacheEnabled()) {
+ _executor = union;
+ }
} else {
union = (Union)_executor;
}
@@ -571,25 +580,24 @@ public abstract class StoreCollectionFie
}
/**
- * Select data for loading, starting in field table.
+ * Selects data for loading, starting in field table.
+ *
*/
protected Joins selectAll(Select sel, ClassMapping elem,
- OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch,
- int eagerMode) {
+ OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode) {
ForeignKey fk = getJoinForeignKey(elem);
Object oid = getObjectIdForJoin(fk, sm);
sel.whereForeignKey(fk, oid, field.getDefiningMapping(), store);
- Joins joins;
- if (!sel.isReadOnly()) {
- // order first, then select so that if the projection introduces
- // additional ordering, it will be after our required ordering
- field.orderLocal(sel, elem, null);
- joins = joinElementRelation(sel.newJoins(), elem);
- field.orderRelation(sel, elem, joins);
- selectElement(sel, elem, store, fetch, eagerMode, joins);
- } else {
- joins = joinElementRelation(sel.newJoins(), elem);
+ if (sel.isReadOnly()) {
+ return sel.getJoins();
}
+ // order first, then select so that if the projection introduces
+ // additional ordering, it will be after our required ordering
+ field.orderLocal(sel, elem, null);
+ Joins joins = joinElementRelation(sel.newJoins(), elem);
+ field.orderRelation(sel, elem, joins);
+ selectElement(sel, elem, store, fetch, eagerMode, joins);
+
return joins;
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1232415&r1=1232414&r2=1232415&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java Tue Jan 17 14:04:07 2012
@@ -1894,7 +1894,8 @@ public class DBDictionary
public SQLBuffer toSelectCount(Select sel) {
SQLBuffer selectSQL = new SQLBuffer(this);
SQLBuffer from;
- sel.addJoinClassConditions();
+ if (!sel.isReadOnly())
+ sel.addJoinClassConditions();
if (sel.getFromSelect() != null)
from = getFromSelect(sel, false);
else
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=1232415&r1=1232414&r2=1232415&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java Tue Jan 17 14:04:07 2012
@@ -255,6 +255,8 @@ public class SelectImpl
}
public SQLBuffer toSelect(boolean forUpdate, JDBCFetchConfiguration fetch) {
+ if (_readOnly)
+ return _full;
_full = _dict.toSelect(this, forUpdate, fetch);
return _full;
}
@@ -378,12 +380,10 @@ public class SelectImpl
throws SQLException {
if (fetch == null)
fetch = store.getFetchConfiguration();
- return execute(store.getContext(), store, fetch,
- fetch.getReadLockLevel());
+ return execute(store.getContext(), store, fetch, fetch.getReadLockLevel());
}
- public Result execute(JDBCStore store, JDBCFetchConfiguration fetch,
- int lockLevel)
+ public Result execute(JDBCStore store, JDBCFetchConfiguration fetch, int lockLevel)
throws SQLException {
if (fetch == null)
fetch = store.getFetchConfiguration();
@@ -394,8 +394,7 @@ public class SelectImpl
* Execute this select in the context of the given store manager. The
* context is passed in separately for profiling purposes.
*/
- protected Result execute(StoreContext ctx, JDBCStore store,
- JDBCFetchConfiguration fetch, int lockLevel)
+ protected Result execute(StoreContext ctx, JDBCStore store, JDBCFetchConfiguration fetch, int lockLevel)
throws SQLException {
boolean forUpdate = false;
if (!isAggregate() && _grouping == null) {
@@ -678,6 +677,7 @@ public class SelectImpl
}
public void addJoinClassConditions() {
+ assertMutable();
if (_joins == null || _joins.joins() == null)
return;
@@ -806,6 +806,7 @@ public class SelectImpl
}
public void clearSelects() {
+ assertMutable();
_selects.clear();
}
@@ -873,6 +874,7 @@ public class SelectImpl
* to count from the back of the select list.
*/
public void insertPlaceholder(String sql, int pos) {
+ assertMutable();
Object holder = (_placeholders >= PLACEHOLDERS.length)
? new Placeholder() : PLACEHOLDERS[_placeholders++];
_selects.insertAlias(pos, holder, sql);
@@ -882,14 +884,17 @@ public class SelectImpl
* Clear selected placeholders, and return removed select indexes.
*/
public void clearPlaceholderSelects() {
+ assertMutable();
_selects.clearPlaceholders();
}
public boolean select(Column col) {
+ assertMutable();
return select(col, (Joins) null);
}
public boolean select(Column col, Joins joins) {
+ assertMutable();
if (!isGrouping())
return select(col, getJoins(joins, true), false);
groupBy(col, joins);
@@ -897,10 +902,12 @@ public class SelectImpl
}
public int select(Column[] cols) {
+ assertMutable();
return select(cols, null);
}
public int select(Column[] cols, Joins joins) {
+ assertMutable();
if (cols == null || cols.length == 0)
return 0;
if (isGrouping()) {
@@ -919,6 +926,7 @@ public class SelectImpl
* Select the given column after making the given joins.
*/
private boolean select(Column col, PathJoins pj, boolean ident) {
+ assertMutable();
// we cache on column object if there are no joins so that when
// looking up columns in the result we don't have to create a string
// buffer for the table + column alias; if there are joins, then
@@ -940,12 +948,14 @@ public class SelectImpl
public void select(ClassMapping mapping, int subclasses,
JDBCStore store, JDBCFetchConfiguration fetch, int eager) {
+ assertMutable();
select(mapping, subclasses, store, fetch, eager, null);
}
public void select(ClassMapping mapping, int subclasses,
JDBCStore store, JDBCFetchConfiguration fetch, int eager,
Joins joins) {
+ assertMutable();
select(this, mapping, subclasses, store, fetch, eager, joins, false);
}
@@ -994,10 +1004,12 @@ public class SelectImpl
}
public boolean selectIdentifier(Column col) {
+ assertMutable();
return selectIdentifier(col, (Joins) null);
}
public boolean selectIdentifier(Column col, Joins joins) {
+ assertMutable();
if (!isGrouping())
return select(col, getJoins(joins, true), true);
groupBy(col, joins);
@@ -1005,10 +1017,12 @@ public class SelectImpl
}
public int selectIdentifier(Column[] cols) {
+ assertMutable();
return selectIdentifier(cols, null);
}
public int selectIdentifier(Column[] cols, Joins joins) {
+ assertMutable();
if (cols == null || cols.length == 0)
return 0;
if (isGrouping()) {
@@ -1025,20 +1039,24 @@ public class SelectImpl
public void selectIdentifier(ClassMapping mapping, int subclasses,
JDBCStore store, JDBCFetchConfiguration fetch, int eager) {
+ assertMutable();
selectIdentifier(mapping, subclasses, store, fetch, eager, null);
}
public void selectIdentifier(ClassMapping mapping, int subclasses,
JDBCStore store, JDBCFetchConfiguration fetch, int eager,
Joins joins) {
+ assertMutable();
select(this, mapping, subclasses, store, fetch, eager, joins, true);
}
public int selectPrimaryKey(ClassMapping mapping) {
+ assertMutable();
return selectPrimaryKey(mapping, null);
}
public int selectPrimaryKey(ClassMapping mapping, Joins joins) {
+ assertMutable();
return primaryKeyOperation(mapping, true, null, joins, false);
}
@@ -1047,6 +1065,7 @@ public class SelectImpl
*/
private int primaryKeyOperation(ClassMapping mapping, boolean sel,
Boolean asc, Joins joins, boolean aliasOrder) {
+ assertMutable();
if (!sel && asc == null)
return 0;
@@ -1134,6 +1153,7 @@ public class SelectImpl
* Append ordering information to our internal buffer.
*/
private void appendOrdering(Object orderBy, boolean asc) {
+ assertMutable();
if (_ordering == null)
_ordering = new SQLBuffer(_dict);
else
@@ -1169,10 +1189,12 @@ public class SelectImpl
}
public boolean orderBy(Column col, boolean asc, boolean sel) {
+ assertMutable();
return orderBy(col, asc, null, sel);
}
public boolean orderBy(Column col, boolean asc, Joins joins, boolean sel) {
+ assertMutable();
return orderBy(col, asc, joins, sel, false);
}
@@ -1181,15 +1203,18 @@ public class SelectImpl
*/
boolean orderBy(Column col, boolean asc, Joins joins, boolean sel,
boolean aliasOrder) {
+ assertMutable();
return columnOperation(col, sel, (asc) ? Boolean.TRUE : Boolean.FALSE,
getJoins(joins, true), aliasOrder);
}
public int orderBy(Column[] cols, boolean asc, boolean sel) {
+ assertMutable();
return orderBy(cols, asc, null, sel);
}
public int orderBy(Column[] cols, boolean asc, Joins joins, boolean sel) {
+ assertMutable();
return orderBy(cols, asc, joins, sel, false);
}
@@ -1198,6 +1223,7 @@ public class SelectImpl
*/
int orderBy(Column[] cols, boolean asc, Joins joins, boolean sel,
boolean aliasOrder) {
+ assertMutable();
PathJoins pj = getJoins(joins, true);
int seld = 0;
for (int i = 0; i < cols.length; i++)
@@ -1207,29 +1233,28 @@ public class SelectImpl
return seld;
}
- public boolean orderBy(SQLBuffer sql, boolean asc, boolean sel, Value selAs)
- {
+ public boolean orderBy(SQLBuffer sql, boolean asc, boolean sel, Value selAs) {
+ assertMutable();
return orderBy(sql, asc, (Joins) null, sel, selAs);
}
- public boolean orderBy(SQLBuffer sql, boolean asc, Joins joins,
- boolean sel, Value selAs) {
+ public boolean orderBy(SQLBuffer sql, boolean asc, Joins joins, boolean sel, Value selAs) {
+ assertMutable();
return orderBy(sql, asc, joins, sel, false, selAs);
}
/**
* Allow unions to set aliases on order columns.
*/
- boolean orderBy(SQLBuffer sql, boolean asc, Joins joins, boolean sel,
- boolean aliasOrder, Value selAs) {
+ boolean orderBy(SQLBuffer sql, boolean asc, Joins joins, boolean sel, boolean aliasOrder, Value selAs) {
+ assertMutable();
return orderBy((Object) sql, asc, joins, sel, aliasOrder, selAs);
}
/**
* Order on a SQL buffer or string.
*/
- private boolean orderBy(Object sql, boolean asc, Joins joins, boolean sel,
- boolean aliasOrder, Value selAs) {
+ private boolean orderBy(Object sql, boolean asc, Joins joins, boolean sel, boolean aliasOrder, Value selAs) {
assertMutable();
Object order = sql;
if (aliasOrder) {
@@ -1255,22 +1280,25 @@ public class SelectImpl
}
public boolean orderBy(String sql, boolean asc, boolean sel) {
+ assertMutable();
return orderBy(sql, asc, null, sel);
}
public boolean orderBy(String sql, boolean asc, Joins joins, boolean sel) {
+ assertMutable();
return orderBy(sql, asc, joins, sel, false);
}
/**
* Allow unions to set aliases on order columns.
*/
- boolean orderBy(String sql, boolean asc, Joins joins, boolean sel,
- boolean aliasOrder) {
+ boolean orderBy(String sql, boolean asc, Joins joins, boolean sel, boolean aliasOrder) {
+ assertMutable();
return orderBy((Object) sql, asc, joins, sel, aliasOrder, null);
}
public void clearOrdering() {
+ assertMutable();
_ordering = null;
_orders = 0;
}
@@ -1279,9 +1307,9 @@ public class SelectImpl
* Allow unions to record the select list indexes of items we order by.
*/
void setRecordOrderedIndexes(boolean record) {
- if (record)
+ if (record) {
_flags |= RECORD_ORDERED;
- else {
+ } else {
_ordered = null;
_flags &= ~RECORD_ORDERED;
}
@@ -1300,8 +1328,7 @@ public class SelectImpl
return idxs;
}
- public void wherePrimaryKey(Object oid, ClassMapping mapping,
- JDBCStore store) {
+ public void wherePrimaryKey(Object oid, ClassMapping mapping, JDBCStore store) {
wherePrimaryKey(oid, mapping, null, store);
}
@@ -1311,8 +1338,7 @@ public class SelectImpl
* primary key, we will recursively join to its superclass until we find
* an ancestor that does.
*/
- private void wherePrimaryKey(Object oid, ClassMapping mapping, Joins joins,
- JDBCStore store) {
+ private void wherePrimaryKey(Object oid, ClassMapping mapping, Joins joins, JDBCStore store) {
// if this mapping's identifiers include something other than
// the pk values, join to super and recurse
if (!mapping.isPrimaryKeyObjectId(false)) {
@@ -1325,12 +1351,10 @@ public class SelectImpl
}
Column[] cols = mapping.getPrimaryKeyColumns();
- where(oid, mapping, cols, cols, null, null, getJoins(joins, true),
- store);
+ where(oid, mapping, cols, cols, null, null, getJoins(joins, true), store);
}
- public void whereForeignKey(ForeignKey fk, Object oid,
- ClassMapping mapping, JDBCStore store) {
+ public void whereForeignKey(ForeignKey fk, Object oid, ClassMapping mapping, JDBCStore store) {
whereForeignKey(fk, oid, mapping, null, store);
}
@@ -1340,8 +1364,7 @@ public class SelectImpl
*
* @see #wherePrimaryKey
*/
- private void whereForeignKey(ForeignKey fk, Object oid,
- ClassMapping mapping, Joins joins, JDBCStore store) {
+ private void whereForeignKey(ForeignKey fk, Object oid, ClassMapping mapping, Joins joins, JDBCStore store) {
// if this mapping's identifiers include something other than
// the pk values, or if this foreign key doesn't link to only
// identifiers, join to table and do a getPrimaryKey
@@ -1364,8 +1387,7 @@ public class SelectImpl
}
where(oid, mapping, fk.getPrimaryKeyColumns(), fk.getColumns(),
- fk.getConstants(), fk.getConstantColumns(),
- getJoins(joins, true), store);
+ fk.getConstants(), fk.getConstantColumns(), getJoins(joins, true), store);
}
/**
@@ -1505,10 +1527,12 @@ public class SelectImpl
public void having(SQLBuffer sql) {
+ assertMutable();
having(sql, (Joins) null);
}
public void having(SQLBuffer sql, Joins joins) {
+ assertMutable();
having(sql, getJoins(joins, true));
}
@@ -1516,6 +1540,7 @@ public class SelectImpl
* Add the given condition to the HAVING clause.
*/
private void having(SQLBuffer sql, PathJoins pj) {
+ assertMutable();
// no need to use joins...
if (sql == null || sql.isEmpty())
return;
@@ -1528,37 +1553,45 @@ public class SelectImpl
}
public void groupBy(SQLBuffer sql) {
+ assertMutable();
groupBy(sql, (Joins) null);
}
public void groupBy(SQLBuffer sql, Joins joins) {
+ assertMutable();
getJoins(joins, true);
groupByAppend(sql.getSQL());
}
public void groupBy(String sql) {
+ assertMutable();
groupBy(sql, (Joins) null);
}
public void groupBy(String sql, Joins joins) {
+ assertMutable();
getJoins(joins, true);
groupByAppend(sql);
}
public void groupBy(Column col) {
+ assertMutable();
groupBy(col, null);
}
public void groupBy(Column col, Joins joins) {
+ assertMutable();
PathJoins pj = getJoins(joins, true);
groupByAppend(getColumnAlias(col, pj));
}
public void groupBy(Column[] cols) {
+ assertMutable();
groupBy(cols, null);
}
public void groupBy(Column[] cols, Joins joins) {
+ assertMutable();
PathJoins pj = getJoins(joins, true);
for (int i = 0; i < cols.length; i++) {
groupByAppend(getColumnAlias(cols[i], pj));
@@ -1566,6 +1599,7 @@ public class SelectImpl
}
private void groupByAppend(String sql) {
+ assertMutable();
if (_grouped == null || !_grouped.contains(sql)) {
if (_grouping == null) {
_grouping = new SQLBuffer(_dict);
@@ -1580,11 +1614,13 @@ public class SelectImpl
public void groupBy(ClassMapping mapping, int subclasses, JDBCStore store,
JDBCFetchConfiguration fetch) {
+ assertMutable();
groupBy(mapping, subclasses, store, fetch, null);
}
public void groupBy(ClassMapping mapping, int subclasses, JDBCStore store,
JDBCFetchConfiguration fetch, Joins joins) {
+ assertMutable();
// we implement this by putting ourselves into grouping mode, where
// all select invocations are re-routed to group-by invocations instead.
// this allows us to utilize the same select APIs of the store manager
@@ -1593,8 +1629,7 @@ public class SelectImpl
boolean wasGrouping = isGrouping();
_flags |= GROUPING;
try {
- select(mapping, subclasses, store, fetch,
- EagerFetchModes.EAGER_NONE, joins);
+ select(mapping, subclasses, store, fetch, EagerFetchModes.EAGER_NONE, joins);
} finally {
if (!wasGrouping)
_flags &= ~GROUPING;
@@ -1627,7 +1662,7 @@ public class SelectImpl
else if (!pre) {
if ((_flags & OUTER) != 0)
pj = (PathJoins) outer(pj);
- if (record) {
+ if (record && !_readOnly) {
if (!pj.isEmpty()) {
if (_joins == null)
_joins = new SelectJoins(this);
@@ -1818,6 +1853,7 @@ public class SelectImpl
}
public void append(SQLBuffer buf, Joins joins) {
+ assertMutable();
if (joins == null || joins.isEmpty())
return;
if (_joinSyntax == JoinSyntaxes.SYNTAX_SQL92)
@@ -1846,6 +1882,7 @@ public class SelectImpl
}
public Joins and(Joins joins1, Joins joins2) {
+ assertMutable();
return and((PathJoins) joins1, (PathJoins) joins2, true);
}
@@ -1857,6 +1894,7 @@ public class SelectImpl
* Combine the given joins.
*/
private SelectJoins and(PathJoins j1, PathJoins j2, boolean nullJoins) {
+ assertMutable();
if ((j1 == null || j1.isEmpty())
&& (j2 == null || j2.isEmpty()))
return null;
@@ -1894,6 +1932,7 @@ public class SelectImpl
}
public Joins or(Joins joins1, Joins joins2) {
+ assertMutable();
PathJoins j1 = (PathJoins) joins1;
PathJoins j2 = (PathJoins) joins2;
@@ -2190,32 +2229,38 @@ public class SelectImpl
}
public Joins join(ForeignKey fk, boolean inverse, boolean toMany) {
+ assertMutable();
return new SelectJoins(this).join(fk, inverse, toMany);
}
public Joins outerJoin(ForeignKey fk, boolean inverse, boolean toMany) {
+ assertMutable();
return new SelectJoins(this).outerJoin(fk, inverse, toMany);
}
public Joins joinRelation(String name, ForeignKey fk, ClassMapping target,
int subs, boolean inverse, boolean toMany) {
+ assertMutable();
return new SelectJoins(this).joinRelation(name, fk, target, subs,
inverse, toMany);
}
public Joins outerJoinRelation(String name, ForeignKey fk,
ClassMapping target, int subs, boolean inverse, boolean toMany) {
+ assertMutable();
return new SelectJoins(this).outerJoinRelation(name, fk, target, subs,
inverse, toMany);
}
public Joins setVariable(String var) {
+ assertMutable();
if (var == null)
return this;
return new SelectJoins(this).setVariable(var);
}
public Joins setSubselect(String alias) {
+ assertMutable();
if (alias == null)
return this;
return new SelectJoins(this).setSubselect(alias);
@@ -2312,6 +2357,10 @@ public class SelectImpl
*/
public void setSelect(SelectImpl sel) {
_sel = sel;
+ if (_sel.isReadOnly()) {
+ _preJoins = new Stack<Joins>();
+ _preJoins.push(_sel.getJoins());
+ }
}
public Object getEager(FieldMapping key) {
@@ -3016,6 +3065,7 @@ public class SelectImpl
}
protected Selects newSelects() {
+ assertMutable();
return new Selects();
}
@@ -3235,6 +3285,7 @@ public class SelectImpl
}
public void moveJoinsToParent() {
+ assertMutable();
}
/**
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java?rev=1232415&r1=1232414&r2=1232415&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java Tue Jan 17 14:04:07 2012
@@ -27,19 +27,20 @@ import java.util.Comparator;
* @author Abe White
* @nojavadoc
*/
+@SuppressWarnings("serial")
public class InheritanceComparator
implements Comparator, Serializable {
- private Class _base = Object.class;
+ private Class<?> _base = Object.class;
/**
* Set the least-derived type possible; defaults to <code>null</code>.
*/
- public void setBase(Class base) {
+ public void setBase(Class<?> base) {
_base = base;
}
- public Class getBase() {
+ public Class<?> getBase() {
return _base;
}
@@ -47,8 +48,8 @@ public class InheritanceComparator
* Subclasses can override this method to extract the class to compare
* on from the elements of the collection.
*/
- protected Class toClass(Object elem) {
- return (Class) elem;
+ protected Class<?> toClass(Object elem) {
+ return (Class<?>) elem;
}
public int compare(Object o1, Object o2) {
@@ -59,8 +60,8 @@ public class InheritanceComparator
if (o2 == null)
return 1;
- Class c1 = toClass(o1);
- Class c2 = toClass(o2);
+ Class<?> c1 = toClass(o1);
+ Class<?> c2 = toClass(o2);
if (c1 == c2)
return 0;
if (c1 == null)
@@ -89,7 +90,7 @@ public class InheritanceComparator
/**
* Count the levels of inheritance between this class and our base class.
*/
- private int levels(Class to) {
+ private int levels(Class<?> to) {
if (to.isInterface())
return to.getInterfaces().length;
for (int i = 0; to != null; i++, to = to.getSuperclass())
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataInheritanceComparator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataInheritanceComparator.java?rev=1232415&r1=1232414&r2=1232415&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataInheritanceComparator.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataInheritanceComparator.java Tue Jan 17 14:04:07 2012
@@ -25,10 +25,11 @@ package org.apache.openjpa.meta;
* @author Abe White
* @nojavadoc
*/
+@SuppressWarnings("serial")
public class MetaDataInheritanceComparator
extends InheritanceComparator {
- protected Class toClass(Object elem) {
+ protected Class<?> toClass(Object elem) {
if (elem == null)
return null;
return ((ClassMetaData) elem).getDescribedType();
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?rev=1232415&r1=1232414&r2=1232415&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java Tue Jan 17 14:04:07 2012
@@ -106,8 +106,7 @@ public class MetaDataRepository implemen
// system sequence
private SequenceMetaData _sysSeq = null;
- // cache of parsed metadata, oid class to class, and interface class
- // to metadatas
+ // cache of parsed metadata, oid class to class, and interface class to metadatas
private Map<Class<?>, ClassMetaData> _metas = new HashMap<Class<?>, ClassMetaData>();
private Map<String, ClassMetaData> _metaStringMap = new ConcurrentHashMap<String, ClassMetaData>();
private Map<Class<?>, Class<?>> _oids = Collections.synchronizedMap(new HashMap<Class<?>, Class<?>>());
@@ -124,7 +123,8 @@ public class MetaDataRepository implemen
private Map<Class<?>, Class<?>> _metamodel = Collections.synchronizedMap(new HashMap<Class<?>, Class<?>>());
// map of classes to lists of their subclasses
- private Map<Class<?>, List<Class<?>>> _subs = Collections.synchronizedMap(new HashMap<Class<?>, List<Class<?>>>());
+ private Map<Class<?>, Collection<Class<?>>> _subs =
+ Collections.synchronizedMap(new HashMap<Class<?>, Collection<Class<?>>>());
// xml mapping
protected final XMLMetaData[] EMPTY_XMLMETAS;
@@ -283,7 +283,7 @@ public class MetaDataRepository implemen
}
/**
- * Sets whether this repository will load all known persistent classes at initialization.
+ * Affirms if this repository will load all known persistent classes at initialization.
* Defaults to false.
*/
public boolean getPreload() {
@@ -304,11 +304,11 @@ public class MetaDataRepository implemen
* MetaData for all persistent classes and will remove locking from this class.
*/
public synchronized void preload() {
- if (_preload == false) {
+ if (!_preload) {
return;
}
// If pooling EMFs, this method may be invoked more than once. Only perform this work once.
- if (_preloadComplete == true) {
+ if (_preloadComplete) {
return;
}
@@ -316,7 +316,7 @@ public class MetaDataRepository implemen
MultiClassLoader multi = AccessController.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
multi.addClassLoader(AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()));
multi.addClassLoader(AccessController.doPrivileged(J2DoPrivHelper
- .getClassLoaderAction(MetaDataRepository.class)));
+ .getClassLoaderAction(MetaDataRepository.class)));
// If a ClassLoader was passed into Persistence.createContainerEntityManagerFactory on the PersistenceUnitInfo
// we need to add that loader to the chain of classloaders
ClassResolver resolver = _conf.getClassResolverInstance();
@@ -359,8 +359,7 @@ public class MetaDataRepository implemen
}
}
- // Hook in this class as a listener and process registered classes list to populate _aliases
- // list.
+ // Hook in this class as a listener and process registered classes list to populate _aliases list.
PCRegistry.addRegisterClassListener(this);
processRegisteredClasses(multi);
_locking = false;
@@ -856,9 +855,8 @@ public class MetaDataRepository implemen
}
private ClassMetaData[] getMetaDatasInternal() {
- // prevent concurrent mod errors when resolving one metadata
- // introduces others
- ClassMetaData[] metas = (ClassMetaData[]) _metas.values().toArray(new ClassMetaData[_metas.size()]);
+ // prevent concurrent modification errors when resolving one metadata introduces others
+ ClassMetaData[] metas = _metas.values().toArray(new ClassMetaData[_metas.size()]);
for (int i = 0; i < metas.length; i++)
if (metas[i] != null)
getMetaData(metas[i].getDescribedType(), metas[i].getEnvClassLoader(), true);
@@ -1800,7 +1798,8 @@ public class MetaDataRepository implemen
/**
* Add the given value to the collection cached in the given map under the given key.
*/
- private void addToCollection(Map map, Class<?> key, Class<?> value, boolean inheritance) {
+ private void addToCollection(Map<Class<?>, Collection<Class<?>>> map, Class<?> key, Class<?> value,
+ boolean inheritance) {
if (_locking) {
synchronized (map) {
addToCollectionInternal(map, key, value, inheritance);
@@ -1810,15 +1809,17 @@ public class MetaDataRepository implemen
}
}
- private void addToCollectionInternal(Map map, Class<?> key, Class<?> value, boolean inheritance) {
- Collection coll = (Collection) map.get(key);
+ private void addToCollectionInternal(Map<Class<?>, Collection<Class<?>>> map, Class<?> key,
+ Class<?> value, boolean inheritance) {
+ Collection<Class<?>> coll = map.get(key);
if (coll == null) {
if (inheritance) {
InheritanceComparator comp = new InheritanceComparator();
comp.setBase(key);
coll = new TreeSet<Class<?>>(comp);
- } else
+ } else {
coll = new LinkedList<Class<?>>();
+ }
map.put(key, coll);
}
coll.add(value);
@@ -1892,7 +1893,7 @@ public class MetaDataRepository implemen
_aliases = new HashMap<String, List<Class<?>>>();
_pawares = new HashMap<Class<?>, NonPersistentMetaData>();
_nonMapped = new HashMap<Class<?>, NonPersistentMetaData>();
- _subs = new HashMap<Class<?>, List<Class<?>>>();
+ _subs = new HashMap<Class<?>, Collection<Class<?>>>();
// Wait till we're done loading MetaData to flip _lock boolean.
}
}
Added: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ImmutableBooleanValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ImmutableBooleanValue.java?rev=1232415&view=auto
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ImmutableBooleanValue.java (added)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ImmutableBooleanValue.java Tue Jan 17 14:04:07 2012
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+/**
+ * An immutable boolean value can be set only once and can never be modified to a different value.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class ImmutableBooleanValue extends BooleanValue {
+ private boolean _dirty;
+
+ public ImmutableBooleanValue(String prop) {
+ super(prop);
+ }
+
+ public void set(boolean value) {
+ if (_dirty) {
+ if (value != get().booleanValue())
+ throw new IllegalStateException(this + " can not be changed from " + get() + " to " + value);
+ } else {
+ _dirty = true;
+ super.set(value);
+ }
+ }
+
+
+}
Propchange: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ImmutableBooleanValue.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataSerializer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataSerializer.java?rev=1232415&r1=1232414&r2=1232415&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataSerializer.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataSerializer.java Tue Jan 17 14:04:07 2012
@@ -1511,11 +1511,9 @@ public class AnnotationPersistenceMetaDa
* then name order.
*/
private class FieldComparator
- implements Comparator {
+ implements Comparator<FieldMetaData> {
- public int compare(Object o1, Object o2) {
- FieldMetaData fmd1 = (FieldMetaData) o1;
- FieldMetaData fmd2 = (FieldMetaData) o2;
+ public int compare(FieldMetaData fmd1, FieldMetaData fmd2) {
if (fmd1.isPrimaryKey()) {
if (fmd2.isPrimaryKey())
return fmd1.compareTo(fmd2);