Package org.h2.server.pg
Class PgServer
- java.lang.Object
-
- 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: https://www.postgresql.org/docs/devel/protocol.html The PostgreSQL catalog is described here: https://www.postgresql.org/docs/7.4/catalogs.html
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowOthersprivate java.lang.StringbaseDirstatic intDEFAULT_PORTThe default port to use for the PG server.private booleanifExistsprivate booleanisDaemonprivate java.lang.Stringkeyprivate java.lang.StringkeyDatabasestatic intPG_TYPE_BOOLstatic intPG_TYPE_BPCHARstatic intPG_TYPE_BYTEAstatic intPG_TYPE_DATEstatic intPG_TYPE_FLOAT4static intPG_TYPE_FLOAT8static intPG_TYPE_INT2static intPG_TYPE_INT2_ARRAYstatic intPG_TYPE_INT4static intPG_TYPE_INT4_ARRAYstatic intPG_TYPE_INT8static intPG_TYPE_NUMERICstatic intPG_TYPE_TEXTstatic intPG_TYPE_TIMEstatic intPG_TYPE_TIMESTAMPstatic intPG_TYPE_TIMESTAMPTZstatic intPG_TYPE_TIMETZstatic intPG_TYPE_UNKNOWNstatic intPG_TYPE_VARCHARThe VARCHAR type.static intPG_TYPE_VARCHAR_ARRAYprivate java.util.concurrent.atomic.AtomicIntegerpidprivate intportprivate booleanportIsSetprivate java.util.Set<PgServerThread>runningprivate java.net.ServerSocketserverSocketprivate booleanstopprivate booleantraceprivate java.util.HashSet<java.lang.Integer>typeSet
-
Constructor Summary
Constructors Constructor Description PgServer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanallow(java.net.Socket socket)java.lang.StringcheckKeyAndGetDatabaseName(java.lang.String db)If no key is set, return the original database name.(package private) voidcheckType(int type)Check whether a data type is supported.static intconvertType(TypeInfo type)Convert the SQL type to a PostgreSQL typestatic java.lang.StringformatType(int pgType)Returns the name of the given type.booleangetAllowOthers()Check if remote connections are allowed.(package private) java.lang.StringgetBaseDir()(package private) booleangetIfExists()java.lang.StringgetName()Get the human readable name of the service.intgetPort()Gets the port this service is listening on.(package private) PgServerThreadgetThread(int processId)Get the thread with the given process id.(package private) booleangetTrace()java.lang.StringgetType()Get the human readable short name of the service.(package private) java.util.HashSet<java.lang.Integer>getTypeSet()Get the type hash set.java.lang.StringgetURL()Get the URL of this service in a human readable formvoidinit(java.lang.String... args)Initialize the service from command line options.booleanisDaemon()Check if a daemon thread should be used.booleanisRunning(boolean traceError)Check if the service is running.voidlisten()Listen for incoming connections.(package private) voidremove(PgServerThread t)Remove a thread from the list.voidstart()Start the service.voidstop()Stop the service.(package private) voidtrace(java.lang.String s)Print a message if the trace flag is enabled.(package private) voidtraceError(java.lang.Exception e)Print the stack trace if the trace flag is enabled.
-
-
-
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
-
PG_TYPE_VARCHAR
public static final int PG_TYPE_VARCHAR
The VARCHAR type.- See Also:
- Constant Field Values
-
PG_TYPE_BOOL
public static final int PG_TYPE_BOOL
- See Also:
- Constant Field Values
-
PG_TYPE_BYTEA
public static final int PG_TYPE_BYTEA
- See Also:
- Constant Field Values
-
PG_TYPE_BPCHAR
public static final int PG_TYPE_BPCHAR
- See Also:
- Constant Field Values
-
PG_TYPE_INT8
public static final int PG_TYPE_INT8
- See Also:
- Constant Field Values
-
PG_TYPE_INT2
public static final int PG_TYPE_INT2
- See Also:
- Constant Field Values
-
PG_TYPE_INT4
public static final int PG_TYPE_INT4
- See Also:
- Constant Field Values
-
PG_TYPE_TEXT
public static final int PG_TYPE_TEXT
- See Also:
- Constant Field Values
-
PG_TYPE_FLOAT4
public static final int PG_TYPE_FLOAT4
- See Also:
- Constant Field Values
-
PG_TYPE_FLOAT8
public static final int PG_TYPE_FLOAT8
- See Also:
- Constant Field Values
-
PG_TYPE_UNKNOWN
public static final int PG_TYPE_UNKNOWN
- See Also:
- Constant Field Values
-
PG_TYPE_INT2_ARRAY
public static final int PG_TYPE_INT2_ARRAY
- See Also:
- Constant Field Values
-
PG_TYPE_INT4_ARRAY
public static final int PG_TYPE_INT4_ARRAY
- See Also:
- Constant Field Values
-
PG_TYPE_VARCHAR_ARRAY
public static final int PG_TYPE_VARCHAR_ARRAY
- See Also:
- Constant Field Values
-
PG_TYPE_DATE
public static final int PG_TYPE_DATE
- See Also:
- Constant Field Values
-
PG_TYPE_TIME
public static final int PG_TYPE_TIME
- See Also:
- Constant Field Values
-
PG_TYPE_TIMETZ
public static final int PG_TYPE_TIMETZ
- See Also:
- Constant Field Values
-
PG_TYPE_TIMESTAMP
public static final int PG_TYPE_TIMESTAMP
- See Also:
- Constant Field Values
-
PG_TYPE_TIMESTAMPTZ
public static final int PG_TYPE_TIMESTAMPTZ
- See Also:
- Constant Field Values
-
PG_TYPE_NUMERIC
public static final int PG_TYPE_NUMERIC
- See Also:
- Constant Field Values
-
typeSet
private final java.util.HashSet<java.lang.Integer> typeSet
-
port
private int port
-
portIsSet
private boolean portIsSet
-
stop
private boolean stop
-
trace
private boolean trace
-
serverSocket
private java.net.ServerSocket serverSocket
-
running
private final java.util.Set<PgServerThread> running
-
pid
private final java.util.concurrent.atomic.AtomicInteger pid
-
baseDir
private java.lang.String baseDir
-
allowOthers
private boolean allowOthers
-
isDaemon
private boolean isDaemon
-
ifExists
private boolean ifExists
-
key
private java.lang.String key
-
keyDatabase
private java.lang.String keyDatabase
-
-
Method Detail
-
init
public void init(java.lang.String... args)
Description copied from interface:ServiceInitialize the service from command line options.
-
getTrace
boolean getTrace()
-
trace
void trace(java.lang.String s)
Print a message if the trace flag is enabled.- Parameters:
s- the message
-
remove
void remove(PgServerThread t)
Remove a thread from the list.- Parameters:
t- the thread to remove
-
traceError
void traceError(java.lang.Exception e)
Print the stack trace if the trace flag is enabled.- Parameters:
e- the exception
-
getURL
public java.lang.String getURL()
Description copied from interface:ServiceGet the URL of this service in a human readable form
-
getPort
public int getPort()
Description copied from interface:ServiceGets the port this service is listening on.
-
allow
private boolean allow(java.net.Socket socket)
-
start
public void start()
Description copied from interface:ServiceStart the service. This usually means create the server socket. This method must not block.
-
listen
public void listen()
Description copied from interface:ServiceListen for incoming connections. This method blocks.
-
stop
public void stop()
Description copied from interface:ServiceStop the service.
-
isRunning
public boolean isRunning(boolean traceError)
Description copied from interface:ServiceCheck if the service is running.
-
getThread
PgServerThread getThread(int processId)
Get the thread with the given process id.- Parameters:
processId- the process id- Returns:
- the thread
-
getBaseDir
java.lang.String getBaseDir()
-
getAllowOthers
public boolean getAllowOthers()
Description copied from interface:ServiceCheck if remote connections are allowed.- Specified by:
getAllowOthersin interfaceService- Returns:
- true if remote connections are allowed
-
getType
public java.lang.String getType()
Description copied from interface:ServiceGet the human readable short name of the service.
-
getName
public java.lang.String getName()
Description copied from interface:ServiceGet the human readable name of the service.
-
getIfExists
boolean getIfExists()
-
formatType
public static java.lang.String formatType(int pgType)
Returns the name of the given type.- Parameters:
pgType- the PostgreSQL type oid- Returns:
- the name of the given type
-
convertType
public static int convertType(TypeInfo type)
Convert the SQL type to a PostgreSQL type- Parameters:
type- the SQL type- Returns:
- the PostgreSQL type
-
getTypeSet
java.util.HashSet<java.lang.Integer> getTypeSet()
Get the type hash set.- Returns:
- the type set
-
checkType
void checkType(int type)
Check whether a data type is supported. A warning is logged if not.- Parameters:
type- the type
-
checkKeyAndGetDatabaseName
public java.lang.String checkKeyAndGetDatabaseName(java.lang.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
-
-