org.h2.server.pg
Class PgServer

java.lang.Object
  extended by org.h2.server.pg.PgServer
All Implemented Interfaces:
Service

public class PgServer
extends java.lang.Object
implements Service

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


Field Summary
static int DEFAULT_PORT
          The default port to use for the PG server.
 
Constructor Summary
PgServer()
           
 
Method Summary
static int convertType(int type)
          Convert the SQL type to a PostgreSQL type
 boolean getAllowOthers()
          Check if remote connections are allowed.
static java.lang.String getCurrentSchema(java.sql.Connection conn)
          Get the name of the current schema.
static int getCurrentTid(java.lang.String table, java.lang.String id)
          Get the current transaction id.
static java.lang.String getEncodingName(int code)
          Get the name of this encoding code.
static java.lang.String getIndexColumn(java.sql.Connection conn, int indexId, java.lang.Integer ordinalPosition, java.lang.Boolean pretty)
          The Java implementation of the PostgreSQL function pg_get_indexdef.
 java.lang.String getName()
          Get the human readable name of the service.
 int getPort()
          Gets the port this service is listening on.
static java.sql.Timestamp getStartTime()
          Get the current system time.
 java.lang.String getType()
          Get the human readable short name of the service.
 java.lang.String getURL()
          Get the URL of this service in a human readable form
static java.lang.String getUserById(java.sql.Connection conn, int id)
          Get the user name for this id.
static java.lang.String getVersion()
          Get the version.
static boolean hasDatabasePrivilege(int id, java.lang.String privilege)
          Check if the this session has the given database privilege.
static boolean hasTablePrivilege(java.lang.String table, java.lang.String privilege)
          Check if the current session has access to this table.
 void init(java.lang.String... args)
          Initialize the service from command line options.
 boolean isRunning(boolean traceError)
          Check if the service is running.
 void listen()
          Listen for incoming connections.
 void start()
          Start the service.
 void stop()
          Stop the service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port to use for the PG server. This value is also in the documentation and in the Server javadoc.

See Also:
Constant Field Values
Constructor Detail

PgServer

public PgServer()
Method Detail

init

public void init(java.lang.String... args)
Description copied from interface: Service
Initialize the service from command line options.

Specified by:
init in interface Service
Parameters:
args - the command line options

getURL

public java.lang.String getURL()
Description copied from interface: Service
Get the URL of this service in a human readable form

Specified by:
getURL in interface Service
Returns:
the url

getPort

public int getPort()
Description copied from interface: Service
Gets the port this service is listening on.

Specified by:
getPort in interface Service
Returns:
the port

start

public void start()
           throws java.sql.SQLException
Description copied from interface: Service
Start the service. This usually means create the server socket. This method must not block.

Specified by:
start in interface Service
Throws:
java.sql.SQLException

listen

public void listen()
Description copied from interface: Service
Listen for incoming connections. This method blocks.

Specified by:
listen in interface Service

stop

public void stop()
Description copied from interface: Service
Stop the service.

Specified by:
stop in interface Service

isRunning

public boolean isRunning(boolean traceError)
Description copied from interface: Service
Check if the service is running.

Specified by:
isRunning in interface Service
Parameters:
traceError - if errors should be written
Returns:
if the server is running

getAllowOthers

public boolean getAllowOthers()
Description copied from interface: Service
Check if remote connections are allowed.

Specified by:
getAllowOthers in interface Service
Returns:
true if remote connections are allowed

getType

public java.lang.String getType()
Description copied from interface: Service
Get the human readable short name of the service.

Specified by:
getType in interface Service
Returns:
the type

getName

public java.lang.String getName()
Description copied from interface: Service
Get the human readable name of the service.

Specified by:
getName in interface Service
Returns:
the name

getIndexColumn

public static java.lang.String getIndexColumn(java.sql.Connection conn,
                                              int indexId,
                                              java.lang.Integer ordinalPosition,
                                              java.lang.Boolean pretty)
                                       throws java.sql.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
Throws:
java.sql.SQLException

getCurrentSchema

public static java.lang.String getCurrentSchema(java.sql.Connection conn)
                                         throws java.sql.SQLException
Get the name of the current schema. This method is called by the database.

Parameters:
conn - the connection
Returns:
the schema name
Throws:
java.sql.SQLException

getEncodingName

public static java.lang.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

getVersion

public static java.lang.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

getStartTime

public static java.sql.Timestamp getStartTime()
Get the current system time. This method is called by the database.

Returns:
the current system time

getUserById

public static java.lang.String getUserById(java.sql.Connection conn,
                                           int id)
                                    throws java.sql.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
Throws:
java.sql.SQLException

hasDatabasePrivilege

public static boolean hasDatabasePrivilege(int id,
                                           java.lang.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

hasTablePrivilege

public static boolean hasTablePrivilege(java.lang.String table,
                                        java.lang.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

getCurrentTid

public static int getCurrentTid(java.lang.String table,
                                java.lang.String id)
Get the current transaction id. This method is called by the database.

Parameters:
table - the table name
id - the id
Returns:
1

convertType

public static int convertType(int type)
Convert the SQL type to a PostgreSQL type

Parameters:
type - the SQL type
Returns:
the PostgreSQL type