KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > dialect > SAPDBDialect


1 //$Id: SAPDBDialect.java,v 1.10 2005/07/07 02:39:10 steveebersole Exp $
2
// contributed by Brad Clow
3
package org.hibernate.dialect;
4
5 import java.sql.Types JavaDoc;
6
7 import org.hibernate.cfg.Environment;
8 import org.hibernate.sql.CaseFragment;
9 import org.hibernate.sql.DecodeCaseFragment;
10 import org.hibernate.sql.OracleJoinFragment;
11 import org.hibernate.sql.JoinFragment;
12 import org.hibernate.util.StringHelper;
13
14 /**
15  * An SQL dialect compatible with SAP DB.
16  * @author Brad Clow
17  */

18 public class SAPDBDialect extends Dialect {
19
20     public SAPDBDialect() {
21         super();
22         registerColumnType( Types.BIT, "boolean" );
23         registerColumnType( Types.BIGINT, "fixed(19,0)" );
24         registerColumnType( Types.SMALLINT, "smallint" );
25         registerColumnType( Types.TINYINT, "fixed(3,0)" );
26         registerColumnType( Types.INTEGER, "int" );
27         registerColumnType( Types.CHAR, "char(1)" );
28         registerColumnType( Types.VARCHAR, "varchar($l)" );
29         registerColumnType( Types.FLOAT, "float" );
30         registerColumnType( Types.DOUBLE, "double precision" );
31         registerColumnType( Types.DATE, "date" );
32         registerColumnType( Types.TIME, "time" );
33         registerColumnType( Types.TIMESTAMP, "timestamp" );
34         registerColumnType( Types.VARBINARY, "long byte" );
35         registerColumnType( Types.NUMERIC, "fixed($p,$s)" );
36         registerColumnType( Types.CLOB, "long varchar" );
37         registerColumnType( Types.BLOB, "long byte" );
38
39         getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
40
41     }
42
43     public boolean dropConstraints() {
44         return false;
45     }
46
47     public String JavaDoc getAddColumnString() {
48         return "add";
49     }
50
51     public String JavaDoc getAddForeignKeyConstraintString(
52             String JavaDoc constraintName,
53             String JavaDoc[] foreignKey,
54             String JavaDoc referencedTable,
55             String JavaDoc[] primaryKey, boolean referencesPrimaryKey
56     ) {
57         StringBuffer JavaDoc res = new StringBuffer JavaDoc(30)
58             .append(" foreign key ")
59             .append(constraintName)
60             .append(" (")
61             .append( StringHelper.join(", ", foreignKey) )
62             .append(") references ")
63             .append(referencedTable);
64         
65         if(!referencesPrimaryKey) {
66             res.append(" (")
67                .append( StringHelper.join(", ", primaryKey) )
68                .append(')');
69         }
70             
71         return res.toString();
72     }
73
74     public String JavaDoc getAddPrimaryKeyConstraintString(String JavaDoc constraintName) {
75         return " primary key ";
76     }
77
78     public String JavaDoc getNullColumnString() {
79         return " null";
80     }
81
82     public String JavaDoc getSequenceNextValString(String JavaDoc sequenceName) {
83         return "select " + getSelectSequenceNextValString( sequenceName ) + " from dual";
84     }
85
86     public String JavaDoc getSelectSequenceNextValString(String JavaDoc sequenceName) {
87         return sequenceName + ".nextval";
88     }
89
90     public String JavaDoc getCreateSequenceString(String JavaDoc sequenceName) {
91         return "create sequence " + sequenceName;
92     }
93
94     public String JavaDoc getDropSequenceString(String JavaDoc sequenceName) {
95         return "drop sequence " + sequenceName;
96     }
97
98     public String JavaDoc getQuerySequencesString() {
99         return "select sequence_name from domain.sequences";
100     }
101
102     public JoinFragment createOuterJoinFragment() {
103         return new OracleJoinFragment();
104     }
105
106
107     public boolean supportsSequences() {
108         return true;
109     }
110
111     public CaseFragment createCaseFragment() {
112         return new DecodeCaseFragment();
113     }
114
115 }
116
Popular Tags