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

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

public class TableQuery
extends Object
implements QueryDelegate, QueryDelegate.RowIdChangeNotifier

See Also:
Serialized Form

Nested Class Summary
 class TableQuery.RowIdChangeEvent
          Simple RowIdChangeEvent implementation.
 
Nested classes/interfaces inherited from interface com.vaadin.data.util.sqlcontainer.query.QueryDelegate
QueryDelegate.RowIdChangeListener, QueryDelegate.RowIdChangeNotifier
 
Constructor Summary
TableQuery(String tableName, JDBCConnectionPool connectionPool)
          Creates a new TableQuery using the given connection pool and table name to fetch the data from.
TableQuery(String tableName, JDBCConnectionPool connectionPool, SQLGenerator sqlGenerator)
          Creates a new TableQuery using the given connection pool, SQL generator and table name to fetch the data from.
 
Method Summary
 void addListener(QueryDelegate.RowIdChangeListener listener)
          Adds RowIdChangeListener to this query
 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.
 SQLGenerator getSqlGenerator()
           
 String getTableName()
           
 String getVersionColumn()
           
 boolean implementationRespectsPagingLimits()
          Allows the SQLContainer implementation to check whether the QueryDelegate implementation implements paging in the getResults method.
 void removeListener(QueryDelegate.RowIdChangeListener listener)
          Removes the given RowIdChangeListener from this query
 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.
 void setVersionColumn(String column)
           
 int storeRow(RowItem row)
          Stores a row in the database.
 RowId storeRowImmediately(RowItem row)
          Inserts the given row in the database table immediately.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableQuery

public TableQuery(String tableName,
                  JDBCConnectionPool connectionPool,
                  SQLGenerator sqlGenerator)
Creates a new TableQuery using the given connection pool, SQL generator and table name to fetch the data from. All parameters must be non-null.

Parameters:
tableName - Name of the database table to connect to
connectionPool - Connection pool for accessing the database
sqlGenerator - SQL query generator implementation

TableQuery

public TableQuery(String tableName,
                  JDBCConnectionPool connectionPool)
Creates a new TableQuery using the given connection pool and table name to fetch the data from. All parameters must be non-null. The default SQL generator will be used for queries.

Parameters:
tableName - Name of the database table to connect to
connectionPool - Connection pool for accessing the database
Method Detail

getCount

public int getCount()
             throws SQLException
Description copied from interface: QueryDelegate
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
Description copied from interface: QueryDelegate
Executes a paged SQL query and returns the ResultSet. The query is defined through implementations of this QueryDelegate interface.

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

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)

storeRow

public int storeRow(RowItem row)
             throws UnsupportedOperationException,
                    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:
UnsupportedOperationException - if the implementation is read only.
SQLException

storeRowImmediately

public RowId storeRowImmediately(RowItem row)
                          throws SQLException
Inserts the given row in the database table immediately. Begins and commits the transaction needed. This method was added specifically to solve the problem of returning the final RowId immediately on the SQLContainer.addItem() call when auto commit mode is enabled in the SQLContainer.

Parameters:
row - RowItem to add to the database
Returns:
Final RowId of the added row
Throws:
SQLException

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.

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:

getVersionColumn

public String getVersionColumn()

setVersionColumn

public void setVersionColumn(String column)

getTableName

public String getTableName()

getSqlGenerator

public SQLGenerator getSqlGenerator()

removeRow

public boolean removeRow(RowItem row)
                  throws UnsupportedOperationException,
                         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:
UnsupportedOperationException
SQLException

containsRowWithKey

public boolean containsRowWithKey(Object... keys)
                           throws SQLException
Description copied from interface: QueryDelegate
Performs a query to find out whether the SQL table contains a row with the given set of primary keys.

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

addListener

public void addListener(QueryDelegate.RowIdChangeListener listener)
Adds RowIdChangeListener to this query

Specified by:
addListener in interface QueryDelegate.RowIdChangeNotifier
Parameters:
listener - listener to be added

removeListener

public void removeListener(QueryDelegate.RowIdChangeListener listener)
Removes the given RowIdChangeListener from this query

Specified by:
removeListener in interface QueryDelegate.RowIdChangeNotifier
Parameters:
listener - listener to be removed


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