01: package simpleorm.core;
02:
03: /** This contains Oracle specific code.
04: *
05: * In oracle VARCHAR2 '' == null. Ie. min string length is 2.
06: * VARCHAR == VARCHAR2? but not recommended?
07: * VARCHARs max size 2000 or 4000 Oracle 8.
08: * CHARS max size 2000 all versions.
09: * LONG for larger strings.
10: *
11: * Dates DATE, TIMESTAMP [WITH TIMEZONE].
12: *
13: * It is reported that CHARs need to be trimed for comparison?
14: * */
15:
16: public class SDriverOracle extends SDriver {
17:
18: protected String driverName() {
19: return "Oracle JDBC driver";
20: }
21:
22: public int maxIdentNameLength() {
23: return 30;
24: } // Correct for Oracle.
25:
26: /** Specializes SDriver.generateKeySequence using Oracle SEQUENCEs. */
27: protected long generateKeySequence(SRecordMeta rec,
28: SFieldMeta keyFld) {
29: Object sequenceName = keyFld.getProperty(SSEQUENCE_NAME);
30:
31: String qry = "SELECT " + (String) sequenceName
32: + ".NEXTVAL FROM DUAL";
33: Object next = SConnection.rawQueryJDBC(qry);
34:
35: return SJSharp.object2Long(next);
36: }
37:
38: public boolean supportsKeySequences() {
39: return true;
40: }
41:
42: protected String createSequenceDDL(String name) {
43: return "CREATE SEQUENCE " + name;
44: }
45:
46: protected String dropSequenceDDL(String name) {
47: return "DROP SEQUENCE " + name;
48: }
49:
50: /**
51: *
52: */
53: protected String columnTypeSQL(SFieldMeta field) {
54: String dataType = (String) field.getProperty(SDATA_TYPE);
55: if (dataType.equals("BYTES"))
56: return "RAW"; // Ie. just a byte array. Use SFieldBlob for BLOB.
57: // if (dataType.equals("INTEGER"))
58: // return "numeric(9,0)";
59: // else if ( dataType.equals("TIMESTAMP") )
60: // return "DATE"; // Is this correct ##
61: else if (dataType.equals("TIME"))
62: return "TIMESTAMP";
63: else if (dataType.equals("VARCHAR"))
64: return "VARCHAR2(" + field.getProperty(SBYTE_SIZE) + ")";
65: else
66: return super.columnTypeSQL(field);
67: }
68:
69: }
|