com.vaadin.data.util.sqlcontainer.query.
Class TableQuery
- java.lang.Object
-
- com.vaadin.data.util.sqlcontainer.query.AbstractTransactionalQuery
-
- com.vaadin.data.util.sqlcontainer.query.TableQuery
-
All Implemented Interfaces:
QueryDelegate
,QueryDelegate.RowIdChangeNotifier
,Serializable
public class TableQuery extends AbstractTransactionalQuery implements QueryDelegate, QueryDelegate.RowIdChangeNotifier
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description 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
Constructors Modifier Constructor Description 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.
TableQuery(String catalogName, String schemaName, 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(String catalogName, String schemaName, 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
All Methods Modifier and Type Method Description void
addListener(QueryDelegate.RowIdChangeListener listener)
Deprecated.
As of 7.0, replaced byaddRowIdChangeListener(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(Object... keys)
Performs a query to find out whether the SQL table contains a row with the given set of primary keys.
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 String
getFullTableName()
Returns the complete table name obtained by concatenation of the catalog and schema names (if any) and the table name.
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.
String
getSchemaName()
Returns the catalog name for the query.
SQLGenerator
getSqlGenerator()
String
getTableName()
Returns the table name for the query without catalog and schema information.
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 byremoveRowIdChangeListener(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(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 com.vaadin.data.util.sqlcontainer.query.AbstractTransactionalQuery
ensureTransaction, getConnection, isInTransaction, releaseConnection
-
-
-
-
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. 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 toconnectionPool
- Connection pool for accessing the databasesqlGenerator
- SQL query generator implementation
-
TableQuery
public TableQuery(String catalogName, String schemaName, 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 toconnectionPool
- Connection pool for accessing the databasesqlGenerator
- SQL query generator implementationSince:
7.1
-
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. 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 toconnectionPool
- Connection pool for accessing the database
-
TableQuery
protected TableQuery(String catalogName, String schemaName, 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 toconnectionPool
- Connection pool for accessing the databasesqlGenerator
- SQL query generator implementationescapeNames
- true to escape special characters in catalog, schema and table names, false to use the names as-isSince:
7.1
-
-
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 interfaceQueryDelegate
Returns:
row count
Throws:
-
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 interfaceQueryDelegate
Parameters:
offset
- the first item of the page to loadpagelength
- the length of the page to loadReturns:
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 interfaceQueryDelegate
Returns:
true if the delegate implements paging
See Also:
-
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 interfaceQueryDelegate
Returns:
the number of affected rows in the database table
Throws:
UnsupportedOperationException
- if the implementation is read only.
-
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 databaseReturns:
Final RowId of the added row
Throws:
-
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 interfaceQueryDelegate
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 interfaceQueryDelegate
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 class:
AbstractTransactionalQuery
Reserves a connection with auto-commit off if no transaction is in progress.
Specified by:
beginTransaction
in interfaceQueryDelegate
Overrides:
beginTransaction
in classAbstractTransactionalQuery
Throws:
SQLException
- if a connection could not be obtained or configured
-
commit
public void commit() throws UnsupportedOperationException, SQLException
Description copied from class:
AbstractTransactionalQuery
Commits (if not in auto-commit mode) and releases the active connection.
Specified by:
commit
in interfaceQueryDelegate
Overrides:
commit
in classAbstractTransactionalQuery
Throws:
SQLException
- if not in a transaction managed by this query
-
rollback
public void rollback() throws UnsupportedOperationException, SQLException
Description copied from class:
AbstractTransactionalQuery
Rolls back and releases the active connection.
Specified by:
rollback
in interfaceQueryDelegate
Overrides:
rollback
in classAbstractTransactionalQuery
Throws:
SQLException
- if not in a transaction managed by this query
-
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 interfaceQueryDelegate
Returns:
-
getVersionColumn
public String getVersionColumn()
-
setVersionColumn
public void setVersionColumn(String column)
-
getTableName
public String getTableName()
Returns the table name for the query without catalog and schema information.
Returns:
table name, not null
-
getCatalogName
public String getCatalogName()
Returns the catalog name for the query.
Returns:
catalog name, can be null
Since:
7.1
-
getSchemaName
public String getSchemaName()
Returns the catalog name for the query.
Returns:
catalog name, can be null
Since:
7.1
-
getFullTableName
protected 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 UnsupportedOperationException, SQLException
Description copied from interface:
QueryDelegate
Removes the given RowItem from the database.
Specified by:
removeRow
in interfaceQueryDelegate
Parameters:
row
- RowItem to be removedReturns:
true on success
Throws:
-
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 interfaceQueryDelegate
Parameters:
keys
- the primary keysReturns:
true if the SQL table contains a row with the provided keys
Throws:
-
addRowIdChangeListener
public void addRowIdChangeListener(QueryDelegate.RowIdChangeListener listener)
Adds RowIdChangeListener to this query
Specified by:
addRowIdChangeListener
in interfaceQueryDelegate.RowIdChangeNotifier
Parameters:
listener
- listener to be added
-
addListener
@Deprecated public void addListener(QueryDelegate.RowIdChangeListener listener)
Deprecated.As of 7.0, replaced byaddRowIdChangeListener(QueryDelegate.RowIdChangeListener)
Specified by:
addListener
in interfaceQueryDelegate.RowIdChangeNotifier
-
removeRowIdChangeListener
public void removeRowIdChangeListener(QueryDelegate.RowIdChangeListener listener)
Removes the given RowIdChangeListener from this query
Specified by:
removeRowIdChangeListener
in interfaceQueryDelegate.RowIdChangeNotifier
Parameters:
listener
- listener to be removed
-
removeListener
@Deprecated public void removeListener(QueryDelegate.RowIdChangeListener listener)
Deprecated.As of 7.0, replaced byremoveRowIdChangeListener(QueryDelegate.RowIdChangeListener)
Specified by:
removeListener
in interfaceQueryDelegate.RowIdChangeNotifier
-
-