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 * 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 // Postgresql defaults to lower case identifiers
65 if (tableName.equals(tableName.toLowerCase())) return tableName;
66 // We quote the table name because it has mixed case
67 if (QuantumUtil.getSchemaName(tableName).equals("")) {
68 return "\"" + tableName + "\""; //$NON-NLS-1$
70 return "\"" + QuantumUtil.getSchemaName(tableName) + "\".\"" +
71 QuantumUtil.getTableName(tableName) + "\"";
75 * @see com.quantum.adapters.DatabaseAdapter#getDefaultSchema(java.lang.String)
77 public String getDefaultSchema(String userid) {
81 public Map getDefaultConnectionParameters() {
82 Map map = new HashMap();
83 map.put("port", "5432");
84 map.put("hostname", "localhost");