Author: tomdz Date: Tue Sep 20 06:45:34 2005 New Revision: 290453 URL: http://svn.apache.org/viewcvs?rev=290453&view=rev Log: Added query hints that allow to specify the tables that are queried via the Platform#query/#fetch methods
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaBean.java db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaClass.java db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaProperty.java db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java?rev=290453&r1=290452&r2=290453&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/Platform.java Tue Sep 20 06:45:34 2005 @@ -27,6 +27,7 @@ import org.apache.commons.beanutils.DynaBean; import org.apache.ddlutils.builder.SqlBuilder; import org.apache.ddlutils.model.Database; +import org.apache.ddlutils.model.Table; /** * A platform encapsulates the database-related functionality such as performing queries @@ -218,6 +219,15 @@ public void dropTables(Connection connection, Database model, boolean continueOnError) throws DynaSqlException; /** + * Performs the given SQL query returning an iterator over the results. + * + * @param model The database model to use + * @param sql The sql query to perform + * @return An iterator for the dyna beans resulting from the query + */ + public Iterator query(Database model, String sql) throws DynaSqlException; + + /** * Performs the given parameterized SQL query returning an iterator over the results. * * @param model The database model to use @@ -230,11 +240,23 @@ /** * Performs the given SQL query returning an iterator over the results. * - * @param model The database model to use - * @param sql The sql query to perform + * @param model The database model to use + * @param sql The sql query to perform + * @param queryHints The tables that are queried (optional) * @return An iterator for the dyna beans resulting from the query */ - public Iterator query(Database model, String sql) throws DynaSqlException; + public Iterator query(Database model, String sql, Table[] queryHints) throws DynaSqlException; + + /** + * Performs the given parameterized SQL query returning an iterator over the results. + * + * @param model The database model to use + * @param sql The sql query to perform + * @param parameters The query parameter values + * @param queryHints The tables that are queried (optional) + * @return An iterator for the dyna beans resulting from the query + */ + public Iterator query(Database model, String sql, Collection parameters, Table[] queryHints) throws DynaSqlException; /** * Queries for a list of dyna beans representing rows of the given query. @@ -261,6 +283,30 @@ /** * Queries for a list of dyna beans representing rows of the given query. * In contrast to the [EMAIL PROTECTED] #query(String)} method all beans will be + * materialized and the connection will be closed before returning the beans. + * + * @param model The database model to use + * @param sql The sql query + * @param queryHints The tables that are queried (optional) + * @return The dyna beans resulting from the query + */ + public List fetch(Database model, String sql, Table[] queryHints) throws DynaSqlException; + + /** + * Queries for a list of dyna beans representing rows of the given query. + * In contrast to the [EMAIL PROTECTED] #query(String, Collection)} method all beans will be + * materialized and the connection will be closed before returning the beans. + * + * @param sql The parameterized query + * @param parameters The parameter values + * @param queryHints The tables that are queried (optional) + * @return The dyna beans resulting from the query + */ + public List fetch(Database model, String sql, Collection parameters, Table[] queryHints) throws DynaSqlException; + + /** + * Queries for a list of dyna beans representing rows of the given query. + * In contrast to the [EMAIL PROTECTED] #query(String)} method all beans will be * materialized and the connection will be closed before returning the beans. * Also, the two int parameters specify which rows of the result set to use. * If there are more rows than desired, they will be ignored (and not read @@ -290,6 +336,41 @@ * @return The dyna beans resulting from the query */ public List fetch(Database model, String sql, Collection parameters, int start, int end) throws DynaSqlException; + + /** + * Queries for a list of dyna beans representing rows of the given query. + * In contrast to the [EMAIL PROTECTED] #query(String)} method all beans will be + * materialized and the connection will be closed before returning the beans. + * Also, the two int parameters specify which rows of the result set to use. + * If there are more rows than desired, they will be ignored (and not read + * from the database). + * + * @param model The database model to use + * @param sql The sql query + * @param queryHints The tables that are queried (optional) + * @param start Row number to start from (0 for first row) + * @param end Row number to stop at (inclusively; -1 for last row) + * @return The dyna beans resulting from the query + */ + public List fetch(Database model, String sql, Table[] queryHints, int start, int end) throws DynaSqlException; + + /** + * Queries for a list of dyna beans representing rows of the given query. + * In contrast to the [EMAIL PROTECTED] #query(String, Collection)} method all beans will be + * materialized and the connection will be closed before returning the beans. + * Also, the two int parameters specify which rows of the result set to use. + * If there are more rows than desired, they will be ignored (and not read + * from the database). + * + * @param model The database model to use + * @param sql The parameterized sql query + * @param parameters The parameter values + * @param queryHints The tables that are queried (optional) + * @param start Row number to start from (0 for first row) + * @param end Row number to stop at (inclusively; -1 for last row) + * @return The dyna beans resulting from the query + */ + public List fetch(Database model, String sql, Collection parameters, Table[] queryHints, int start, int end) throws DynaSqlException; /** * Stores the given bean in the database, inserting it if there is no primary key Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java?rev=290453&r1=290452&r2=290453&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java Tue Sep 20 06:45:34 2005 @@ -5,6 +5,7 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; +import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; @@ -48,10 +49,12 @@ * @param platformInfo The platform info * @param model The database model * @param resultSet The result set + * @param queryHints The tables that were queried in the query that produced the given result set + * (optional) * @param cleanUpAfterFinish Whether to close the statement and connection after finishing * the iteration, upon on exception, or when this iterator is garbage collected */ - public DynaSqlIterator(PlatformInfo platformInfo, Database model, ResultSet resultSet, boolean cleanUpAfterFinish) throws DynaSqlException + public DynaSqlIterator(PlatformInfo platformInfo, Database model, ResultSet resultSet, Table[] queryHints, boolean cleanUpAfterFinish) throws DynaSqlException { if (resultSet != null) { @@ -60,7 +63,7 @@ try { - initFromMetaData(platformInfo, model, resultSet); + initFromMetaData(platformInfo, model, resultSet, queryHints); } catch (SQLException ex) { @@ -80,33 +83,44 @@ * @param platformInfo The platform info * @param model The database model * @param resultSet The result set + * @param queryHints The tables that were queried in the query that produced the given result set */ - private void initFromMetaData(PlatformInfo platformInfo, Database model, ResultSet resultSet) throws SQLException + private void initFromMetaData(PlatformInfo platformInfo, Database model, ResultSet resultSet, Table[] queryHints) throws SQLException { - ResultSetMetaData metaData = resultSet.getMetaData(); - String tableName = null; - boolean singleKnownTable = true; - boolean caseSensitive = platformInfo.isCaseSensitive(); + ResultSetMetaData metaData = resultSet.getMetaData(); + String tableName = null; + boolean singleKnownTable = true; + boolean caseSensitive = platformInfo.isUseDelimitedIdentifiers(); + Map preparedQueryHints = prepareQueryHints(queryHints, caseSensitive); for (int idx = 1; idx <= metaData.getColumnCount(); idx++) { + String columnName = metaData.getColumnName(idx); String tableOfColumn = metaData.getTableName(idx); + Table table = null; if ((tableOfColumn != null) && (tableOfColumn.length() > 0)) { - if (tableName == null) - { - tableName = tableOfColumn; - } - else if (!tableName.equals(tableOfColumn)) - { - singleKnownTable = false; - } + // the JDBC driver gave us enough meta data info + table = model.findTable(tableOfColumn, caseSensitive); + } + else + { + // not enough info in the meta data of the result set, lets try the + // user-supplied query hints + table = (Table)preparedQueryHints.get(caseSensitive ? columnName : columnName.toLowerCase()); + tableOfColumn = (table == null ? null : table.getName()); + } + if (tableName == null) + { + tableName = tableOfColumn; + } + else if (!tableName.equals(tableOfColumn)) + { + singleKnownTable = false; } - Table table = model.findTable(tableOfColumn, caseSensitive); - String columnName = metaData.getColumnName(idx); - String propName = columnName; + String propName = columnName; if (table != null) { @@ -134,6 +148,36 @@ } _dynaClass = new BasicDynaClass("result", BasicDynaBean.class, props); } + } + + /** + * Prepares the query hints by extracting the column names and using them as keys + * into the resulting map pointing to the corresponding table. + * + * @param queryHints The query hints + * @return The column name -> table map + */ + private Map prepareQueryHints(Table[] queryHints, boolean caseSensitive) + { + Map result = new HashMap(); + + for (int tableIdx = 0; (queryHints != null) && (tableIdx < queryHints.length); tableIdx++) + { + for (int columnIdx = 0; columnIdx < queryHints[tableIdx].getColumnCount(); columnIdx++) + { + String columnName = queryHints[tableIdx].getColumn(columnIdx).getName(); + + if (caseSensitive) + { + columnName = columnName.toLowerCase(); + } + if (!result.containsKey(columnName)) + { + result.put(columnName, queryHints[tableIdx]); + } + } + } + return result; } /* (non-Javadoc) Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaBean.java URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaBean.java?rev=290453&r1=290452&r2=290453&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaBean.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaBean.java Tue Sep 20 06:45:34 2005 @@ -18,24 +18,52 @@ import org.apache.commons.beanutils.BasicDynaBean; import org.apache.commons.beanutils.DynaClass; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.apache.commons.beanutils.DynaProperty; /** * SqlDynaBean is a DynaBean which can be persisted as a single row in * a Database Table. * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Thomas Dudziak</a> * @version $Revision$ */ -public class SqlDynaBean extends BasicDynaBean { +public class SqlDynaBean extends BasicDynaBean +{ + /** Unique ID for serializaion purposes */ + private static final long serialVersionUID = -6946514447446174227L; - /** The Log to which logging calls will be made. */ - private static final Log log = LogFactory.getLog( SqlDynaBean.class ); - - public SqlDynaBean(DynaClass dynaClass) { + /** + * Creates a new dyna bean of the given class. + * + * @param dynaClass The dyna class + */ + public SqlDynaBean(DynaClass dynaClass) + { super(dynaClass); } - + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() + { + StringBuffer result = new StringBuffer(); + DynaClass type = getDynaClass(); + DynaProperty[] props = type.getDynaProperties(); + + result.append(type.getName()); + result.append(": "); + for (int idx = 0; idx < props.length; idx++) + { + if (idx > 0) + { + result.append(", "); + } + result.append(props[idx].getName()); + result.append(" = "); + result.append(get(props[idx].getName())); + } + return result.toString(); + } } Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaClass.java URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaClass.java?rev=290453&r1=290452&r2=290453&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaClass.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaClass.java Tue Sep 20 06:45:34 2005 @@ -21,8 +21,6 @@ import org.apache.commons.beanutils.BasicDynaClass; import org.apache.commons.beanutils.DynaProperty; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.ddlutils.model.Table; /** @@ -30,19 +28,27 @@ * Table in a Database. * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Thomas Dudziak</a> * @version $Revision$ */ -public class SqlDynaClass extends BasicDynaClass { - - /** The Log to which logging calls will be made. */ - private static final Log log = LogFactory.getLog( SqlDynaClass.class ); - - private Table table; - private SqlDynaProperty[] primaryKeys; - private SqlDynaProperty[] nonPrimaryKeyProperties; - - /** - * Creates a new SqlDynaClass instance from a Table model. +public class SqlDynaClass extends BasicDynaClass +{ + /** Unique ID for serializaion purposes */ + private static final long serialVersionUID = -5768155698352911245L; + + /** The table for which this dyna class is defined */ + private Table _table; + /** The primary key dyna properties */ + private SqlDynaProperty[] _primaryKeyProperties; + /** The non-primary key dyna properties */ + private SqlDynaProperty[] _nonPrimaryKeyProperties; + + /** + * Factory method for creating and initializing a new dyna class instance + * for the given table. + * + * @param table The table + * @return The dyna class for the table */ public static SqlDynaClass newInstance(Table table) { @@ -58,88 +64,109 @@ properties.toArray(array); return new SqlDynaClass(table, array); } - - public SqlDynaClass(Table table) { - super(table.getName(), SqlDynaBean.class); - this.table = table; - } - public SqlDynaClass(Table table, SqlDynaProperty[] properties) { + /** + * Creates a new dyna class instance for the given table that has the given properties. + * + * @param table The table + * @param properties The dyna properties + */ + public SqlDynaClass(Table table, SqlDynaProperty[] properties) + { super(table.getName(), SqlDynaBean.class, properties); - this.table = table; + _table = table; } /** - * @return the database Table this DynaClass maps to + * Returns the table for which this dyna class is defined. + * + * @return The table */ - public Table getTable() { - return table; + public Table getTable() + { + return _table; } // Helper methods //------------------------------------------------------------------------- /** - * @return the name of the table + * Returns the table name for which this dyna class is defined. + * + * @return The table name */ - public String getTableName() { + public String getTableName() + { return getTable().getName(); } /** - * @return the SqlDynaProperty objects of this class + * Returns the properties of this dyna class. + * + * @return The properties */ - public SqlDynaProperty[] getSqlDynaProperties() { - return (SqlDynaProperty[]) getDynaProperties(); + public SqlDynaProperty[] getSqlDynaProperties() + { + return (SqlDynaProperty[])getDynaProperties(); } /** - * @return an array of the primary key DynaProperty objects + * Returns the properties for the primary keys of the corresponding table. + * + * @return The properties */ - public SqlDynaProperty[] getPrimaryKeyProperties() { - if ( primaryKeys == null ) { + public SqlDynaProperty[] getPrimaryKeyProperties() + { + if (_primaryKeyProperties == null) + { initPrimaryKeys(); } - return primaryKeys; + return _primaryKeyProperties; } /** - * @return an array of the non-primary key DynaProperty objects + * Returns the properties for the non-primary keys of the corresponding table. + * + * @return The properties */ - public SqlDynaProperty[] getNonPrimaryKeyProperties() { - if ( nonPrimaryKeyProperties == null ) { + public SqlDynaProperty[] getNonPrimaryKeyProperties() + { + if (_nonPrimaryKeyProperties == null) + { initPrimaryKeys(); } - return nonPrimaryKeyProperties; + return _nonPrimaryKeyProperties; } // Implementation methods //------------------------------------------------------------------------- /** - * Creates the primary key and non primary key property arrays, laziliy. + * Initializes the primary key and non primary key property arrays. */ - protected void initPrimaryKeys() { - List primaryKeyList = new ArrayList(); - List otherList = new ArrayList(); - + protected void initPrimaryKeys() + { + List pkProps = new ArrayList(); + List nonPkProps = new ArrayList(); DynaProperty[] properties = getDynaProperties(); - for (int i = 0, size = properties.length; i < size; i++ ) { - DynaProperty property = properties[i]; - if (property instanceof SqlDynaProperty) { - SqlDynaProperty sqlProperty = (SqlDynaProperty) property; - if ( sqlProperty.isPrimaryKey() ) { - primaryKeyList.add( sqlProperty ); + + for (int idx = 0; idx < properties.length; idx++) + { + if (properties[idx] instanceof SqlDynaProperty) + { + SqlDynaProperty sqlProperty = (SqlDynaProperty)properties[idx]; + + if (sqlProperty.isPrimaryKey()) + { + pkProps.add(sqlProperty); } - else { - otherList.add( sqlProperty ); + else + { + nonPkProps.add(sqlProperty); } } } - this.primaryKeys = new SqlDynaProperty[primaryKeyList.size()]; - primaryKeyList.toArray(this.primaryKeys); - - this.nonPrimaryKeyProperties = new SqlDynaProperty[otherList.size()]; - otherList.toArray(this.nonPrimaryKeyProperties); + _primaryKeyProperties = (SqlDynaProperty[])pkProps.toArray(new SqlDynaProperty[pkProps.size()]); + _nonPrimaryKeyProperties = (SqlDynaProperty[])nonPkProps.toArray(new SqlDynaProperty[nonPkProps.size()]); } } Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaProperty.java URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaProperty.java?rev=290453&r1=290452&r2=290453&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaProperty.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/SqlDynaProperty.java Tue Sep 20 06:45:34 2005 @@ -17,8 +17,6 @@ */ import org.apache.commons.beanutils.DynaProperty; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.ddlutils.model.Column; /** @@ -28,51 +26,60 @@ * an autoIncrement column and the SQL type etc. * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Thomas Dudziak</a> * @version $Revision$ */ -public class SqlDynaProperty extends DynaProperty { +public class SqlDynaProperty extends DynaProperty +{ + /** Unique ID for serializaion purposes */ + private static final long serialVersionUID = -4491018827449106588L; - /** The Log to which logging calls will be made. */ - private static final Log log = LogFactory.getLog( SqlDynaProperty.class ); - - private Column column; + /** The column for which this dyna property is defined */ + private Column _column; /** - * Construct a property that accepts any data type. + * Creates a property instance for the given column that accepts any data type. * - * @param name Name of the property being described - * @param column the database Column this property maps to + * @param column The column */ - public SqlDynaProperty(Column column) { + public SqlDynaProperty(Column column) + { super(column.getName()); - this.column = column; + _column = column; } /** - * Construct a property that accepts any data type. + * Creates a property instance for the given column that only accepts the given type. * - * @param name Name of the property being described - * @param column the database Column this property maps to + * @param column The column + * @param type The type of the property */ - public SqlDynaProperty(Column column, Class type) { + public SqlDynaProperty(Column column, Class type) + { super(column.getName(), type); - this.column = column; + _column = column; } /** - * @return the database Column this property maps to + * Returns the column for which this property is defined. + * + * @return The column */ - public Column getColumn() { - return column; + public Column getColumn() + { + return _column; } // Helper methods //------------------------------------------------------------------------- /** - * @return whether the property is part of the primary key + * Determines whether this property is for a primary key column. + * + * @return <code>true</code> if the property is for a primary key column */ - public boolean isPrimaryKey() { + public boolean isPrimaryKey() + { return getColumn().isPrimaryKey(); } Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java?rev=290453&r1=290452&r2=290453&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java Tue Sep 20 06:45:34 2005 @@ -377,6 +377,22 @@ */ public Iterator query(Database model, String sql) throws DynaSqlException { + return query(model, sql, (Table[])null); + } + + /* (non-Javadoc) + * @see org.apache.ddlutils.Platform#query(org.apache.ddlutils.model.Database, java.lang.String, java.util.Collection) + */ + public Iterator query(Database model, String sql, Collection parameters) throws DynaSqlException + { + return query(model, sql, parameters, null); + } + + /* (non-Javadoc) + * @see org.apache.ddlutils.Platform#query(org.apache.ddlutils.model.Database, java.lang.String, org.apache.ddlutils.model.Table[]) + */ + public Iterator query(Database model, String sql, Table[] queryHints) throws DynaSqlException + { Connection connection = borrowConnection(); Statement statement = null; ResultSet resultSet = null; @@ -386,7 +402,7 @@ { statement = connection.createStatement(); resultSet = statement.executeQuery(sql); - answer = createResultSetIterator(model, resultSet); + answer = createResultSetIterator(model, resultSet, queryHints); return answer; } catch (SQLException ex) @@ -406,9 +422,9 @@ } /* (non-Javadoc) - * @see org.apache.ddlutils.Platform#query(org.apache.ddlutils.model.Database, java.lang.String, java.util.Collection) + * @see org.apache.ddlutils.Platform#query(org.apache.ddlutils.model.Database, java.lang.String, java.util.Collection, org.apache.ddlutils.model.Table[]) */ - public Iterator query(Database model, String sql, Collection parameters) throws DynaSqlException + public Iterator query(Database model, String sql, Collection parameters, Table[] queryHints) throws DynaSqlException { Connection connection = borrowConnection(); PreparedStatement statement = null; @@ -426,7 +442,7 @@ statement.setObject(paramIdx, iter.next()); } resultSet = statement.executeQuery(); - answer = createResultSetIterator(model, resultSet); + answer = createResultSetIterator(model, resultSet, queryHints); return answer; } catch (SQLException ex) @@ -450,7 +466,15 @@ */ public List fetch(Database model, String sql) throws DynaSqlException { - return fetch(model, sql, 0, -1); + return fetch(model, sql, (Table[])null, 0, -1); + } + + /* (non-Javadoc) + * @see org.apache.ddlutils.Platform#fetch(org.apache.ddlutils.model.Database, java.lang.String, org.apache.ddlutils.model.Table[]) + */ + public List fetch(Database model, String sql, Table[] queryHints) throws DynaSqlException + { + return fetch(model, sql, queryHints, 0, -1); } /* (non-Javadoc) @@ -458,6 +482,14 @@ */ public List fetch(Database model, String sql, int start, int end) throws DynaSqlException { + return fetch(model, sql, (Table[])null, start, end); + } + + /* (non-Javadoc) + * @see org.apache.ddlutils.Platform#fetch(org.apache.ddlutils.model.Database, java.lang.String, org.apache.ddlutils.model.Table[], int, int) + */ + public List fetch(Database model, String sql, Table[] queryHints, int start, int end) throws DynaSqlException + { Connection connection = borrowConnection(); Statement statement = null; ResultSet resultSet = null; @@ -470,7 +502,7 @@ int rowIdx = 0; - for (Iterator it = createResultSetIterator(model, resultSet); ((end < 0) || (rowIdx <= end)) && it.hasNext(); rowIdx++) + for (Iterator it = createResultSetIterator(model, resultSet, queryHints); ((end < 0) || (rowIdx <= end)) && it.hasNext(); rowIdx++) { if (rowIdx >= start) { @@ -493,7 +525,7 @@ */ public List fetch(Database model, String sql, Collection parameters) throws DynaSqlException { - return fetch(model, sql, parameters, 0, -1); + return fetch(model, sql, parameters, null, 0, -1); } /* (non-Javadoc) @@ -501,6 +533,22 @@ */ public List fetch(Database model, String sql, Collection parameters, int start, int end) throws DynaSqlException { + return fetch(model, sql, parameters, null, start, end); + } + + /* (non-Javadoc) + * @see org.apache.ddlutils.Platform#fetch(org.apache.ddlutils.model.Database, java.lang.String, java.util.Collection, org.apache.ddlutils.model.Table[]) + */ + public List fetch(Database model, String sql, Collection parameters, Table[] queryHints) throws DynaSqlException + { + return fetch(model, sql, parameters, queryHints, 0, -1); + } + + /* (non-Javadoc) + * @see org.apache.ddlutils.Platform#fetch(org.apache.ddlutils.model.Database, java.lang.String, java.util.Collection, org.apache.ddlutils.model.Table[], int, int) + */ + public List fetch(Database model, String sql, Collection parameters, Table[] queryHints, int start, int end) throws DynaSqlException + { Connection connection = borrowConnection(); PreparedStatement statement = null; ResultSet resultSet = null; @@ -520,7 +568,7 @@ int rowIdx = 0; - for (Iterator it = createResultSetIterator(model, resultSet); ((end < 0) || (rowIdx <= end)) && it.hasNext(); rowIdx++) + for (Iterator it = createResultSetIterator(model, resultSet, queryHints); ((end < 0) || (rowIdx <= end)) && it.hasNext(); rowIdx++) { if (rowIdx >= start) { @@ -1044,9 +1092,11 @@ * * @param model The database model * @param resultSet The result set to iterate over + * @param queryHints The tables that were queried in the query that produced the given result set + * (optional) */ - protected DynaSqlIterator createResultSetIterator(Database model, ResultSet resultSet) + protected DynaSqlIterator createResultSetIterator(Database model, ResultSet resultSet, Table[] queryHints) { - return new DynaSqlIterator(getPlatformInfo(), model, resultSet, true); + return new DynaSqlIterator(getPlatformInfo(), model, resultSet, queryHints, true); } }