com.vaadin.data.util.sqlcontainer.query
Class FreeformQuery

java.lang.Object
  extended by com.vaadin.data.util.sqlcontainer.query.FreeformQuery
All Implemented Interfaces:
QueryDelegate, Serializable

public class FreeformQuery
extends Object
implements QueryDelegate

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.data.util.sqlcontainer.query.QueryDelegate
QueryDelegate.RowIdChangeEvent, QueryDelegate.RowIdChangeListener, QueryDelegate.RowIdChangeNotifier
 
Constructor Summary
FreeformQuery(String queryString, JDBCConnectionPool connectionPool, String... primaryKeyColumns)
          Creates a new freeform query delegate to be used with the SQLContainer.
FreeformQuery(String queryString, List<String> primaryKeyColumns, JDBCConnectionPool connectionPool)
          Deprecated. @see FreeformQuery(String, JDBCConnectionPool, String...)
 
Method Summary
 void beginTransaction()
          Starts a new database transaction.
 void commit()
          Commits a transaction.
 boolean containsRowWithKey(Object... keys)
          This implementation of the containsRowWithKey method rewrites existing WHERE clauses in the query string.
 int getCount()
          This implementation of getCount() actually fetches all records from the database, which might be a performance issue.
 FreeformQueryDelegate getDelegate()
           
 List<String> getPrimaryKeyColumns()
          Returns a list of primary key column names.
 String getQueryString()
           
 ResultSet getResults(int offset, int pagelength)
          Fetches the results for the query.
 boolean implementationRespectsPagingLimits()
          Allows the SQLContainer implementation to check whether the QueryDelegate implementation implements paging in the getResults method.
 boolean removeRow(RowItem row)
          Removes the given RowItem from the database.
 void rollback()
          Rolls a transaction back.
 void setDelegate(FreeformQueryDelegate delegate)
           
 void setFilters(List<Container.Filter> filters)
          Sets the filters to apply when performing the SQL query.
 void setOrderBy(List<OrderBy> orderBys)
          Sets the order in which to retrieve rows from the database.
 int storeRow(RowItem row)
          Stores a row in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FreeformQuery

@Deprecated
public FreeformQuery(String queryString,
                                List<String> primaryKeyColumns,
                                JDBCConnectionPool connectionPool)
Deprecated. @see FreeformQuery(String, JDBCConnectionPool, String...)

Creates a new freeform query delegate to be used with the SQLContainer.

Parameters:
queryString - The actual query to perform.
primaryKeyColumns - The primary key columns. Read-only mode is forced if this parameter is null or empty.
connectionPool - the JDBCConnectionPool to use to open connections to the SQL database.

FreeformQuery

public FreeformQuery(String queryString,
                     JDBCConnectionPool connectionPool,
                     String... primaryKeyColumns)
Creates a new freeform query delegate to be used with the SQLContainer.

Parameters:
queryString - The actual query to perform.
connectionPool - the JDBCConnectionPool to use to open connections to the SQL database.
primaryKeyColumns - The primary key columns. Read-only mode is forced if none are provided. (optional)
Method Detail

getCount

public int getCount()
             throws SQLException
This implementation of getCount() actually fetches all records from the database, which might be a performance issue. Override this method with a SELECT COUNT(*) ... query if this is too slow for your needs. Generates and executes a query to determine the current row count from the DB. Row count will be fetched using filters that are currently set to the QueryDelegate.

Specified by:
getCount in interface QueryDelegate
Returns:
row count
Throws:
SQLException

getResults

public ResultSet getResults(int offset,
                            int pagelength)
                     throws SQLException
Fetches the results for the query. This implementation always fetches the entire record set, ignoring the offset and page length parameters. In order to support lazy loading of records, you must supply a FreeformQueryDelegate that implements the FreeformQueryDelegate.getQueryString(int,int) method.

Specified by:
getResults in interface QueryDelegate
Parameters:
offset - the first item of the page to load
pagelength - the length of the page to load
Returns:
a ResultSet containing the rows of the page
Throws:
SQLException
See Also:
FreeformQueryDelegate.getQueryString(int, int)

