OPENJPA-511

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@619471 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2008-02-07 16:01:06 +00:00
parent 321ede95ee
commit 0033a6b3d9
3 changed files with 33 additions and 3 deletions

View File

@ -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");
}

View File

@ -148,6 +148,8 @@ public class DB2Dictionary
}));
super.setBatchLimit(defaultBatchLimit);
selectWordSet.add("WITH");
}
public boolean supportsRandomAccessResultSet(Select sel,

View File

@ -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;
}
}