Add some unit testing of the CfbSchema.
[cfb.git] / prod / net / jaekl / cfb / db / driver / PostgresqlDriver.java
index a8d28f9bb0a3b6700a92953bb00f3589cf01bb29..fbb328503add803379a1cab500a959bdefc0c9f0 100644 (file)
@@ -7,6 +7,9 @@ import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.util.Properties;
 
+import net.jaekl.cfb.db.Sequence;
+import net.jaekl.cfb.db.Column.Type;
+
 public class PostgresqlDriver extends DbDriver {
 
        @Override
@@ -26,4 +29,22 @@ public class PostgresqlDriver extends DbDriver {
                //props.setProperty("ssl", "true");
                return DriverManager.getConnection(url, props);
        }
-}
+       
+       @Override 
+       public String nextValSql(Sequence seq) 
+       {
+               return " SELECT NEXTVAL('" + seq.getName() + "') ";
+       }
+       
+       @Override
+       protected String typeName(Type type) {
+               // Special case:  TIMESTAMPTZ stored as INTEGER (milliseconds since the epoch)
+               // Reading a TIMESTAMPTZ back from the DB, and converting it to a java.util.Date,
+               // is fraught with peril.  The best way around this is to store the dates in 
+               // milliseconds-since-the-epoch (01.01.1970 00:00:00.000 UTC).
+               if (Type.TIMESTAMPTZ.equals(type)) {
+                       return "BIGINT";
+               }
+               
+               return type.toString();
+       }}