01: package simpleorm.core;
02:
03: /** This contains HSQL specific code. Note that this toy database
04: does not support locking, so is not safe in multi user mode even
05: with optimistic locking. See {@link SDriver#supportsLocking}.*/
06:
07: public class SDriverHSQL extends SDriver {
08:
09: // ## Should add some sort of crude JVM based locking hack -- the
10: // first transaction to select FOR UPDATE locks entire databse.
11:
12: protected String driverName() {
13: return "HSQL Database Engine Driver";
14: }
15:
16: /** HSQL has a major hole but optimisic locking papers over it.*/
17: public boolean supportsLocking() {
18: return false;
19: }
20:
21: protected String columnTypeSQL(SFieldMeta field) {
22: if (((String) field.getProperty(SDATA_TYPE)).equals("BYTES"))
23: return "BINARY"; // Ie. just a byte array.
24: else
25: return super .columnTypeSQL(field);
26: }
27:
28: protected long generateKeySequence(SRecordMeta rec,
29: SFieldMeta keyFld) {
30: Object sequenceName = keyFld.getProperty(SSEQUENCE_NAME);
31:
32: String qry = "SELECT NEXT VALUE FOR " + (String) sequenceName
33: + " FROM DUAL"; // ### Dual!
34: // Thanks elifarley. Note that HSQL also supports Identity.
35:
36: Object next = SConnection.rawQueryJDBC(qry);
37: return SJSharp.object2Long(next);
38: }
39:
40: public boolean supportsKeySequences() {
41: return true;
42: }
43:
44: protected String createSequenceDDL(String name) {
45: return "CREATE SEQUENCE " + name;
46: }
47:
48: protected String dropSequenceDDL(String name) {
49: return "DROP SEQUENCE " + name;
50: }
51:
52: }
|