Class DefaultQueryRewriter
- java.lang.Object
-
- org.apache.metamodel.jdbc.dialects.AbstractQueryRewriter
-
- org.apache.metamodel.jdbc.dialects.DefaultQueryRewriter
-
- All Implemented Interfaces:
IQueryRewriter
- Direct Known Subclasses:
HsqldbQueryRewriter,LimitOffsetQueryRewriter,OffsetFetchQueryRewriter,RowNumberQueryRewriter,SQLiteQueryRewriter
public class DefaultQueryRewriter extends AbstractQueryRewriter
Generic query rewriter that adds syntax enhancements that are only possible to resolve just before execution time.
-
-
Constructor Summary
Constructors Constructor Description DefaultQueryRewriter(JdbcDataContext dataContext)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.apache.metamodel.query.QuerybeforeRewrite(org.apache.metamodel.query.Query query)Method to modify query before rewriting begins.StringescapeQuotes(String item)Escapes the quotes within a String literal of a query item.booleanisAggregateFunctionSupported(org.apache.metamodel.query.AggregateFunction function)Determines whether a specific aggregate function is supported by the database or not.booleanisFirstRowSupported(org.apache.metamodel.query.Query query)Gets whether this query rewriter is able to write the "First row" query property to the query string.booleanisMaxRowsSupported()Gets whether this query rewriter is able to write the "Max rows" query property to the query string.booleanisPrimaryKeySupported()Determines if the JDBC data source supports primary keys or not.booleanisScalarFunctionSupported(org.apache.metamodel.query.ScalarFunction function)Determines whether a specific scalar function is supported by the database or not.protected booleanneedsQuoting(String alias, String identifierQuoteString)StringrewriteColumnType(org.apache.metamodel.schema.ColumnType columnType, Integer columnSize)Rewrites the name of a column type, as it is written in CREATE TABLE statements.StringrewriteFilterItem(org.apache.metamodel.query.FilterItem item)protected StringrewriteFilterItemWithOperandLiteral(org.apache.metamodel.query.FilterItem item, String operandLiteral)Rewrites a (non-compound)FilterItemwhen it's operand has already been rewritten into a SQL literal.protected StringrewriteTimestamp(Timestamp ts)Rewrites aTimestampinto it's literal representation as known by this SQL dialect.-
Methods inherited from class org.apache.metamodel.jdbc.dialects.AbstractQueryRewriter
getColumnType, getDataContext, getResultSetValue, isSchemaIncludedInColumnPaths, isSupportedVersion, isTransactional, rewriteColumnTypeInternal, rewriteFromClause, rewriteFromItem, rewriteFromItem, rewriteGroupByClause, rewriteGroupByItem, rewriteHavingClause, rewriteOrderByClause, rewriteOrderByItem, rewriteQuery, rewriteSelectClause, rewriteSelectItem, rewriteWhereClause, setStatementParameter, toTime, toTimestamp
-
-
-
-
Constructor Detail
-
DefaultQueryRewriter
public DefaultQueryRewriter(JdbcDataContext dataContext)
-
-
Method Detail
-
beforeRewrite
protected org.apache.metamodel.query.Query beforeRewrite(org.apache.metamodel.query.Query query)
Description copied from class:AbstractQueryRewriterMethod to modify query before rewriting begins. Overwrite this method if you want to change parts of the query that are not just rendering related. Cloning the query before modifying is recommended in order to not violate referential integrity of clients (the query is mutable).- Overrides:
beforeRewritein classAbstractQueryRewriter- Returns:
- the modified query
-
rewriteColumnType
public String rewriteColumnType(org.apache.metamodel.schema.ColumnType columnType, Integer columnSize)
Description copied from interface:IQueryRewriterRewrites the name of a column type, as it is written in CREATE TABLE statements. Some databases dont support all column types, or have different names for them. The implementation of this method will do that conversion.- Specified by:
rewriteColumnTypein interfaceIQueryRewriter- Overrides:
rewriteColumnTypein classAbstractQueryRewriter- Parameters:
columnType- the (non-null)ColumnTypeto rewritecolumnSize- the (possibly null) column size that may or may not have been specified- Returns:
-
rewriteFilterItem
public String rewriteFilterItem(org.apache.metamodel.query.FilterItem item)
- Specified by:
rewriteFilterItemin interfaceIQueryRewriter- Overrides:
rewriteFilterItemin classAbstractQueryRewriter
-
rewriteFilterItemWithOperandLiteral
protected String rewriteFilterItemWithOperandLiteral(org.apache.metamodel.query.FilterItem item, String operandLiteral)
Rewrites a (non-compound)FilterItemwhen it's operand has already been rewritten into a SQL literal.- Parameters:
item-operandLiteral-- Returns:
-
rewriteTimestamp
protected String rewriteTimestamp(Timestamp ts)
Rewrites aTimestampinto it's literal representation as known by this SQL dialect. This default implementation returns the JDBC spec's escape syntax for a timestamp: {ts 'yyyy-mm-dd hh:mm:ss.f . . .'}- Parameters:
ts-- Returns:
-
isScalarFunctionSupported
public boolean isScalarFunctionSupported(org.apache.metamodel.query.ScalarFunction function)
Description copied from interface:IQueryRewriterDetermines whether a specific scalar function is supported by the database or not. If the function is not supported then MetaModel will handle the function on the client side.- Returns:
-
isAggregateFunctionSupported
public boolean isAggregateFunctionSupported(org.apache.metamodel.query.AggregateFunction function)
Description copied from interface:IQueryRewriterDetermines whether a specific aggregate function is supported by the database or not. If the function is not supported then MetaModel will handle the function on the client side.- Returns:
-
isFirstRowSupported
public boolean isFirstRowSupported(org.apache.metamodel.query.Query query)
Description copied from interface:IQueryRewriterGets whether this query rewriter is able to write the "First row" query property to the query string.- Parameters:
query- For some database engines, the content of the query decides the ability to change first row- Returns:
- whether this query rewriter is able to write the "First row" query property to the query string.
-
isMaxRowsSupported
public boolean isMaxRowsSupported()
Description copied from interface:IQueryRewriterGets whether this query rewriter is able to write the "Max rows" query property to the query string.- Returns:
- whether this query rewriter is able to write the "Max rows" query property to the query string.
-
escapeQuotes
public String escapeQuotes(String item)
Description copied from interface:IQueryRewriterEscapes the quotes within a String literal of a query item.- Returns:
- String item with quotes escaped.
-
isPrimaryKeySupported
public boolean isPrimaryKeySupported()
Description copied from interface:IQueryRewriterDetermines if the JDBC data source supports primary keys or not.- Returns:
-
-