Top Description Fields Constructors Methods
org.h2.server.pg

public Class PgServer

extends Object
implements Service
Class Inheritance
All Implemented Interfaces
org.h2.server.Service
Imports
java.io.IOException, java.net.ServerSocket, .Socket, .UnknownHostException, java.util.ArrayList, .Collections, .HashSet, .Set, java.util.concurrent.atomic.AtomicInteger, org.h2.api.ErrorCode, org.h2.message.DbException, org.h2.server.Service, org.h2.util.NetUtils, .Tool, .Utils, .Utils10, .Utils21, org.h2.value.TypeInfo, .Value

This class implements a subset of the PostgreSQL protocol as described here: https://www.postgresql.org/docs/devel/protocol.html The PostgreSQL catalog is described here: https://www.postgresql.org/docs/7.4/catalogs.html
Authors
Thomas Mueller, Sergi Vladykin 2009-07-03 (convertType)

Field Summary

Modifier and TypeField and Description
private boolean
private String
public static final int
DEFAULT_PORT

The default port to use for the PG server.

private boolean
private boolean
private String
private String
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
PG_TYPE_VARCHAR

The VARCHAR type.

public static final int
private final AtomicInteger
private int
private boolean
private final Set<PgServerThread>
private ServerSocket
private boolean
private boolean
private final HashSet<Integer>
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private boolean
allow(Socket socket)

public String

Returns:

the database name
checkKeyAndGetDatabaseName
(String
the key to test (or database name if no key is used)
db
)

If no key is set, return the original database name.

pack-priv void
checkType(int
the type
type
)

Check whether a data type is supported.

public static int

Returns:

the PostgreSQL type
convertType
(TypeInfo
the SQL type
type
)

Convert the SQL type to a PostgreSQL type

public static String

Returns:

the name of the given type
formatType
(int
the PostgreSQL type oid
pgType
)

Returns the name of the given type.

public boolean
getAllowOthers()

Implements org.h2.server.Service.getAllowOthers.

Check if remote connections are allowed.

pack-priv String
pack-priv boolean
public String
getName()

Implements org.h2.server.Service.getName.

Get the human readable name of the service.

public int
getPort()

Implements org.h2.server.Service.getPort.

Gets the port this service is listening on.

pack-priv PgServerThread

Returns:

the thread
getThread
(int
the process id
processId
)

Get the thread with the given process id.

pack-priv boolean
public String
getType()

Implements org.h2.server.Service.getType.

Get the human readable short name of the service.

pack-priv HashSet<Integer>

Returns:

the type set
getTypeSet
()

Get the type hash set.

public String
getURL()

Implements org.h2.server.Service.getURL.

Get the URL of this service in a human readable form

public void
init(String...
the command line options
args
)

Implements org.h2.server.Service.init.

Initialize the service from command line options.

public boolean
isDaemon()

Implements org.h2.server.Service.isDaemon.

Check if a daemon thread should be used.

public boolean
isRunning(boolean
if errors should be written
traceError
)

Implements org.h2.server.Service.isRunning.

Check if the service is running.

public void
listen()

Implements org.h2.server.Service.listen.

Listen for incoming connections.

pack-priv synchronized void
remove(PgServerThread
the thread to remove
t
)

Remove a thread from the list.

public void
start()

Implements org.h2.server.Service.start.

Start the service.

public void
stop()

Implements org.h2.server.Service.stop.

Stop the service.

pack-priv void
trace(String
the message
s
)

Print a message if the trace flag is enabled.

pack-priv void
traceError(Exception
the exception
e
)

Print the stack trace if the trace flag is enabled.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowOthersback to summary
private boolean allowOthers
baseDirback to summary
private String baseDir
DEFAULT_PORTback to summary
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.

ifExistsback to summary
private boolean ifExists
isDaemonback to summary
private boolean isDaemon
keyback to summary
private String key
keyDatabaseback to summary
private String keyDatabase
PG_TYPE_BOOLback to summary
public static final int PG_TYPE_BOOL
PG_TYPE_BPCHARback to summary
public static final int PG_TYPE_BPCHAR
PG_TYPE_BYTEAback to summary
public static final int PG_TYPE_BYTEA
PG_TYPE_DATEback to summary
public static final int PG_TYPE_DATE
PG_TYPE_FLOAT4back to summary
public static final int PG_TYPE_FLOAT4
PG_TYPE_FLOAT8back to summary
public static final int PG_TYPE_FLOAT8
PG_TYPE_INT2back to summary
public static final int PG_TYPE_INT2
PG_TYPE_INT2_ARRAYback to summary
public static final int PG_TYPE_INT2_ARRAY
PG_TYPE_INT4back to summary
public static final int PG_TYPE_INT4
PG_TYPE_INT4_ARRAYback to summary
public static final int PG_TYPE_INT4_ARRAY
PG_TYPE_INT8back to summary
public static final int PG_TYPE_INT8
PG_TYPE_NUMERICback to summary
public static final int PG_TYPE_NUMERIC
PG_TYPE_TEXTback to summary
public static final int PG_TYPE_TEXT
PG_TYPE_TIMEback to summary
public static final int PG_TYPE_TIME
PG_TYPE_TIMESTAMPback to summary
public static final int PG_TYPE_TIMESTAMP
PG_TYPE_TIMESTAMPTZback to summary
public static final int PG_TYPE_TIMESTAMPTZ
PG_TYPE_TIMETZback to summary
public static final int PG_TYPE_TIMETZ
PG_TYPE_UNKNOWNback to summary
public static final int PG_TYPE_UNKNOWN
PG_TYPE_VARCHARback to summary
public static final int PG_TYPE_VARCHAR

