Class JDBCProcessor

  • All Implemented Interfaces:
    ProtocolConstants
    Direct Known Subclasses:
    StreamJDBCServerConnection

    abstract class JDBCProcessor
    extends java.lang.Object
    implements ProtocolConstants
    This processes JDBC commands from a JDBC client and dispatches the commands to the database. This is a state based class. There is a single processor for each JDBC client connected. This class is designed to be flexible enough to handle packet based protocols as well as stream based protocols.
    • Field Detail

      • SERVER_VERSION

        private static final int SERVER_VERSION
        The version of the server protocol.
        See Also:
        Constant Field Values
      • state

        private int state
        The current state we are in. 0 indicates we haven't logged in yet. 100 indicates we are logged in.
      • authentication_tries

        private int authentication_tries
        Number of authentications tried.
      • db_interface

        private DatabaseInterface db_interface
        The interface to the database.
      • debug

        private DebugLogger debug
        An object the debug information can be logged to.
      • db_call_back

        private DatabaseCallBack db_call_back
        The database call back method that sends database events back to the client.
    • Method Detail

      • printByteArray

        protected static void printByteArray​(byte[] array)
      • processJDBCCommand

        byte[] processJDBCCommand​(byte[] command)
                           throws java.io.IOException
        Processes a single JDBCCommand from the client. The command comes in as a byte[] array and the response is written out as a byte[] array. If it returns 'null' then it means the connection has been closed.
        Throws:
        java.io.IOException
      • getState

        int getState()
        Returns the state of the connection. 0 = not logged in yet. 1 = logged in.
      • single

        private byte[] single​(int val)
        Convenience, returns a single 4 byte array with the given int encoded into it.
      • exception

        private byte[] exception​(int dispatch_id,
                                 java.sql.SQLException e)
                          throws java.io.IOException
        Creates a response that represents an SQL exception failure.
        Throws:
        java.io.IOException
      • simpleSuccess

        private byte[] simpleSuccess​(int dispatch_id)
                              throws java.io.IOException
        Creates a response that indicates a simple success of an operation with the given dispatch id.
        Throws:
        java.io.IOException
      • processQuery

        private byte[] processQuery​(byte[] command)
                             throws java.io.IOException
        Processes a query on the byte[] array and returns the result.
        Throws:
        java.io.IOException
      • dispose

        void dispose()
        Disposes of this processor.
      • queryCommand

        private byte[] queryCommand​(int dispatch_id,
                                    byte[] command)
                             throws java.io.IOException
        Executes a query and returns the header for the result in the response. This keeps track of all result sets because sections of the result are later queries via the 'RESULT_SECTION' command.

        'dispatch_id' is the number we need to respond with.

        Throws:
        java.io.IOException
      • pushStreamableObjectPart

        private byte[] pushStreamableObjectPart​(int dispatch_id,
                                                byte[] command)
                                         throws java.io.IOException
        Pushes a part of a streamable object onto the server.

        'dispatch_id' is the number we need to respond with.

        Throws:
        java.io.IOException
      • resultSection

        private byte[] resultSection​(int dispatch_id,
                                     byte[] command)
                              throws java.io.IOException
        Responds with a part of the result set of a query made via the 'QUERY' command.

        'dispatch_id' is the number we need to respond with.

        Throws:
        java.io.IOException
      • streamableObjectSection

        private byte[] streamableObjectSection​(int dispatch_id,
                                               byte[] command)
                                        throws java.io.IOException
        Returns a section of a streamable object.

        'dispatch_id' is the number we need to respond with.

        Throws:
        java.io.IOException
      • disposeStreamableObject

        private byte[] disposeStreamableObject​(int dispatch_id,
                                               byte[] command)
                                        throws java.io.IOException
        Disposes of a streamable object.

        'dispatch_id' is the number we need to respond with.

        Throws:
        java.io.IOException
      • disposeResult

        private byte[] disposeResult​(int dispatch_id,
                                     byte[] command)
                              throws java.io.IOException
        Disposes of a result set we queries via the 'QUERY' command.

        'dispatch_id' is the number we need to respond with.

        Throws:
        java.io.IOException
      • sendEvent

        public abstract void sendEvent​(byte[] event_msg)
                                throws java.io.IOException
        Sends an event to the client. This is used to notify the client of trigger events, etc.

        SECURITY ISSUE: This is always invoked by the DatabaseDispatcher. We have to be careful that this method isn't allowed to block. Otherwise the DatabaseDispatcher thread will be out of operation. Unfortunately assuring this may not be possible until Java has non-blocking IO, or we use datagrams for transmission. I know for sure that the TCP implementation is vunrable. If the client doesn't 'read' what we are sending then this'll block when the buffers become full.

        Throws:
        java.io.IOException
      • close

        public abstract void close()
                            throws java.io.IOException
        Closes the connection with the client.
        Throws:
        java.io.IOException
      • isClosed

        public abstract boolean isClosed()
                                  throws java.io.IOException
        Returns true if the connection to the client is closed.
        Throws:
        java.io.IOException
      • finalize

        public final void finalize()
                            throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable