-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
HSQLDialect.java
672 lines (592 loc) · 22.9 KB
/
HSQLDialect.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.dialect;
import java.io.Serializable;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Locale;
import org.hibernate.JDBCException;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.StaleObjectStateException;
import org.hibernate.boot.TempTableDdlTransactionHandling;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.AvgWithArgumentCastFunction;
import org.hibernate.dialect.function.NoArgSQLFunction;
import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.dialect.function.VarArgsSQLFunction;
import org.hibernate.dialect.identity.HSQLIdentityColumnSupport;
import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.lock.LockingStrategy;
import org.hibernate.dialect.lock.OptimisticForceIncrementLockingStrategy;
import org.hibernate.dialect.lock.OptimisticLockingStrategy;
import org.hibernate.dialect.lock.PessimisticForceIncrementLockingStrategy;
import org.hibernate.dialect.lock.PessimisticReadSelectLockingStrategy;
import org.hibernate.dialect.lock.PessimisticWriteSelectLockingStrategy;
import org.hibernate.dialect.lock.SelectLockingStrategy;
import org.hibernate.dialect.pagination.AbstractLimitHandler;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.LimitHelper;
import org.hibernate.engine.jdbc.env.spi.NameQualifierSupport;
import org.hibernate.engine.spi.RowSelection;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter;
import org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
import org.hibernate.hql.spi.id.IdTableSupportStandardImpl;
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy;
import org.hibernate.hql.spi.id.local.AfterUseAction;
import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.type.StandardBasicTypes;
import org.jboss.logging.Logger;
/**
* An SQL dialect compatible with HSQLDB (HyperSQL).
* <p/>
* Note this version supports HSQLDB version 1.8 and higher, only.
* <p/>
* Enhancements to version 3.5.0 GA to provide basic support for both HSQLDB 1.8.x and 2.x
* Does not works with Hibernate 3.2 - 3.4 without alteration.
*
* @author Christoph Sturm
* @author Phillip Baird
* @author Fred Toussi
*/
@SuppressWarnings("deprecation")
public class HSQLDialect extends Dialect {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class,
HSQLDialect.class.getName()
);
private final class HSQLLimitHandler extends AbstractLimitHandler {
@Override
public String processSql(String sql, RowSelection selection) {
final boolean hasOffset = LimitHelper.hasFirstRow( selection );
if ( hsqldbVersion < 200 ) {
return new StringBuilder( sql.length() + 10 )
.append( sql )
.insert(
sql.toLowerCase(Locale.ROOT).indexOf( "select" ) + 6,
hasOffset ? " limit ? ?" : " top ?"
)
.toString();
}
else {
return sql + (hasOffset ? " offset ? limit ?" : " limit ?");
}
}
@Override
public boolean supportsLimit() {
return true;
}
@Override
public boolean bindLimitParametersFirst() {
return hsqldbVersion < 200;
}
}
/**
* version is 180 for 1.8.0 or 200 for 2.0.0
*/
private int hsqldbVersion = 180;
private final LimitHandler limitHandler;
/**
* Constructs a HSQLDialect
*/
public HSQLDialect() {
super();
try {
final Class props = ReflectHelper.classForName( "org.hsqldb.persist.HsqlDatabaseProperties" );
final String versionString = (String) props.getDeclaredField( "THIS_VERSION" ).get( null );
hsqldbVersion = Integer.parseInt( versionString.substring( 0, 1 ) ) * 100;
hsqldbVersion += Integer.parseInt( versionString.substring( 2, 3 ) ) * 10;
hsqldbVersion += Integer.parseInt( versionString.substring( 4, 5 ) );
}
catch ( Throwable e ) {
// must be a very old version
}
registerColumnType( Types.BIGINT, "bigint" );
registerColumnType( Types.BINARY, "binary($l)" );
registerColumnType( Types.BIT, "bit" );
registerColumnType( Types.BOOLEAN, "boolean" );
registerColumnType( Types.CHAR, "char($l)" );
registerColumnType( Types.DATE, "date" );
registerColumnType( Types.DECIMAL, "decimal($p,$s)" );
registerColumnType( Types.DOUBLE, "double" );
registerColumnType( Types.FLOAT, "float" );
registerColumnType( Types.INTEGER, "integer" );
registerColumnType( Types.LONGVARBINARY, "longvarbinary" );
registerColumnType( Types.LONGVARCHAR, "longvarchar" );
registerColumnType( Types.SMALLINT, "smallint" );
registerColumnType( Types.TINYINT, "tinyint" );
registerColumnType( Types.TIME, "time" );
registerColumnType( Types.TIMESTAMP, "timestamp" );
registerColumnType( Types.VARCHAR, "varchar($l)" );
registerColumnType( Types.VARBINARY, "varbinary($l)" );
registerColumnType( Types.NCLOB, "clob" );
if ( hsqldbVersion < 200 ) {
registerColumnType( Types.NUMERIC, "numeric" );
}
else {
registerColumnType( Types.NUMERIC, "numeric($p,$s)" );
}
//HSQL has no Blob/Clob support .... but just put these here for now!
if ( hsqldbVersion < 200 ) {
registerColumnType( Types.BLOB, "longvarbinary" );
registerColumnType( Types.CLOB, "longvarchar" );
}
else {
registerColumnType( Types.BLOB, "blob($l)" );
registerColumnType( Types.CLOB, "clob($l)" );
}
// aggregate functions
registerFunction( "avg", new AvgWithArgumentCastFunction( "double" ) );
// string functions
registerFunction( "ascii", new StandardSQLFunction( "ascii", StandardBasicTypes.INTEGER ) );
registerFunction( "char", new StandardSQLFunction( "char", StandardBasicTypes.CHARACTER ) );
registerFunction( "lower", new StandardSQLFunction( "lower" ) );
registerFunction( "upper", new StandardSQLFunction( "upper" ) );
registerFunction( "lcase", new StandardSQLFunction( "lcase" ) );
registerFunction( "ucase", new StandardSQLFunction( "ucase" ) );
registerFunction( "soundex", new StandardSQLFunction( "soundex", StandardBasicTypes.STRING ) );
registerFunction( "ltrim", new StandardSQLFunction( "ltrim" ) );
registerFunction( "rtrim", new StandardSQLFunction( "rtrim" ) );
registerFunction( "reverse", new StandardSQLFunction( "reverse" ) );
registerFunction( "space", new StandardSQLFunction( "space", StandardBasicTypes.STRING ) );
registerFunction( "str", new SQLFunctionTemplate( StandardBasicTypes.STRING, "cast(?1 as varchar(256))" ) );
registerFunction( "to_char", new StandardSQLFunction( "to_char", StandardBasicTypes.STRING ) );
registerFunction( "rawtohex", new StandardSQLFunction( "rawtohex" ) );
registerFunction( "hextoraw", new StandardSQLFunction( "hextoraw" ) );
// system functions
registerFunction( "user", new NoArgSQLFunction( "user", StandardBasicTypes.STRING ) );
registerFunction( "database", new NoArgSQLFunction( "database", StandardBasicTypes.STRING ) );
// datetime functions
if ( hsqldbVersion < 200 ) {
registerFunction( "sysdate", new NoArgSQLFunction( "sysdate", StandardBasicTypes.DATE, false ) );
}
else {
registerFunction( "sysdate", new NoArgSQLFunction( "sysdate", StandardBasicTypes.TIMESTAMP, false ) );
}
registerFunction( "current_date", new NoArgSQLFunction( "current_date", StandardBasicTypes.DATE, false ) );
registerFunction( "curdate", new NoArgSQLFunction( "curdate", StandardBasicTypes.DATE ) );
registerFunction(
"current_timestamp", new NoArgSQLFunction( "current_timestamp", StandardBasicTypes.TIMESTAMP, false )
);
registerFunction( "now", new NoArgSQLFunction( "now", StandardBasicTypes.TIMESTAMP ) );
registerFunction( "current_time", new NoArgSQLFunction( "current_time", StandardBasicTypes.TIME, false ) );
registerFunction( "curtime", new NoArgSQLFunction( "curtime", StandardBasicTypes.TIME ) );
registerFunction( "day", new StandardSQLFunction( "day", StandardBasicTypes.INTEGER ) );
registerFunction( "dayofweek", new StandardSQLFunction( "dayofweek", StandardBasicTypes.INTEGER ) );
registerFunction( "dayofyear", new StandardSQLFunction( "dayofyear", StandardBasicTypes.INTEGER ) );
registerFunction( "dayofmonth", new StandardSQLFunction( "dayofmonth", StandardBasicTypes.INTEGER ) );
registerFunction( "month", new StandardSQLFunction( "month", StandardBasicTypes.INTEGER ) );
registerFunction( "year", new StandardSQLFunction( "year", StandardBasicTypes.INTEGER ) );
registerFunction( "week", new StandardSQLFunction( "week", StandardBasicTypes.INTEGER ) );
registerFunction( "quarter", new StandardSQLFunction( "quarter", StandardBasicTypes.INTEGER ) );
registerFunction( "hour", new StandardSQLFunction( "hour", StandardBasicTypes.INTEGER ) );
registerFunction( "minute", new StandardSQLFunction( "minute", StandardBasicTypes.INTEGER ) );
registerFunction( "second", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "cast(second(?1) as int)" ) );
registerFunction( "dayname", new StandardSQLFunction( "dayname", StandardBasicTypes.STRING ) );
registerFunction( "monthname", new StandardSQLFunction( "monthname", StandardBasicTypes.STRING ) );
// numeric functions
registerFunction( "abs", new StandardSQLFunction( "abs" ) );
registerFunction( "sign", new StandardSQLFunction( "sign", StandardBasicTypes.INTEGER ) );
registerFunction( "acos", new StandardSQLFunction( "acos", StandardBasicTypes.DOUBLE ) );
registerFunction( "asin", new StandardSQLFunction( "asin", StandardBasicTypes.DOUBLE ) );
registerFunction( "atan", new StandardSQLFunction( "atan", StandardBasicTypes.DOUBLE ) );
registerFunction( "cos", new StandardSQLFunction( "cos", StandardBasicTypes.DOUBLE ) );
registerFunction( "cot", new StandardSQLFunction( "cot", StandardBasicTypes.DOUBLE ) );
registerFunction( "exp", new StandardSQLFunction( "exp", StandardBasicTypes.DOUBLE ) );
registerFunction( "log", new StandardSQLFunction( "log", StandardBasicTypes.DOUBLE ) );
registerFunction( "log10", new StandardSQLFunction( "log10", StandardBasicTypes.DOUBLE ) );
registerFunction( "sin", new StandardSQLFunction( "sin", StandardBasicTypes.DOUBLE ) );
registerFunction( "sqrt", new StandardSQLFunction( "sqrt", StandardBasicTypes.DOUBLE ) );
registerFunction( "tan", new StandardSQLFunction( "tan", StandardBasicTypes.DOUBLE ) );
registerFunction( "pi", new NoArgSQLFunction( "pi", StandardBasicTypes.DOUBLE ) );
registerFunction( "rand", new StandardSQLFunction( "rand", StandardBasicTypes.FLOAT ) );
registerFunction( "radians", new StandardSQLFunction( "radians", StandardBasicTypes.DOUBLE ) );
registerFunction( "degrees", new StandardSQLFunction( "degrees", StandardBasicTypes.DOUBLE ) );
registerFunction( "round", new StandardSQLFunction( "round" ) );
registerFunction( "roundmagic", new StandardSQLFunction( "roundmagic" ) );
registerFunction( "truncate", new StandardSQLFunction( "truncate" ) );
registerFunction( "ceiling", new StandardSQLFunction( "ceiling" ) );
registerFunction( "floor", new StandardSQLFunction( "floor" ) );
// special functions
// from v. 2.2.0 ROWNUM() is supported in all modes as the equivalent of Oracle ROWNUM
if ( hsqldbVersion > 219 ) {
registerFunction( "rownum", new NoArgSQLFunction( "rownum", StandardBasicTypes.INTEGER ) );
}
// function templates
registerFunction( "concat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "(", "||", ")" ) );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
limitHandler = new HSQLLimitHandler();
}
@Override
public String getAddColumnString() {
return "add column";
}
@Override
public boolean supportsLockTimeouts() {
return false;
}
@Override
public String getForUpdateString() {
if ( hsqldbVersion >= 200 ) {
return " for update";
}
else {
return "";
}
}
@Override
public LimitHandler getLimitHandler() {
return limitHandler;
}
@Override
public boolean supportsLimit() {
return true;
}
@Override
public String getLimitString(String sql, boolean hasOffset) {
if ( hsqldbVersion < 200 ) {
return new StringBuilder( sql.length() + 10 )
.append( sql )
.insert(
sql.toLowerCase(Locale.ROOT).indexOf( "select" ) + 6,
hasOffset ? " limit ? ?" : " top ?"
)
.toString();
}
else {
return sql + (hasOffset ? " offset ? limit ?" : " limit ?");
}
}
@Override
public boolean bindLimitParametersFirst() {
return hsqldbVersion < 200;
}
@Override
public boolean supportsIfExistsAfterTableName() {
return true;
}
@Override
public boolean supportsColumnCheck() {
return hsqldbVersion >= 200;
}
@Override
public boolean supportsSequences() {
return true;
}
@Override
public boolean supportsPooledSequences() {
return true;
}
/**
* HSQL will start with 0, by default. In order for Hibernate to know that this not transient,
* manually start with 1.
*/
@Override
protected String getCreateSequenceString(String sequenceName) {
return "create sequence " + sequenceName + " start with 1";
}
/**
* Because of the overridden {@link #getCreateSequenceString(String)}, we must also override
* {@link #getCreateSequenceString(String, int, int)} to prevent 2 instances of "start with".
*/
@Override
protected String getCreateSequenceString(String sequenceName, int initialValue, int incrementSize) throws MappingException {
if ( supportsPooledSequences() ) {
return "create sequence " + sequenceName + " start with " + initialValue + " increment by " + incrementSize;
}
throw new MappingException( getClass().getName() + " does not support pooled sequences" );
}
@Override
protected String getDropSequenceString(String sequenceName) {
return "drop sequence " + sequenceName + " if exists";
}
@Override
public String getSelectSequenceNextValString(String sequenceName) {
return "next value for " + sequenceName;
}
@Override
public String getSequenceNextValString(String sequenceName) {
return "call next value for " + sequenceName;
}
@Override
public String getQuerySequencesString() {
// this assumes schema support, which is present in 1.8.0 and later...
return "select sequence_name from information_schema.system_sequences";
}
@Override
public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() {
return hsqldbVersion < 200 ? EXTRACTER_18 : EXTRACTER_20;
}
private static final ViolatedConstraintNameExtracter EXTRACTER_18 = new TemplatedViolatedConstraintNameExtracter() {
@Override
protected String doExtractConstraintName(SQLException sqle) throws NumberFormatException {
String constraintName = null;
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqle );
if ( errorCode == -8 ) {
constraintName = extractUsingTemplate(
"Integrity constraint violation ", " table:", sqle.getMessage()
);
}
else if ( errorCode == -9 ) {
constraintName = extractUsingTemplate(
"Violation of unique index: ", " in statement [", sqle.getMessage()
);
}
else if ( errorCode == -104 ) {
constraintName = extractUsingTemplate(
"Unique constraint violation: ", " in statement [", sqle.getMessage()
);
}
else if ( errorCode == -177 ) {
constraintName = extractUsingTemplate(
"Integrity constraint violation - no parent ", " table:",
sqle.getMessage()
);
}
return constraintName;
}
};
/**
* HSQLDB 2.0 messages have changed
* messages may be localized - therefore use the common, non-locale element " table: "
*/
private static final ViolatedConstraintNameExtracter EXTRACTER_20 = new TemplatedViolatedConstraintNameExtracter() {
@Override
protected String doExtractConstraintName(SQLException sqle) throws NumberFormatException {
String constraintName = null;
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqle );
if ( errorCode == -8 ) {
constraintName = extractUsingTemplate(
"; ", " table: ", sqle.getMessage()
);
}
else if ( errorCode == -9 ) {
constraintName = extractUsingTemplate(
"; ", " table: ", sqle.getMessage()
);
}
else if ( errorCode == -104 ) {
constraintName = extractUsingTemplate(
"; ", " table: ", sqle.getMessage()
);
}
else if ( errorCode == -177 ) {
constraintName = extractUsingTemplate(
"; ", " table: ", sqle.getMessage()
);
}
return constraintName;
}
};
@Override
public String getSelectClauseNullString(int sqlType) {
String literal;
switch ( sqlType ) {
case Types.LONGVARCHAR:
case Types.VARCHAR:
case Types.CHAR:
literal = "cast(null as varchar(100))";
break;
case Types.LONGVARBINARY:
case Types.VARBINARY:
case Types.BINARY:
literal = "cast(null as varbinary(100))";
break;
case Types.CLOB:
literal = "cast(null as clob)";
break;
case Types.BLOB:
literal = "cast(null as blob)";
break;
case Types.DATE:
literal = "cast(null as date)";
break;
case Types.TIMESTAMP:
literal = "cast(null as timestamp)";
break;
case Types.BOOLEAN:
literal = "cast(null as boolean)";
break;
case Types.BIT:
literal = "cast(null as bit)";
break;
case Types.TIME:
literal = "cast(null as time)";
break;
default:
literal = "cast(null as int)";
}
return literal;
}
@Override
public boolean supportsUnionAll() {
return true;
}
@Override
public MultiTableBulkIdStrategy getDefaultMultiTableBulkIdStrategy() {
// Hibernate uses this information for temporary tables that it uses for its own operations
// therefore the appropriate strategy is taken with different versions of HSQLDB
// All versions of HSQLDB support GLOBAL TEMPORARY tables where the table
// definition is shared by all users but data is private to the session
// HSQLDB 2.0 also supports session-based LOCAL TEMPORARY tables where
// the definition and data is private to the session and table declaration
// can happen in the middle of a transaction
if ( hsqldbVersion < 200 ) {
return new GlobalTemporaryTableBulkIdStrategy(
new IdTableSupportStandardImpl() {
@Override
public String generateIdTableName(String baseName) {
return "HT_" + baseName;
}
@Override
public String getCreateIdTableCommand() {
return "create global temporary table";
}
},
// Version 1.8 GLOBAL TEMPORARY table definitions persist beyond the end
// of the session (by default, data is cleared at commit).
AfterUseAction.CLEAN
);
}
else {
return new LocalTemporaryTableBulkIdStrategy(
new IdTableSupportStandardImpl() {
@Override
public String generateIdTableName(String baseName) {
// With HSQLDB 2.0, the table name is qualified with MODULE to assist the drop
// statement (in-case there is a global name beginning with HT_)
return "MODULE.HT_" + baseName;
}
@Override
public String getCreateIdTableCommand() {
return "declare local temporary table";
}
},
AfterUseAction.DROP,
TempTableDdlTransactionHandling.NONE
);
}
}
// current timestamp support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* HSQLDB 1.8.x requires CALL CURRENT_TIMESTAMP but this should not
* be treated as a callable statement. It is equivalent to
* "select current_timestamp from dual" in some databases.
* HSQLDB 2.0 also supports VALUES CURRENT_TIMESTAMP
* <p/>
* {@inheritDoc}
*/
@Override
public boolean supportsCurrentTimestampSelection() {
return true;
}
@Override
public boolean isCurrentTimestampSelectStringCallable() {
return false;
}
@Override
public String getCurrentTimestampSelectString() {
return "call current_timestamp";
}
@Override
public String getCurrentTimestampSQLFunctionName() {
// the standard SQL function name is current_timestamp...
return "current_timestamp";
}
/**
* For HSQLDB 2.0, this is a copy of the base class implementation.
* For HSQLDB 1.8, only READ_UNCOMMITTED is supported.
* <p/>
* {@inheritDoc}
*/
@Override
public LockingStrategy getLockingStrategy(Lockable lockable, LockMode lockMode) {
if ( lockMode == LockMode.PESSIMISTIC_FORCE_INCREMENT ) {
return new PessimisticForceIncrementLockingStrategy( lockable, lockMode );
}
else if ( lockMode == LockMode.PESSIMISTIC_WRITE ) {
return new PessimisticWriteSelectLockingStrategy( lockable, lockMode );
}
else if ( lockMode == LockMode.PESSIMISTIC_READ ) {
return new PessimisticReadSelectLockingStrategy( lockable, lockMode );
}
else if ( lockMode == LockMode.OPTIMISTIC ) {
return new OptimisticLockingStrategy( lockable, lockMode );
}
else if ( lockMode == LockMode.OPTIMISTIC_FORCE_INCREMENT ) {
return new OptimisticForceIncrementLockingStrategy( lockable, lockMode );
}
if ( hsqldbVersion < 200 ) {
return new ReadUncommittedLockingStrategy( lockable, lockMode );
}
else {
return new SelectLockingStrategy( lockable, lockMode );
}
}
private static class ReadUncommittedLockingStrategy extends SelectLockingStrategy {
public ReadUncommittedLockingStrategy(Lockable lockable, LockMode lockMode) {
super( lockable, lockMode );
}
@Override
public void lock(Serializable id, Object version, Object object, int timeout, SharedSessionContractImplementor session)
throws StaleObjectStateException, JDBCException {
if ( getLockMode().greaterThan( LockMode.READ ) ) {
LOG.hsqldbSupportsOnlyReadCommittedIsolation();
}
super.lock( id, version, object, timeout, session );
}
}
@Override
public boolean supportsCommentOn() {
return hsqldbVersion >= 200;
}
// Overridden informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public boolean supportsEmptyInList() {
return false;
}
@Override
public boolean requiresCastingOfParametersInSelectClause() {
return true;
}
@Override
public boolean doesReadCommittedCauseWritersToBlockReaders() {
return hsqldbVersion >= 200;
}
@Override
public boolean doesRepeatableReadCauseReadersToBlockWriters() {
return hsqldbVersion >= 200;
}
@Override
public boolean supportsLobValueChangePropogation() {
return false;
}
@Override
public String toBooleanValueString(boolean bool) {
return String.valueOf( bool );
}
@Override
public boolean supportsTupleDistinctCounts() {
// from v. 2.2.9 is added support for COUNT(DISTINCT ...) with multiple arguments
return hsqldbVersion >= 229;
}
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new HSQLIdentityColumnSupport( this.hsqldbVersion );
}
@Override
public NameQualifierSupport getNameQualifierSupport() {
return NameQualifierSupport.SCHEMA;
}
}