Permalink
Browse files

implement DELETE

  • Loading branch information...
kazuho committed Jul 14, 2014
1 parent 192485e commit 723ed7997a9f2f04f5ec8b095cb3138cd5c1a347
@@ -66,4 +66,8 @@ public Condition(TableDefinition<Row> tableDefinition, String term, AnyType... p
public void update(Connection conn, Row changes) throws SQLException {
tableDefinition.update(conn, this, changes);
}
+
+ public void delete(Connection conn) throws SQLException {
+ tableDefinition.delete(conn, this);
+ }
}
@@ -76,6 +76,13 @@ public void update(Connection conn, Condition<Row> cond, Row changes) throws SQL
ps.execute();
}
+ public void delete(Connection conn, Condition<Row> cond) throws SQLException {
+ String sql = "DELETE FROM " + TABLE_NAME + _buildWhere(cond);
+ PreparedStatement ps = conn.prepareStatement(sql);
+ _bindWhere(cond, ps, 1);
+ ps.execute();
+ }
+
private ArrayList<String> _getColumnNames(Row row) {
ArrayList<String> columnNames = new ArrayList<String>();
if (row == null) {
@@ -39,6 +39,8 @@ public static void main(String[] args) {
System.out.println(Long.toString(m.getId()) + ":" + m.getName());
}
+ Member.all.delete(conn);
+
} catch (Exception e) {
throw new RuntimeException(e);
}

0 comments on commit 723ed79

Please sign in to comment.