예제 #1
0
  /**
   * Load the Session associated with the id <code>id</code>. If no such session is found <code>null
   * </code> is returned.
   *
   * @param id a value of type <code>String</code>
   * @return the stored <code>Session</code>
   * @exception ClassNotFoundException if an error occurs
   * @exception IOException if an input/output error occurred
   */
  public Session load(String id) throws ClassNotFoundException, IOException {
    ResultSet rst = null;
    StandardSession _session = null;
    Loader loader = null;
    ClassLoader classLoader = null;
    ObjectInputStream ois = null;
    BufferedInputStream bis = null;
    Container container = manager.getContainer();
    String loadSql =
        "SELECT "
            + sessionIdCol
            + ", "
            + sessionDataCol
            + " FROM "
            + sessionTable
            + " WHERE "
            + sessionIdCol
            + " = ? AND "
            + sessionAppCol
            + " = ?";

    synchronized (this) {
      Connection _conn = getConnection();
      if (_conn == null) {
        return (null);
      }

      try {
        if (preparedLoadSql == null) {
          preparedLoadSql = _conn.prepareStatement(loadSql);
        }

        preparedLoadSql.setString(1, id);
        preparedLoadSql.setString(2, getName());
        rst = preparedLoadSql.executeQuery();
        if (rst.next()) {
          bis = new BufferedInputStream(rst.getBinaryStream(2));

          if (container != null) {
            loader = container.getLoader();
          }
          if (loader != null) {
            classLoader = loader.getClassLoader();
          }
          if (classLoader != null) {
            ois = new CustomObjectInputStream(bis, classLoader);
          } else {
            ois = new ObjectInputStream(bis);
          }

          if (debug > 0) {
            log(sm.getString(getStoreName() + ".loading", id, sessionTable));
          }

          _session = (StandardSession) manager.createEmptySession();
          _session.readObjectData(ois);
          _session.setManager(manager);

        } else if (debug > 0) {
          log(getStoreName() + ": No persisted data object found");
        }
      } catch (SQLException e) {
        log(sm.getString(getStoreName() + ".SQLException", e));
      } finally {
        try {
          if (rst != null) {
            rst.close();
          }
        } catch (SQLException e) {;
        }
        if (ois != null) {
          try {
            ois.close();
          } catch (IOException e) {;
          }
        }
        release(_conn);
      }
    }

    return (_session);
  }
예제 #2
0
 public Loader getLoader() {
   if (loader != null) return (loader);
   if (parent != null) return (parent.getLoader());
   return (null);
 }