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