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.RunnableOne server thread is opened for each client.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classPgServerThread.PortalRepresents a PostgreSQL Portal object.(package private) static classPgServerThread.PreparedRepresents a PostgreSQL Prepared object.
-
Field Summary
Fields Modifier and Type Field Description private CommandInterfaceactiveRequestprivate java.lang.StringclientEncodingprivate java.lang.StringdatabaseNameprivate java.io.DataInputStreamdataInprivate java.io.DataInputStreamdataInRawprivate java.io.DataOutputStreamdataOutprivate java.lang.StringdateStyleprivate booleaninitDoneprivate static booleanINTEGER_DATE_TYPESprivate static intMAX_GROUP_SCALEprivate static intMAX_GROUP_SIZEprivate intmessageTypeprivate java.io.OutputStreamoutprivate java.io.ByteArrayOutputStreamoutBufferprivate java.util.HashMap<java.lang.String,PgServerThread.Portal>portalsprivate static int[]POWERS10private java.util.HashMap<java.lang.String,PgServerThread.Prepared>preparedprivate intprocessIdprivate intsecretprivate PgServerserverprivate SessionLocalsessionprivate static java.util.regex.PatternSHOULD_QUOTEprivate java.net.Socketsocketprivate booleanstopprivate java.lang.Threadthreadprivate TimeZoneProvidertimeZoneprivate java.lang.StringuserName
-
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 voidcancelRequest()Kill a currently running query on this thread.private static voidcheckParamLength(int expected, int got)(package private) voidclose()Close this connection.private static java.lang.StringconvertTimeZone(java.lang.String value, java.lang.String prefix)private static intdivide(java.math.BigInteger[] unscaled, int divisor)private voidexecuteQuery(PgServerThread.Prepared prepared, CommandInterface prep, int[] resultColumnFormat, int maxRows)private static booleanformatAsText(int pgType, int[] formatCodes, int column)Check whether the given type should be formatted as text.private java.nio.charset.CharsetgetEncoding()(package private) intgetProcessId()private java.lang.StringgetSQL(java.lang.String s)(package private) java.lang.ThreadgetThread()private static intgetTypeSize(int pgType, int precision)private voidinitDb()private static java.lang.StringpgTimeZone(java.lang.String value)private voidprocess()private bytereadByte()private voidreadFully(byte[] buff)private intreadInt()private shortreadShort()private java.lang.StringreadString()voidrun()private voidsendAuthenticationCleartextPassword()private voidsendAuthenticationOk()private voidsendBackendKeyData()private voidsendBindComplete()private voidsendCancelQueryResponse()private voidsendCloseComplete()private voidsendCommandComplete(CommandInterface command, long updateCount)private voidsendCommandSuspended()private voidsendDataRow(ResultInterface result, int[] formatCodes)private voidsendErrorOrCancelResponse(java.lang.Exception e)private voidsendErrorResponse(java.lang.Exception re)private voidsendErrorResponse(java.lang.String message)private voidsendMessage()private voidsendNoData()private voidsendParameterDescription(java.util.ArrayList<? extends ParameterInterface> parameters, int[] paramTypes)private voidsendParameterStatus(java.lang.String param, java.lang.String value)private voidsendParseComplete()private voidsendReadyForQuery()private voidsendRowDescription(ResultInterface result, int[] formatCodes)private voidsetActiveRequest(CommandInterface statement)private voidsetParameter(java.util.ArrayList<? extends ParameterInterface> parameters, int pgType, int i, int[] formatCodes)(package private) voidsetProcessId(int id)(package private) voidsetThread(java.lang.Thread thread)private voidstartMessage(int newMessageType)private static longtoPostgreDays(long dateValue)private voidwrite(byte[] data)private voidwrite(int b)private voidwrite(java.io.ByteArrayOutputStream baos)private voidwriteDataColumn(Value v, int pgType, boolean text)private voidwriteInt(int i)private voidwriteNumericBinary(java.math.BigDecimal value)private voidwriteShort(int i)private voidwriteString(java.lang.String s)private voidwriteStringPart(java.lang.String s)private voidwriteTimeBinary(long m, int numBytes)private voidwriteTimestampBinary(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:
runin 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, ornullcolumn- 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.
-
-