View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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