-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathKingbaseSQLDialect.java
More file actions
86 lines (72 loc) · 2.27 KB
/
Copy pathKingbaseSQLDialect.java
File metadata and controls
86 lines (72 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*Copyright (C) 2026 the APIJSON group. All rights reserved.
This source code is licensed under the Apache License Version 2.0.*/
package apijson.orm;
/** Centralized SQL capabilities for KingbaseES compatibility modes. */
public enum KingbaseSQLDialect {
NONE(null, null, false, false),
LEGACY(SQLConfig.DATABASE_KINGBASE, "\"", false, false),
MYSQL(SQLConfig.DATABASE_KINGBASE_MYSQL, "`", true, true),
ORACLE(SQLConfig.DATABASE_KINGBASE_ORACLE, "\"", false, false),
SQLSERVER(SQLConfig.DATABASE_KINGBASE_SQLSERVER, "\"", false, false);
private final String database;
private final String identifierQuote;
private final boolean mysqlSyntax;
private final boolean dmlLimit;
KingbaseSQLDialect(String database, String identifierQuote, boolean mysqlSyntax, boolean dmlLimit) {
this.database = database;
this.identifierQuote = identifierQuote;
this.mysqlSyntax = mysqlSyntax;
this.dmlLimit = dmlLimit;
}
public static KingbaseSQLDialect from(String database) {
if (database != null) {
for (KingbaseSQLDialect dialect : values()) {
if (database.equals(dialect.database)) {
return dialect;
}
}
}
return NONE;
}
public boolean isKingbase() {
return this != NONE;
}
public boolean isMySQL() {
return mysqlSyntax;
}
public boolean isOracle() {
return this == ORACLE;
}
public boolean isSQLServer() {
return this == SQLSERVER;
}
public boolean supportsDmlLimit() {
return dmlLimit;
}
/**
* SQL Server compatibility mode follows the SQL Server spelling of the
* OFFSET/FETCH clause. Other T-SQL-family databases in APIJSON retain their
* existing FETCH FIRST spelling.
*/
public String getSelectLimit(int offset, int count) {
if (isSQLServer()) {
return " OFFSET " + offset + " ROWS FETCH NEXT " + count + " ROWS ONLY";
}
return null;
}
/**
* KingbaseES exposes an explain statement returning the plan result set.
* SQL Server's session-level STATISTICS PROFILE switch is therefore neither
* required nor suitable for APIJSON's one-shot explain request. Oracle mode
* retains its compatible EXPLAIN PLAN FOR spelling.
*/
public String getExplainPrefix() {
if (isOracle()) {
return "EXPLAIN PLAN FOR ";
}
return isKingbase() ? "EXPLAIN " : null;
}
public String getIdentifierQuote() {
return identifierQuote;
}
}