Coverage Summary for Class: DialectSpecificSQLGenerator (com.acciente.oacc.sql.internal.persister)
Class | Method, % | Line, % |
---|---|---|
DialectSpecificSQLGenerator | 100% (7/ 7) | 78.6% (22/ 28) |
DialectSpecificSQLGenerator$1 | 100% (1/ 1) | 100% (1/ 1) |
total | 100% (8/ 8) | 79.3% (23/ 29) |
1 /*
2 * Copyright 2009-2018, Acciente LLC
3 *
4 * Acciente LLC licenses this file to you under the
5 * Apache License, Version 2.0 (the "License"); you
6 * may not use this file except in compliance with the
7 * License. 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
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
14 * OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License.
17 */
18 package com.acciente.oacc.sql.internal.persister;
19
20 import com.acciente.oacc.sql.SQLDialect;
21
22 class DialectSpecificSQLGenerator {
23 private final String withClause;
24 private final String unionClause;
25 private final String nextSeqValueStatementPrefix;
26 private final String nextSeqValueStatementSuffix;
27 private final String nextSeqValueFragmentPrefix;
28 private final String nextSeqValueFragmentSuffix;
29
30 private static final DialectSpecificSQLGenerator DB2_10_5 = new DialectSpecificSQLGenerator("WITH", "UNION ALL", "VALUES ( NEXT VALUE FOR ", " )", "NEXT VALUE FOR ", "");
31 private static final DialectSpecificSQLGenerator Oracle_11_2 = new DialectSpecificSQLGenerator("WITH", "UNION ALL", "SELECT ", ".NEXTVAL FROM DUAL", "", ".NEXTVAL");
32 private static final DialectSpecificSQLGenerator PostgreSQL_9_3 = new DialectSpecificSQLGenerator("WITH RECURSIVE", "UNION ALL", "SELECT nextval('", "')", "nextval('", "')");
33 private static final DialectSpecificSQLGenerator SQLServer_12_0 = new DialectSpecificSQLGenerator("WITH", "UNION ALL", "SELECT NEXT VALUE FOR ", "", "NEXT VALUE FOR ", "");
34 private static final DialectSpecificSQLGenerator SQLite_3_8 = new DialectSpecificSQLGenerator("WITH RECURSIVE", "UNION ALL", null, null, null, null);
35 private static final DialectSpecificSQLGenerator MySQL_5_6 = new DialectSpecificSQLGenerator(null, null, null, null, null, null);
36 private static final DialectSpecificSQLGenerator HSQLDB_2_3 = new DialectSpecificSQLGenerator(null, null, "VALUES NEXT VALUE FOR ", "", "NEXT VALUE FOR ", "");
37
38 static DialectSpecificSQLGenerator getInstance(SQLDialect sqlDialect) {
39 switch (sqlDialect) {
40 case DB2_10_5:
41 return DB2_10_5;
42 case Oracle_11_2:
43 return Oracle_11_2;
44 case PostgreSQL_9_3:
45 return PostgreSQL_9_3;
46 case SQLServer_12_0:
47 return SQLServer_12_0;
48 case SQLite_3_8:
49 return SQLite_3_8;
50 case MySQL_5_6:
51 return MySQL_5_6;
52 case HSQLDB_2_3:
53 return HSQLDB_2_3;
54 default:
55 throw new IllegalArgumentException("Unsupported SQL dialect: " + sqlDialect);
56 }
57 }
58
59 String getWithClause() {
60 return withClause;
61 }
62
63 String getUnionClause() {
64 return unionClause;
65 }
66
67 String nextSequenceValueStatement(String qualifiedSequenceName) {
68 return nextSeqValueStatementPrefix + qualifiedSequenceName + nextSeqValueStatementSuffix;
69 }
70
71 String nextSequenceValueFragment(String qualifiedSequenceName) {
72 return nextSeqValueFragmentPrefix + qualifiedSequenceName + nextSeqValueFragmentSuffix;
73 }
74
75 // private constructor to force use of constants
76 private DialectSpecificSQLGenerator(String withClause,
77 String unionClause,
78 String nextSeqValueStatementPrefix,
79 String nextSeqValueStatementSuffix,
80 String nextSeqValueFragmentPrefix,
81 String nextSeqValueFragmentSuffix) {
82 this.withClause = withClause;
83 this.unionClause = unionClause;
84 this.nextSeqValueStatementPrefix = nextSeqValueStatementPrefix;
85 this.nextSeqValueStatementSuffix = nextSeqValueStatementSuffix;
86 this.nextSeqValueFragmentPrefix = nextSeqValueFragmentPrefix;
87 this.nextSeqValueFragmentSuffix = nextSeqValueFragmentSuffix;
88 }
89 }