mirror of https://github.com/apache/openjpa.git
OPENJPA-511
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@619471 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
321ede95ee
commit
0033a6b3d9
|
@ -184,8 +184,7 @@ public class SQLStoreQuery
|
|||
String sql = StringUtils.trimToNull(ctx.getQueryString());
|
||||
if (sql == null)
|
||||
throw new UserException(_loc.get("no-sql"));
|
||||
_select = sql.length() > 6
|
||||
&& sql.substring(0, 6).equalsIgnoreCase("select");
|
||||
_select = q.getStore().getDBDictionary().isSelect(sql);
|
||||
_call = sql.length() > 4
|
||||
&& sql.substring(0, 4).equalsIgnoreCase("call");
|
||||
}
|
||||
|
|
|
@ -148,6 +148,8 @@ public class DB2Dictionary
|
|||
}));
|
||||
|
||||
super.setBatchLimit(defaultBatchLimit);
|
||||
|
||||
selectWordSet.add("WITH");
|
||||
}
|
||||
|
||||
public boolean supportsRandomAccessResultSet(Select sel,
|
||||
|
|
|
@ -330,6 +330,12 @@ public class DBDictionary
|
|||
protected final Set fixedSizeTypeNameSet = new HashSet();
|
||||
protected final Set typeModifierSet = new HashSet();
|
||||
|
||||
/**
|
||||
* If a native query begins with any of the values found here then it will
|
||||
* be treated as a select statement.
|
||||
*/
|
||||
protected final Set selectWordSet = new HashSet();
|
||||
|
||||
// when we store values that lose precion, track the types so that the
|
||||
// first time it happens we can warn the user
|
||||
private Set _precisionWarnedTypes = null;
|
||||
|
@ -352,6 +358,8 @@ public class DBDictionary
|
|||
"OTHER", "REAL", "REF", "SMALLINT", "STRUCT", "TIME", "TIMESTAMP",
|
||||
"TINYINT",
|
||||
}));
|
||||
|
||||
selectWordSet.add("SELECT");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4324,5 +4332,26 @@ public class DBDictionary
|
|||
protected void calculateValue(Val val, Select sel, ExpContext ctx,
|
||||
ExpState state, Path path, ExpState pathState) {
|
||||
val.calculateValue(sel, ctx, state, (Val) path, pathState);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the provided <code>sql</code> may be treated as a
|
||||
* select statement on this database.
|
||||
*
|
||||
* @param sql A sql statement.
|
||||
*
|
||||
* @return true if <code>sql</code> represents a select statement.
|
||||
*/
|
||||
public boolean isSelect(String sql) {
|
||||
Iterator i = selectWordSet.iterator();
|
||||
String cur;
|
||||
while (i.hasNext()) {
|
||||
cur = (String) i.next();
|
||||
if (sql.length() >= cur.length()
|
||||
&& sql.substring(0, cur.length()).equalsIgnoreCase(cur)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue