public java.util.List<AreaOfInterest> getAll() throws DataException { // get a jdbc connection Connection conn = cp.get(); LinkedList<AreaOfInterest> areas = new LinkedList(); PreparedStatement pstmt; try { pstmt = conn.prepareStatement("SELECT guid FROM areaOfInterest"); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { String myGuid = rs.getString("guid"); AreaOfInterest a; try { a = read(myGuid, conn); } catch (Exception ex) { throw new DataException("bad read areas"); } areas.add(a); } } catch (SQLException ex) { throw new DataException("bad read all areas"); } finally { cp.release(conn); } return areas; }
/** Reads an existing pkg from the database */ public AreaOfInterest read(String id) throws DataException { // check cache AreaOfInterest pkg = (AreaOfInterest) cache.get(id); if (pkg != null) { return pkg; } // get pkg jdbc connection Connection conn = cp.get(); try { // call the other read method pkg = read(id, conn); } catch (Exception ex) { throw new DataException("can't read AreaOfInterest", ex); } finally { cp.release(conn); } // use pkg finally clause to release the connection // return the object return pkg; }