/**
   * Method declaration
   *
   * @return
   */
  private Session init() {

    try {
      mSocket.setTcpNoDelay(true);

      mInput = new DataInputStream(new BufferedInputStream(mSocket.getInputStream()));
      mOutput = new DataOutputStream(new BufferedOutputStream(mSocket.getOutputStream()));
      user = mInput.readUTF();

      String password = mInput.readUTF();
      Session c;

      try {
        mServer.trace(mThread + ":trying to connect user " + user);

        return mServer.mDatabase.connect(user, password);
      } catch (SQLException e) {
        write(new Result(e.getMessage(), e.getErrorCode()).getBytes());
      }
    } catch (Exception e) {
      mServer.trace(mThread + ":couldn't connect " + user);
    }

    close();

    return null;
  }
  /** Method declaration */
  public void run() {

    Channel c = init();

    if (c != null) {
      try {
        while (true) {
          String sql = mInput.readUTF();

          mServer.trace(mThread + ":" + sql);

          if (sql == null) {
            break;
          }

          write(mDatabase.execute(sql, c).getBytes());
        }
      } catch (Exception e) {
      }
    }

    try {
      mSocket.close();
    } catch (IOException e) {
    }

    if (mDatabase.isShutdown()) {
      System.out.println("The database is shutdown");
      System.exit(0);
    }
  }
  /** Method declaration */
  public void run() {

    session = init();

    if (session != null) {
      try {
        while (true) {

          // fredt@users 20011220 - patch 448121 by sma@users - large binary values
          byte[] bytes = new byte[mInput.readInt()];

          mInput.readFully(bytes);

          String sql = new String(bytes, "utf-8");

          mServer.trace(mThread + ":" + sql);

          if (sql == null) {
            break;
          }

          write(mServer.mDatabase.execute(sql, session).getBytes());

          if (mServer.mDatabase.isShutdown()) {
            break;
          }
        }
      } catch (IOException e) {
        mServer.trace(mThread + ":disconnected " + user);

        // fredt - todo - after the client abrubtly drops, should perform equivalent
        // of Session.disconnect() to clear any TEMP tables
      } catch (SQLException e) {

        // is thrown by Result.getBytes()
        String s = e.getMessage();

        e.printStackTrace();
      }

      close();
    }
  }