implementationRespectsPagingLimits

public boolean implementationRespectsPagingLimits()
Description copied from interface: QueryDelegate
Allows the SQLContainer implementation to check whether the QueryDelegate implementation implements paging in the getResults method.

Specified by:
implementationRespectsPagingLimits in interface QueryDelegate
Returns:
true if the delegate implements paging
See Also:
QueryDelegate.getResults(int, int)

setFilters

public void setFilters(List<Container.Filter> filters)
                throws UnsupportedOperationException
Description copied from interface: QueryDelegate
Sets the filters to apply when performing the SQL query. These are translated into a WHERE clause. Default filtering mode will be used.

Specified by:
setFilters in interface QueryDelegate
Parameters:
filters - The filters to apply.
Throws:
UnsupportedOperationException - if the implementation doesn't support filtering.

setOrderBy

public void setOrderBy(List<OrderBy> orderBys)
                throws UnsupportedOperationException
Description copied from interface: QueryDelegate
Sets the order in which to retrieve rows from the database. The result can be ordered by zero or more columns and each column can be in ascending or descending order. These are translated into an ORDER BY clause in the SQL query.

Specified by:
setOrderBy in interface QueryDelegate
Parameters:
orderBys - A list of the OrderBy conditions.
Throws:
UnsupportedOperationException - if the implementation doesn't support ordering.

storeRow

public int storeRow(RowItem row)
             throws SQLException
Description copied from interface: QueryDelegate
Stores a row in the database. The implementation of this interface decides how to identify whether to store a new row or update an existing one.

Specified by:
storeRow in interface QueryDelegate
Returns:
the number of affected rows in the database table
Throws:
SQLException

removeRow

public boolean removeRow(RowItem row)
                  throws SQLException
Description copied from interface: QueryDelegate
Removes the given RowItem from the database.

Specified by:
removeRow in interface QueryDelegate
Parameters:
row - RowItem to be removed
Returns:
true on success
Throws:
SQLException

beginTransaction

public void beginTransaction()
                      throws UnsupportedOperationException,
                             SQLException
Description copied from interface: QueryDelegate
Starts a new database transaction. Used when storing multiple changes. Note that if a transaction is already open, it will be rolled back when a new transaction is started.

Specified by:
beginTransaction in interface QueryDelegate
Throws:
SQLException - if the database access fails.
UnsupportedOperationException

commit

public void commit()
            throws UnsupportedOperationException,
                   SQLException
Description copied from interface: QueryDelegate
Commits a transaction. If a transaction is not open nothing should happen.

Specified by:
commit in interface QueryDelegate
Throws:
SQLException - if the database access fails.
UnsupportedOperationException

rollback

public void rollback()
              throws UnsupportedOperationException,
                     SQLException
Description copied from interface: QueryDelegate
Rolls a transaction back. If a transaction is not open nothing should happen.

Specified by:
rollback in interface QueryDelegate
Throws:
SQLException - if the database access fails.
UnsupportedOperationException

getPrimaryKeyColumns

public List<String> getPrimaryKeyColumns()
Description copied from interface: QueryDelegate
Returns a list of primary key column names. The list is either fetched from the database (TableQuery) or given as an argument depending on implementation.

Specified by:
getPrimaryKeyColumns in interface QueryDelegate
Returns:

getQueryString

public String getQueryString()

getDelegate

public FreeformQueryDelegate getDelegate()

setDelegate

public void setDelegate(FreeformQueryDelegate delegate)

containsRowWithKey

public boolean containsRowWithKey(Object... keys)
                           throws SQLException
This implementation of the containsRowWithKey method rewrites existing WHERE clauses in the query string. The logic is, however, not very complex and some times can do the Wrong ThingTM. For the situations where this logic is not enough, you can implement the getContainsRowQueryString method in FreeformQueryDelegate and this will be used instead of the logic.

Specified by:
containsRowWithKey in interface QueryDelegate
Parameters:
keys - the primary keys
Returns:
true if the SQL table contains a row with the provided keys
Throws:
SQLException
See Also:
FreeformQueryDelegate.getContainsRowQueryString(Object...)


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.