You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SQLDialectDerby.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2011 James Moger.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of 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,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.iciql;
  17. import com.iciql.util.StatementBuilder;
  18. /**
  19. * Derby database dialect.
  20. */
  21. public class SQLDialectDerby extends SQLDialectDefault {
  22. @Override
  23. public Class<? extends java.util.Date> getDateTimeClass() {
  24. return java.sql.Timestamp.class;
  25. }
  26. @Override
  27. public String convertSqlType(String sqlType) {
  28. if ("TINYINT".equals(sqlType)) {
  29. // Derby does not have a TINYINT/BYTE type
  30. return "SMALLINT";
  31. }
  32. return sqlType;
  33. }
  34. @Override
  35. public void appendLimitOffset(SQLStatement stat, long limit, long offset) {
  36. // FETCH/OFFSET added in 10.5
  37. if (databaseMajorVersion >= 10 && databaseMinorVersion >= 5) {
  38. if (offset > 0) {
  39. stat.appendSQL(" OFFSET " + offset + (offset == 1 ? " ROW" : " ROWS"));
  40. }
  41. if (limit > 0) {
  42. stat.appendSQL(" FETCH NEXT " + limit + (limit == 1 ? " ROW" : " ROWS") + " ONLY");
  43. }
  44. }
  45. }
  46. @Override
  47. protected boolean prepareColumnDefinition(StatementBuilder buff, String dataType,
  48. boolean isAutoIncrement, boolean isPrimaryKey) {
  49. String convertedType = convertSqlType(dataType);
  50. buff.append(convertedType);
  51. if (isIntegerType(dataType) && isAutoIncrement) {
  52. buff.append(" GENERATED BY DEFAULT AS IDENTITY");
  53. }
  54. return false;
  55. }
  56. @Override
  57. public <T> void prepareDropTable(SQLStatement stat, TableDefinition<T> def) {
  58. StatementBuilder buff = new StatementBuilder("DROP TABLE "
  59. + prepareTableName(def.schemaName, def.tableName));
  60. stat.setSQL(buff.toString());
  61. return;
  62. }
  63. }