Class 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.
    • Field Detail

      • SHOULD_QUOTE

        private static final java.util.regex.Pattern SHOULD_QUOTE
      • socket

        private java.net.Socket socket
      • 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
      • clientEncoding

        private java.lang.String clientEncoding
      • dateStyle

        private java.lang.String dateStyle
      • POWERS10

        private static final int[] POWERS10
      • 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 interface java.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 type
        formatCodes - format codes, or null
        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.