PgServer

This class implements a subset of the PostgreSQL protocol as described here: http://developer.postgresql.org/pgdocs/postgres/protocol.html The PostgreSQL catalog is described here: http://www.postgresql.org/docs/7.4/static/catalogs.html

Methods
static int convertType(int type)
Convert the SQL type to a PostgreSQL type
static int convertType(int type)
Convert the SQL type to a PostgreSQL type
Parameters:
type - the SQL type
Returns:
the PostgreSQL type
static String formatType(Connection conn, int pgType, int typeMod)
Check if the current session has access to this table.
static String formatType(Connection conn, int pgType, int typeMod) throws SQLException
Check if the current session has access to this table. This method is called by the database.
Parameters:
conn - the connection
pgType - the PostgreSQL type oid
typeMod - the type modifier (typically -1)
Returns:
the name of the given type
static String getCurrentSchema(Connection conn)
Get the name of the current schema.
static String getCurrentSchema(Connection conn) throws SQLException
Get the name of the current schema. This method is called by the database.
Parameters:
conn - the connection
Returns:
the schema name
static int getCurrentTid(String table, String id)
Get the current transaction id.
static int getCurrentTid(String table, String id)
Get the current transaction id. This method is called by the database.
Parameters:
table - the table name
id - the id
Returns:
1
static String getEncodingName(int code)
Get the name of this encoding code.
static String getEncodingName(int code)
Get the name of this encoding code. This method is called by the database.
Parameters:
code - the encoding code
Returns:
the encoding name
static String getIndexColumn(Connection conn, int indexId, Integer ordinalPosition, Boolean pretty)
The Java implementation of the PostgreSQL function pg_get_indexdef.
static String getIndexColumn(Connection conn, int indexId, Integer ordinalPosition, Boolean pretty) throws SQLException
The Java implementation of the PostgreSQL function pg_get_indexdef. The method is used to get CREATE INDEX command for an index, or the column definition of one column in the index.
Parameters:
conn - the connection
indexId - the index id
ordinalPosition - the ordinal position (null if the SQL statement should be returned)
pretty - this flag is ignored
Returns:
the SQL statement or the column name
static int getOid(Connection conn, String tableName)
Get the OID of an object.
static int getOid(Connection conn, String tableName) throws SQLException
Get the OID of an object. This method is called by the database.
Parameters:
conn - the connection
tableName - the table name
Returns:
the oid
static String getPgExpr(String exprText, int relationOid)
A fake wrapper around pg_get_expr(expr_text, relation_oid), in PostgreSQL it "decompiles the internal form of an expression, assuming that any vars in it refer to the relation indicated by the second parameter".
static String getPgExpr(String exprText, int relationOid)
A fake wrapper around pg_get_expr(expr_text, relation_oid), in PostgreSQL it "decompiles the internal form of an expression, assuming that any vars in it refer to the relation indicated by the second parameter".
Parameters:
exprText - the expression text
relationOid - the relation object id
Returns:
always null
static Timestamp getStartTime()
Get the current system time.
static Timestamp getStartTime()
Get the current system time. This method is called by the database.
Returns:
the current system time
static String getUserById(Connection conn, int id)
Get the user name for this id.
static String getUserById(Connection conn, int id) throws SQLException
Get the user name for this id. This method is called by the database.
Parameters:
conn - the connection
id - the user id
Returns:
the user name
static String getVersion()
Get the version.
static String getVersion()
Get the version. This method must return PostgreSQL to keep some clients happy. This method is called by the database.
Returns:
the server name and version
static boolean hasDatabasePrivilege(int id, String privilege)
Check if the this session has the given database privilege.
static boolean hasDatabasePrivilege(int id, String privilege)
Check if the this session has the given database privilege. This method is called by the database.
Parameters:
id - the session id
privilege - the privilege to check
Returns:
true
static boolean hasTablePrivilege(String table, String privilege)
Check if the current session has access to this table.
static boolean hasTablePrivilege(String table, String privilege)
Check if the current session has access to this table. This method is called by the database.
Parameters:
table - the table name
privilege - the privilege to check
Returns:
true
String checkKeyAndGetDatabaseName(String db)
If no key is set, return the original database name.
String checkKeyAndGetDatabaseName(String db)
If no key is set, return the original database name. If a key is set, check if the key matches. If yes, return the correct database name. If not, throw an exception.
Parameters:
db - the key to test (or database name if no key is used)
Returns:
the database name
Throws:
DbException - if a key is set but doesn't match
void checkType(int type)
Check whether a data type is supported.
void checkType(int type)
Check whether a data type is supported. A warning is logged if not.
Parameters:
type - the type
boolean getAllowOthers()
boolean getAllowOthers()
String getBaseDir()
String getBaseDir()
boolean getIfExists()
boolean getIfExists()
String getName()
String getName()
int getPort()
int getPort()
PgServerThread getThread(int processId)
Get the thread with the given process id.
PgServerThread getThread(int processId)
Get the thread with the given process id.
Parameters:
processId - the process id
Returns:
the thread
boolean getTrace()
boolean getTrace()
String getType()
String getType()
HashSet getTypeSet()
Get the type hash set.
HashSet getTypeSet()
Get the type hash set.
Returns:
the type set
String getURL()
String getURL()
void init(String... args)
void init(String... args)
boolean isDaemon()
boolean isDaemon()
boolean isRunning(boolean traceError)
boolean isRunning(boolean traceError)
void listen()
void listen()
void remove(PgServerThread t)
Remove a thread from the list.
void remove(PgServerThread t)
Remove a thread from the list.
Parameters:
t - the thread to remove
void start()
void start()
void stop()
void stop()
void trace(String s)
Print a message if the trace flag is enabled.
void trace(String s)
Print a message if the trace flag is enabled.
Parameters:
s - the message
void traceError(Exception e)
Print the stack trace if the trace flag is enabled.
void traceError(Exception e)
Print the stack trace if the trace flag is enabled.
Parameters:
e - the exception