Default our PostgreSQL tables to be WITHOUT OIDS

Its strongly recommended that all user tables in a PostgreSQL schema
be built as "WITHOUT OIDS", or more recently "WITH (OIDS = FALSE)".
This reduces the risk of oid wraparound during normal operation, as
user operations don't cause allocations from the system oid sequence.

Since the syntax changed in PostgreSQL 8.2, we use the new refine
method to select a Pre8.2 dialect for the older "WITHOUT OIDS"
syntax, and the default dialect for 8.2 and newer to use the new
"WITH (OIDS = FALSE)" syntax.

Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/src/main/java/com/google/gwtorm/schema/sql/DialectPostgreSQL.java b/src/main/java/com/google/gwtorm/schema/sql/DialectPostgreSQL.java
index 83fe3fc..f20e259 100644
--- a/src/main/java/com/google/gwtorm/schema/sql/DialectPostgreSQL.java
+++ b/src/main/java/com/google/gwtorm/schema/sql/DialectPostgreSQL.java
@@ -2,7 +2,9 @@
 
 import com.google.gwtorm.client.OrmDuplicateKeyException;
 import com.google.gwtorm.client.OrmException;
+import com.google.gwtorm.schema.RelationModel;
 
+import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Types;
 
@@ -14,6 +16,16 @@
   }
 
   @Override
+  public SqlDialect refine(final Connection c) throws SQLException {
+    final int major = c.getMetaData().getDatabaseMajorVersion();
+    final int minor = c.getMetaData().getDatabaseMinorVersion();
+    if (major < 8 || (major == 8 && minor < 2)) {
+      return new Pre82();
+    }
+    return this;
+  }
+
+  @Override
   public OrmException convertError(final String op, final String entity,
       final SQLException err) {
     switch (getSQLStateInt(err)) {
@@ -33,4 +45,18 @@
   public String getNextSequenceValueSql(final String seqname) {
     return "SELECT nextval('" + seqname + "')";
   }
+
+  @Override
+  public void appendCreateTableStorage(final StringBuilder sqlBuffer,
+      final RelationModel relationModel) {
+    sqlBuffer.append("WITH (OIDS = FALSE)");
+  }
+
+  private static class Pre82 extends DialectPostgreSQL {
+    @Override
+    public void appendCreateTableStorage(final StringBuilder sqlBuffer,
+        final RelationModel relationModel) {
+      sqlBuffer.append("WITHOUT OIDS");
+    }
+  }
 }