/* (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; }
/* (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); }
/* (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); }
/* (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; }
/** * 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); }
/* (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); }
/* (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; }
/* (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; }
@Override public void connect(String url) throws Exception { JdbcDB.connect(url); }
@Override public void rollbackTransaction() throws Exception { JdbcDB.rollbackTransaction(); }
@Override public void commitTransaction() throws Exception { JdbcDB.commitTransaction(); }
@Override public void beginTransaction() throws Exception { JdbcDB.beginTransaction(); }
@Override public ResultSet execQuery(String string) throws Exception { return JdbcDB.execQuery(string); }
@Override public void execSQL(String string) throws Exception { JdbcDB.execSQL(string); }
@Override public void close() throws Exception { JdbcDB.close(); }
@Override public Connection getConnection() { return JdbcDB.getConnection(); }
@Override public String buildURL() { return JdbcDB.buildDbDir(); }