1 package com.quantum.adapters;
3 import java.util.HashMap;
6 import com.quantum.util.QuantumUtil;
7 import com.quantum.util.sql.TypesHelper;
10 public class PostgresAdapter extends DatabaseAdapter {
11 protected PostgresAdapter() {
12 super(AdapterFactory.POSTGRES);
14 public String getShowTableQuery(String qualifier) {
15 return "SELECT SCHEMANAME, TABLENAME FROM PG_TABLES WHERE SCHEMANAME = '"
18 public String getShowViewQuery(String qualifier) {
19 return "SELECT SCHEMANAME, VIEWNAME FROM PG_VIEWS WHERE SCHEMANAME = '"
22 public String getShowSequenceQuery(String qualifier) {
23 return "select pg_namespace.nspname, relname " +
24 "from pg_class, pg_namespace where relkind = 'S' " +
25 "and relnamespace = pg_namespace.oid " +
26 "and pg_namespace.nspname = '" + qualifier + "'";
28 public String getNextValue(String sequence, String owner) {
29 return "SELECT NEXTVAL('" + getQualifiedName(owner, sequence) + "')";
31 public String getPrevValue(String sequence, String owner) {
32 return "SELECT * FROM " + getQualifiedName(owner, sequence);
36 * Quotes a string according to the type of the column
37 * @param string to be quoted
38 * @param type according to java.sql.Types
41 public String quote(String string, int type, String typeString) {
42 // Booleans in PostgreSQL are queried "t" or "f", but require "true" or "false" when inputed.
43 if (type == TypesHelper.BIT || type == TypesHelper.BOOLEAN ) // Postgresql seems to identify booleans as BITs
45 if (string.indexOf('t') >= 0 || string.indexOf('T') >= 0 )
47 else if (string.indexOf('f') >= 0 || string.indexOf('F') >= 0 )
52 // use the default (upper type)
53 return super.quote(string, type, typeString);
56 public String getTableQuery(String table) {
57 return "SELECT OID, * FROM " + filterTableName(table); //$NON-NLS-1$
60 * @see com.quantum.adapters.DatabaseAdapter#filterTableName(java.lang.String)
62 public String filterTableName(String tableName) {
63 // If there is no mixed case, better not quote, it's prettier on display
64 if (tableName.equals(tableName.toUpperCase())) return tableName;
65 // We quote the table name (and only the table name) because it has mixed case
66 if (QuantumUtil.getSchemaName(tableName).equals("")) {
67 return "\"" + tableName +"\""; //$NON-NLS-1$
69 return QuantumUtil.getSchemaName(tableName) + ".\"" +
70 QuantumUtil.getTableName(tableName) + "\"";
74 * @see com.quantum.adapters.DatabaseAdapter#getDefaultSchema(java.lang.String)
76 public String getDefaultSchema(String userid) {
80 public Map getDefaultConnectionParameters() {
81 Map map = new HashMap();
82 map.put("port", "5432");
83 map.put("hostname", "localhost");