選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

OracleGenerator.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  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
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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
  14. * the License.
  15. */
  16. package com.vaadin.v7.data.util.sqlcontainer.query.generator;
  17. import java.util.List;
  18. import com.vaadin.v7.data.Container.Filter;
  19. import com.vaadin.v7.data.util.sqlcontainer.query.OrderBy;
  20. import com.vaadin.v7.data.util.sqlcontainer.query.generator.filter.QueryBuilder;
  21. /**
  22. * @deprecated As of 8.0, no replacement available.
  23. */
  24. @SuppressWarnings("serial")
  25. @Deprecated
  26. public class OracleGenerator extends DefaultSQLGenerator {
  27. public OracleGenerator() {
  28. }
  29. public OracleGenerator(
  30. Class<? extends StatementHelper> statementHelperClazz) {
  31. super(statementHelperClazz);
  32. }
  33. /**
  34. * Construct an OracleSQLGenerator with the specified identifiers for start
  35. * and end of quoted strings. The identifiers may be different depending on
  36. * the database engine and it's settings.
  37. *
  38. * @param quoteStart
  39. * the identifier (character) denoting the start of a quoted
  40. * string
  41. * @param quoteEnd
  42. * the identifier (character) denoting the end of a quoted string
  43. */
  44. public OracleGenerator(String quoteStart, String quoteEnd) {
  45. super(quoteStart, quoteEnd);
  46. }
  47. public OracleGenerator(String quoteStart, String quoteEnd,
  48. Class<? extends StatementHelper> statementHelperClazz) {
  49. super(quoteStart, quoteEnd, statementHelperClazz);
  50. }
  51. /*
  52. * (non-Javadoc)
  53. *
  54. * @see com.vaadin.addon.sqlcontainer.query.generator.DefaultSQLGenerator#
  55. * generateSelectQuery(java.lang.String, java.util.List,
  56. * com.vaadin.addon.sqlcontainer.query.FilteringMode, java.util.List, int,
  57. * int, java.lang.String)
  58. */
  59. @Override
  60. public StatementHelper generateSelectQuery(String tableName,
  61. List<Filter> filters, List<OrderBy> orderBys, int offset,
  62. int pagelength, String toSelect) {
  63. if (tableName == null || tableName.trim().equals("")) {
  64. throw new IllegalArgumentException("Table name must be given.");
  65. }
  66. /* Adjust offset and page length parameters to match "row numbers" */
  67. offset = pagelength > 1 ? ++offset : offset;
  68. pagelength = pagelength > 1 ? --pagelength : pagelength;
  69. toSelect = toSelect == null ? "*" : toSelect;
  70. StatementHelper sh = getStatementHelper();
  71. StringBuffer query = new StringBuffer();
  72. /* Row count request is handled here */
  73. if ("COUNT(*)".equalsIgnoreCase(toSelect)) {
  74. query.append(String.format(
  75. "SELECT COUNT(*) AS %s FROM (SELECT * FROM %s",
  76. QueryBuilder.quote("rowcount"), tableName));
  77. if (filters != null && !filters.isEmpty()) {
  78. query.append(
  79. QueryBuilder.getWhereStringForFilters(filters, sh));
  80. }
  81. query.append(")");
  82. sh.setQueryString(query.toString());
  83. return sh;
  84. }
  85. /* SELECT without row number constraints */
  86. if (offset == 0 && pagelength == 0) {
  87. query.append("SELECT ").append(toSelect).append(" FROM ")
  88. .append(tableName);
  89. if (filters != null) {
  90. query.append(
  91. QueryBuilder.getWhereStringForFilters(filters, sh));
  92. }
  93. if (orderBys != null) {
  94. for (OrderBy o : orderBys) {
  95. generateOrderBy(query, o, orderBys.indexOf(o) == 0);
  96. }
  97. }
  98. sh.setQueryString(query.toString());
  99. return sh;
  100. }
  101. /* Remaining SELECT cases are handled here */
  102. query.append(String.format(
  103. "SELECT * FROM (SELECT x.*, ROWNUM AS %s FROM (SELECT %s FROM %s",
  104. QueryBuilder.quote("rownum"), toSelect, tableName));
  105. if (filters != null) {
  106. query.append(QueryBuilder.getWhereStringForFilters(filters, sh));
  107. }
  108. if (orderBys != null) {
  109. for (OrderBy o : orderBys) {
  110. generateOrderBy(query, o, orderBys.indexOf(o) == 0);
  111. }
  112. }
  113. query.append(String.format(") x) WHERE %s BETWEEN %d AND %d",
  114. QueryBuilder.quote("rownum"), offset, offset + pagelength));
  115. sh.setQueryString(query.toString());
  116. return sh;
  117. }
  118. }