01: package simpleorm.core;
02:
03: /** This contains PostgreSQL specific code.
04: *
05: * VARCHAR without size means unlimited. No artificial upper size?
06: * TEXT has the same behaviour as VARCHAR, apparantly.
07: *
08: * */
09:
10: public class SDriverPostgres extends SDriver {
11:
12: protected String driverName() {
13: return "PostgreSQL Native Driver";
14: }
15:
16: public int maxIdentNameLength() {
17: return 60;
18: } // I think that this is correct.
19:
20: /** Never need to specify byteSize for varchar */
21: protected String columnTypeSQL(SFieldMeta field) {
22: if (((String) field.getProperty(SDATA_TYPE)).equals("VARCHAR"))
23: return "VARCHAR"; // No max size necessary or useful for Postgres
24: else if (((String) field.getProperty(SDATA_TYPE))
25: .equals("BYTES"))
26: return "BYTEA"; // Ie. just a byte array.
27: else
28: return super .columnTypeSQL(field);
29: }
30:
31: /** Specializes SDriver.generateKeySequence using the Postgres SEQUENCEs. */
32: protected long generateKeySequence(SRecordMeta rec,
33: SFieldMeta keyFld) {
34: Object sequenceName = keyFld.getProperty(SSEQUENCE_NAME);
35:
36: String qry = "SELECT nextval('" + (String) sequenceName + "')";
37: Object next = SConnection.rawQueryJDBC(qry);
38:
39: return SJSharp.object2Long(next);
40: }
41:
42: public boolean supportsKeySequences() {
43: return true;
44: }
45:
46: protected String createSequenceDDL(String name) {
47: return "CREATE SEQUENCE " + name;
48: }
49:
50: protected String dropSequenceDDL(String name) {
51: return "DROP SEQUENCE " + name;
52: }
53:
54: }
|