changed some more finally and catch blocks that didn't get properly reformatted with earlier reformattings / sed scripts

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@423693 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Linskey 2006-07-20 01:15:04 +00:00
parent b108a39e7e
commit a1f4fd3eb0
7 changed files with 206 additions and 251 deletions

View File

@ -63,8 +63,8 @@ public abstract class AbstractUpdateManager
public Collection flush(Collection states, JDBCStore store) { public Collection flush(Collection states, JDBCStore store) {
Connection conn = store.getConnection(); Connection conn = store.getConnection();
try { try {
PreparedStatementManager psMgr = newPreparedStatementManager PreparedStatementManager psMgr = newPreparedStatementManager(store,
(store, conn); conn);
return flush(states, store, psMgr); return flush(states, store, psMgr);
} finally { } finally {
try { try {
@ -81,9 +81,8 @@ public abstract class AbstractUpdateManager
Collection customs = new LinkedList(); Collection customs = new LinkedList();
Collection exceps = null; Collection exceps = null;
for (Iterator itr = states.iterator(); itr.hasNext();) for (Iterator itr = states.iterator(); itr.hasNext();)
exceps = exceps = populateRowManager((OpenJPAStateManager) itr.next(),
populateRowManager((OpenJPAStateManager) itr.next(), rowMgr, rowMgr, store, exceps, customs);
store, exceps, customs);
// flush rows // flush rows
exceps = flush(rowMgr, psMgr, exceps); exceps = flush(rowMgr, psMgr, exceps);
@ -93,8 +92,7 @@ public abstract class AbstractUpdateManager
try { try {
((CustomMapping) itr.next()).execute(store); ((CustomMapping) itr.next()).execute(store);
} catch (SQLException se) { } catch (SQLException se) {
exceps = addException(exceps, SQLExceptions.getStore(se, exceps = addException(exceps, SQLExceptions.getStore(se, dict));
dict));
} catch (OpenJPAException ke) { } catch (OpenJPAException ke) {
exceps = addException(exceps, ke); exceps = addException(exceps, ke);
} }
@ -118,8 +116,8 @@ public abstract class AbstractUpdateManager
/** /**
* Return a new {@link PreparedStatementManager}. * Return a new {@link PreparedStatementManager}.
*/ */
protected abstract PreparedStatementManager newPreparedStatementManager protected abstract PreparedStatementManager newPreparedStatementManager(
(JDBCStore store, Connection conn); JDBCStore store, Connection conn);
/** /**
* Flush all rows of the given row manager. Add exceptions to * Flush all rows of the given row manager. Add exceptions to
@ -142,16 +140,15 @@ public abstract class AbstractUpdateManager
Collection customs) { Collection customs) {
try { try {
if (sm.getPCState() == PCState.PNEW && !sm.isFlushed()) { if (sm.getPCState() == PCState.PNEW && !sm.isFlushed()) {
insert(sm, (ClassMapping) sm.getMetaData(), rowMgr, insert(sm, (ClassMapping) sm.getMetaData(), rowMgr, store,
store, customs); customs);
} else if (sm.getPCState() == PCState.PNEWFLUSHEDDELETED } else if (sm.getPCState() == PCState.PNEWFLUSHEDDELETED
|| sm.getPCState() == PCState.PDELETED) { || sm.getPCState() == PCState.PDELETED) {
delete(sm, (ClassMapping) sm.getMetaData(), rowMgr, delete(sm, (ClassMapping) sm.getMetaData(), rowMgr, store,
store, customs); customs);
} else if ((sm.getPCState() == PCState.PDIRTY } else if ((sm.getPCState() == PCState.PDIRTY && (!sm.isFlushed() || sm
&& (!sm.isFlushed() || sm.isFlushedDirty())) .isFlushedDirty()))
|| (sm.getPCState() == PCState.PNEW || (sm.getPCState() == PCState.PNEW && sm.isFlushedDirty())) {
&& sm.isFlushedDirty())) {
BitSet dirty = sm.getDirty(); BitSet dirty = sm.getDirty();
if (sm.isFlushed()) { if (sm.isFlushed()) {
dirty = (BitSet) dirty.clone(); dirty = (BitSet) dirty.clone();
@ -159,19 +156,18 @@ public abstract class AbstractUpdateManager
} }
if (dirty.length() > 0) if (dirty.length() > 0)
update(sm, dirty, (ClassMapping) sm.getMetaData(), update(sm, dirty, (ClassMapping) sm.getMetaData(), rowMgr,
rowMgr, store, customs); store, customs);
} else if (sm.isVersionUpdateRequired()) { } else if (sm.isVersionUpdateRequired()) {
updateIndicators(sm, (ClassMapping) sm.getMetaData(), updateIndicators(sm, (ClassMapping) sm.getMetaData(), rowMgr,
rowMgr, store, customs, true); store, customs, true);
} else if (sm.isVersionCheckRequired()) { } else if (sm.isVersionCheckRequired()) {
if (!((ClassMapping) sm.getMetaData()).getVersion(). if (!((ClassMapping) sm.getMetaData()).getVersion()
checkVersion(sm, store, false)) .checkVersion(sm, store, false))
exceps = addException(exceps, new OptimisticException exceps = addException(exceps, new OptimisticException(sm
(sm.getManagedInstance())); .getManagedInstance()));
} }
} } catch (SQLException se) {
catch (SQLException se) {
exceps = addException(exceps, SQLExceptions.getStore(se, dict)); exceps = addException(exceps, SQLExceptions.getStore(se, dict));
} catch (OpenJPAException ke) { } catch (OpenJPAException ke) {
exceps = addException(exceps, ke); exceps = addException(exceps, ke);
@ -284,8 +280,7 @@ public abstract class AbstractUpdateManager
*/ */
private void update(OpenJPAStateManager sm, BitSet dirty, private void update(OpenJPAStateManager sm, BitSet dirty,
ClassMapping mapping, RowManager rowMgr, JDBCStore store, ClassMapping mapping, RowManager rowMgr, JDBCStore store,
Collection customs) Collection customs) throws SQLException {
throws SQLException {
Boolean custom = mapping.isCustomUpdate(sm, store); Boolean custom = mapping.isCustomUpdate(sm, store);
if (!Boolean.FALSE.equals(custom)) if (!Boolean.FALSE.equals(custom))
mapping.customUpdate(sm, store); mapping.customUpdate(sm, store);
@ -314,8 +309,7 @@ public abstract class AbstractUpdateManager
*/ */
private void updateIndicators(OpenJPAStateManager sm, ClassMapping mapping, private void updateIndicators(OpenJPAStateManager sm, ClassMapping mapping,
RowManager rowMgr, JDBCStore store, Collection customs, RowManager rowMgr, JDBCStore store, Collection customs,
boolean versionUpdateOnly) boolean versionUpdateOnly) throws SQLException {
throws SQLException {
while (mapping.getJoinablePCSuperclassMapping() != null) while (mapping.getJoinablePCSuperclassMapping() != null)
mapping = mapping.getJoinablePCSuperclassMapping(); mapping = mapping.getJoinablePCSuperclassMapping();
@ -359,25 +353,23 @@ public abstract class AbstractUpdateManager
private final OpenJPAStateManager _sm; private final OpenJPAStateManager _sm;
private final Strategy _strat; private final Strategy _strat;
public CustomMapping(int action, OpenJPAStateManager sm, public CustomMapping(int action, OpenJPAStateManager sm, Strategy strat) {
Strategy strat) {
_action = action; _action = action;
_sm = sm; _sm = sm;
_strat = strat; _strat = strat;
} }
public void execute(JDBCStore store) public void execute(JDBCStore store) throws SQLException {
throws SQLException {
switch (_action) { switch (_action) {
case INSERT: case INSERT:
_strat.customInsert(_sm, store); _strat.customInsert(_sm, store);
break; break;
case UPDATE: case UPDATE:
_strat.customUpdate(_sm, store); _strat.customUpdate(_sm, store);
break; break;
case DELETE: case DELETE:
_strat.customDelete(_sm, store); _strat.customDelete(_sm, store);
break; break;
} }
} }
} }

View File

@ -44,8 +44,8 @@ import org.apache.openjpa.meta.JavaTypes;
public class ClassTableJDBCSeq public class ClassTableJDBCSeq
extends TableJDBCSeq { extends TableJDBCSeq {
private static final Localizer _loc = Localizer.forPackage private static final Localizer _loc = Localizer
(ClassTableJDBCSeq.class); .forPackage(ClassTableJDBCSeq.class);
private final Map _stats = new HashMap(); private final Map _stats = new HashMap();
private boolean _ignore = false; private boolean _ignore = false;
@ -109,8 +109,8 @@ public class ClassTableJDBCSeq
protected Column addPrimaryKeyColumn(Table table) { protected Column addPrimaryKeyColumn(Table table) {
DBDictionary dict = getConfiguration().getDBDictionaryInstance(); DBDictionary dict = getConfiguration().getDBDictionaryInstance();
Column pkColumn = table.addColumn(dict.getValidColumnName Column pkColumn = table.addColumn(dict.getValidColumnName(
(getPrimaryKeyColumn(), table)); getPrimaryKeyColumn(), table));
pkColumn.setType(dict.getPreferredType(Types.VARCHAR)); pkColumn.setType(dict.getPreferredType(Types.VARCHAR));
pkColumn.setJavaType(JavaTypes.STRING); pkColumn.setJavaType(JavaTypes.STRING);
pkColumn.setSize(dict.characterColumnSize); pkColumn.setSize(dict.characterColumnSize);
@ -163,8 +163,7 @@ public class ClassTableJDBCSeq
* <li><i>set</i>: Set the sequence value for the given class.</li> * <li><i>set</i>: Set the sequence value for the given class.</li>
* </ul> * </ul>
*/ */
public static void main(String[] args) public static void main(String[] args) throws Exception {
throws Exception {
Options opts = new Options(); Options opts = new Options();
args = opts.setFromCmdLine(args); args = opts.setFromCmdLine(args);
JDBCConfiguration conf = new JDBCConfigurationImpl(); JDBCConfiguration conf = new JDBCConfigurationImpl();
@ -180,8 +179,7 @@ public class ClassTableJDBCSeq
* Run the tool. Returns false if invalid options were given. * Run the tool. Returns false if invalid options were given.
*/ */
public static boolean run(JDBCConfiguration conf, String[] args, public static boolean run(JDBCConfiguration conf, String[] args,
Options opts) Options opts) throws Exception {
throws Exception {
if (opts.containsKey("help") || opts.containsKey("-help")) if (opts.containsKey("help") || opts.containsKey("-help"))
return false; return false;
@ -213,11 +211,11 @@ public class ClassTableJDBCSeq
return false; return false;
if (loader == null) if (loader == null)
loader = conf.getClassResolverInstance(). loader = conf.getClassResolverInstance().getClassLoader(
getClassLoader(ClassTableJDBCSeq.class, null); ClassTableJDBCSeq.class, null);
ClassArgParser cap = conf.getMetaDataRepository(). ClassArgParser cap = conf.getMetaDataRepository()
getMetaDataFactory().newClassArgParser(); .getMetaDataFactory().newClassArgParser();
cap.setClassLoader(loader); cap.setClassLoader(loader);
Class cls = cap.parseTypes(args[0])[0]; Class cls = cap.parseTypes(args[0])[0];
@ -246,8 +244,7 @@ public class ClassTableJDBCSeq
} }
System.err.println(mapping + ": " + set); System.err.println(mapping + ": " + set);
} }
} } catch (NumberFormatException nfe) {
catch (NumberFormatException nfe) {
return false; return false;
} finally { } finally {
try { try {

View File

@ -84,8 +84,8 @@ import org.apache.openjpa.util.UserException;
public class JDBCStoreManager public class JDBCStoreManager
implements StoreManager, JDBCStore { implements StoreManager, JDBCStore {
private static final Localizer _loc = Localizer.forPackage private static final Localizer _loc = Localizer
(JDBCStoreManager.class); .forPackage(JDBCStoreManager.class);
private StoreContext _ctx = null; private StoreContext _ctx = null;
private JDBCConfiguration _conf = null; private JDBCConfiguration _conf = null;
@ -142,10 +142,10 @@ public class JDBCStoreManager
return (JDBCFetchConfiguration) _ctx.getFetchConfiguration(); return (JDBCFetchConfiguration) _ctx.getFetchConfiguration();
} }
private JDBCFetchConfiguration getFetchConfiguration private JDBCFetchConfiguration getFetchConfiguration(
(JDBCFetchState fetchState) { JDBCFetchState fetchState) {
return (fetchState == null) ? getFetchConfiguration() return (fetchState == null) ? getFetchConfiguration() : fetchState
: fetchState.getJDBCFetchConfiguration(); .getJDBCFetchConfiguration();
} }
public void beginOptimistic() { public void beginOptimistic() {
@ -187,8 +187,9 @@ public class JDBCStoreManager
return; return;
try { try {
if (_conn != null && (!_ctx.isManaged() if (_conn != null
|| !_conf.isConnectionFactoryModeManaged())) && (!_ctx.isManaged() || !_conf
.isConnectionFactoryModeManaged()))
_conn.rollback(); _conn.rollback();
} catch (SQLException se) { } catch (SQLException se) {
throw SQLExceptions.getStore(se, _dict); throw SQLExceptions.getStore(se, _dict);
@ -256,8 +257,7 @@ public class JDBCStoreManager
FetchState fetchState, Object context) { FetchState fetchState, Object context) {
ConnectionInfo info = (ConnectionInfo) context; ConnectionInfo info = (ConnectionInfo) context;
try { try {
return initializeState(sm, state, (JDBCFetchState) fetchState, return initializeState(sm, state, (JDBCFetchState) fetchState, info);
info);
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
throw new UserException(cnfe); throw new UserException(cnfe);
} catch (SQLException se) { } catch (SQLException se) {
@ -281,8 +281,8 @@ public class JDBCStoreManager
if (info.mapping == null) if (info.mapping == null)
info.mapping = mapping; info.mapping = mapping;
mapping = info.mapping; mapping = info.mapping;
} else } else if (oid instanceof OpenJPAId
if (oid instanceof OpenJPAId && !((OpenJPAId) oid).hasSubclasses()) { && !((OpenJPAId) oid).hasSubclasses()) {
Boolean custom = customLoad(sm, mapping, state, jfetch); Boolean custom = customLoad(sm, mapping, state, jfetch);
if (custom != null) if (custom != null)
return custom.booleanValue(); return custom.booleanValue();
@ -293,8 +293,8 @@ public class JDBCStoreManager
if (res != null && !res.next()) if (res != null && !res.next())
return false; return false;
} else { } else {
ClassMapping[] mappings = mapping. ClassMapping[] mappings = mapping
getIndependentAssignableMappings(); .getIndependentAssignableMappings();
if (mappings.length == 1) { if (mappings.length == 1) {
mapping = mappings[0]; mapping = mappings[0];
Boolean custom = customLoad(sm, mapping, state, jfetch); Boolean custom = customLoad(sm, mapping, state, jfetch);
@ -388,8 +388,7 @@ public class JDBCStoreManager
*/ */
private Result getInitializeStateUnionResult(final OpenJPAStateManager sm, private Result getInitializeStateUnionResult(final OpenJPAStateManager sm,
ClassMapping mapping, final ClassMapping[] mappings, ClassMapping mapping, final ClassMapping[] mappings,
final JDBCFetchState fetchState) final JDBCFetchState fetchState) throws SQLException {
throws SQLException {
final JDBCStoreManager store = this; final JDBCStoreManager store = this;
JDBCFetchConfiguration jfetch = getFetchConfiguration(fetchState); JDBCFetchConfiguration jfetch = getFetchConfiguration(fetchState);
final int eager = Math.min(jfetch.getEagerFetchMode(), final int eager = Math.min(jfetch.getEagerFetchMode(),
@ -400,6 +399,7 @@ public class JDBCStoreManager
if (jfetch.getSubclassFetchMode(mapping) != jfetch.EAGER_JOIN) if (jfetch.getSubclassFetchMode(mapping) != jfetch.EAGER_JOIN)
union.abortUnion(); union.abortUnion();
union.select(new Union.Selector() { union.select(new Union.Selector() {
public void select(Select sel, int i) { public void select(Select sel, int i) {
sel.select(mappings[i], Select.SUBS_ANY_JOINABLE, store, sel.select(mappings[i], Select.SUBS_ANY_JOINABLE, store,
fetchState, eager); fetchState, eager);
@ -414,8 +414,7 @@ public class JDBCStoreManager
* if needed. * if needed.
*/ */
private boolean selectPrimaryKey(OpenJPAStateManager sm, private boolean selectPrimaryKey(OpenJPAStateManager sm,
ClassMapping mapping, ClassMapping mapping, JDBCFetchConfiguration jfetch)
JDBCFetchConfiguration jfetch)
throws SQLException { throws SQLException {
// select pks from base class record to ensure it exists and lock // select pks from base class record to ensure it exists and lock
// it if needed // it if needed
@ -442,8 +441,8 @@ public class JDBCStoreManager
public boolean load(OpenJPAStateManager sm, BitSet fields, public boolean load(OpenJPAStateManager sm, BitSet fields,
FetchState fetchState, int lockLevel, Object context) { FetchState fetchState, int lockLevel, Object context) {
JDBCFetchState jfetchState = (fetchState == null) JDBCFetchState jfetchState = (fetchState == null) ? (JDBCFetchState) getFetchConfiguration()
? (JDBCFetchState) getFetchConfiguration().newFetchState() .newFetchState()
: (JDBCFetchState) fetchState; : (JDBCFetchState) fetchState;
JDBCFetchConfiguration jfetch = getFetchConfiguration(jfetchState); JDBCFetchConfiguration jfetch = getFetchConfiguration(jfetchState);
@ -586,8 +585,7 @@ public class JDBCStoreManager
public Object copyDataStoreId(Object oid, ClassMetaData meta) { public Object copyDataStoreId(Object oid, ClassMetaData meta) {
Id id = (Id) oid; Id id = (Id) oid;
return new Id(meta.getDescribedType(), id.getId(), return new Id(meta.getDescribedType(), id.getId(), id.hasSubclasses());
id.hasSubclasses());
} }
public Object newDataStoreId(Object val, ClassMetaData meta) { public Object newDataStoreId(Object val, ClassMetaData meta) {
@ -605,12 +603,12 @@ public class JDBCStoreManager
if (subclasses) if (subclasses)
mappings = mapping.getIndependentAssignableMappings(); mappings = mapping.getIndependentAssignableMappings();
else else
mappings = new ClassMapping[]{ mapping }; mappings = new ClassMapping[] { mapping };
ResultObjectProvider[] rops = null; ResultObjectProvider[] rops = null;
final JDBCFetchConfiguration jfetch = (JDBCFetchConfiguration) fetch; final JDBCFetchConfiguration jfetch = (JDBCFetchConfiguration) fetch;
final JDBCFetchState jfetchState = (JDBCFetchState) final JDBCFetchState jfetchState = (JDBCFetchState) jfetch
jfetch.newFetchState(); .newFetchState();
if (jfetch.getSubclassFetchMode(mapping) != jfetch.EAGER_JOIN) if (jfetch.getSubclassFetchMode(mapping) != jfetch.EAGER_JOIN)
rops = new ResultObjectProvider[mappings.length]; rops = new ResultObjectProvider[mappings.length];
@ -657,6 +655,7 @@ public class JDBCStoreManager
union.setLRS(true); union.setLRS(true);
final BitSet[] paged = new BitSet[mappings.length]; final BitSet[] paged = new BitSet[mappings.length];
union.select(new Union.Selector() { union.select(new Union.Selector() {
public void select(Select sel, int idx) { public void select(Select sel, int idx) {
paged[idx] = selectExtent(sel, mappings[idx], jfetchState, paged[idx] = selectExtent(sel, mappings[idx], jfetchState,
subclasses); subclasses);
@ -670,8 +669,8 @@ public class JDBCStoreManager
JDBCStoreManager.this, jfetchState, paged, JDBCStoreManager.this, jfetchState, paged,
Long.MAX_VALUE); Long.MAX_VALUE);
} }
return new InstanceResultObjectProvider(union, mappings[0], return new InstanceResultObjectProvider(union, mappings[0], this,
this, jfetchState); jfetchState);
} catch (SQLException se) { } catch (SQLException se) {
throw SQLExceptions.getStore(se, _dict); throw SQLExceptions.getStore(se, _dict);
} }
@ -684,8 +683,8 @@ public class JDBCStoreManager
JDBCFetchState jfetchState, boolean subclasses) { JDBCFetchState jfetchState, boolean subclasses) {
int subs = (subclasses) ? Select.SUBS_JOINABLE : Select.SUBS_NONE; int subs = (subclasses) ? Select.SUBS_JOINABLE : Select.SUBS_NONE;
// decide between paging and standard iteration // decide between paging and standard iteration
BitSet paged = PagingResultObjectProvider.getPagedFields(sel, BitSet paged = PagingResultObjectProvider.getPagedFields(sel, mapping,
mapping, this, jfetchState, JDBCFetchConfiguration.EAGER_PARALLEL, this, jfetchState, JDBCFetchConfiguration.EAGER_PARALLEL,
Long.MAX_VALUE); Long.MAX_VALUE);
if (paged == null) if (paged == null)
sel.selectIdentifier(mapping, subs, this, jfetchState, sel.selectIdentifier(mapping, subs, this, jfetchState,
@ -752,16 +751,14 @@ public class JDBCStoreManager
* Connect to the database. This method is separated out so that it * Connect to the database. This method is separated out so that it
* can be profiled. * can be profiled.
*/ */
private RefCountConnection connectInternal() private RefCountConnection connectInternal() throws SQLException {
throws SQLException {
return new RefCountConnection(_ds.getConnection()); return new RefCountConnection(_ds.getConnection());
} }
/** /**
* Find the object with the given oid. * Find the object with the given oid.
*/ */
public Object find(Object oid, ValueMapping vm, public Object find(Object oid, ValueMapping vm, JDBCFetchState fetchState) {
JDBCFetchState fetchState) {
if (oid == null) if (oid == null)
return null; return null;
Object pc = _ctx.find(oid, fetchState, null, null, 0); Object pc = _ctx.find(oid, fetchState, null, null, 0);
@ -776,11 +773,10 @@ public class JDBCStoreManager
* Load the object in the current row of the given result. * Load the object in the current row of the given result.
*/ */
public Object load(ClassMapping mapping, JDBCFetchState fetchState, public Object load(ClassMapping mapping, JDBCFetchState fetchState,
BitSet exclude, Result result) BitSet exclude, Result result) throws SQLException {
throws SQLException {
if (!mapping.isMapped()) if (!mapping.isMapped())
throw new InvalidStateException(_loc.get("virtual-mapping", throw new InvalidStateException(_loc
mapping)); .get("virtual-mapping", mapping));
// get the object id for the row; base class selects pk columns // get the object id for the row; base class selects pk columns
ClassMapping base = mapping; ClassMapping base = mapping;
@ -801,8 +797,7 @@ public class JDBCStoreManager
* mappings originally selected will be loaded. * mappings originally selected will be loaded.
*/ */
private void load(ClassMapping mapping, OpenJPAStateManager sm, private void load(ClassMapping mapping, OpenJPAStateManager sm,
JDBCFetchState fetchState, Result res) JDBCFetchState fetchState, Result res) throws SQLException {
throws SQLException {
FieldMapping eagerToMany = load(mapping, sm, fetchState, res, null); FieldMapping eagerToMany = load(mapping, sm, fetchState, res, null);
if (eagerToMany != null) if (eagerToMany != null)
eagerToMany.loadEagerJoin(sm, this, fetchState, res); eagerToMany.loadEagerJoin(sm, this, fetchState, res);
@ -832,8 +827,7 @@ public class JDBCStoreManager
FieldMapping[] fms = mapping.getDefinedFieldMappings(); FieldMapping[] fms = mapping.getDefinedFieldMappings();
Object eres, processed; Object eres, processed;
for (int i = 0; i < fms.length; i++) { for (int i = 0; i < fms.length; i++) {
if (fms[i].isPrimaryKey() if (fms[i].isPrimaryKey() || sm.getLoaded().get(fms[i].getIndex()))
|| sm.getLoaded().get(fms[i].getIndex()))
continue; continue;
// check for eager result, and if not present do standard load // check for eager result, and if not present do standard load
@ -894,8 +888,8 @@ public class JDBCStoreManager
// preventing infinite recursion // preventing infinite recursion
JDBCFetchConfiguration fetch = getFetchConfiguration(fetchState); JDBCFetchConfiguration fetch = getFetchConfiguration(fetchState);
eager = Math.min(eager, fetch.getEagerFetchMode()); eager = Math.min(eager, fetch.getEagerFetchMode());
FieldMapping eagerToMany = createEagerSelects(sel, mapping, sm, FieldMapping eagerToMany = createEagerSelects(sel, mapping, sm, fields,
fields, fetchState, eager); fetchState, eager);
// select all base class mappings; do this after batching so that // select all base class mappings; do this after batching so that
// the joins needed by these selects don't get in the WHERE clause // the joins needed by these selects don't get in the WHERE clause
@ -928,8 +922,8 @@ public class JDBCStoreManager
return null; return null;
JDBCFetchConfiguration fetch = getFetchConfiguration(fetchState); JDBCFetchConfiguration fetch = getFetchConfiguration(fetchState);
FieldMapping eagerToMany = createEagerSelects(sel, mapping. FieldMapping eagerToMany = createEagerSelects(sel, mapping
getJoinablePCSuperclassMapping(), sm, fields, fetchState, eager); .getJoinablePCSuperclassMapping(), sm, fields, fetchState, eager);
FieldMapping[] fms = mapping.getDefinedFieldMappings(); FieldMapping[] fms = mapping.getDefinedFieldMappings();
boolean inEagerJoin = sel.hasEagerJoin(false); boolean inEagerJoin = sel.hasEagerJoin(false);
@ -944,10 +938,9 @@ public class JDBCStoreManager
continue; continue;
// try to select with join first // try to select with join first
jtype = (fms[i].getNullValue() == fms[i].NULL_EXCEPTION) jtype = (fms[i].getNullValue() == fms[i].NULL_EXCEPTION) ? sel.EAGER_INNER
? sel.EAGER_INNER : sel.EAGER_OUTER; : sel.EAGER_OUTER;
if (mode != fetch.EAGER_PARALLEL if (mode != fetch.EAGER_PARALLEL && !fms[i].isEagerSelectToMany()
&& !fms[i].isEagerSelectToMany()
&& fms[i].supportsSelect(sel, jtype, sm, this, fetch) > 0 && fms[i].supportsSelect(sel, jtype, sm, this, fetch) > 0
&& sel.eagerClone(fms[i], jtype, false, 1) != null) && sel.eagerClone(fms[i], jtype, false, 1) != null)
continue; continue;
@ -959,13 +952,12 @@ public class JDBCStoreManager
// to use a to-many join also. currently we limit eager // to use a to-many join also. currently we limit eager
// outer joins to non-LRS, non-ranged selects that don't already // outer joins to non-LRS, non-ranged selects that don't already
// have an eager to-many join // have an eager to-many join
if ((hasJoin || mode == fetch.EAGER_JOIN if ((hasJoin || mode == fetch.EAGER_JOIN || (mode == fetch.DEFAULT && sm != null))
|| (mode == fetch.DEFAULT && sm != null))
&& fms[i].isEagerSelectToMany() && fms[i].isEagerSelectToMany()
&& !inEagerJoin && !sel.hasEagerJoin(true) && !inEagerJoin
&& !sel.hasEagerJoin(true)
&& (!sel.getAutoDistinct() || (!sel.isLRS() && (!sel.getAutoDistinct() || (!sel.isLRS()
&& sel.getStartIndex() == 0 && sel.getStartIndex() == 0 && sel.getEndIndex() == Long.MAX_VALUE))
&& sel.getEndIndex() == Long.MAX_VALUE))
&& fms[i].supportsSelect(sel, jtype, sm, this, fetch) > 0) { && fms[i].supportsSelect(sel, jtype, sm, this, fetch) > 0) {
if (sel.eagerClone(fms[i], jtype, true, 1) != null) if (sel.eagerClone(fms[i], jtype, true, 1) != null)
eagerToMany = fms[i]; eagerToMany = fms[i];
@ -974,10 +966,11 @@ public class JDBCStoreManager
} }
// finally, try parallel // finally, try parallel
if (eager == fetch.EAGER_PARALLEL && (sels = fms[i]. if (eager == fetch.EAGER_PARALLEL
supportsSelect(sel, sel.EAGER_PARALLEL, sm, this, fetch)) != 0) && (sels = fms[i].supportsSelect(sel, sel.EAGER_PARALLEL, sm,
sel.eagerClone(fms[i], Select.EAGER_PARALLEL, this, fetch)) != 0)
fms[i].isEagerSelectToMany(), sels); sel.eagerClone(fms[i], Select.EAGER_PARALLEL, fms[i]
.isEagerSelectToMany(), sels);
} }
return eagerToMany; return eagerToMany;
} }
@ -986,8 +979,7 @@ public class JDBCStoreManager
* Determine if the given field needs to be selected. * Determine if the given field needs to be selected.
*/ */
private static boolean requiresSelect(FieldMapping fm, private static boolean requiresSelect(FieldMapping fm,
OpenJPAStateManager sm, OpenJPAStateManager sm, BitSet fields, JDBCFetchState fetchState) {
BitSet fields, JDBCFetchState fetchState) {
if (fields != null) if (fields != null)
return fields.get(fm.getIndex()); return fields.get(fm.getIndex());
if (sm != null && sm.getPCState() != PCState.TRANSIENT if (sm != null && sm.getPCState() != PCState.TRANSIENT
@ -1018,8 +1010,8 @@ public class JDBCStoreManager
JDBCFetchConfiguration fetch = getFetchConfiguration(fetchState); JDBCFetchConfiguration fetch = getFetchConfiguration(fetchState);
ClassMapping parent = mapping.getJoinablePCSuperclassMapping(); ClassMapping parent = mapping.getJoinablePCSuperclassMapping();
if (parent == null && !mapping.isMapped()) if (parent == null && !mapping.isMapped())
throw new InvalidStateException(_loc.get("virtual-mapping", throw new InvalidStateException(_loc.get("virtual-mapping", mapping
mapping.getDescribedType())); .getDescribedType()));
int seld = -1; int seld = -1;
int pseld = -1; int pseld = -1;
@ -1036,9 +1028,9 @@ public class JDBCStoreManager
} }
// if no instance or not initialized and not exact oid, select type // if no instance or not initialized and not exact oid, select type
if ((sm == null || (sm.getPCState() == PCState.TRANSIENT if ((sm == null || (sm.getPCState() == PCState.TRANSIENT && (!(sm
&& (!(sm.getObjectId()instanceof OpenJPAId) .getObjectId() instanceof OpenJPAId) || ((OpenJPAId) sm
|| ((OpenJPAId) sm.getObjectId()).hasSubclasses()))) .getObjectId()).hasSubclasses())))
&& mapping.getDiscriminator().select(sel, orig)) && mapping.getDiscriminator().select(sel, orig))
seld = 1; seld = 1;
@ -1102,13 +1094,12 @@ public class JDBCStoreManager
* case as an optimization. * case as an optimization.
*/ */
private boolean optSelect(FieldMapping fm, Select sel, private boolean optSelect(FieldMapping fm, Select sel,
OpenJPAStateManager sm, OpenJPAStateManager sm, JDBCFetchState fetchState) {
JDBCFetchState fetchState) {
return !fm.isDefaultFetchGroupExplicit() return !fm.isDefaultFetchGroupExplicit()
&& (sm == null || sm.getPCState() == PCState.TRANSIENT && (sm == null || sm.getPCState() == PCState.TRANSIENT || !sm
|| !sm.getLoaded().get(fm.getIndex())) .getLoaded().get(fm.getIndex()))
&& fm.supportsSelect(sel, sel.TYPE_TWO_PART, sm, this, && fm.supportsSelect(sel, sel.TYPE_TWO_PART, sm, this,
getFetchConfiguration(fetchState)) > 0 getFetchConfiguration(fetchState)) > 0
&& fetchState.requiresSelect(fm, true); && fetchState.requiresSelect(fm, true);
} }
@ -1153,9 +1144,8 @@ public class JDBCStoreManager
if (!fms[j].isInDefaultFetchGroup() if (!fms[j].isInDefaultFetchGroup()
&& !fetch.hasFetchGroup(fms[j].getFetchGroups()) && !fetch.hasFetchGroup(fms[j].getFetchGroups())
&& !fetch.hasField(fms[j].getFullName()) && !fetch.hasField(fms[j].getFullName())
&& (fms[j].isDefaultFetchGroupExplicit() && (fms[j].isDefaultFetchGroupExplicit() || fms[j]
|| fms[j].supportsSelect(sel, sel.TYPE_TWO_PART, sm, .supportsSelect(sel, sel.TYPE_TWO_PART, sm, this, fetch) <= 0))
this, fetch) <= 0))
continue; continue;
// if we can join to the subclass, do so; much better chance // if we can join to the subclass, do so; much better chance
@ -1164,15 +1154,14 @@ public class JDBCStoreManager
// mark joined whether or not we join, so we don't have to // mark joined whether or not we join, so we don't have to
// test conditions again for this subclass // test conditions again for this subclass
joined = true; joined = true;
sel.where(joinSubclass(sel, mapping, subMappings[i], sel.where(joinSubclass(sel, mapping, subMappings[i], null));
null));
} }
// if can select with tables already selected, do it // if can select with tables already selected, do it
if (fms[j].supportsSelect(sel, sel.TYPE_JOINLESS, sm, if (fms[j].supportsSelect(sel, sel.TYPE_JOINLESS, sm, this,
this, fetch) > 0) fetch) > 0)
fms[j].select(sel, null, this, fetchState, fms[j]
fetch.EAGER_NONE); .select(sel, null, this, fetchState, fetch.EAGER_NONE);
} }
} }
} }
@ -1237,8 +1226,8 @@ public class JDBCStoreManager
// join down to base class where the conditions will be added // join down to base class where the conditions will be added
ClassMapping from = mapping; ClassMapping from = mapping;
ClassMapping sup = mapping.getJoinablePCSuperclassMapping(); ClassMapping sup = mapping.getJoinablePCSuperclassMapping();
for (; sup != null; from = sup, for (; sup != null; from = sup, sup = from
sup = from.getJoinablePCSuperclassMapping()) { .getJoinablePCSuperclassMapping()) {
if (from.getTable() != sup.getTable()) { if (from.getTable() != sup.getTable()) {
if (joins == null) if (joins == null)
joins = sel.newJoins(); joins = sel.newJoins();
@ -1273,8 +1262,7 @@ public class JDBCStoreManager
* Connection returned to client code. Makes sure its wrapped connection * Connection returned to client code. Makes sure its wrapped connection
* ref count is decremented on finalize. * ref count is decremented on finalize.
*/ */
private static class ClientConnection private static class ClientConnection extends DelegatingConnection {
extends DelegatingConnection {
private boolean _closed = false; private boolean _closed = false;
@ -1282,14 +1270,12 @@ public class JDBCStoreManager
super(conn); super(conn);
} }
public void close() public void close() throws SQLException {
throws SQLException {
_closed = true; _closed = true;
super.close(); super.close();
} }
protected void finalize() protected void finalize() throws SQLException {
throws SQLException {
if (!_closed) if (!_closed)
close(); close();
} }
@ -1299,8 +1285,7 @@ public class JDBCStoreManager
* Connection wrapper that keeps an internal ref count so that it knows * Connection wrapper that keeps an internal ref count so that it knows
* when to really close. * when to really close.
*/ */
private class RefCountConnection private class RefCountConnection extends DelegatingConnection {
extends DelegatingConnection {
private boolean _retain = false; private boolean _retain = false;
private int _refs = 0; private int _refs = 0;
@ -1325,8 +1310,7 @@ public class JDBCStoreManager
_refs++; _refs++;
} }
public void close() public void close() throws SQLException {
throws SQLException {
// lock at broker level to avoid deadlocks // lock at broker level to avoid deadlocks
_ctx.lock(); _ctx.lock();
try { try {
@ -1354,30 +1338,27 @@ public class JDBCStoreManager
_conn = null; _conn = null;
} }
protected Statement createStatement(boolean wrap) protected Statement createStatement(boolean wrap) throws SQLException {
throws SQLException {
return new CancelStatement(super.createStatement(false), return new CancelStatement(super.createStatement(false),
RefCountConnection.this); RefCountConnection.this);
} }
protected Statement createStatement(int rsType, int rsConcur, protected Statement createStatement(int rsType, int rsConcur,
boolean wrap) boolean wrap) throws SQLException {
throws SQLException { return new CancelStatement(super.createStatement(rsType, rsConcur,
return new CancelStatement(super.createStatement(rsType, false), RefCountConnection.this);
rsConcur, false), RefCountConnection.this);
} }
protected PreparedStatement prepareStatement(String sql, boolean wrap) protected PreparedStatement prepareStatement(String sql, boolean wrap)
throws SQLException { throws SQLException {
return new CancelPreparedStatement(super.prepareStatement return new CancelPreparedStatement(super.prepareStatement(sql,
(sql, false), RefCountConnection.this); false), RefCountConnection.this);
} }
protected PreparedStatement prepareStatement(String sql, int rsType, protected PreparedStatement prepareStatement(String sql, int rsType,
int rsConcur, boolean wrap) int rsConcur, boolean wrap) throws SQLException {
throws SQLException { return new CancelPreparedStatement(super.prepareStatement(sql,
return new CancelPreparedStatement(super.prepareStatement rsType, rsConcur, false), RefCountConnection.this);
(sql, rsType, rsConcur, false), RefCountConnection.this);
} }
} }
@ -1385,15 +1366,13 @@ public class JDBCStoreManager
* Statement type that adds and removes itself from the set of active * Statement type that adds and removes itself from the set of active
* statements so that it can be canceled. * statements so that it can be canceled.
*/ */
private class CancelStatement private class CancelStatement extends DelegatingStatement {
extends DelegatingStatement {
public CancelStatement(Statement stmnt, Connection conn) { public CancelStatement(Statement stmnt, Connection conn) {
super(stmnt, conn); super(stmnt, conn);
} }
public int executeUpdate(String sql) public int executeUpdate(String sql) throws SQLException {
throws SQLException {
beforeExecuteStatement(this); beforeExecuteStatement(this);
try { try {
return super.executeUpdate(sql); return super.executeUpdate(sql);
@ -1417,16 +1396,13 @@ public class JDBCStoreManager
* Statement type that adds and removes itself from the set of active * Statement type that adds and removes itself from the set of active
* statements so that it can be canceled. * statements so that it can be canceled.
*/ */
private class CancelPreparedStatement private class CancelPreparedStatement extends DelegatingPreparedStatement {
extends DelegatingPreparedStatement {
public CancelPreparedStatement(PreparedStatement stmnt, public CancelPreparedStatement(PreparedStatement stmnt, Connection conn) {
Connection conn) {
super(stmnt, conn); super(stmnt, conn);
} }
public int executeUpdate() public int executeUpdate() throws SQLException {
throws SQLException {
beforeExecuteStatement(this); beforeExecuteStatement(this);
try { try {
return super.executeUpdate(); return super.executeUpdate();
@ -1435,8 +1411,7 @@ public class JDBCStoreManager
} }
} }
protected ResultSet executeQuery(boolean wrap) protected ResultSet executeQuery(boolean wrap) throws SQLException {
throws SQLException {
beforeExecuteStatement(this); beforeExecuteStatement(this);
try { try {
return super.executeQuery(wrap); return super.executeQuery(wrap);
@ -1445,8 +1420,7 @@ public class JDBCStoreManager
} }
} }
public int[] executeBatch() public int[] executeBatch() throws SQLException {
throws SQLException {
beforeExecuteStatement(this); beforeExecuteStatement(this);
try { try {
return super.executeBatch(); return super.executeBatch();

View File

@ -107,8 +107,8 @@ public class JDBCStoreQuery
} }
public Object newCompilationKey() { public Object newCompilationKey() {
JDBCFetchConfiguration fetch = (JDBCFetchConfiguration) JDBCFetchConfiguration fetch = (JDBCFetchConfiguration) ctx
ctx.getFetchConfiguration(); .getFetchConfiguration();
return Numbers.valueOf(fetch.getJoinSyntax()); return Numbers.valueOf(fetch.getJoinSyntax());
} }
@ -116,10 +116,10 @@ public class JDBCStoreQuery
return true; return true;
} }
protected ClassMetaData[] getIndependentExpressionCandidates protected ClassMetaData[] getIndependentExpressionCandidates(
(ClassMetaData meta, boolean subclasses) { ClassMetaData meta, boolean subclasses) {
if (!subclasses) if (!subclasses)
return new ClassMapping[]{ (ClassMapping) meta }; return new ClassMapping[] { (ClassMapping) meta };
return ((ClassMapping) meta).getIndependentAssignableMappings(); return ((ClassMapping) meta).getIndependentAssignableMappings();
} }
@ -132,12 +132,12 @@ public class JDBCStoreQuery
ExpressionFactory[] facts, QueryExpressions[] exps, Object[] params, ExpressionFactory[] facts, QueryExpressions[] exps, Object[] params,
boolean lrs, long startIdx, long endIdx) { boolean lrs, long startIdx, long endIdx) {
if (metas.length > 1 && exps[0].aggregate) if (metas.length > 1 && exps[0].aggregate)
throw new UserException(Localizer.forPackage(JDBCStoreQuery.class). throw new UserException(Localizer.forPackage(JDBCStoreQuery.class)
get("mult-mapping-aggregate", Arrays.asList(metas))); .get("mult-mapping-aggregate", Arrays.asList(metas)));
ClassMapping[] mappings = (ClassMapping[]) metas; ClassMapping[] mappings = (ClassMapping[]) metas;
JDBCFetchConfiguration fetch = (JDBCFetchConfiguration) JDBCFetchConfiguration fetch = (JDBCFetchConfiguration) ctx
ctx.getFetchConfiguration(); .getFetchConfiguration();
JDBCFetchState fetchState = (JDBCFetchState) fetch.newFetchState(); JDBCFetchState fetchState = (JDBCFetchState) fetch.newFetchState();
if (exps[0].fetchPaths != null) { if (exps[0].fetchPaths != null) {
fetch.addFields(Arrays.asList(exps[0].fetchPaths)); fetch.addFields(Arrays.asList(exps[0].fetchPaths));
@ -147,8 +147,8 @@ public class JDBCStoreQuery
int eager = calculateEagerMode(exps[0], startIdx, endIdx); int eager = calculateEagerMode(exps[0], startIdx, endIdx);
int subclassMode = fetch.getSubclassFetchMode((ClassMapping) base); int subclassMode = fetch.getSubclassFetchMode((ClassMapping) base);
DBDictionary dict = _store.getDBDictionary(); DBDictionary dict = _store.getDBDictionary();
long start = (mappings.length == 1 && dict.supportsSelectStartIndex) long start = (mappings.length == 1 && dict.supportsSelectStartIndex) ? startIdx
? startIdx : 0L; : 0L;
long end = (dict.supportsSelectEndIndex) ? endIdx : Long.MAX_VALUE; long end = (dict.supportsSelectEndIndex) ? endIdx : Long.MAX_VALUE;
// add selects with populate WHERE conditions to list // add selects with populate WHERE conditions to list
@ -157,24 +157,25 @@ public class JDBCStoreQuery
BitSet subclassBits = new BitSet(); BitSet subclassBits = new BitSet();
BitSet nextBits = new BitSet(); BitSet nextBits = new BitSet();
boolean unionable = createWhereSelects(sels, mappings, selMappings, boolean unionable = createWhereSelects(sels, mappings, selMappings,
subclasses, subclassBits, nextBits, facts, exps, params, fetchState, subclasses, subclassBits, nextBits, facts, exps, params,
subclassMode) fetchState, subclassMode)
&& subclassMode == JDBCFetchConfiguration.EAGER_JOIN && subclassMode == JDBCFetchConfiguration.EAGER_JOIN
&& start == 0 && end == Long.MAX_VALUE; && start == 0
&& end == Long.MAX_VALUE;
// we might want to use lrs settings if we can't use the range // we might want to use lrs settings if we can't use the range
if (sels.size() > 1) if (sels.size() > 1)
start = 0L; start = 0L;
lrs = lrs || (fetch.getFetchBatchSize() >= 0 lrs = lrs
&& (start != startIdx || end != endIdx)); || (fetch.getFetchBatchSize() >= 0 && (start != startIdx || end != endIdx));
ResultObjectProvider[] rops = null; ResultObjectProvider[] rops = null;
ResultObjectProvider rop = null; ResultObjectProvider rop = null;
if (unionable) { if (unionable) {
Union union = _store.getSQLFactory().newUnion((Select[]) Union union = _store.getSQLFactory().newUnion(
sels.toArray(new Select[sels.size()])); (Select[]) sels.toArray(new Select[sels.size()]));
BitSet[] paged = populateUnion(union, mappings, subclasses, BitSet[] paged = populateUnion(union, mappings, subclasses, facts,
facts, exps, params, fetchState, lrs, eager, start, end); exps, params, fetchState, lrs, eager, start, end);
union.setLRS(lrs); union.setLRS(lrs);
rop = executeUnion(union, mappings, exps, paged, fetchState); rop = executeUnion(union, mappings, exps, paged, fetchState);
} else { } else {
@ -209,8 +210,8 @@ public class JDBCStoreQuery
} }
// need to fake result range? // need to fake result range?
if ((rops != null && endIdx != Long.MAX_VALUE) if ((rops != null && endIdx != Long.MAX_VALUE) || start != startIdx
|| start != startIdx || end != endIdx) || end != endIdx)
rop = new RangeResultObjectProvider(rop, startIdx, endIdx); rop = new RangeResultObjectProvider(rop, startIdx, endIdx);
return rop; return rop;
} }
@ -226,6 +227,7 @@ public class JDBCStoreQuery
final BitSet[] paged = (exps[0].projections.length > 0) ? null final BitSet[] paged = (exps[0].projections.length > 0) ? null
: new BitSet[mappings.length]; : new BitSet[mappings.length];
union.select(new Union.Selector() { union.select(new Union.Selector() {
public void select(Select sel, int idx) { public void select(Select sel, int idx) {
BitSet bits = populateSelect(sel, mappings[idx], subclasses, BitSet bits = populateSelect(sel, mappings[idx], subclasses,
(JDBCExpressionFactory) facts[idx], exps[idx], params, (JDBCExpressionFactory) facts[idx], exps[idx], params,
@ -267,8 +269,8 @@ public class JDBCStoreQuery
ClassMapping[] mappings, QueryExpressions[] exps, BitSet[] paged, ClassMapping[] mappings, QueryExpressions[] exps, BitSet[] paged,
JDBCFetchState fetchState) { JDBCFetchState fetchState) {
if (exps[0].projections.length > 0) if (exps[0].projections.length > 0)
return new ProjectionResultObjectProvider(union, _store, fetchState, return new ProjectionResultObjectProvider(union, _store,
exps); fetchState, exps);
if (paged != null) if (paged != null)
for (int i = 0; i < paged.length; i++) for (int i = 0; i < paged.length; i++)
@ -341,11 +343,11 @@ public class JDBCStoreQuery
private ClassMapping[] getVerticalMappings(ClassMapping mapping, private ClassMapping[] getVerticalMappings(ClassMapping mapping,
boolean subclasses, QueryExpressions exps, int subclassMode) { boolean subclasses, QueryExpressions exps, int subclassMode) {
if (!subclasses || exps.projections.length > 0) if (!subclasses || exps.projections.length > 0)
return new ClassMapping[]{ mapping }; return new ClassMapping[] { mapping };
if (subclassMode != JDBCFetchConfiguration.EAGER_PARALLEL if (subclassMode != JDBCFetchConfiguration.EAGER_PARALLEL
|| !hasVerticalSubclasses(mapping)) || !hasVerticalSubclasses(mapping))
return new ClassMapping[]{ mapping }; return new ClassMapping[] { mapping };
List subs = new ArrayList(4); List subs = new ArrayList(4);
addSubclasses(mapping, subs); addSubclasses(mapping, subs);
@ -382,7 +384,7 @@ public class JDBCStoreQuery
private static boolean hasVerticalSubclasses(ClassMapping mapping) { private static boolean hasVerticalSubclasses(ClassMapping mapping) {
ClassMapping[] subs = mapping.getJoinablePCSubclassMappings(); ClassMapping[] subs = mapping.getJoinablePCSubclassMappings();
for (int i = 0; i < subs.length; i++) for (int i = 0; i < subs.length; i++)
if (subs[i].getStrategy()instanceof VerticalClassStrategy) if (subs[i].getStrategy() instanceof VerticalClassStrategy)
return true; return true;
return false; return false;
} }
@ -405,15 +407,15 @@ public class JDBCStoreQuery
protected Number executeDelete(Executor ex, ClassMetaData base, protected Number executeDelete(Executor ex, ClassMetaData base,
ClassMetaData[] metas, boolean subclasses, ExpressionFactory[] facts, ClassMetaData[] metas, boolean subclasses, ExpressionFactory[] facts,
QueryExpressions[] exps, Object[] params) { QueryExpressions[] exps, Object[] params) {
return executeBulkOperation(ex, base, metas, subclasses, facts, return executeBulkOperation(ex, base, metas, subclasses, facts, exps,
exps, params, null); params, null);
} }
protected Number executeUpdate(Executor ex, ClassMetaData base, protected Number executeUpdate(Executor ex, ClassMetaData base,
ClassMetaData[] metas, boolean subclasses, ExpressionFactory[] facts, ClassMetaData[] metas, boolean subclasses, ExpressionFactory[] facts,
QueryExpressions[] exps, Object[] params) { QueryExpressions[] exps, Object[] params) {
return executeBulkOperation(ex, base, metas, subclasses, facts, return executeBulkOperation(ex, base, metas, subclasses, facts, exps,
exps, params, exps[0].updates); params, exps[0].updates);
} }
private Number executeBulkOperation(Executor ex, ClassMetaData base, private Number executeBulkOperation(Executor ex, ClassMetaData base,
@ -430,15 +432,15 @@ public class JDBCStoreQuery
if (!isUpdate) { if (!isUpdate) {
// if there are any delete callbacks, we need to // if there are any delete callbacks, we need to
// execute in-memory so the callbacks are invoked // execute in-memory so the callbacks are invoked
LifecycleEventManager mgr = ctx.getStoreContext().getBroker(). LifecycleEventManager mgr = ctx.getStoreContext().getBroker()
getLifecycleEventManager(); .getLifecycleEventManager();
if (mgr.hasDeleteListeners(null, mappings[i])) if (mgr.hasDeleteListeners(null, mappings[i]))
return null; return null;
} }
} }
JDBCFetchConfiguration fetch = (JDBCFetchConfiguration) JDBCFetchConfiguration fetch = (JDBCFetchConfiguration) ctx
ctx.getFetchConfiguration(); .getFetchConfiguration();
DBDictionary dict = _store.getDBDictionary(); DBDictionary dict = _store.getDBDictionary();
SQLBuffer[] sql = new SQLBuffer[mappings.length]; SQLBuffer[] sql = new SQLBuffer[mappings.length];
@ -448,8 +450,8 @@ public class JDBCStoreQuery
jdbcFactory = (JDBCExpressionFactory) facts[i]; jdbcFactory = (JDBCExpressionFactory) facts[i];
JDBCFetchState fetchState = (JDBCFetchState) fetch.newFetchState(); JDBCFetchState fetchState = (JDBCFetchState) fetch.newFetchState();
sel = jdbcFactory.evaluate(this, fetchState, exps[i], params); sel = jdbcFactory.evaluate(this, fetchState, exps[i], params);
jdbcFactory.select(this, mappings[i], subclasses, sel, jdbcFactory.select(this, mappings[i], subclasses, sel, exps[i],
exps[i], params, fetchState, JDBCFetchConfiguration.EAGER_NONE); params, fetchState, JDBCFetchConfiguration.EAGER_NONE);
// specification of the "udpates" map indicates that this is // specification of the "udpates" map indicates that this is
// an update query; otherwise, this is a delete statement // an update query; otherwise, this is a delete statement
@ -487,8 +489,7 @@ public class JDBCStoreQuery
} }
} }
} }
} } catch (SQLException se) {
catch (SQLException se) {
throw SQLExceptions.getStore(se, ctx, _store.getDBDictionary()); throw SQLExceptions.getStore(se, ctx, _store.getDBDictionary());
} finally { } finally {
try { try {
@ -577,8 +578,8 @@ public class JDBCStoreQuery
ClassMetaData[] metas, boolean subclasses, ExpressionFactory[] facts, ClassMetaData[] metas, boolean subclasses, ExpressionFactory[] facts,
QueryExpressions[] exps, Object[] params, long startIdx, long endIdx) { QueryExpressions[] exps, Object[] params, long startIdx, long endIdx) {
ClassMapping[] mappings = (ClassMapping[]) metas; ClassMapping[] mappings = (ClassMapping[]) metas;
JDBCFetchConfiguration fetch = (JDBCFetchConfiguration) JDBCFetchConfiguration fetch = (JDBCFetchConfiguration) ctx
ctx.getFetchConfiguration(); .getFetchConfiguration();
JDBCFetchState fetchState = (JDBCFetchState) fetch.newFetchState(); JDBCFetchState fetchState = (JDBCFetchState) fetch.newFetchState();
if (exps[0].fetchPaths != null) { if (exps[0].fetchPaths != null) {
fetch.addFields(Arrays.asList(exps[0].fetchPaths)); fetch.addFields(Arrays.asList(exps[0].fetchPaths));
@ -589,8 +590,8 @@ public class JDBCStoreQuery
eager = Math.min(eager, JDBCFetchConfiguration.EAGER_JOIN); eager = Math.min(eager, JDBCFetchConfiguration.EAGER_JOIN);
int subclassMode = fetch.getSubclassFetchMode((ClassMapping) base); int subclassMode = fetch.getSubclassFetchMode((ClassMapping) base);
DBDictionary dict = _store.getDBDictionary(); DBDictionary dict = _store.getDBDictionary();
long start = (mappings.length == 1 && dict.supportsSelectStartIndex) long start = (mappings.length == 1 && dict.supportsSelectStartIndex) ? startIdx
? startIdx : 0L; : 0L;
long end = (dict.supportsSelectEndIndex) ? endIdx : Long.MAX_VALUE; long end = (dict.supportsSelectEndIndex) ? endIdx : Long.MAX_VALUE;
// add selects with populate WHERE conditions to list // add selects with populate WHERE conditions to list
@ -599,20 +600,19 @@ public class JDBCStoreQuery
BitSet subclassBits = new BitSet(); BitSet subclassBits = new BitSet();
BitSet nextBits = new BitSet(); BitSet nextBits = new BitSet();
boolean unionable = createWhereSelects(sels, mappings, selMappings, boolean unionable = createWhereSelects(sels, mappings, selMappings,
subclasses, subclassBits, nextBits, facts, exps, params, fetchState, subclasses, subclassBits, nextBits, facts, exps, params,
subclassMode) fetchState, subclassMode)
&& subclassMode == JDBCFetchConfiguration.EAGER_JOIN; && subclassMode == JDBCFetchConfiguration.EAGER_JOIN;
if (sels.size() > 1) if (sels.size() > 1)
start = 0L; start = 0L;
if (unionable) { if (unionable) {
Union union = _store.getSQLFactory().newUnion((Select[]) Union union = _store.getSQLFactory().newUnion(
sels.toArray(new Select[sels.size()])); (Select[]) sels.toArray(new Select[sels.size()]));
populateUnion(union, mappings, subclasses, facts, exps, params, populateUnion(union, mappings, subclasses, facts, exps, params,
fetchState, false, eager, start, end); fetchState, false, eager, start, end);
if (union.isUnion()) if (union.isUnion())
return new String[]{ union.toSelect(false, fetch). return new String[] { union.toSelect(false, fetch).getSQL(true) };
getSQL(true) };
sels = Arrays.asList(union.getSelects()); sels = Arrays.asList(union.getSelects());
} else { } else {
Select sel; Select sel;
@ -628,8 +628,7 @@ public class JDBCStoreQuery
String[] sql = new String[sels.size()]; String[] sql = new String[sels.size()];
for (int i = 0; i < sels.size(); i++) for (int i = 0; i < sels.size(); i++)
sql[i] = ((Select) sels.get(i)).toSelect(false, fetch). sql[i] = ((Select) sels.get(i)).toSelect(false, fetch).getSQL(true);
getSQL(true);
return sql; return sql;
} }
} }

View File

@ -40,8 +40,8 @@ import org.apache.openjpa.util.OptimisticException;
class PreparedStatementManagerImpl class PreparedStatementManagerImpl
implements PreparedStatementManager { implements PreparedStatementManager {
private final static Localizer _loc = Localizer.forPackage private final static Localizer _loc = Localizer
(PreparedStatementManagerImpl.class); .forPackage(PreparedStatementManagerImpl.class);
private final JDBCStore _store; private final JDBCStore _store;
private final Connection _conn; private final Connection _conn;
@ -76,8 +76,7 @@ class PreparedStatementManagerImpl
/** /**
* Flush the given row. * Flush the given row.
*/ */
private void flushInternal(RowImpl row) private void flushInternal(RowImpl row) throws SQLException {
throws SQLException {
// can't batch rows with auto-inc columns // can't batch rows with auto-inc columns
Column[] autoAssign = null; Column[] autoAssign = null;
if (row.getAction() == Row.ACTION_INSERT) if (row.getAction() == Row.ACTION_INSERT)
@ -96,12 +95,11 @@ class PreparedStatementManagerImpl
if (failed != null) if (failed != null)
_exceptions.add(new OptimisticException(failed)); _exceptions.add(new OptimisticException(failed));
else if (row.getAction() == Row.ACTION_INSERT) else if (row.getAction() == Row.ACTION_INSERT)
throw new SQLException(_loc.get throw new SQLException(_loc.get(
("update-failed-no-failed-obj", String.valueOf(count), "update-failed-no-failed-obj", String.valueOf(count),
sql)); sql));
} }
} } catch (SQLException se) {
catch (SQLException se) {
throw SQLExceptions.getStore(se, row.getFailedObject(), _dict); throw SQLExceptions.getStore(se, row.getFailedObject(), _dict);
} finally { } finally {
try { try {
@ -118,8 +116,8 @@ class PreparedStatementManagerImpl
Object val; Object val;
for (int i = 0; i < autoAssign.length; i++) { for (int i = 0; i < autoAssign.length; i++) {
val = _dict.getGeneratedKey(autoAssign[i], _conn); val = _dict.getGeneratedKey(autoAssign[i], _conn);
mapping.assertJoinable(autoAssign[i]).setAutoAssignedValue mapping.assertJoinable(autoAssign[i]).setAutoAssignedValue(sm,
(sm, _store, autoAssign[i], val); _store, autoAssign[i], val);
} }
} }
} }

View File

@ -166,8 +166,7 @@ public abstract class AbstractTestCase extends TestCase {
_watchdog.enteringTest(this); _watchdog.enteringTest(this);
try { try {
super.run(result); super.run(result);
} } finally {
finally {
_watchdog.leavingTest(this); _watchdog.leavingTest(this);
} }
} }
@ -530,8 +529,7 @@ public abstract class AbstractTestCase extends TestCase {
meth.invoke(thiz, args); meth.invoke(thiz, args);
} }
}); });
} } finally {
finally {
multiThreadExecuting = null; multiThreadExecuting = null;
} }
} }
@ -806,8 +804,7 @@ public abstract class AbstractTestCase extends TestCase {
method.invoke(thz, (Object[]) null); method.invoke(thz, (Object[]) null);
} catch (Throwable t) { } catch (Throwable t) {
throwable = t; throwable = t;
} } finally {
finally {
completed = true; completed = true;
} }
} }
@ -846,8 +843,7 @@ public abstract class AbstractTestCase extends TestCase {
// I guess everything was OK // I guess everything was OK
return true; return true;
} } finally {
finally {
inTimeoutThread = false; inTimeoutThread = false;
} }
} }

View File

@ -1074,8 +1074,7 @@ public class XMLPersistenceMetaDataParser
member = meta.getDescribedType().getDeclaredField(name); member = meta.getDescribedType().getDeclaredField(name);
type = ((Field) member).getType(); type = ((Field) member).getType();
} }
} } catch (Exception e) {
catch (Exception e) {
throw getException(_loc.get("invalid-attr", name, meta), e); throw getException(_loc.get("invalid-attr", name, meta), e);
} }