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
|
@ -370,9 +370,9 @@ public class JDBCStoreManager
|
|||
JDBCFetchConfiguration.EAGER_JOIN, true, false))
|
||||
return null;
|
||||
sel.wherePrimaryKey(sm.getObjectId(), mapping, this);
|
||||
//Set the expectedResultCount for the select as 1 as a single
|
||||
//object is being loaded. force = true is an indicator that it is
|
||||
//internally generated value
|
||||
// Set the expectedResultCount for the select as 1 as a single
|
||||
// object is being loaded. force = true is an indicator that it is
|
||||
// internally generated value
|
||||
sel.setExpectedResultCount(1,true);
|
||||
return sel.execute(this, fetch);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
//expectedResultCount to 1.force = true indicates that this is
|
||||
//internally generated value
|
||||
if(this.ctx.isUnique())
|
||||
// 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
|
||||
//expectedResultCount based on any optimize hint if provided
|
||||
else{
|
||||
if((optHint = ctx.fetch.getHint
|
||||
(this.optimizeHint))!= null)
|
||||
// It means this is coming from getResultList so set the
|
||||
// expectedResultCount based on any optimize hint if provided
|
||||
else {
|
||||
if ((optHint = ctx.fetch.getHint
|
||||
(QueryHints.HINT_RESULT_COUNT))!= null)
|
||||
sel.setExpectedResultCount
|
||||
(((Integer)optHint).intValue(),false);
|
||||
}
|
||||
|
|
|
@ -28,8 +28,7 @@ import org.apache.openjpa.jdbc.schema.Sequence;
|
|||
*/
|
||||
public class DB2Dictionary
|
||||
extends AbstractDB2Dictionary {
|
||||
|
||||
//variables to support optimize clause
|
||||
// variables to support optimize clause
|
||||
public String optimizeClause = "optimize for";
|
||||
public String rowClause = "row";
|
||||
public DB2Dictionary() {
|
||||
|
@ -197,50 +196,47 @@ 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)
|
||||
if (expectedResultCount != 0)
|
||||
optimizeString.append(" ").append(optimizeClause).append(" ")
|
||||
.append(expectedResultCount).append(" ")
|
||||
.append(rowClause).append(" ");
|
||||
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)
|
||||
if (fetch != null)
|
||||
optimizeString = getOptimizeClause(fetch, expectedResultCount);
|
||||
if(optimizeString != null && optimizeString.length() > 0)
|
||||
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,14 +308,14 @@ 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
|
||||
if(this.expectedResultCount == 1 && force ){
|
||||
if(this.hasEagerJoin(true))
|
||||
// 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);
|
||||
else
|
||||
this.setExpectedResultCount(1,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";
|
||||
}
|
|
@ -1290,7 +1290,7 @@ public class QueryImpl
|
|||
return Arrays.asList(new Object[]{ single });
|
||||
}
|
||||
|
||||
if(single == null)
|
||||
if (single == null)
|
||||
throw new InvalidStateException(_loc.get("is-null",
|
||||
_class, _query));
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -279,13 +279,12 @@ public class QueryImpl
|
|||
*/
|
||||
public Object getSingleResult() {
|
||||
_em.assertNotCloseInvoked();
|
||||
//Indicate that this query returns single result.Later copied into
|
||||
//select.expectedResultCount
|
||||
// Indicate that this query returns single result.Later copied into
|
||||
// select.expectedResultCount
|
||||
_query.setUnique(true);
|
||||
try{
|
||||
try {
|
||||
Object ob = execute();
|
||||
return ob;
|
||||
|
||||
} finally {
|
||||
_query.setUnique(false);
|
||||
}
|
||||
|
@ -366,16 +365,17 @@ public class QueryImpl
|
|||
} else if (k.startsWith("FetchPlan.")) {
|
||||
k = k.substring("FetchPlan.".length());
|
||||
Filters.hintToSetter(getFetchPlan(), k, value);
|
||||
} else if (k.startsWith("hint.")){
|
||||
if("hint.OptimizeResultCount".equals(k)){
|
||||
if((!(value instanceof String)&&!(value instanceof Integer))
|
||||
} else if (k.startsWith("hint.")) {
|
||||
if ("hint.OptimizeResultCount".equals(k)) {
|
||||
if ((!(value instanceof String)&&! (value instanceof Integer))
|
||||
|| (value instanceof String &&(Integer.parseInt
|
||||
((String)value)< 0))||((value instanceof Integer)
|
||||
&& (((Integer)value).intValue()<0)) )
|
||||
((String)value)< 0))||
|
||||
((value instanceof Integer)
|
||||
&& (((Integer)value).intValue()<0)))
|
||||
throw new ArgumentException(_loc.get
|
||||
("bad-hint-value", key),
|
||||
null, null, false);
|
||||
if(value instanceof String)
|
||||
if (value instanceof String)
|
||||
value = new Integer((String)value);
|
||||
}
|
||||
_query.getFetchConfiguration().setHint(key, value);
|
||||
|
@ -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