2 * Copyright 2000-2018 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.v7.data.util.sqlcontainer.query.generator;
18 import java.util.List;
20 import com.vaadin.v7.data.Container.Filter;
21 import com.vaadin.v7.data.util.sqlcontainer.query.OrderBy;
22 import com.vaadin.v7.data.util.sqlcontainer.query.generator.filter.QueryBuilder;
25 * @deprecated As of 8.0, no replacement available.
27 @SuppressWarnings("serial")
29 public class OracleGenerator extends DefaultSQLGenerator {
31 public OracleGenerator() {
35 public OracleGenerator(
36 Class<? extends StatementHelper> statementHelperClazz) {
37 super(statementHelperClazz);
41 * Construct an OracleSQLGenerator with the specified identifiers for start
42 * and end of quoted strings. The identifiers may be different depending on
43 * the database engine and it's settings.
46 * the identifier (character) denoting the start of a quoted
49 * the identifier (character) denoting the end of a quoted string
51 public OracleGenerator(String quoteStart, String quoteEnd) {
52 super(quoteStart, quoteEnd);
55 public OracleGenerator(String quoteStart, String quoteEnd,
56 Class<? extends StatementHelper> statementHelperClazz) {
57 super(quoteStart, quoteEnd, statementHelperClazz);
63 * @see com.vaadin.addon.sqlcontainer.query.generator.DefaultSQLGenerator#
64 * generateSelectQuery(java.lang.String, java.util.List,
65 * com.vaadin.addon.sqlcontainer.query.FilteringMode, java.util.List, int,
66 * int, java.lang.String)
69 public StatementHelper generateSelectQuery(String tableName,
70 List<Filter> filters, List<OrderBy> orderBys, int offset,
71 int pagelength, String toSelect) {
72 if (tableName == null || tableName.trim().equals("")) {
73 throw new IllegalArgumentException("Table name must be given.");
75 /* Adjust offset and page length parameters to match "row numbers" */
76 offset = pagelength > 1 ? ++offset : offset;
77 pagelength = pagelength > 1 ? --pagelength : pagelength;
78 toSelect = toSelect == null ? "*" : toSelect;
79 StatementHelper sh = getStatementHelper();
80 StringBuffer query = new StringBuffer();
82 /* Row count request is handled here */
83 if ("COUNT(*)".equalsIgnoreCase(toSelect)) {
84 query.append(String.format(
85 "SELECT COUNT(*) AS %s FROM (SELECT * FROM %s",
86 QueryBuilder.quote("rowcount"), tableName));
87 if (filters != null && !filters.isEmpty()) {
89 QueryBuilder.getWhereStringForFilters(filters, sh));
92 sh.setQueryString(query.toString());
96 /* SELECT without row number constraints */
97 if (offset == 0 && pagelength == 0) {
98 query.append("SELECT ").append(toSelect).append(" FROM ")
100 if (filters != null) {
102 QueryBuilder.getWhereStringForFilters(filters, sh));
104 if (orderBys != null) {
105 for (OrderBy o : orderBys) {
106 generateOrderBy(query, o, orderBys.indexOf(o) == 0);
109 sh.setQueryString(query.toString());
113 /* Remaining SELECT cases are handled here */
114 query.append(String.format(
115 "SELECT * FROM (SELECT x.*, ROWNUM AS %s FROM (SELECT %s FROM %s",
116 QueryBuilder.quote("rownum"), toSelect, tableName));
117 if (filters != null) {
118 query.append(QueryBuilder.getWhereStringForFilters(filters, sh));
120 if (orderBys != null) {
121 for (OrderBy o : orderBys) {
122 generateOrderBy(query, o, orderBys.indexOf(o) == 0);
125 query.append(String.format(") x) WHERE %s BETWEEN %d AND %d",
126 QueryBuilder.quote("rownum"), offset, offset + pagelength));
127 sh.setQueryString(query.toString());