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

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

public class TableQuery
extends AbstractTransactionalQuery
implements QueryDelegate, QueryDelegate.RowIdChangeNotifier

See Also:
Serialized Form

Nested Class Summary
static 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(java.lang.String tableName, JDBCConnectionPool connectionPool)
          Creates a new TableQuery using the given connection pool and table name to fetch the data from.
  TableQuery(java.lang.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.
  TableQuery(java.lang.String catalogName, java.lang.String schemaName, java.lang.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.
protected TableQuery(java.lang.String catalogName, java.lang.String schemaName, java.lang.String tableName, JDBCConnectionPool connectionPool, SQLGenerator sqlGenerator, boolean escapeNames)
          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)
          Deprecated. As of 7.0, replaced by addRowIdChangeListener(com.vaadin.data.util.sqlcontainer.query.QueryDelegate.RowIdChangeListener)
 void addRowIdChangeListener(QueryDelegate.RowIdChangeListener listener)
          Adds RowIdChangeListener to this query
 void beginTransaction()
          Reserves a connection with auto-commit off if no transaction is in progress.
 void commit()
          Commits (if not in auto-commit mode) and releases the active connection.
 boolean containsRowWithKey(java.lang.Object... keys)
          Performs a query to find out whether the SQL table contains a row with the given set of primary keys.
 java.lang.String getCatalogName()
          Returns the catalog name for the query.
 int getCount()
          Generates and executes a query to determine the current row count from the DB.
protected  java.lang.String getFullTableName()
          Returns the complete table name obtained by concatenation of the catalog and schema names (if any) and the table name.
 java.util.List<java.lang.String> getPrimaryKeyColumns()
          Returns a list of primary key column names.
 java.sql.ResultSet getResults(int offset, int pagelength)
          Executes a paged SQL query and returns the ResultSet.
 java.lang.String getSchemaName()
          Returns the catalog name for the query.
 SQLGenerator getSqlGenerator()
           
 java.lang.String getTableName()
          Returns the table name for the query without catalog and schema information.
 java.lang.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)
          Deprecated. As of 7.0, replaced by removeRowIdChangeListener(com.vaadin.data.util.sqlcontainer.query.QueryDelegate.RowIdChangeListener)
 boolean removeRow(RowItem row)
          Removes the given RowItem from the database.
 void removeRowIdChangeListener(QueryDelegate.RowIdChangeListener listener)
          Removes the given RowIdChangeListener from this query
 void rollback()
          Rolls back and releases the active connection.
 void setFilters(java.util.List<Container.Filter> filters)
          Sets the filters to apply when performing the SQL query.
 void setOrderBy(java.util.List<OrderBy> orderBys)
          Sets the order in which to retrieve rows from the database.
 void setVersionColumn(java.lang.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 com.vaadin.data.util.sqlcontainer.query.AbstractTransactionalQuery
ensureTransaction, getConnection, isInTransaction, releaseConnection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableQuery

public TableQuery(java.lang.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. The table name must be a simple name with no catalog or schema information. If those are needed, use TableQuery(String, String, String, JDBCConnectionPool, SQLGenerator) .

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(java.lang.String catalogName,
                  java.lang.String schemaName,
                  java.lang.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. Catalog and schema names can be null, all other parameters must be non-null.

Parameters:
catalogName - Name of the database catalog (can be null)
schemaName - Name of the database schema (can be null)
tableName - Name of the database table to connect to
connectionPool - Connection pool for accessing the database
sqlGenerator - SQL query generator implementation
Since:
7.1

TableQuery

public TableQuery(java.lang.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. The table name must be a simple name with no catalog or schema information. If those are needed, use TableQuery(String, String, String, JDBCConnectionPool, SQLGenerator) .

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

TableQuery

protected TableQuery(java.lang.String catalogName,
                     java.lang.String schemaName,
                     java.lang.String tableName,
                     JDBCConnectionPool connectionPool,
                     SQLGenerator sqlGenerator,
                     boolean escapeNames)
Creates a new TableQuery using the given connection pool, SQL generator and table name to fetch the data from. Catalog and schema names can be null, all other parameters must be non-null.

Parameters:
catalogName - Name of the database catalog (can be null)
schemaName - Name of the database schema (can be null)
tableName - Name of the database table to connect to
connectionPool - Connection pool for accessing the database
sqlGenerator - SQL query generator implementation
escapeNames - true to escape special characters in catalog, schema and table names, false to use the names as-is
Since:
7.1
Method Detail

getCount

public int getCount()
             throws java.sql.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:
java.sql.SQLException

getResults

public java.sql.ResultSet getResults(int offset,
                                     int pagelength)
                              throws java.sql.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:
java.sql.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 java.lang.UnsupportedOperationException,
                    java.sql.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:
java.lang.UnsupportedOperationException - if the implementation is read only.
java.sql.SQLException

storeRowImmediately

public RowId storeRowImmediately(RowItem row)
                          throws java.sql.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:
java.sql.SQLException

setFilters

public void setFilters(java.util.List<Container.Filter> filters)
                throws java.lang.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:
java.lang.UnsupportedOperationException - if the implementation doesn't support filtering.

setOrderBy

public void setOrderBy(java.util.List<OrderBy> orderBys)
                throws java.lang.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:
java.lang.UnsupportedOperationException - if the implementation doesn't support ordering.

beginTransaction

public void beginTransaction()
                      throws java.lang.UnsupportedOperationException,
                             java.sql.SQLException
Description copied from class: AbstractTransactionalQuery
Reserves a connection with auto-commit off if no transaction is in progress.

Specified by:
beginTransaction in interface QueryDelegate
Overrides:
beginTransaction in class AbstractTransactionalQuery
Throws:
java.sql.SQLException - if a connection could not be obtained or configured
java.lang.UnsupportedOperationException

commit

public void commit()
            throws java.lang.UnsupportedOperationException,
                   java.sql.SQLException
Description copied from class: AbstractTransactionalQuery
Commits (if not in auto-commit mode) and releases the active connection.

Specified by:
commit in interface QueryDelegate
Overrides:
commit in class AbstractTransactionalQuery
Throws:
java.sql.SQLException - if not in a transaction managed by this query
java.lang.UnsupportedOperationException

rollback

public void rollback()
              throws java.lang.UnsupportedOperationException,
                     java.sql.SQLException
Description copied from class: AbstractTransactionalQuery
Rolls back and releases the active connection.

Specified by:
rollback in interface QueryDelegate
Overrides:
rollback in class AbstractTransactionalQuery
Throws:
java.sql.SQLException - if not in a transaction managed by this query
java.lang.UnsupportedOperationException

getPrimaryKeyColumns

public java.util.List<java.lang.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 java.lang.String getVersionColumn()

setVersionColumn

public void setVersionColumn(java.lang.String column)

getTableName

public java.lang.String getTableName()
Returns the table name for the query without catalog and schema information.

Returns:
table name, not null

getCatalogName

public java.lang.String getCatalogName()
Returns the catalog name for the query.

Returns:
catalog name, can be null
Since:
7.1

getSchemaName

public java.lang.String getSchemaName()
Returns the catalog name for the query.

Returns:
catalog name, can be null
Since:
7.1

getFullTableName

protected java.lang.String getFullTableName()
Returns the complete table name obtained by concatenation of the catalog and schema names (if any) and the table name. This method can be overridden if customization is needed.

Returns:
table name in the form it should be used in query and update statements
Since:
7.1

getSqlGenerator

public SQLGenerator getSqlGenerator()

removeRow

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

containsRowWithKey

public boolean containsRowWithKey(java.lang.Object... keys)
                           throws java.sql.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:
java.sql.SQLException

addRowIdChangeListener

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

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

addListener

@Deprecated
public void addListener(QueryDelegate.RowIdChangeListener listener)
Deprecated. As of 7.0, replaced by addRowIdChangeListener(com.vaadin.data.util.sqlcontainer.query.QueryDelegate.RowIdChangeListener)

Specified by:
addListener in interface QueryDelegate.RowIdChangeNotifier

removeRowIdChangeListener

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

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

removeListener

@Deprecated
public void removeListener(QueryDelegate.RowIdChangeListener listener)
Deprecated. As of 7.0, replaced by removeRowIdChangeListener(com.vaadin.data.util.sqlcontainer.query.QueryDelegate.RowIdChangeListener)

Specified by:
removeListener in interface QueryDelegate.RowIdChangeNotifier


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