com.vaadin.data.util.sqlcontainer.query.generator.
Class DefaultSQLGenerator
java.lang.Object
com.vaadin.data.util.sqlcontainer.query.generator.DefaultSQLGenerator
All Implemented Interfaces:
Direct Known Subclasses:
- extends Object
- implements SQLGenerator
public class DefaultSQLGenerator
Generates generic SQL that is supported by HSQLDB, MySQL and PostgreSQL.
Author:
Jonatan Kronqvist / Vaadin Ltd
See Also:
Constructor Summary | |
---|---|
DefaultSQLGenerator()
|
|
DefaultSQLGenerator(Class<? extends StatementHelper> statementHelperClazz)
Create a new DefaultSqlGenerator instance that uses the given implementation of StatementHelper |
|
DefaultSQLGenerator(String quoteStart,
String quoteEnd)
Construct a DefaultSQLGenerator with the specified identifiers for start and end of quoted strings. |
|
DefaultSQLGenerator(String quoteStart,
String quoteEnd,
Class<? extends StatementHelper> statementHelperClazz)
Same as DefaultSQLGenerator(String, String) but with support for
custom StatementHelper implementation. |
Method Summary | |
---|---|
protected Map<String,Object> |
generateColumnToValueMap(RowItem item)
|
StatementHelper |
generateDeleteQuery(String tableName,
List<String> primaryKeyColumns,
String versionColumn,
RowItem item)
Generates a DELETE query for deleting data related to the given RowItem from the database. |
StatementHelper |
generateInsertQuery(String tableName,
RowItem item)
Generates an INSERT query for inserting a new row with the provided values. |
protected StringBuffer |
generateLimits(StringBuffer sb,
int offset,
int pagelength)
Generates the LIMIT and OFFSET clause. |
protected StringBuffer |
generateOrderBy(StringBuffer sb,
OrderBy o,
boolean firstOrderBy)
Generates sorting rules as an ORDER BY -clause |
protected Map<String,Object> |
generateRowIdentifiers(RowItem item)
|
StatementHelper |
generateSelectQuery(String tableName,
List<Container.Filter> filters,
List<OrderBy> orderBys,
int offset,
int pagelength,
String toSelect)
Generates a SELECT query with the provided parameters. |
StatementHelper |
generateUpdateQuery(String tableName,
RowItem item)
Generates an UPDATE query with the provided parameters. |
protected StatementHelper |
getStatementHelper()
Returns the statement helper for the generator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
DefaultSQLGenerator
public DefaultSQLGenerator()
DefaultSQLGenerator
public DefaultSQLGenerator(Class<? extends StatementHelper> statementHelperClazz)
- Parameters:
statementHelper
-
Create a new DefaultSqlGenerator instance that uses the given
implementation of StatementHelper
DefaultSQLGenerator
public DefaultSQLGenerator(String quoteStart,
String quoteEnd)
- Parameters:
quoteStart
- the identifier (character) denoting the start of a quoted stringquoteEnd
- the identifier (character) denoting the end of a quoted string
Construct a DefaultSQLGenerator with the specified identifiers for start and end of quoted strings. The identifiers may be different depending on the database engine and it's settings.
DefaultSQLGenerator
public DefaultSQLGenerator(String quoteStart,
String quoteEnd,
Class<? extends StatementHelper> statementHelperClazz)
- Parameters:
quoteStart
-quoteEnd
-statementHelperClazz
-
Same as DefaultSQLGenerator(String, String)
but with support for
custom StatementHelper
implementation.
Method Detail |
---|
generateSelectQuery
public StatementHelper generateSelectQuery(String tableName,
List<Container.Filter> filters,
List<OrderBy> orderBys,
int offset,
int pagelength,
String toSelect)
- Specified by:
generateSelectQuery
in interfaceSQLGenerator
- Parameters:
tableName
- Name of the table queriedfilters
- The filters, converted into a WHERE clauseorderBys
- The the ordering conditions, converted into an ORDER BY clauseoffset
- The offset of the first row to be includedpagelength
- The number of rows to be returned when the query executestoSelect
- String containing what to select, e.g. "*", "COUNT(*)"- Returns:
- StatementHelper instance containing the query string for a PreparedStatement and the values required for the parameters
Description copied from interface: SQLGenerator
Generates a SELECT query with the provided parameters. Uses default filtering mode (INCLUSIVE).
generateUpdateQuery
public StatementHelper generateUpdateQuery(String tableName,
RowItem item)
- Specified by:
generateUpdateQuery
in interfaceSQLGenerator
- Parameters:
tableName
- Name of the table querieditem
- RowItem containing the updated values update.- Returns:
- StatementHelper instance containing the query string for a PreparedStatement and the values required for the parameters
Description copied from interface: SQLGenerator
Generates an UPDATE query with the provided parameters.
generateInsertQuery
public StatementHelper generateInsertQuery(String tableName,
RowItem item)
- Specified by:
generateInsertQuery
in interfaceSQLGenerator
- Parameters:
tableName
- Name of the table querieditem
- New RowItem to be inserted into the database.- Returns:
- StatementHelper instance containing the query string for a PreparedStatement and the values required for the parameters
Description copied from interface: SQLGenerator
Generates an INSERT query for inserting a new row with the provided values.
generateDeleteQuery
public StatementHelper generateDeleteQuery(String tableName,
List<String> primaryKeyColumns,
String versionColumn,
RowItem item)
- Specified by:
generateDeleteQuery
in interfaceSQLGenerator
- Parameters:
tableName
- Name of the table queriedprimaryKeyColumns
- the names of the columns holding the primary key. Usually just one column, but might be several.versionColumn
- the column containing the version number of the row, null if versioning (optimistic locking) not enabled.item
- Item to be deleted from the database- Returns:
- StatementHelper instance containing the query string for a PreparedStatement and the values required for the parameters
Description copied from interface: SQLGenerator
Generates a DELETE query for deleting data related to the given RowItem from the database.
generateOrderBy
protected StringBuffer generateOrderBy(StringBuffer sb,
OrderBy o,
boolean firstOrderBy)
- Parameters:
sb
- StringBuffer to which the clause is appended.o
- OrderBy object to be added into the sb.firstOrderBy
- If true, this is the first OrderBy.- Returns:
Generates sorting rules as an ORDER BY -clause
generateLimits
protected StringBuffer generateLimits(StringBuffer sb,
int offset,
int pagelength)
- Parameters:
sb
- StringBuffer to which the clause is appended.offset
- Value for offset.pagelength
- Value for pagelength.- Returns:
- StringBuffer with LIMIT and OFFSET clause added.
Generates the LIMIT and OFFSET clause.
generateColumnToValueMap
protected Map<String,Object> generateColumnToValueMap(RowItem item)
generateRowIdentifiers
protected Map<String,Object> generateRowIdentifiers(RowItem item)
getStatementHelper
protected StatementHelper getStatementHelper()
- Returns:
- a new instance of the statement helper
- See Also:
http://dev.vaadin.com/ticket/9148
Returns the statement helper for the generator. Override this to handle platform specific data types.