Exemple #1
0
        /// <summary>
        /// Constructs a new <c>HsqlTcpClient</c> instance
        /// with the given host, port, etc.
        /// </summary>
        /// <param name="host">The server host name or IP address.</param>
        /// <param name="port">The server listen port.</param>
        /// <param name="path">The database remote open path. (presently unused/unsupported)</param>
        /// <param name="database">The server alias for one of its mounted databases</param>
        /// <param name="tls">The Transport Layer Security flag</param>
        /// <param name="user">The initial database user name.</param>
        /// <param name="password">The initial database user password.</param>
        /// <exception cref="HsqlException">
        /// </exception>
        internal HsqlTcpClient(
            string host,
            int port,
            string path,
            string database,
            bool tls,
            string user,
            string password)
        {
            m_host     = host;
            m_port     = port;
            m_path     = path;
            m_database = database;
            m_tls      = tls;

            InitializeInstance();
            InitializeConnection(host, port, tls);

            Request loginRequest = m_Protocol.CreateTcpClientLoginRequest(
                user,
                password,
                database);

            Response loginResponse = Session.execute(loginRequest);

            if (loginResponse.isError())
            {
                throw Trace.error(loginResponse);
            }

            m_sessionId  = m_Protocol.GetSessionId(loginResponse);
            m_databaseId = m_Protocol.GetDatabaseId(loginResponse);
        }
 /// <summary>
 /// Checks if row data is available.
 /// </summary>
 internal void CheckAvailable()
 {
     if (!m_isInitialized ||
         (m_currentRecord == null) ||
         (m_result == null))
     {
         throw new HsqlDataSourceException(Trace.error(
                                               Trace.NO_DATA_IS_AVAILABLE));
     }
 }
Exemple #3
0
        /// <summary>
        /// Opens the connection.
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="port">The port.</param>
        /// <param name="tls">
        /// if set to <c>true</c>, use transport layer security.
        /// </param>
        /// <exception cref="HsqlException">
        /// </exception>
        protected virtual void OpenConnection(
            string host,
            int port,
            bool tls)
        {
            if (m_tcpClient != null)
            {
                throw new System.InvalidOperationException(
                          "The connection is already open.");
            }

            HsqlDiagnostics.Debug("...");

            try
            {
                HsqlDiagnostics.Debug("Entered with arguments ({0},{1},{2})",
                                      host, port, tls);

                m_tcpClient = new TcpClient(host, port);

                HsqlDiagnostics.Debug("Created TcpClient({0},{1})", host, port);

                Stream stream = m_tcpClient.GetStream();

                HsqlDiagnostics.Debug("Got client stream from TcpClient");

                if (m_tls)
                {
                    HsqlDiagnostics.Debug("Initializing Client TLS...");

                    SslStream sslStream = new SslStream(
                        stream,
                        false,
                        ValidateRemoteCertificate,
                        null);

                    HsqlDiagnostics.Debug("Invoking sslStream.AuthenticateAsClient({0})",
                                          host);

                    sslStream.AuthenticateAsClient(host);

                    stream = sslStream;
                }

                JavaInputStreamAdapter  input  = new JavaInputStreamAdapter(stream);
                JavaOutputStreamAdapter output = new JavaOutputStreamAdapter(stream);

                m_dataInput  = new DataInputStream(new BufferedInputStream(input));
                m_dataOutput = new BufferedOutputStream(output);
            }
            catch (System.Exception e)
            {
                throw Trace.error(Trace.SOCKET_ERROR, e);
            }
        }
