Exemplo n.º 1
0
  /* (non-Javadoc)
   * @see net.sf.borg.model.db.jdbc.JdbcBeanDB#getPSOne(int)
   */
  @Override
  PreparedStatement getPSOne(int key) throws SQLException {
    PreparedStatement stmt =
        JdbcDB.getConnection().prepareStatement("SELECT * FROM links WHERE id = ?");
    stmt.setInt(1, key);

    return stmt;
  }
Exemplo n.º 2
0
  /* (non-Javadoc)
   * @see net.sf.borg.model.db.EntityDB#delete(int)
   */
  @Override
  public void delete(int key) throws Exception {
    PreparedStatement stmt =
        JdbcDB.getConnection().prepareStatement("DELETE FROM links WHERE id = ?");
    stmt.setInt(1, key);
    stmt.executeUpdate();
    stmt.close();

    delCache(key);
  }
Exemplo n.º 3
0
  /* (non-Javadoc)
   * @see net.sf.borg.model.db.EntityDB#addObj(net.sf.borg.model.entity.KeyedEntity)
   */
  @Override
  public void addObj(Link att) throws Exception {
    PreparedStatement stmt =
        JdbcDB.getConnection()
            .prepareStatement(
                "INSERT INTO links ( id, linktype, ownerkey, ownertype, path) "
                    + " VALUES "
                    + "( ?, ?, ?, ?, ?)");

    stmt.setInt(1, att.getKey());
    stmt.setString(2, att.getLinkType());
    stmt.setInt(3, JdbcDB.toInt(att.getOwnerKey()));
    stmt.setString(4, att.getOwnerType());
    stmt.setString(5, att.getPath());

    stmt.executeUpdate();
    stmt.close();

    writeCache(att);
  }
Exemplo n.º 4
0
  /* (non-Javadoc)
   * @see net.sf.borg.model.db.EntityDB#nextkey()
   */
  @Override
  public int nextkey() throws Exception {
    PreparedStatement stmt = JdbcDB.getConnection().prepareStatement("SELECT MAX(id) FROM links");
    ResultSet r = stmt.executeQuery();
    int maxKey = 0;
    if (r.next()) maxKey = r.getInt(1);
    r.close();
    stmt.close();

    return ++maxKey;
  }
Exemplo n.º 5
0
  /**
   * Gets the keys.
   *
   * @return the keys
   * @throws Exception the exception
   */
  public Collection<Integer> getKeys() throws Exception {
    ArrayList<Integer> keys = new ArrayList<Integer>();
    PreparedStatement stmt = JdbcDB.getConnection().prepareStatement("SELECT id FROM links");
    ResultSet rs = stmt.executeQuery();
    while (rs.next()) {
      keys.add(new Integer(rs.getInt("id")));
    }
    rs.close();
    stmt.close();

    return (keys);
  }
Exemplo n.º 6
0
  /* (non-Javadoc)
   * @see net.sf.borg.model.db.EntityDB#updateObj(net.sf.borg.model.entity.KeyedEntity)
   */
  @Override
  public void updateObj(Link att) throws Exception {

    PreparedStatement stmt =
        JdbcDB.getConnection()
            .prepareStatement(
                "UPDATE links SET linktype = ?, ownerkey = ?, ownertype = ?, path = ?"
                    + " WHERE id = ?");

    stmt.setString(1, att.getLinkType());
    stmt.setInt(2, att.getOwnerKey().intValue());
    stmt.setString(3, att.getOwnerType());
    stmt.setString(4, att.getPath());
    stmt.setInt(5, att.getKey());

    stmt.executeUpdate();
    stmt.close();

    delCache(att.getKey());
    writeCache(att);
  }
Exemplo n.º 7
0
  /* (non-Javadoc)
   * @see net.sf.borg.model.db.LinkDB#getLinks(int, java.lang.String)
   */
  @Override
  public Collection<Link> getLinks(int ownerkey, String ownertype) throws SQLException {
    PreparedStatement stmt =
        JdbcDB.getConnection()
            .prepareStatement("SELECT * from links where ownerkey = ? and ownertype = ?");
    ResultSet r = null;
    List<Link> lst = new ArrayList<Link>();
    try {

      stmt.setInt(1, ownerkey);
      stmt.setString(2, ownertype);
      r = stmt.executeQuery();
      while (r.next()) {
        Link s = createFrom(r);
        lst.add(s);
      }

    } finally {
      if (r != null) r.close();
      if (stmt != null) stmt.close();
    }
    return lst;
  }
Exemplo n.º 8
0
 /* (non-Javadoc)
  * @see net.sf.borg.model.db.jdbc.JdbcBeanDB#getPSAll()
  */
 @Override
 PreparedStatement getPSAll() throws SQLException {
   PreparedStatement stmt = JdbcDB.getConnection().prepareStatement("SELECT * FROM links");
   return stmt;
 }
Exemplo n.º 9
0
 @Override
 public void connect(String url) throws Exception {
   JdbcDB.connect(url);
 }
Exemplo n.º 10
0
 @Override
 public void rollbackTransaction() throws Exception {
   JdbcDB.rollbackTransaction();
 }
Exemplo n.º 11
0
 @Override
 public void commitTransaction() throws Exception {
   JdbcDB.commitTransaction();
 }
Exemplo n.º 12
0
 @Override
 public void beginTransaction() throws Exception {
   JdbcDB.beginTransaction();
 }
Exemplo n.º 13
0
 @Override
 public ResultSet execQuery(String string) throws Exception {
   return JdbcDB.execQuery(string);
 }
Exemplo n.º 14
0
 @Override
 public void execSQL(String string) throws Exception {
   JdbcDB.execSQL(string);
 }
Exemplo n.º 15
0
 @Override
 public void close() throws Exception {
   JdbcDB.close();
 }
Exemplo n.º 16
0
 @Override
 public Connection getConnection() {
   return JdbcDB.getConnection();
 }
Exemplo n.º 17
0
 @Override
 public String buildURL() {
   return JdbcDB.buildDbDir();
 }