1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.generator.internal.db;
17
18 import java.util.Optional;
19
20
21
22
23
24
25 public enum DatabaseDialects {
26
27 DB2("VALUES IDENTITY_VAL_LOCAL()"),
28 MYSQL("SELECT LAST_INSERT_ID()"),
29 SQLSERVER("SELECT SCOPE_IDENTITY()"),
30 CLOUDSCAPE("VALUES IDENTITY_VAL_LOCAL()"),
31 DERBY("VALUES IDENTITY_VAL_LOCAL()"),
32 HSQLDB("CALL IDENTITY()"),
33 SYBASE("SELECT @@IDENTITY"),
34 DB2_MF("SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1"),
35 INFORMIX("select dbinfo('sqlca.sqlerrd1') from systables where tabid=1");
36
37 private final String identityRetrievalStatement;
38
39 DatabaseDialects(String identityRetrievalStatement) {
40 this.identityRetrievalStatement = identityRetrievalStatement;
41 }
42
43 public String getIdentityRetrievalStatement() {
44 return identityRetrievalStatement;
45 }
46
47
48
49
50
51
52
53
54
55
56 public static Optional<DatabaseDialects> getDatabaseDialect(String database) {
57 DatabaseDialects returnValue = null;
58
59 if ("DB2".equalsIgnoreCase(database)) {
60 returnValue = DB2;
61 } else if ("MySQL".equalsIgnoreCase(database)) {
62 returnValue = MYSQL;
63 } else if ("SqlServer".equalsIgnoreCase(database)) {
64 returnValue = SQLSERVER;
65 } else if ("Cloudscape".equalsIgnoreCase(database)) {
66 returnValue = CLOUDSCAPE;
67 } else if ("Derby".equalsIgnoreCase(database)) {
68 returnValue = DERBY;
69 } else if ("HSQLDB".equalsIgnoreCase(database)) {
70 returnValue = HSQLDB;
71 } else if ("SYBASE".equalsIgnoreCase(database)) {
72 returnValue = SYBASE;
73 } else if ("DB2_MF".equalsIgnoreCase(database)) {
74 returnValue = DB2_MF;
75 } else if ("Informix".equalsIgnoreCase(database)) {
76 returnValue = INFORMIX;
77 }
78
79 return Optional.ofNullable(returnValue);
80 }
81 }