1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.isenshi.util.extlib;
17
18 import org.hibernate.dialect.HSQLDialect;
19 import org.hibernate.util.StringHelper;
20
21 /***
22 * @author someda
23 * @see <a href="http://opensource2.atlassian.com/projects/hibernate/browse/HHH-608">update HSQLDialect for HSQL 1.8 sequence support</a>
24 */
25 public class HSQL18Dialect extends HSQLDialect {
26
27 public String[] getCreateSequenceStrings(String sequenceName) {
28 return new String[] {
29 "create table information_schema." + sequenceName
30 + " (zero integer)",
31 "insert into information_schema." + sequenceName + " values (0)",
32 "create sequence " + sequenceName + " start with 1"
33 };
34 }
35
36 public String[] getDropSequenceStrings(String sequenceName) {
37 return new String[] {
38 "drop table information_schema." + sequenceName + " if exists",
39 "drop sequence " + sequenceName
40 };
41 }
42
43 public String getSequenceNextValString(String sequenceName) {
44 return "select next value for " + sequenceName
45 + " from information_schema." + sequenceName;
46 }
47
48 public String getQuerySequencesString() {
49 return "select sequence_name from information_schema.system_sequences";
50 }
51
52 public String getAddForeignKeyConstraintString(String constraintName,
53 String[] foreignKey,
54 String referencedTable,
55 String[] primaryKey) {
56 StringBuffer buf = new StringBuffer(30);
57 buf.append(" add");
58
59 if(constraintName != null){
60 buf.append(" constraint ");
61 buf.append(constraintName);
62 }
63
64 buf.append( " foreign key (" )
65 .append( StringHelper.join( ", ", foreignKey ) )
66 .append( ") references " )
67 .append( referencedTable )
68 .append( "(" )
69 .append( StringHelper.join(", ",primaryKey))
70 .append( ")" );
71
72 return buf.toString();
73 }
74
75 }
76