Package org.h2.server.pg
Class PgServerThread
- java.lang.Object
-
- org.h2.server.pg.PgServerThread
-
- All Implemented Interfaces:
java.lang.Runnable
public final class PgServerThread extends java.lang.Object implements java.lang.Runnable
One server thread is opened for each client.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
PgServerThread.Portal
Represents a PostgreSQL Portal object.(package private) static class
PgServerThread.Prepared
Represents a PostgreSQL Prepared object.
-
Field Summary
Fields Modifier and Type Field Description private CommandInterface
activeRequest
private java.lang.String
clientEncoding
private java.lang.String
databaseName
private java.io.DataInputStream
dataIn
private java.io.DataInputStream
dataInRaw
private java.io.DataOutputStream
dataOut
private java.lang.String
dateStyle
private boolean
initDone
private static boolean
INTEGER_DATE_TYPES
private static int
MAX_GROUP_SCALE
private static int
MAX_GROUP_SIZE
private int
messageType
private java.io.OutputStream
out
private java.io.ByteArrayOutputStream
outBuffer
private java.util.HashMap<java.lang.String,PgServerThread.Portal>
portals
private static int[]
POWERS10
private java.util.HashMap<java.lang.String,PgServerThread.Prepared>
prepared
private int
processId
private int
secret
private PgServer
server
private SessionLocal
session
private static java.util.regex.Pattern
SHOULD_QUOTE
private java.net.Socket
socket
private boolean
stop
private java.lang.Thread
thread
private TimeZoneProvider
timeZone
private java.lang.String
userName
-
Constructor Summary
Constructors Constructor Description PgServerThread(java.net.Socket socket, PgServer server)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
cancelRequest()
Kill a currently running query on this thread.private static void
checkParamLength(int expected, int got)
(package private) void
close()
Close this connection.private static java.lang.String
convertTimeZone(java.lang.String value, java.lang.String prefix)
private static int
divide(java.math.BigInteger[] unscaled, int divisor)
private void
executeQuery(PgServerThread.Prepared prepared, CommandInterface prep, int[] resultColumnFormat, int maxRows)
private static boolean
formatAsText(int pgType, int[] formatCodes, int column)
Check whether the given type should be formatted as text.private java.nio.charset.Charset
getEncoding()
(package private) int
getProcessId()
private java.lang.String
getSQL(java.lang.String s)
(package private) java.lang.Thread
getThread()
private static int
getTypeSize(int pgType, int precision)
private void
initDb()
private static java.lang.String
pgTimeZone(java.lang.String value)
private void
process()
private byte
readByte()
private void
readFully(byte[] buff)
private int
readInt()
private short
readShort()
private java.lang.String
readString()
void
run()
private void
sendAuthenticationCleartextPassword()
private void
sendAuthenticationOk()
private void
sendBackendKeyData()
private void
sendBindComplete()
private void
sendCancelQueryResponse()
private void
sendCloseComplete()
private void
sendCommandComplete(CommandInterface command, long updateCount)
private void
sendCommandSuspended()
private void
sendDataRow(ResultInterface result, int[] formatCodes)
private void
sendErrorOrCancelResponse(java.lang.Exception e)
private void
sendErrorResponse(java.lang.Exception re)
private void
sendErrorResponse(java.lang.String message)
private void
sendMessage()
private void
sendNoData()
private void
sendParameterDescription(java.util.ArrayList<? extends ParameterInterface> parameters, int[] paramTypes)
private void
sendParameterStatus(java.lang.String param, java.lang.String value)
private void
sendParseComplete()
private void
sendReadyForQuery()
private void
sendRowDescription(ResultInterface result, int[] formatCodes)
private void
setActiveRequest(CommandInterface statement)
private void
setParameter(java.util.ArrayList<? extends ParameterInterface> parameters, int pgType, int i, int[] formatCodes)
(package private) void
setProcessId(int id)
(package private) void
setThread(java.lang.Thread thread)
private void
startMessage(int newMessageType)
private static long
toPostgreDays(long dateValue)
private void
write(byte[] data)
private void
write(int b)
private void
write(java.io.ByteArrayOutputStream baos)
private void
writeDataColumn(Value v, int pgType, boolean text)
private void
writeInt(int i)
private void
writeNumericBinary(java.math.BigDecimal value)
private void
writeShort(int i)
private void
writeString(java.lang.String s)
private void
writeStringPart(java.lang.String s)
private void
writeTimeBinary(long m, int numBytes)
private void
writeTimestampBinary(long m, long nanos)
-
-
-
Field Detail
-
INTEGER_DATE_TYPES
private static final boolean INTEGER_DATE_TYPES
- See Also:
- Constant Field Values
-
SHOULD_QUOTE
private static final java.util.regex.Pattern SHOULD_QUOTE
-
server
private final PgServer server
-
socket
private java.net.Socket socket
-
session
private SessionLocal session
-
stop
private boolean stop
-
dataInRaw
private java.io.DataInputStream dataInRaw
-
dataIn
private java.io.DataInputStream dataIn
-
out
private java.io.OutputStream out
-
messageType
private int messageType
-
outBuffer
private java.io.ByteArrayOutputStream outBuffer
-
dataOut
private java.io.DataOutputStream dataOut
-
thread
private java.lang.Thread thread
-
initDone
private boolean initDone
-
userName
private java.lang.String userName
-
databaseName
private java.lang.String databaseName
-
processId
private int processId
-
secret
private final int secret
-
activeRequest
private CommandInterface activeRequest
-
clientEncoding
private java.lang.String clientEncoding
-
dateStyle
private java.lang.String dateStyle
-
timeZone
private TimeZoneProvider timeZone
-
prepared
private final java.util.HashMap<java.lang.String,PgServerThread.Prepared> prepared
-
portals
private final java.util.HashMap<java.lang.String,PgServerThread.Portal> portals
-
POWERS10
private static final int[] POWERS10
-
MAX_GROUP_SCALE
private static final int MAX_GROUP_SCALE
- See Also:
- Constant Field Values
-
MAX_GROUP_SIZE
private static final int MAX_GROUP_SIZE
-
-
Constructor Detail
-
PgServerThread
PgServerThread(java.net.Socket socket, PgServer server)
-
-
Method Detail
-
pgTimeZone
private static java.lang.String pgTimeZone(java.lang.String value)
-
convertTimeZone
private static java.lang.String convertTimeZone(java.lang.String value, java.lang.String prefix)
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
readString
private java.lang.String readString() throws java.io.IOException
- Throws:
java.io.IOException
-
readInt
private int readInt() throws java.io.IOException
- Throws:
java.io.IOException
-
readShort
private short readShort() throws java.io.IOException
- Throws:
java.io.IOException
-
readByte
private byte readByte() throws java.io.IOException
- Throws:
java.io.IOException
-
readFully
private void readFully(byte[] buff) throws java.io.IOException
- Throws:
java.io.IOException
-
process
private void process() throws java.io.IOException
- Throws:
java.io.IOException
-
executeQuery
private void executeQuery(PgServerThread.Prepared prepared, CommandInterface prep, int[] resultColumnFormat, int maxRows) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getSQL
private java.lang.String getSQL(java.lang.String s)
-
sendCommandComplete
private void sendCommandComplete(CommandInterface command, long updateCount) throws java.io.IOException
- Throws:
java.io.IOException
-
sendCommandSuspended
private void sendCommandSuspended() throws java.io.IOException
- Throws:
java.io.IOException
-
sendDataRow
private void sendDataRow(ResultInterface result, int[] formatCodes) throws java.io.IOException
- Throws:
java.io.IOException
-
toPostgreDays
private static long toPostgreDays(long dateValue)
-
writeDataColumn
private void writeDataColumn(Value v, int pgType, boolean text) throws java.io.IOException
- Throws:
java.io.IOException
-
divide
private static int divide(java.math.BigInteger[] unscaled, int divisor)
-
writeNumericBinary
private void writeNumericBinary(java.math.BigDecimal value) throws java.io.IOException
- Throws:
java.io.IOException
-
writeTimeBinary
private void writeTimeBinary(long m, int numBytes) throws java.io.IOException
- Throws:
java.io.IOException
-
writeTimestampBinary
private void writeTimestampBinary(long m, long nanos) throws java.io.IOException
- Throws:
java.io.IOException
-
getEncoding
private java.nio.charset.Charset getEncoding()
-
setParameter
private void setParameter(java.util.ArrayList<? extends ParameterInterface> parameters, int pgType, int i, int[] formatCodes) throws java.io.IOException
- Throws:
java.io.IOException
-
checkParamLength
private static void checkParamLength(int expected, int got)
-
sendErrorOrCancelResponse
private void sendErrorOrCancelResponse(java.lang.Exception e) throws java.io.IOException
- Throws:
java.io.IOException
-
sendErrorResponse
private void sendErrorResponse(java.lang.Exception re) throws java.io.IOException
- Throws:
java.io.IOException
-
sendCancelQueryResponse
private void sendCancelQueryResponse() throws java.io.IOException
- Throws:
java.io.IOException
-
sendParameterDescription
private void sendParameterDescription(java.util.ArrayList<? extends ParameterInterface> parameters, int[] paramTypes) throws java.lang.Exception
- Throws:
java.lang.Exception
-
sendNoData
private void sendNoData() throws java.io.IOException
- Throws:
java.io.IOException
-
sendRowDescription
private void sendRowDescription(ResultInterface result, int[] formatCodes) throws java.io.IOException
- Throws:
java.io.IOException
-
formatAsText
private static boolean formatAsText(int pgType, int[] formatCodes, int column)
Check whether the given type should be formatted as text.- Parameters:
pgType
- data typeformatCodes
- format codes, ornull
column
- 0-based column number- Returns:
- true for text
-
getTypeSize
private static int getTypeSize(int pgType, int precision)
-
sendErrorResponse
private void sendErrorResponse(java.lang.String message) throws java.io.IOException
- Throws:
java.io.IOException
-
sendParseComplete
private void sendParseComplete() throws java.io.IOException
- Throws:
java.io.IOException
-
sendBindComplete
private void sendBindComplete() throws java.io.IOException
- Throws:
java.io.IOException
-
sendCloseComplete
private void sendCloseComplete() throws java.io.IOException
- Throws:
java.io.IOException
-
initDb
private void initDb()
-
close
void close()
Close this connection.
-
sendAuthenticationCleartextPassword
private void sendAuthenticationCleartextPassword() throws java.io.IOException
- Throws:
java.io.IOException
-
sendAuthenticationOk
private void sendAuthenticationOk() throws java.io.IOException
- Throws:
java.io.IOException
-
sendReadyForQuery
private void sendReadyForQuery() throws java.io.IOException
- Throws:
java.io.IOException
-
sendBackendKeyData
private void sendBackendKeyData() throws java.io.IOException
- Throws:
java.io.IOException
-
writeString
private void writeString(java.lang.String s) throws java.io.IOException
- Throws:
java.io.IOException
-
writeStringPart
private void writeStringPart(java.lang.String s) throws java.io.IOException
- Throws:
java.io.IOException
-
writeInt
private void writeInt(int i) throws java.io.IOException
- Throws:
java.io.IOException
-
writeShort
private void writeShort(int i) throws java.io.IOException
- Throws:
java.io.IOException
-
write
private void write(byte[] data) throws java.io.IOException
- Throws:
java.io.IOException
-
write
private void write(java.io.ByteArrayOutputStream baos) throws java.io.IOException
- Throws:
java.io.IOException
-
write
private void write(int b) throws java.io.IOException
- Throws:
java.io.IOException
-
startMessage
private void startMessage(int newMessageType)
-
sendMessage
private void sendMessage() throws java.io.IOException
- Throws:
java.io.IOException
-
sendParameterStatus
private void sendParameterStatus(java.lang.String param, java.lang.String value) throws java.io.IOException
- Throws:
java.io.IOException
-
setThread
void setThread(java.lang.Thread thread)
-
getThread
java.lang.Thread getThread()
-
setProcessId
void setProcessId(int id)
-
getProcessId
int getProcessId()
-
setActiveRequest
private void setActiveRequest(CommandInterface statement)
-
cancelRequest
private void cancelRequest()
Kill a currently running query on this thread.
-
-