The VARCHAR type.

PG_TYPE_VARCHAR_ARRAYback to summary
public static final int PG_TYPE_VARCHAR_ARRAY
pidback to summary
private final AtomicInteger pid
portback to summary
private int port
portIsSetback to summary
private boolean portIsSet
runningback to summary
private final Set<PgServerThread> running
serverSocketback to summary
private ServerSocket serverSocket
stopback to summary
private boolean stop
traceback to summary
private boolean trace
typeSetback to summary
private final HashSet<Integer> typeSet
virtualThreadsback to summary
private boolean virtualThreads

Constructor Detail

PgServerback to summary
public PgServer()

Method Detail

allowback to summary
private boolean allow(Socket socket)
checkKeyAndGetDatabaseNameback to summary
public 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:String

the key to test (or database name if no key is used)

Returns:String

the database name

Exceptions
DbException:
if a key is set but doesn't match
checkTypeback to summary
pack-priv void checkType(int type)

Check whether a data type is supported. A warning is logged if not.

Parameters
type:int

the type

convertTypeback to summary
public static int convertType(TypeInfo type)

Convert the SQL type to a PostgreSQL type

Parameters
type:TypeInfo

the SQL type

Returns:int

the PostgreSQL type

formatTypeback to summary
public static String formatType(int pgType)

Returns the name of the given type.

Parameters
pgType:int

the PostgreSQL type oid

Returns:String

the name of the given type

getAllowOthersback to summary
public boolean getAllowOthers()

Implements org.h2.server.Service.getAllowOthers.

Doc from org.h2.server.Service.getAllowOthers.

Check if remote connections are allowed.

Returns:boolean

true if remote connections are allowed

Annotations
@Override
getBaseDirback to summary
pack-priv String getBaseDir()
getIfExistsback to summary
pack-priv boolean getIfExists()
getNameback to summary
public String getName()

Implements org.h2.server.Service.getName.

Doc from org.h2.server.Service.getName.

Get the human readable name of the service.

Returns:String

the name

Annotations
@Override
getPortback to summary
public int getPort()

Implements org.h2.server.Service.getPort.

Doc from org.h2.server.Service.getPort.

Gets the port this service is listening on.

Returns:int

the port

Annotations
@Override
getThreadback to summary
pack-priv PgServerThread getThread(int processId)

Get the thread with the given process id.

Parameters
processId:int

the process id

Returns:PgServerThread

the thread

getTraceback to summary
pack-priv boolean getTrace()
getTypeback to summary
public String getType()

Implements org.h2.server.Service.getType.

Doc from org.h2.server.Service.getType.

Get the human readable short name of the service.

Returns:String

the type

Annotations
@Override
getTypeSetback to summary
pack-priv HashSet<Integer> getTypeSet()

Get the type hash set.

Returns:HashSet<Integer>

the type set

getURLback to summary
public String getURL()

Implements org.h2.server.Service.getURL.

Doc from org.h2.server.Service.getURL.

Get the URL of this service in a human readable form

Returns:String

the url

Annotations
@Override
initback to summary
public void init(String... args)

Implements org.h2.server.Service.init.

Doc from org.h2.server.Service.init.

Initialize the service from command line options.

Parameters
args:String[]

the command line options

Annotations
@Override
isDaemonback to summary
public boolean isDaemon()

Implements org.h2.server.Service.isDaemon.

Doc from org.h2.server.Service.isDaemon.

Check if a daemon thread should be used.

Returns:boolean

true if a daemon thread should be used

Annotations
@Override
isRunningback to summary
public boolean isRunning(boolean traceError)

Implements org.h2.server.Service.isRunning.

Doc from org.h2.server.Service.isRunning.

Check if the service is running.

Parameters
traceError:boolean

if errors should be written

Returns:boolean

if the server is running

Annotations
@Override
listenback to summary
public void listen()

Implements org.h2.server.Service.listen.

Doc from org.h2.server.Service.listen.

Listen for incoming connections. This method blocks.

Annotations
@Override
removeback to summary
pack-priv synchronized void remove(PgServerThread t)

Remove a thread from the list.

Parameters
t:PgServerThread

the thread to remove

startback to summary
public void start()

Implements org.h2.server.Service.start.

Doc from org.h2.server.Service.start.

Start the service. This usually means create the server socket. This method must not block.

Annotations
@Override
stopback to summary
public void stop()

Implements org.h2.server.Service.stop.

Doc from org.h2.server.Service.stop.

Stop the service.

Annotations
@Override
traceback to summary
pack-priv void trace(String s)

Print a message if the trace flag is enabled.

Parameters
s:String

the message

traceErrorback to summary
pack-priv void traceError(Exception e)

Print the stack trace if the trace flag is enabled.

Parameters
e:Exception

the exception