Class FreeformQuery
- java.lang.Object
-
- com.vaadin.data.util.sqlcontainer.query.AbstractTransactionalQuery
-
- com.vaadin.data.util.sqlcontainer.query.FreeformQuery
-
- All Implemented Interfaces:
QueryDelegate,Serializable
public class FreeformQuery extends AbstractTransactionalQuery 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
Constructors Constructor Description FreeformQuery(String queryString, JDBCConnectionPool connectionPool, String... primaryKeyColumns)Creates a new freeform query delegate to be used with theSQLContainer.FreeformQuery(String queryString, List<String> primaryKeyColumns, JDBCConnectionPool connectionPool)Deprecated.As of 6.7, @seeFreeformQuery(String, JDBCConnectionPool, String...)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginTransaction()Reserves a connection with auto-commit off if no transaction is in progress.voidcommit()Commits (if not in auto-commit mode) and releases the active connection.booleancontainsRowWithKey(Object... keys)This implementation of the containsRowWithKey method rewrites existing WHERE clauses in the query string.intgetCount()This implementation of getCount() actually fetches all records from the database, which might be a performance issue.FreeformQueryDelegategetDelegate()List<String>getPrimaryKeyColumns()Returns a list of primary key column names.StringgetQueryString()ResultSetgetResults(int offset, int pagelength)Fetches the results for the query.booleanimplementationRespectsPagingLimits()Allows the SQLContainer implementation to check whether the QueryDelegate implementation implements paging in the getResults method.booleanremoveRow(RowItem row)Removes the given RowItem from the database.voidrollback()Rolls back and releases the active connection.voidsetDelegate(FreeformQueryDelegate delegate)voidsetFilters(List<Container.Filter> filters)Sets the filters to apply when performing the SQL query.voidsetOrderBy(List<OrderBy> orderBys)Sets the order in which to retrieve rows from the database.intstoreRow(RowItem row)Stores a row in the database.-
Methods inherited from class com.vaadin.data.util.sqlcontainer.query.AbstractTransactionalQuery
ensureTransaction, getConnection, isInTransaction, releaseConnection
-
-
-
-
Constructor Detail
-
FreeformQuery
@Deprecated public FreeformQuery(String queryString, List<String> primaryKeyColumns, JDBCConnectionPool connectionPool)
Deprecated.As of 6.7, @seeFreeformQuery(String, JDBCConnectionPool, String...)Creates a new freeform query delegate to be used with theSQLContainer.- 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 theSQLContainer.- 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 SQLExceptionThis 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:
getCountin interfaceQueryDelegate- 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:
getResultsin interfaceQueryDelegate- Parameters:
offset- the first item of the page to loadpagelength- 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:QueryDelegateAllows the SQLContainer implementation to check whether the QueryDelegate implementation implements paging in the getResults method.- Specified by:
implementationRespectsPagingLimitsin interfaceQueryDelegate- 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:QueryDelegateSets the filters to apply when performing the SQL query. These are translated into a WHERE clause. Default filtering mode will be used.- Specified by:
setFiltersin 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:QueryDelegateSets 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:
setOrderByin interfaceQueryDelegate- 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:QueryDelegateStores 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:
storeRowin interfaceQueryDelegate- Returns:
- the number of affected rows in the database table
- Throws:
SQLException
-
removeRow
public boolean removeRow(RowItem row) throws SQLException
Description copied from interface:QueryDelegateRemoves the given RowItem from the database.- Specified by:
removeRowin interfaceQueryDelegate- Parameters:
row- RowItem to be removed- Returns:
- true on success
- Throws:
SQLException
-
beginTransaction
public void beginTransaction() throws UnsupportedOperationException, SQLExceptionDescription copied from class:AbstractTransactionalQueryReserves a connection with auto-commit off if no transaction is in progress.- Specified by:
beginTransactionin interfaceQueryDelegate- Overrides:
beginTransactionin classAbstractTransactionalQuery- Throws:
SQLException- if a connection could not be obtained or configuredUnsupportedOperationException
-
commit
public void commit() throws UnsupportedOperationException, SQLExceptionDescription copied from class:AbstractTransactionalQueryCommits (if not in auto-commit mode) and releases the active connection.- Specified by:
commitin interfaceQueryDelegate- Overrides:
commitin classAbstractTransactionalQuery- Throws:
SQLException- if not in a transaction managed by this queryUnsupportedOperationException
-
rollback
public void rollback() throws UnsupportedOperationException, SQLExceptionDescription copied from class:AbstractTransactionalQueryRolls back and releases the active connection.- Specified by:
rollbackin interfaceQueryDelegate- Overrides:
rollbackin classAbstractTransactionalQuery- Throws:
SQLException- if not in a transaction managed by this queryUnsupportedOperationException
-
getPrimaryKeyColumns
public List<String> getPrimaryKeyColumns()
Description copied from interface:QueryDelegateReturns 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:
getPrimaryKeyColumnsin interfaceQueryDelegate- 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:
containsRowWithKeyin interfaceQueryDelegate- 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...)
-
-