Exemple #4
0
        /// <summary>
        /// Gets the value of the session attribute with the given identifier.
        /// </summary>
        /// <param name="attributeId">The attribute identifier.</param>
        /// <returns>The attribute value</returns>
        private object GetAttribute(int attributeId)
        {
            m_Protocol.SetType(m_request, RequestType.GETSESSIONATTR);

            Response response = Session.execute(m_request);

            if (response.isError())
            {
                throw Trace.error(response);
            }

            switch (attributeId)
            {
            case SessionInfo.INFO_AUTOCOMMIT:
            {
                return(m_Protocol.GetAttributeAutoCommit(response));
            }

            case SessionInfo.INFO_CONNECTION_READONLY:
            {
                return(m_Protocol.GetAttributeConnectionReadOnly(
                           response));
            }

            case SessionInfo.INFO_DATABASE:
            {
                return(m_Protocol.GetAttributeDatabase(response));
            }

            case SessionInfo.INFO_DATABASE_READONLY:
            {
                return(m_Protocol.GetAttributeDatabaseReadOnly(
                           response));
            }

            case SessionInfo.INFO_ISOLATION:
            {
                return(m_Protocol.GetAttributeIsolation(response));
            }

            case SessionInfo.INFO_USER:
            {
                return(m_Protocol.GetAttributeUser(response));
            }

            default:
            {
                throw new ArgumentException(
                          "attributeId",
                          "Unknown Attribute Id: " + attributeId);
            }
            }
        }
Exemple #5
0
        /// <summary>
        /// Sets the value of the attribute denoted by the given identifier.
        /// </summary>
        /// <param name="value">The attribute value.</param>
        /// <param name="attributeId">The attribute identifier.</param>
        /// <exception cref="HsqlException">
        /// </exception>
        private void SetAttribute(object value, int attributeId)
        {
            m_Protocol.SetType(m_request, RequestType.SETSESSIONATTR);
            m_Protocol.ClearAttributes(m_request);

            switch (attributeId)
            {
            case SessionInfo.INFO_AUTOCOMMIT:
            {
                m_Protocol.SetAttributeAutoCommit(
                    m_request,
                    (bool)value);
                break;
            }

            case SessionInfo.INFO_CONNECTION_READONLY:
            {
                m_Protocol.SetAttributeConnectionReadOnly(
                    m_request,
                    (bool)value);
                break;
            }

            case SessionInfo.INFO_ISOLATION:
            {
                m_Protocol.SetAttributeIsolation(
                    m_request,
                    (int)value);
                break;
            }

            default:
            {
                throw new System.ArgumentException(
                          "attributeId",
                          "Invalid Attribute Id: "
                          + attributeId);
            }
            }

            Response response = Session.execute(m_request);

            if (response.isError())
            {
                throw Trace.error(response);
            }
        }
Exemple #6
0
        /// <summary>
        /// Resets this session.
        /// </summary>
        /// <remarks>
        /// Used to reset the remote session object. In case of
        /// failure, the underlying TPC connection is physically
        /// closed. When a pooled database connection's close()
        /// method is called, it should delegate to this method
        /// instead of ISession.close() and return this object
        /// to the pool upon success. In this way, a remote session
        /// proxy object can be reused with no further
        /// initialisation.
        /// </remarks>
        /// <exception cref="HsqlException">
        /// </exception>
        void ISession.resetSession()
        {
            Request  request  = new Request(RequestType.HSQLRESETSESSION);
            Response response = Session.execute(request);

            if (response.isError())
            {
                m_closed = true;

                CloseConnection();

                throw Trace.error(response);
            }

            m_sessionId  = m_Protocol.GetSessionId(response);
            m_databaseId = m_Protocol.GetDatabaseId(response);
        }
Exemple #7
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        /// <exception cref="HsqlException">
        /// </exception>
        Response ISession.execute(Request request)
        {
            lock (this)
            {
                try
                {
                    m_Protocol.SetSessionId(request, m_sessionId);
                    m_Protocol.SetDatabaseId(request, m_databaseId);

                    WriteRequest(request);

                    return(ReadResponse());
                }
                catch (System.Exception e)
                {
                    throw Trace.error(
                              Trace.CONNECTION_IS_BROKEN,
                              e.ToString());
                }
            }
        }
 /// <summary>
 /// Constructs a new <c>HsqlDataSourceException</c> instance
 /// with the specified error message and code.
 /// </summary>
 /// <remarks>
 /// If possible, <c>SQLState</c> is derived from <c>errorCode</c>;
 /// otherwise, <c>SQLState</c> will be <c>null</c>.
 /// </remarks>
 /// <param name="message">
 /// The error message that explains the reason for the exception.
 /// </param>
 /// <param name="errorCode">
 /// The error code for the exception.
 /// </param>
 public HsqlDataSourceException(string message, int errorCode)
     : this(HsqlTrace.error(errorCode, message))
 {
 }