Implement query hints as suggested by bug 306
http://helma.org/bugs/show_bug.cgi?id=306
This commit is contained in:
parent
ae56944420
commit
6f213b481c
3 changed files with 33 additions and 11 deletions
|
@ -903,20 +903,28 @@ public final class DbMapping implements Updatable {
|
||||||
* Get a StringBuffer initialized to the first part of the select statement
|
* Get a StringBuffer initialized to the first part of the select statement
|
||||||
* for objects defined by this DbMapping
|
* for objects defined by this DbMapping
|
||||||
*
|
*
|
||||||
|
* @param rel the Relation we use to select. Currently only used for optimizer hints.
|
||||||
|
* Is null if selecting by primary key.
|
||||||
* @return the StringBuffer containing the first part of the select query
|
* @return the StringBuffer containing the first part of the select query
|
||||||
*
|
*
|
||||||
* @throws SQLException if the table meta data could not be retrieved
|
* @throws SQLException if the table meta data could not be retrieved
|
||||||
* @throws ClassNotFoundException if the JDBC driver class was not found
|
* @throws ClassNotFoundException if the JDBC driver class was not found
|
||||||
*/
|
*/
|
||||||
public StringBuffer getSelect() throws SQLException, ClassNotFoundException {
|
public StringBuffer getSelect(Relation rel) throws SQLException, ClassNotFoundException {
|
||||||
|
// assign to local variable first so we are thread safe
|
||||||
|
// (selectString may be reset by other threads)
|
||||||
String sel = selectString;
|
String sel = selectString;
|
||||||
|
|
||||||
if (sel != null) {
|
if (rel == null && sel != null) {
|
||||||
return new StringBuffer(sel);
|
return new StringBuffer(sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuffer s = new StringBuffer("SELECT ");
|
StringBuffer s = new StringBuffer("SELECT ");
|
||||||
|
|
||||||
|
if (rel != null && rel.queryHints != null) {
|
||||||
|
s.append(rel.queryHints).append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
String table = getTableName();
|
String table = getTableName();
|
||||||
|
|
||||||
// all columns from the main table
|
// all columns from the main table
|
||||||
|
@ -951,8 +959,11 @@ public final class DbMapping implements Updatable {
|
||||||
joins[i].renderJoinConstraints(s);
|
joins[i].renderJoinConstraints(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cache rendered string for later calls.
|
// cache rendered string for later calls, but only if it wasn't
|
||||||
selectString = s.toString();
|
// built for a particular Relation
|
||||||
|
if (rel == null) {
|
||||||
|
selectString = s.toString();
|
||||||
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -994,9 +994,15 @@ public final class NodeManager {
|
||||||
tables.append(',').append(rel.additionalTables);
|
tables.append(',').append(rel.additionalTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuffer b = new StringBuffer("SELECT ").append(table).append('.')
|
StringBuffer b = new StringBuffer("SELECT ");
|
||||||
.append(idfield).append(" FROM ")
|
|
||||||
.append(tables);
|
if (rel != null && rel.queryHints != null) {
|
||||||
|
b.append(rel.queryHints).append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
b.append(table).append('.')
|
||||||
|
.append(idfield).append(" FROM ")
|
||||||
|
.append(tables);
|
||||||
|
|
||||||
if (home.getSubnodeRelation() != null) {
|
if (home.getSubnodeRelation() != null) {
|
||||||
// subnode relation was explicitly set
|
// subnode relation was explicitly set
|
||||||
|
@ -1089,7 +1095,7 @@ public final class NodeManager {
|
||||||
Statement stmt = con.createStatement();
|
Statement stmt = con.createStatement();
|
||||||
DbColumn[] columns = dbm.getColumns();
|
DbColumn[] columns = dbm.getColumns();
|
||||||
Relation[] joins = dbm.getJoins();
|
Relation[] joins = dbm.getJoins();
|
||||||
StringBuffer q = dbm.getSelect();
|
StringBuffer q = dbm.getSelect(rel);
|
||||||
|
|
||||||
if (rel.additionalTables != null) {
|
if (rel.additionalTables != null) {
|
||||||
q.append(',').append(rel.additionalTables);
|
q.append(',').append(rel.additionalTables);
|
||||||
|
@ -1171,7 +1177,7 @@ public final class NodeManager {
|
||||||
Statement stmt = con.createStatement();
|
Statement stmt = con.createStatement();
|
||||||
DbColumn[] columns = dbm.getColumns();
|
DbColumn[] columns = dbm.getColumns();
|
||||||
Relation[] joins = dbm.getJoins();
|
Relation[] joins = dbm.getJoins();
|
||||||
StringBuffer q = dbm.getSelect();
|
StringBuffer q = dbm.getSelect(rel);
|
||||||
|
|
||||||
if (rel.additionalTables != null) {
|
if (rel.additionalTables != null) {
|
||||||
q.append(',').append(rel.additionalTables);
|
q.append(',').append(rel.additionalTables);
|
||||||
|
@ -1498,7 +1504,7 @@ public final class NodeManager {
|
||||||
|
|
||||||
DbColumn[] columns = dbm.getColumns();
|
DbColumn[] columns = dbm.getColumns();
|
||||||
Relation[] joins = dbm.getJoins();
|
Relation[] joins = dbm.getJoins();
|
||||||
StringBuffer q = dbm.getSelect().append("WHERE ")
|
StringBuffer q = dbm.getSelect(null).append("WHERE ")
|
||||||
.append(dbm.getTableName())
|
.append(dbm.getTableName())
|
||||||
.append(".")
|
.append(".")
|
||||||
.append(idfield)
|
.append(idfield)
|
||||||
|
@ -1582,7 +1588,7 @@ public final class NodeManager {
|
||||||
Connection con = dbm.getConnection();
|
Connection con = dbm.getConnection();
|
||||||
DbColumn[] columns = dbm.getColumns();
|
DbColumn[] columns = dbm.getColumns();
|
||||||
Relation[] joins = dbm.getJoins();
|
Relation[] joins = dbm.getJoins();
|
||||||
StringBuffer q = dbm.getSelect();
|
StringBuffer q = dbm.getSelect(rel);
|
||||||
|
|
||||||
if (rel.additionalTables != null) {
|
if (rel.additionalTables != null) {
|
||||||
q.append(',').append(rel.additionalTables);
|
q.append(',').append(rel.additionalTables);
|
||||||
|
|
|
@ -93,6 +93,7 @@ public final class Relation {
|
||||||
String groupbyPrototype;
|
String groupbyPrototype;
|
||||||
String filter;
|
String filter;
|
||||||
String additionalTables;
|
String additionalTables;
|
||||||
|
String queryHints;
|
||||||
Vector filterFragments;
|
Vector filterFragments;
|
||||||
Vector filterPropertyRefs;
|
Vector filterPropertyRefs;
|
||||||
int maxSize = 0;
|
int maxSize = 0;
|
||||||
|
@ -114,6 +115,7 @@ public final class Relation {
|
||||||
this.filterFragments = rel.filterFragments;
|
this.filterFragments = rel.filterFragments;
|
||||||
this.filterPropertyRefs = rel.filterPropertyRefs;
|
this.filterPropertyRefs = rel.filterPropertyRefs;
|
||||||
this.additionalTables = rel.additionalTables;
|
this.additionalTables = rel.additionalTables;
|
||||||
|
this.queryHints = rel.queryHints;
|
||||||
this.maxSize = rel.maxSize;
|
this.maxSize = rel.maxSize;
|
||||||
this.constraints = rel.constraints;
|
this.constraints = rel.constraints;
|
||||||
this.accessName = rel.accessName;
|
this.accessName = rel.accessName;
|
||||||
|
@ -292,6 +294,9 @@ public final class Relation {
|
||||||
additionalTables = null;
|
additionalTables = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get query hints
|
||||||
|
queryHints = props.getProperty(propName + ".hints");
|
||||||
|
|
||||||
// get max size of collection
|
// get max size of collection
|
||||||
String max = props.getProperty(propName + ".maxSize");
|
String max = props.getProperty(propName + ".maxSize");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue