Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SQLDialect.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright 2004-2011 H2 Group.
  3. * Copyright 2011 James Moger.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package com.iciql;
  18. import java.sql.DatabaseMetaData;
  19. import com.iciql.TableDefinition.IndexDefinition;
  20. /**
  21. * This interface defines points where iciql can build different statements
  22. * depending on the database used.
  23. */
  24. public interface SQLDialect {
  25. /**
  26. * Configure the dialect from the database metadata.
  27. *
  28. * @param databaseName
  29. * @param data
  30. */
  31. void configureDialect(String databaseName, DatabaseMetaData data);
  32. /**
  33. * Returns a properly formatted table name for the dialect.
  34. *
  35. * @param schemaName
  36. * the schema name, or null for no schema
  37. * @param tableName
  38. * the properly formatted table name
  39. * @return the SQL snippet
  40. */
  41. String prepareTableName(String schemaName, String tableName);
  42. /**
  43. * Returns a properly formatted column name for the dialect.
  44. *
  45. * @param name
  46. * the column name
  47. * @return the properly formatted column name
  48. */
  49. String prepareColumnName(String name);
  50. /**
  51. * Get the CREATE TABLE statement.
  52. *
  53. * @param stat
  54. * @param def
  55. */
  56. <T> void prepareCreateTable(SQLStatement stat, TableDefinition<T> def);
  57. /**
  58. * Get the CREATE INDEX statement.
  59. *
  60. * @param schemaName
  61. * the schema name
  62. * @param tableName
  63. * the table name
  64. * @param index
  65. * the index definition
  66. * @return the SQL statement
  67. */
  68. void prepareCreateIndex(SQLStatement stat, String schemaName, String tableName, IndexDefinition index);
  69. /**
  70. * Get a MERGE or REPLACE INTO statement.
  71. *
  72. * @param schemaName
  73. * the schema name
  74. * @param tableName
  75. * the table name
  76. * @param index
  77. * the index definition
  78. */
  79. <T> void prepareMerge(SQLStatement stat, String schemaName, String tableName, TableDefinition<T> def,
  80. Object obj);
  81. /**
  82. * Append "LIMIT limit OFFSET offset" to the SQL statement.
  83. *
  84. * @param stat
  85. * the statement
  86. * @param limit
  87. * the limit
  88. * @param offset
  89. * the offset
  90. */
  91. void appendLimitOffset(SQLStatement stat, long limit, long offset);
  92. /**
  93. * Whether memory tables are supported.
  94. *
  95. * @return true if they are
  96. */
  97. boolean supportsMemoryTables();
  98. /**
  99. * Whether IF NOT EXISTS notation is supported.
  100. *
  101. * @return true if they are
  102. */
  103. boolean supportsIfNotExists();
  104. /**
  105. * Whether LIMIT/OFFSET notation is supported.
  106. *
  107. * @return true if they are
  108. */
  109. boolean supportsLimitOffset();
  110. /**
  111. * Returns the preferred DATETIME class for the database.
  112. * <p>
  113. * Either java.util.Date or java.sql.Timestamp
  114. *
  115. * @return preferred DATETIME class
  116. */
  117. Class<? extends java.util.Date> getDateTimeClass();
  118. }