mirror of https://github.com/apache/openjpa.git
fixing indentation and few changes suggested by Abe for OpenJPA patch-168
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@523071 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f7aef45814
commit
fee930886b
|
@ -48,6 +48,7 @@ import org.apache.openjpa.jdbc.sql.Select;
|
|||
import org.apache.openjpa.jdbc.sql.Union;
|
||||
import org.apache.openjpa.kernel.ExpressionStoreQuery;
|
||||
import org.apache.openjpa.kernel.OrderingMergedResultObjectProvider;
|
||||
import org.apache.openjpa.kernel.QueryHints;
|
||||
import org.apache.openjpa.kernel.exps.ExpressionFactory;
|
||||
import org.apache.openjpa.kernel.exps.ExpressionParser;
|
||||
import org.apache.openjpa.kernel.exps.FilterListener;
|
||||
|
@ -319,20 +320,19 @@ public class JDBCStoreQuery
|
|||
subclassMode);
|
||||
if (verts.length == 1 && subclasses)
|
||||
subclassBits.set(sels.size());
|
||||
|
||||
// create criteria select and clone for each vert mapping
|
||||
sel = ((JDBCExpressionFactory) facts[i]).getSelectConstructor().
|
||||
evaluate(ctx, null, null, exps[i], states[i]);
|
||||
//it means it is coming from getSingleResult so set the
|
||||
// It means it is coming from getSingleResult so set the
|
||||
// expectedResultCount to 1.force = true indicates that this is
|
||||
// internally generated value
|
||||
if (this.ctx.isUnique())
|
||||
sel.setExpectedResultCount(1,true);
|
||||
//it means this is coming from getResultList so set the
|
||||
// It means this is coming from getResultList so set the
|
||||
// expectedResultCount based on any optimize hint if provided
|
||||
else {
|
||||
if ((optHint = ctx.fetch.getHint
|
||||
(this.optimizeHint))!= null)
|
||||
(QueryHints.HINT_RESULT_COUNT))!= null)
|
||||
sel.setExpectedResultCount
|
||||
(((Integer)optHint).intValue(),false);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.apache.openjpa.jdbc.schema.Sequence;
|
|||
*/
|
||||
public class DB2Dictionary
|
||||
extends AbstractDB2Dictionary {
|
||||
|
||||
// variables to support optimize clause
|
||||
public String optimizeClause = "optimize for";
|
||||
public String rowClause = "row";
|
||||
|
@ -197,13 +196,14 @@ public class DB2Dictionary
|
|||
}
|
||||
}
|
||||
}
|
||||
//based on the expectedResultCount of the select create the optimize
|
||||
//for clause
|
||||
|
||||
/** Based on the expectedResultCount of the select create the optimize
|
||||
* for clause
|
||||
*/
|
||||
public String getOptimizeClause(JDBCFetchConfiguration fetch,
|
||||
int expectedResultCount) {
|
||||
Integer rows = null;
|
||||
StringBuffer optimizeString = new StringBuffer();
|
||||
|
||||
if (expectedResultCount != 0)
|
||||
optimizeString.append(" ").append(optimizeClause).append(" ")
|
||||
.append(expectedResultCount).append(" ")
|
||||
|
@ -211,36 +211,32 @@ public class DB2Dictionary
|
|||
return optimizeString.toString();
|
||||
}
|
||||
|
||||
//override the DBDictionary toSelect to call getOptimizeClause and append
|
||||
//to the select string
|
||||
/** Override the DBDictionary toSelect to call getOptimizeClause and append
|
||||
* to the select string
|
||||
*/
|
||||
public SQLBuffer toSelect(SQLBuffer selects, JDBCFetchConfiguration fetch,
|
||||
SQLBuffer from, SQLBuffer where, SQLBuffer group,
|
||||
SQLBuffer having, SQLBuffer order,
|
||||
boolean distinct, boolean forUpdate, long start, long end,
|
||||
int expectedResultCount) {
|
||||
|
||||
String optimizeString = null;
|
||||
SQLBuffer selString = toOperation(getSelectOperation(fetch),
|
||||
selects, from, where,
|
||||
group, having, order, distinct,
|
||||
forUpdate, start, end);
|
||||
//return toOperation(getSelectOperation(fetch), selects, from, where,
|
||||
//group, having, order, distinct, forUpdate, start, end);
|
||||
|
||||
if (fetch != null)
|
||||
optimizeString = getOptimizeClause(fetch, expectedResultCount);
|
||||
if (optimizeString != null && optimizeString.length() > 0)
|
||||
selString.append(optimizeString);
|
||||
|
||||
return selString;
|
||||
|
||||
}
|
||||
//override the DBDictionary toSelect to pass expectedResultcount to the
|
||||
//other toSelect method
|
||||
|
||||
/** Override the DBDictionary toSelect to pass expectedResultcount to the
|
||||
* other toSelect method
|
||||
*/
|
||||
public SQLBuffer toSelect(Select sel, boolean forUpdate,
|
||||
JDBCFetchConfiguration fetch) {
|
||||
sel.addJoinClassConditions();
|
||||
|
||||
boolean update = forUpdate && sel.getFromSelect() == null;
|
||||
SQLBuffer select = getSelects(sel, false, update);
|
||||
SQLBuffer ordering = null;
|
||||
|
@ -257,5 +253,4 @@ public class DB2Dictionary
|
|||
sel.getStartIndex(),
|
||||
sel.getEndIndex(),sel.getExpectedResultCount());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,11 +47,7 @@ public class LogicalUnion
|
|||
|
||||
private static final Localizer _loc = Localizer.forPackage
|
||||
(LogicalUnion.class);
|
||||
//expected number of results for this select to be used in
|
||||
// optimize for clause
|
||||
protected int expectedResultCount = 0;
|
||||
//indicate if this is internally generated result count
|
||||
//or not
|
||||
protected boolean force = false;
|
||||
protected final UnionSelect[] sels;
|
||||
protected final DBDictionary dict;
|
||||
|
@ -215,8 +211,9 @@ public class LogicalUnion
|
|||
if (this.getExpectedResultCount()== 1) {
|
||||
AbstractResult res;
|
||||
for (int i = 0; i < sels.length; i++) {
|
||||
//for each select set the expected result count to 1
|
||||
//and force true indicating that this internally generated value
|
||||
// For each select set the expected result count to 1
|
||||
// and force true indicating that this internally generated
|
||||
// value
|
||||
sels[i].sel.setExpectedResultCount(1,true);
|
||||
res = (AbstractResult) sels[i].execute(store, fetch,
|
||||
lockLevel);
|
||||
|
@ -305,10 +302,7 @@ public class LogicalUnion
|
|||
protected final int pos;
|
||||
protected int orders = 0;
|
||||
protected List orderIdxs = null;
|
||||
// expected number of results for this select to be used in
|
||||
// optimize for clause
|
||||
protected int expectedResultCount = 0;
|
||||
//force indicates it is internally generated result count or not
|
||||
protected boolean force = false;
|
||||
|
||||
public UnionSelect(SelectImpl sel, int pos) {
|
||||
|
@ -848,10 +842,12 @@ public class LogicalUnion
|
|||
return expectedResultCount;
|
||||
}
|
||||
|
||||
public void setExpectedResultCount(int expectedResultCount, boolean force) {
|
||||
public void setExpectedResultCount(int expectedResultCount,
|
||||
boolean force) {
|
||||
this.expectedResultCount = expectedResultCount;
|
||||
this.force = force;
|
||||
}
|
||||
|
||||
public boolean isExpRsltCntForced() {
|
||||
return force;
|
||||
}
|
||||
|
@ -940,10 +936,12 @@ public class LogicalUnion
|
|||
return expectedResultCount;
|
||||
}
|
||||
|
||||
public void setExpectedResultCount(int expectedResultCount,boolean force) {
|
||||
public void setExpectedResultCount(int expectedResultCount,
|
||||
boolean force) {
|
||||
this.expectedResultCount = expectedResultCount;
|
||||
this.force = force;
|
||||
}
|
||||
|
||||
public boolean isExpRsltCntForced() {
|
||||
return force;
|
||||
}
|
||||
|
|
|
@ -130,12 +130,10 @@ public interface SelectExecutor {
|
|||
* force indicates whether the count is internally generated
|
||||
* or given by the user as optimize hint
|
||||
*/
|
||||
|
||||
public void setExpectedResultCount(int expectedResultCount,boolean force) ;
|
||||
|
||||
/**
|
||||
* Indicates whether the expectedResultCount is internally generated
|
||||
*/
|
||||
|
||||
public boolean isExpRsltCntForced();
|
||||
}
|
||||
|
|
|
@ -154,11 +154,7 @@ public class SelectImpl
|
|||
private SelectImpl _from = null;
|
||||
private SelectImpl _outer = null;
|
||||
|
||||
//expected number of results for this select to be used in
|
||||
// optimize for clause
|
||||
private int expectedResultCount = 0;
|
||||
//true if the expectedResultCount is internally set false if
|
||||
//it is set by the user
|
||||
private boolean force = false;
|
||||
|
||||
/**
|
||||
|
@ -312,12 +308,12 @@ public class SelectImpl
|
|||
throws SQLException {
|
||||
boolean forUpdate = false;
|
||||
|
||||
//expectedResultCount = 1 and force means that it is internally generated value
|
||||
//for getSingleResult,single valued relationship.We need to check if
|
||||
//there are any eager joins in the select if there are then the
|
||||
//optimize for 1 row clause is not generated else we do. if
|
||||
//!force then it is set by the user through hint and we
|
||||
//do not check the eager joins
|
||||
// ExpectedResultCount = 1 and force means that it is internally
|
||||
// generated value for getSingleResult,single valued relationship.
|
||||
// We need to check if there are any eager joins in the select if
|
||||
// there are then the optimize for 1 row clause is not generated
|
||||
// else we do. if !force then it is set by the user through hint
|
||||
// and we do not check the eager joins
|
||||
if (this.expectedResultCount == 1 && force ) {
|
||||
if (this.hasEagerJoin(true))
|
||||
this.setExpectedResultCount(0,false);
|
||||
|
@ -2825,7 +2821,8 @@ public class SelectImpl
|
|||
return expectedResultCount;
|
||||
}
|
||||
|
||||
public void setExpectedResultCount(int expectedResultCount, boolean force) {
|
||||
public void setExpectedResultCount(int expectedResultCount,
|
||||
boolean force) {
|
||||
this.expectedResultCount = expectedResultCount;
|
||||
this.force = force;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ public abstract class AbstractStoreQuery
|
|||
implements StoreQuery {
|
||||
|
||||
protected QueryContext ctx = null;
|
||||
public static final String optimizeHint ="openjpa.hint.OptimizeResultCount";
|
||||
|
||||
public QueryContext getContext() {
|
||||
return ctx;
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright 2006 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.kernel;
|
||||
|
||||
public interface QueryHints {
|
||||
|
||||
/** Hint to specify the number of rows for the optimize
|
||||
* clause for DB2
|
||||
*/
|
||||
public static final String HINT_RESULT_COUNT =
|
||||
"openjpa.hint.OptimizeResultCount";
|
||||
}
|
|
@ -24,6 +24,7 @@ import javax.persistence.Query;
|
|||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.apache.openjpa.kernel.QueryFlushModes;
|
||||
import org.apache.openjpa.kernel.QueryHints;
|
||||
import org.apache.openjpa.kernel.QueryOperations;
|
||||
import org.apache.openjpa.kernel.exps.AggregateListener;
|
||||
import org.apache.openjpa.kernel.exps.FilterListener;
|
||||
|
@ -36,7 +37,7 @@ import org.apache.openjpa.kernel.exps.FilterListener;
|
|||
* @published
|
||||
*/
|
||||
public interface OpenJPAQuery
|
||||
extends Query, QueryOperations, QueryFlushModes {
|
||||
extends Query, QueryOperations, QueryFlushModes, QueryHints {
|
||||
|
||||
/**
|
||||
* The owning entity manage.
|
||||
|
|
|
@ -285,7 +285,6 @@ public class QueryImpl
|
|||
try {
|
||||
Object ob = execute();
|
||||
return ob;
|
||||
|
||||
} finally {
|
||||
_query.setUnique(false);
|
||||
}
|
||||
|
@ -370,7 +369,8 @@ public class QueryImpl
|
|||
if ("hint.OptimizeResultCount".equals(k)) {
|
||||
if ((!(value instanceof String)&&! (value instanceof Integer))
|
||||
|| (value instanceof String &&(Integer.parseInt
|
||||
((String)value)< 0))||((value instanceof Integer)
|
||||
((String)value)< 0))||
|
||||
((value instanceof Integer)
|
||||
&& (((Integer)value).intValue()<0)))
|
||||
throw new ArgumentException(_loc.get
|
||||
("bad-hint-value", key),
|
||||
|
@ -384,7 +384,8 @@ public class QueryImpl
|
|||
throw new ArgumentException(_loc.get("bad-query-hint", key),
|
||||
null, null, false);
|
||||
return this;
|
||||
}catch(NumberFormatException e1){
|
||||
}
|
||||
catch (NumberFormatException e1) {
|
||||
throw new ArgumentException(_loc.get("bad-hint-value", key),
|
||||
null, null, false);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue