KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: Dialect.java,v 1.55 2005/07/20 05:00:17 oneovthafew Exp $
2
package org.hibernate.dialect;
3
4 import java.sql.CallableStatement JavaDoc;
5 import java.sql.ResultSet JavaDoc;
6 import java.sql.SQLException JavaDoc;
7 import java.sql.Types JavaDoc;
8 import java.util.HashMap JavaDoc;
9 import java.util.Map JavaDoc;
10 import java.util.Properties JavaDoc;
11
12 import org.apache.commons.logging.Log;
13 import org.apache.commons.logging.LogFactory;
14 import org.hibernate.Hibernate;
15 import org.hibernate.HibernateException;
16 import org.hibernate.LockMode;
17 import org.hibernate.MappingException;
18 import org.hibernate.QueryException;
19 import org.hibernate.cfg.Environment;
20 import org.hibernate.dialect.function.CastFunction;
21 import org.hibernate.dialect.function.SQLFunction;
22 import org.hibernate.dialect.function.SQLFunctionTemplate;
23 import org.hibernate.dialect.function.StandardSQLFunction;
24 import org.hibernate.engine.Mapping;
25 import org.hibernate.exception.SQLExceptionConverter;
26 import org.hibernate.exception.SQLStateConverter;
27 import org.hibernate.exception.ViolatedConstraintNameExtracter;
28 import org.hibernate.id.IdentityGenerator;
29 import org.hibernate.id.SequenceGenerator;
30 import org.hibernate.id.TableHiLoGenerator;
31 import org.hibernate.mapping.Column;
32 import org.hibernate.sql.ANSICaseFragment;
33 import org.hibernate.sql.ANSIJoinFragment;
34 import org.hibernate.sql.CaseFragment;
35 import org.hibernate.sql.JoinFragment;
36 import org.hibernate.type.Type;
37 import org.hibernate.util.ReflectHelper;
38 import org.hibernate.util.StringHelper;
39
40 /**
41  * Represents a dialect of SQL implemented by a particular RDBMS.
42  * Subclasses implement Hibernate compatibility with different systems.<br>
43  * <br>
44  * Subclasses should provide a public default constructor that <tt>register()</tt>
45  * a set of type mappings and default Hibernate properties.<br>
46  * <br>
47  * Subclasses should be immutable.
48  *
49  * @author Gavin King, David Channon
50  */

51 public abstract class Dialect {
52
53     private static final Log log = LogFactory.getLog( Dialect.class );
54
55     static final String JavaDoc DEFAULT_BATCH_SIZE = "15";
56     static final String JavaDoc NO_BATCH = "0";
57
58     private static final Map JavaDoc STANDARD_AGGREGATE_FUNCTIONS = new HashMap JavaDoc();
59
60     static {
61         STANDARD_AGGREGATE_FUNCTIONS.put( "count", new StandardSQLFunction("count") {
62             public Type getReturnType(Type columnType, Mapping mapping) {
63                 return Hibernate.INTEGER;
64             }
65         } );
66
67         STANDARD_AGGREGATE_FUNCTIONS.put( "avg", new StandardSQLFunction("avg") {
68             public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
69                 int[] sqlTypes;
70                 try {
71                     sqlTypes = columnType.sqlTypes( mapping );
72                 }
73                 catch ( MappingException me ) {
74                     throw new QueryException( me );
75                 }
76                 if ( sqlTypes.length != 1 ) throw new QueryException( "multi-column type in avg()" );
77                 int sqlType = sqlTypes[0];
78                 if ( sqlType == Types.INTEGER || sqlType == Types.BIGINT || sqlType == Types.TINYINT ) {
79                     return Hibernate.FLOAT;
80                 }
81                 else {
82                     return columnType;
83                 }
84             }
85         } );
86
87         STANDARD_AGGREGATE_FUNCTIONS.put( "max", new StandardSQLFunction("max") );
88         STANDARD_AGGREGATE_FUNCTIONS.put( "min", new StandardSQLFunction("min") );
89         STANDARD_AGGREGATE_FUNCTIONS.put( "sum", new StandardSQLFunction("sum") );
90     }
91
92     protected Dialect() {
93         log.info( "Using dialect: " + this );
94         sqlFunctions.putAll( STANDARD_AGGREGATE_FUNCTIONS );
95
96         // standard sql92 functions (can be overridden by subclasses)
97
registerFunction( "substring", new SQLFunctionTemplate( Hibernate.STRING, "substring(?1, ?2, ?3)" ) );
98         registerFunction( "locate", new SQLFunctionTemplate( Hibernate.INTEGER, "locate(?1, ?2, ?3)" ) );
99         registerFunction( "trim", new SQLFunctionTemplate( Hibernate.STRING, "trim(?1 ?2 ?3 ?4)" ) );
100         registerFunction( "length", new StandardSQLFunction( "length", Hibernate.INTEGER ) );
101         registerFunction( "bit_length", new StandardSQLFunction( "bit_length", Hibernate.INTEGER ) );
102         registerFunction( "coalesce", new StandardSQLFunction( "coalesce" ) );
103         registerFunction( "nullif", new StandardSQLFunction( "nullif" ) );
104         registerFunction( "abs", new StandardSQLFunction( "abs" ) );
105         registerFunction( "mod", new StandardSQLFunction( "mod", Hibernate.INTEGER) );
106         registerFunction( "sqrt", new StandardSQLFunction( "sqrt", Hibernate.DOUBLE) );
107         registerFunction( "upper", new StandardSQLFunction("upper") );
108         registerFunction( "lower", new StandardSQLFunction("lower") );
109         registerFunction( "cast", new CastFunction() );
110         registerFunction( "extract", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(?1 ?2 ?3)") );
111         
112         //map second/minute/hour/day/month/year to ANSI extract(), override on subclasses
113
registerFunction( "second", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(second from ?1)") );
114         registerFunction( "minute", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(minute from ?1)") );
115         registerFunction( "hour", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(hour from ?1)") );
116         registerFunction( "day", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(day from ?1)") );
117         registerFunction( "month", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(month from ?1)") );
118         registerFunction( "year", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(year from ?1)") );
119         
120         registerFunction( "str", new SQLFunctionTemplate(Hibernate.STRING, "cast(?1 as char)") );
121
122     }
123
124     public String JavaDoc toString() {
125         return getClass().getName();
126     }
127
128     private final TypeNames typeNames = new TypeNames();
129     private final Properties JavaDoc properties = new Properties JavaDoc();
130     private final Map JavaDoc sqlFunctions = new HashMap JavaDoc();
131
132     /**
133      * Characters used for quoting SQL identifiers
134      */

135     public static final String JavaDoc QUOTE = "`\"[";
136     public static final String JavaDoc CLOSED_QUOTE = "`\"]";
137
138
139     /**
140      * Get the name of the database type associated with the given
141      * <tt>java.sql.Types</tt> typecode.
142      *
143      * @param code <tt>java.sql.Types</tt> typecode
144      * @return the database type name
145      * @throws HibernateException
146      */

147     public String JavaDoc getTypeName(int code) throws HibernateException {
148         String JavaDoc result = typeNames.get( code );
149         if ( result == null ) {
150             throw new HibernateException( "No default type mapping for (java.sql.Types) " + code );
151         }
152         return result;
153     }
154
155     /**
156      * Get the name of the database type associated with the given
157      * <tt>java.sql.Types</tt> typecode.
158      * @param code <tt>java.sql.Types</tt> typecode
159      * @param length the length or precision of the column
160      * @param precision the precision of the column
161      * @param scale the scale of the column
162      *
163      * @return the database type name
164      * @throws HibernateException
165      */

166     public String JavaDoc getTypeName(int code, int length, int precision, int scale) throws HibernateException {
167         String JavaDoc result = typeNames.get( code, length, precision, scale );
168         if ( result == null ) {
169             throw new HibernateException(
170                     "No type mapping for java.sql.Types code: " +
171                     code +
172                     ", length: " +
173                     length
174                 );
175         }
176         return result;
177     }
178     
179     public String JavaDoc getCastTypeName(int code) {
180         return getTypeName(
181                 code,
182                 Column.DEFAULT_LENGTH,
183                 Column.DEFAULT_PRECISION,
184                 Column.DEFAULT_SCALE
185             );
186     }
187
188     protected void registerFunction(String JavaDoc name, SQLFunction function) {
189         sqlFunctions.put( name, function );
190     }
191
192     /**
193      * Subclasses register a typename for the given type code and maximum
194      * column length. <tt>$l</tt> in the type name with be replaced by the
195      * column length (if appropriate).
196      *
197      * @param code <tt>java.sql.Types</tt> typecode
198      * @param capacity maximum length of database type
199      * @param name the database type name
200      */

201     protected void registerColumnType(int code, int capacity, String JavaDoc name) {
202         typeNames.put( code, capacity, name );
203     }
204
205     /**
206      * Subclasses register a typename for the given type code. <tt>$l</tt> in
207      * the type name with be replaced by the column length (if appropriate).
208      *
209      * @param code <tt>java.sql.Types</tt> typecode
210      * @param name the database type name
211      */

212     protected void registerColumnType(int code, String JavaDoc name) {
213         typeNames.put( code, name );
214     }
215
216     /**
217      * Does this dialect support the <tt>ALTER TABLE</tt> syntax?
218      *
219      * @return boolean
220      */

221     public boolean hasAlterTable() {
222         return true;
223     }
224
225     /**
226      * Do we need to drop constraints before dropping tables in this dialect?
227      *
228      * @return boolean
229      */

230     public boolean dropConstraints() {
231         return true;
232     }
233
234     /**
235      * Do we need to qualify index names with the schema name?
236      *
237      * @return boolean
238      */

239     public boolean qualifyIndexName() {
240         return true;
241     }
242
243     /**
244      * Does the <tt>FOR UPDATE OF</tt> syntax specify particular
245      * columns?
246      */

247     public boolean forUpdateOfColumns() {
248         return false;
249     }
250
251     /**
252      * Does this dialect support the <tt>FOR UPDATE OF</tt> syntax?
253      *
254      * @return boolean
255      */

256     public String JavaDoc getForUpdateString(String JavaDoc aliases) {
257         return getForUpdateString();
258     }
259
260     /**
261      * Does this dialect support the Oracle-style <tt>FOR UPDATE OF ... NOWAIT</tt>
262      * syntax?
263      *
264      * @return boolean
265      */

266     public String JavaDoc getForUpdateNowaitString(String JavaDoc aliases) {
267         return getForUpdateString( aliases );
268     }
269
270     /**
271      * Does this dialect support the <tt>FOR UPDATE</tt> syntax?
272      *
273      * @return boolean
274      */

275     public String JavaDoc getForUpdateString() {
276         return " for update";
277     }
278
279     /**
280      * Does this dialect support the Oracle-style <tt>FOR UPDATE NOWAIT</tt> syntax?
281      *
282      * @return boolean
283      */

284     public String JavaDoc getForUpdateNowaitString() {
285         return getForUpdateString();
286     }
287
288     /**
289      * Does this dialect support the <tt>UNIQUE</tt> column syntax?
290      *
291      * @return boolean
292      */

293     public boolean supportsUnique() {
294         return true;
295     }
296     
297
298     /**
299      * Does this dialect support adding Unique constraints via create and alter table ?
300      * @return boolean
301      */

302     public boolean supportsUniqueConstraintInCreateAlterTable() {
303         return true;
304     }
305
306
307     /**
308      * The syntax used to add a column to a table (optional).
309      */

310     public String JavaDoc getAddColumnString() {
311         throw new UnsupportedOperationException JavaDoc( "No add column syntax supported by Dialect" );
312     }
313
314     public String JavaDoc getDropForeignKeyString() {
315         return " drop constraint ";
316     }
317
318     public String JavaDoc getTableTypeString() {
319         return "";
320     }
321
322     /**
323      * The syntax used to add a foreign key constraint to a table.
324      *
325      * @param referencesPrimaryKey if false, constraint should be
326      * explicit about which column names the constraint refers to
327      *
328      * @return String
329      */

330     public String JavaDoc getAddForeignKeyConstraintString(
331             String JavaDoc constraintName,
332             String JavaDoc[] foreignKey,
333             String JavaDoc referencedTable,
334             String JavaDoc[] primaryKey,
335             boolean referencesPrimaryKey
336     ) {
337         StringBuffer JavaDoc res = new StringBuffer JavaDoc( 30 );
338         
339         res.append( " add constraint " )
340            .append( constraintName )
341            .append( " foreign key (" )
342            .append( StringHelper.join( ", ", foreignKey ) )
343            .append( ") references " )
344            .append( referencedTable );
345         
346         if(!referencesPrimaryKey) {
347             res.append(" (")
348                .append( StringHelper.join(", ", primaryKey) )
349                .append(')');
350         }
351
352         return res.toString();
353     }
354
355     /**
356      * The syntax used to add a primary key constraint to a table.
357      *
358      * @return String
359      */

360     public String JavaDoc getAddPrimaryKeyConstraintString(String JavaDoc constraintName) {
361         return " add constraint " + constraintName + " primary key ";
362     }
363
364     /**
365      * The keyword used to specify a nullable column.
366      *
367      * @return String
368      */

369     public String JavaDoc getNullColumnString() {
370         return "";
371     }
372
373     /**
374      * Does this dialect support identity column key generation?
375      *
376      * @return boolean
377      */

378     public boolean supportsIdentityColumns() {
379         return false;
380     }
381
382     /**
383      * Does this dialect support sequences?
384      *
385      * @return boolean
386      */

387     public boolean supportsSequences() {
388         return false;
389     }
390
391     public boolean supportsInsertSelectIdentity() {
392         return false;
393     }
394
395     /**
396      * Append a clause to retrieve the generated identity value for the
397      * given <tt>INSERT</tt> statement.
398      */

399     public String JavaDoc appendIdentitySelectToInsert(String JavaDoc insertString) {
400         return insertString;
401     }
402
403     protected String JavaDoc getIdentitySelectString() throws MappingException {
404         throw new MappingException( "Dialect does not support identity key generation" );
405     }
406
407     /**
408      * The syntax that returns the identity value of the last insert, if
409      * identity column key generation is supported.
410      *
411      * @param type TODO
412      * @throws MappingException if no native key generation
413      */

414     public String JavaDoc getIdentitySelectString(String JavaDoc table, String JavaDoc column, int type)
415             throws MappingException {
416         return getIdentitySelectString();
417     }
418
419     protected String JavaDoc getIdentityColumnString() throws MappingException {
420         throw new MappingException( "Dialect does not support identity key generation" );
421     }
422
423     /**
424      * The keyword used to specify an identity column, if identity
425      * column key generation is supported.
426      *
427      * @param type the SQL column type, as defined by <tt>java.sql.Types</tt>
428      * @throws MappingException if no native key generation
429      */

430     public String JavaDoc getIdentityColumnString(int type) throws MappingException {
431         return getIdentityColumnString();
432     }
433
434     /**
435      * The keyword used to insert a generated value into an identity column (or null)
436      *
437      * @return String
438      */

439     public String JavaDoc getIdentityInsertString() {
440         return null;
441     }
442
443     /**
444      * The keyword used to insert a row without specifying any column values
445      */

446     public String JavaDoc getNoColumnsInsertString() {
447         return "values ( )";
448     }
449
450     /**
451      * Generate the appropriate select statement to to retreive the next value
452      * of a sequence, if sequences are supported.
453      * <p/>
454      * This should be a "stand alone" select statement.
455      *
456      * @param sequenceName the name of the sequence
457      * @return String The "nextval" select string.
458      * @throws MappingException if no sequences
459      */

460     public String JavaDoc getSequenceNextValString(String JavaDoc sequenceName) throws MappingException {
461         throw new MappingException( "Dialect does not support sequences" );
462     }
463
464     /**
465      * Generate the select expression fragment that will retreive the next
466      * value of a sequence, if sequences are supported.
467      * <p/>
468      * This differs from {@link #getSequenceNextValString(String)} in that this
469      * should return an expression usable within another select statement.
470      *
471      * @param sequenceName the name of the sequence
472      * @return String
473      * @throws MappingException if no sequences
474      */

475     public String JavaDoc getSelectSequenceNextValString(String JavaDoc sequenceName) throws MappingException {
476         throw new MappingException( "Dialect does not support sequences" );
477     }
478
479     /**
480      * The syntax used to create a sequence, if sequences are supported.
481      *
482      * @param sequenceName the name of the sequence
483      * @return String
484      * @throws MappingException if no sequences
485      */

486     protected String JavaDoc getCreateSequenceString(String JavaDoc sequenceName) throws MappingException {
487         throw new MappingException( "Dialect does not support sequences" );
488     }
489
490     /**
491      * The multiline script used to create a sequence, if sequences are supported.
492      *
493      * @param sequenceName the name of the sequence
494      * @return String[]
495      * @throws MappingException if no sequences
496      */

497     public String JavaDoc[] getCreateSequenceStrings(String JavaDoc sequenceName) throws MappingException {
498         return new String JavaDoc[]{getCreateSequenceString( sequenceName )};
499     }
500
501     /**
502      * The syntax used to drop a sequence, if sequences are supported.
503      *
504      * @param sequenceName the name of the sequence
505      * @return String
506      * @throws MappingException if no sequences
507      */

508     protected String JavaDoc getDropSequenceString(String JavaDoc sequenceName) throws MappingException {
509         throw new MappingException( "Dialect does not support sequences" );
510     }
511
512     /**
513      * The multiline script used to drop a sequence, if sequences are supported.
514      *
515      * @param sequenceName the name of the sequence
516      * @return String[]
517      * @throws MappingException if no sequences
518      */

519     public String JavaDoc[] getDropSequenceStrings(String JavaDoc sequenceName) throws MappingException {
520         return new String JavaDoc[]{getDropSequenceString( sequenceName )};
521     }
522
523     /**
524      * A query used to find all sequences
525      *
526      * @see org.hibernate.tool.hbm2ddl.SchemaUpdate
527      */

528     public String JavaDoc getQuerySequencesString() {
529         return null;
530     }
531
532     /**
533      * Get the <tt>Dialect</tt> specified by the current <tt>System</tt> properties.
534      *
535      * @return Dialect
536      * @throws HibernateException
537      */

538     public static Dialect getDialect() throws HibernateException {
539         String JavaDoc dialectName = Environment.getProperties().getProperty( Environment.DIALECT );
540         if ( dialectName == null ) throw new HibernateException( "The dialect was not set. Set the property hibernate.dialect." );
541         try {
542             return ( Dialect ) ReflectHelper.classForName( dialectName ).newInstance();
543         }
544         catch ( ClassNotFoundException JavaDoc cnfe ) {
545             throw new HibernateException( "Dialect class not found: " + dialectName );
546         }
547         catch ( Exception JavaDoc e ) {
548             throw new HibernateException( "Could not instantiate dialect class", e );
549         }
550     }
551
552
553     /**
554      * Get the <tt>Dialect</tt> specified by the given properties or system properties.
555      *
556      * @param props
557      * @return Dialect
558      * @throws HibernateException
559      */

560     public static Dialect getDialect(Properties JavaDoc props) throws HibernateException {
561         String JavaDoc dialectName = props.getProperty( Environment.DIALECT );
562         if ( dialectName == null ) return getDialect();
563         try {
564             return ( Dialect ) ReflectHelper.classForName( dialectName ).newInstance();
565         }
566         catch ( ClassNotFoundException JavaDoc cnfe ) {
567             throw new HibernateException( "Dialect class not found: " + dialectName );
568         }
569         catch ( Exception JavaDoc e ) {
570             throw new HibernateException( "Could not instantiate dialect class", e );
571         }
572     }
573
574     /**
575      * Retrieve a set of default Hibernate properties for this database.
576      *
577      * @return a set of Hibernate properties
578      */

579     public final Properties JavaDoc getDefaultProperties() {
580         return properties;
581     }
582
583     /**
584      * Completely optional cascading drop clause
585      *
586      * @return String
587      */

588     public String JavaDoc getCascadeConstraintsString() {
589         return "";
590     }
591
592     /**
593      * Create an <tt>OuterJoinGenerator</tt> for this dialect.
594      *
595      * @return OuterJoinGenerator
596      */

597     public JoinFragment createOuterJoinFragment() {
598         return new ANSIJoinFragment();
599     }
600
601     /**
602      * Create a <tt>CaseFragment</tt> for this dialect.
603      *
604      * @return OuterJoinGenerator
605      */

606     public CaseFragment createCaseFragment() {
607         return new ANSICaseFragment();
608     }
609
610     /**
611      * The name of the SQL function that transforms a string to
612      * lowercase
613      *
614      * @return String
615      */

616     public String JavaDoc getLowercaseFunction() {
617         return "lower";
618     }
619
620     /**
621      * Does this <tt>Dialect</tt> have some kind of <tt>LIMIT</tt> syntax?
622      */

623     public boolean supportsLimit() {
624         return false;
625     }
626
627     /**
628      * Does this dialect support an offset?
629      */

630     public boolean supportsLimitOffset() {
631         return supportsLimit();
632     }
633
634     /**
635      * Add a <tt>LIMIT</tt> clause to the given SQL <tt>SELECT</tt>
636      *
637      * @return the modified SQL
638      */

639     public String JavaDoc getLimitString(String JavaDoc querySelect, boolean hasOffset) {
640         throw new UnsupportedOperationException JavaDoc( "paged queries not supported" );
641     }
642
643     public String JavaDoc getLimitString(String JavaDoc querySelect, int offset, int limit) {
644         return getLimitString( querySelect, offset>0 );
645     }
646
647     public boolean supportsVariableLimit() {
648         return supportsLimit();
649     }
650
651     /**
652      * Does the <tt>LIMIT</tt> clause specify arguments in the "reverse" order
653      * limit, offset instead of offset, limit?
654      *
655      * @return true if the correct order is limit, offset
656      */

657     public boolean bindLimitParametersInReverseOrder() {
658         return false;
659     }
660
661     /**
662      * Does the <tt>LIMIT</tt> clause come at the start of the
663      * <tt>SELECT</tt> statement, rather than at the end?
664      *
665      * @return true if limit parameters should come before other parameters
666      */

667     public boolean bindLimitParametersFirst() {
668         return false;
669     }
670
671     /**
672      * Does the <tt>LIMIT</tt> clause take a "maximum" row number instead
673      * of a total number of returned rows?
674      */

675     public boolean useMaxForLimit() {
676         return false;
677     }
678
679     /**
680      * The opening quote for a quoted identifier
681      */

682     public char openQuote() {
683         return '"';
684     }
685
686     /**
687      * The closing quote for a quoted identifier
688      */

689     public char closeQuote() {
690         return '"';
691     }
692
693     /**
694      * SQL functions as defined in general. The results of this
695      * method should be integrated with the specialisation's data.
696      */

697     public final Map JavaDoc getFunctions() {
698         return sqlFunctions;
699     }
700
701     public boolean supportsIfExistsBeforeTableName() {
702         return false;
703     }
704
705     public boolean supportsIfExistsAfterTableName() {
706         return false;
707     }
708
709     /**
710      * The separator between the schema/catalog/tablespace name and the table name.
711      */

712     public char getSchemaSeparator() {
713         return '.';
714     }
715
716     /**
717      * Does this dialect support column-level check constraints?
718      */

719     public boolean supportsColumnCheck() {
720         return true;
721     }
722     
723     /**
724      * Does this dialect support table-level check constraints?
725      */

726     public boolean supportsTableCheck() {
727         return true;
728     }
729
730     /**
731      * Whether this dialect have an Identity clause added to the data type or a
732      * completely seperate identity data type
733      *
734      * @return boolean
735      */

736     public boolean hasDataTypeInIdentityColumn() {
737         return true;
738     }
739
740     public boolean supportsCascadeDelete() {
741         return true;
742     }
743
744     /**
745      * Method <code>appendLockHint</code> appends according to the given
746      * lock mode a lock hint behind the given table name, if this dialect
747      * needs this. MS SQL Server for example doesn't support the
748      * standard "<code>select ... for update</code>" syntax and use a
749      * special "<code>select ... from TABLE as ALIAS with (updlock, rowlock)
750      * where ...</code>" syntax instead.
751      *
752      * @param tableName name of table to append lock hint
753      * @return String
754      * <p/>
755      * author <a HREF="http://sourceforge.net/users/heschulz">Helge Schulz</a>
756      */

757     public String JavaDoc appendLockHint(LockMode mode, String JavaDoc tableName) {
758         return tableName;
759     }
760
761     public Class JavaDoc getNativeIdentifierGeneratorClass() {
762         if ( supportsIdentityColumns() ) {
763             return IdentityGenerator.class;
764         }
765         else if ( supportsSequences() ) {
766             return SequenceGenerator.class;
767         }
768         else {
769             return TableHiLoGenerator.class;
770         }
771     }
772
773     public String JavaDoc getSelectGUIDString() {
774         throw new UnsupportedOperationException JavaDoc( "dialect does not support GUIDs" );
775     }
776
777     public boolean supportsOuterJoinForUpdate() {
778         return true;
779     }
780
781     public String JavaDoc getSelectClauseNullString(int sqlType) {
782         return "null";
783     }
784     
785     public boolean supportsNotNullUnique() {
786         return true;
787     }
788
789     /**
790      * Build an instance of the SQLExceptionConverter preferred by this dialect for
791      * converting SQLExceptions into Hibernate's JDBCException hierarchy. The default
792      * Dialect implementation simply returns a converter based on X/Open SQLState codes.
793      * <p/>
794      * It is strongly recommended that specific Dialect implementations override this
795      * method, since interpretation of a SQL error is much more accurate when based on
796      * the ErrorCode rather than the SQLState. Unfortunately, the ErrorCode is a vendor-
797      * specific approach.
798      *
799      * @return The Dialect's preferred SQLExceptionConverter.
800      */

801     public SQLExceptionConverter buildSQLExceptionConverter() {
802         // The default SQLExceptionConverter for all dialects is based on SQLState
803
// since SQLErrorCode is extremely vendor-specific. Specific Dialects
804
// may override to return whatever is most appropriate for that vendor.
805
return new SQLStateConverter( getViolatedConstraintNameExtracter() );
806     }
807
808     private static final ViolatedConstraintNameExtracter EXTRACTER = new ViolatedConstraintNameExtracter() {
809         public String JavaDoc extractConstraintName(SQLException JavaDoc sqle) {
810             return null;
811         }
812     };
813
814     public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() {
815         return EXTRACTER;
816     }
817
818     public final String JavaDoc quote(String JavaDoc column) {
819         if ( column.charAt( 0 ) == '`' ) {
820             return openQuote() + column.substring( 1, column.length() - 1 ) + closeQuote();
821         }
822         else {
823             return column;
824         }
825     }
826
827     public boolean hasSelfReferentialForeignKeyBug() {
828         return false;
829     }
830     
831
832     public boolean useInputStreamToInsertBlob() {
833         return true;
834     }
835
836     public int registerResultSetOutParameter(CallableStatement JavaDoc statement, int col) throws SQLException JavaDoc {
837         throw new UnsupportedOperationException JavaDoc(
838                 getClass().getName() +
839                 " does not support resultsets via stored procedures"
840             );
841     }
842
843     public ResultSet JavaDoc getResultSet(CallableStatement JavaDoc ps) throws SQLException JavaDoc {
844         throw new UnsupportedOperationException JavaDoc(
845                 getClass().getName() +
846                 " does not support resultsets via stored procedures"
847             );
848     }
849     
850     public boolean supportsUnionAll() {
851         return false;
852     }
853     
854     public boolean supportsCommentOn() {
855         return false;
856     }
857     
858     public String JavaDoc getTableComment(String JavaDoc comment) {
859         return "";
860     }
861
862     public String JavaDoc getColumnComment(String JavaDoc comment) {
863         return "";
864     }
865     
866     public String JavaDoc transformSelectString(String JavaDoc select) {
867         return select;
868     }
869
870     public boolean supportsTemporaryTables() {
871         return false;
872     }
873
874     public String JavaDoc generateTemporaryTableName(String JavaDoc baseTableName) {
875         return "HT_" + baseTableName;
876     }
877
878     public String JavaDoc getTemporaryTableCreationCommand() {
879         return "";
880     }
881
882     public String JavaDoc getTemporaryTableCreationPostfix() {
883         return "";
884     }
885
886     public boolean dropTemporaryTableAfterUse() {
887         return true;
888     }
889
890     public String JavaDoc getForUpdateString(LockMode lockMode) {
891         if ( lockMode==LockMode.UPGRADE ) {
892             return getForUpdateString();
893         }
894         else if ( lockMode==LockMode.UPGRADE_NOWAIT ) {
895             return getForUpdateNowaitString();
896         }
897         else {
898             return "";
899         }
900     }
901     
902     public int getMaxAliasLength() {
903         return 10;
904     }
905 }
906
Popular Tags