コード例 #1
0
  /** Creates pkg new pkg in the database */
  public AreaOfInterest create(String id) throws DataException {
    // create new BO, set whether in the DB or not
    AreaOfInterest pkg = new AreaOfInterest(id);
    pkg.setObjectAlreadyInDB(false);

    // put into the cache
    cache.put(pkg.id, pkg);

    // return the new object
    return pkg;
  } // create
コード例 #2
0
  /** Inserts pkg new pkg into the database */
  private void insert(AreaOfInterest pkg, Connection conn) throws Exception {
    PreparedStatement pstmt = conn.prepareStatement("INSERT INTO AreaOfInterest VALUES (?,?)");
    pstmt.setString(1, pkg.getId());
    pstmt.setString(2, pkg.getDescription());

    int numUpd = pstmt.executeUpdate();

    if (numUpd == 1) {
      pkg.setObjectAlreadyInDB(true);
      pkg.setDirty(false);
    } else {
      throw new DataException("bad AreaOfInterest update");
    }
    pstmt.close();
  }
コード例 #3
0
  /** Internal method to update pkg pkg in the database */
  void save(AreaOfInterest pkg, Connection conn) throws Exception {
    // update the cache
    cache.put(pkg.getId(), pkg);

    // if not dirty, return
    if (!pkg.isDirty() && pkg.isObjectAlreadyInDB()) {
      return;
    }

    // call either update() or insert()
    if (pkg.isObjectAlreadyInDB()) {
      update(pkg, conn);
    } else {
      insert(pkg, conn);
    }
  } // save
コード例 #4
0
  /** Internal method to read an existing pkg from the database */
  synchronized AreaOfInterest read(String id, Connection conn) throws Exception {
    // check cache
    AreaOfInterest pkg = (AreaOfInterest) cache.get(id);
    if (pkg != null) {
      return pkg;
    }
    // pull from database and populate the object
    PreparedStatement pstmt =
        conn.prepareStatement("SELECT * FROM AreaOfInterest WHERE guid LIKE ?");
    pstmt.setString(1, id);
    ResultSet rs = pstmt.executeQuery();
    pkg = new AreaOfInterest(id);
    if (rs.next()) {
      pkg.setObjectAlreadyInDB(true);
      pkg.setDirty(false);
      pkg.setDescription(rs.getString(2));

    } else {
      throw new DataException("bad AreaOfInterest read");
    }
    pkg.setDirty(false);
    pkg.setObjectAlreadyInDB(true);
    // put in the cache

    cache.put(pkg.getId(), pkg);

    // return the object

    return pkg;
  } // read
コード例 #5
0
  /** Saves an existing pkg to the database */
  private void update(AreaOfInterest pkg, Connection conn) throws Exception {
    PreparedStatement pstmt =
        conn.prepareStatement("UPDATE AreaOfInterest SET description=? WHERE guid LIKE ?");

    pstmt.setString(1, pkg.getDescription());
    pstmt.setString(2, pkg.getId());

    int numUpd = pstmt.executeUpdate();

    if (numUpd == 1) {
      pkg.setObjectAlreadyInDB(true);
      pkg.setDirty(false);
    } else {
      throw new DataException("bad AreaOfInterest update");
    }

    pstmt.close();
  }