com.vaadin.data.util.sqlcontainer.query
Interface QueryDelegate

All Superinterfaces:
Serializable
All Known Implementing Classes:
FreeformQuery, TableQuery

public interface QueryDelegate
extends Serializable


Nested Class Summary
static interface QueryDelegate.RowIdChangeEvent
          An Event object specifying the old and new RowId of an added item after the addition has been successfully committed.
static interface QueryDelegate.RowIdChangeListener
          RowId change listener interface.
static interface QueryDelegate.RowIdChangeNotifier
          The interface for adding and removing RowIdChangeEvent listeners.
 
Method Summary
 void beginTransaction()
          Starts a new database transaction.
 void commit()
          Commits a transaction.
 boolean containsRowWithKey(Object... keys)
          Performs a query to find out whether the SQL table contains a row with the given set of primary keys.
 int getCount()
          Generates and executes a query to determine the current row count from the DB.
 List<String> getPrimaryKeyColumns()
          Returns a list of primary key column names.
 ResultSet getResults(int offset, int pagelength)
          Executes a paged SQL query and returns the ResultSet.
 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 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.
 

Method Detail

getCount

int getCount()
             throws SQLException
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.

Returns:
row count
Throws:
SQLException

getResults

ResultSet getResults(int offset,
                     int pagelength)
                     throws SQLException
Executes a paged SQL query and returns the ResultSet. The query is defined through implementations of this QueryDelegate interface.

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 - if the database access fails.

implementationRespectsPagingLimits

boolean implementationRespectsPagingLimits()
Allows the SQLContainer implementation to check whether the QueryDelegate implementation implements paging in the getResults method.

Returns:
true if the delegate implements paging
See Also:
getResults(int, int)

setFilters

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

Parameters:
filters - The filters to apply.
Throws:
UnsupportedOperationException - if the implementation doesn't support filtering.

setOrderBy

void setOrderBy(List<OrderBy> orderBys)
                throws UnsupportedOperationException
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.

Parameters:
orderBys - A list of the OrderBy conditions.
Throws:
UnsupportedOperationException - if the implementation doesn't support ordering.

storeRow

int storeRow(RowItem row)
             throws UnsupportedOperationException,
                    SQLException
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.

Parameters:
columnToValueMap - A map containing the values for all columns to be stored or updated.
Returns:
the number of affected rows in the database table
Throws:
UnsupportedOperationException - if the implementation is read only.
SQLException

removeRow

boolean removeRow(RowItem row)
                  throws UnsupportedOperationException,
                         SQLException
Removes the given RowItem from the database.

Parameters:
row - RowItem to be removed
Returns:
true on success
Throws:
UnsupportedOperationException
SQLException

beginTransaction

void beginTransaction()
                      throws SQLException
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.

Throws:
SQLException - if the database access fails.

commit

void commit()
            throws SQLException
Commits a transaction. If a transaction is not open nothing should happen.

Throws:
SQLException - if the database access fails.

rollback

void rollback()
              throws SQLException
Rolls a transaction back. If a transaction is not open nothing should happen.

Throws:
SQLException - if the database access fails.

getPrimaryKeyColumns

List<String> getPrimaryKeyColumns()
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.

Returns:

containsRowWithKey

boolean containsRowWithKey(Object... keys)
                           throws SQLException
Performs a query to find out whether the SQL table contains a row with the given set of primary keys.

Parameters:
keys - the primary keys
Returns:
true if the SQL table contains a row with the provided keys
Throws:
SQLException


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