com.vaadin.data.util.sqlcontainer.query.
Class FreeformQuery
- java.lang.Object
-
- com.vaadin.data.util.sqlcontainer.query.AbstractTransactionalQuery
-
- com.vaadin.data.util.sqlcontainer.query.FreeformQuery
-
All Implemented Interfaces:
public class FreeformQuery extends AbstractTransactionalQuery implements QueryDelegate
See Also:
-
-
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 the
SQLContainer
.FreeformQuery(String queryString, List<String> primaryKeyColumns, JDBCConnectionPool connectionPool)
Deprecated.
As of 6.7, @seeFreeformQuery(String, JDBCConnectionPool, String...)
-
Method Summary
All Methods Modifier and Type Method Description 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)
This implementation of the containsRowWithKey method rewrites existing WHERE clauses in the query string.
int
getCount()
This implementation of getCount() actually fetches all records from the database, which might be a performance issue.
FreeformQueryDelegate
getDelegate()
List<String>
getPrimaryKeyColumns()
Returns a list of primary key column names.
String
getQueryString()
ResultSet
getResults(int offset, int pagelength)
Fetches the results for the query.
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 back and releases the active connection.
void
setDelegate(FreeformQueryDelegate delegate)
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.
-
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 the
SQLContainer
.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 the
SQLContainer
.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 SQLException
This 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:
getCount
in interfaceQueryDelegate
Returns:
row count
Throws:
-
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:
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:
See Also:
-
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:
-
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.
-
storeRow
public int storeRow(RowItem row) throws 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:
-
removeRow
public boolean removeRow(RowItem row) throws 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:
-
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:
-
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:
containsRowWithKey
in interfaceQueryDelegate
Parameters:
keys
- the primary keysReturns:
true if the SQL table contains a row with the provided keys
Throws:
See Also:
-
-