Implemented method deleteRecords() in class MSqlTable.
authorMarco Zanon <info@marcozanon.com>
Tue, 10 Dec 2013 15:36:59 +0000 (15:36 +0000)
committerMarco Zanon <info@marcozanon.com>
Tue, 10 Dec 2013 15:36:59 +0000 (15:36 +0000)
3.x/src/java/com/marcozanon/macaco/sql/MSqlTable.java

index b921d1460b876ed9e6dfa27821f226b40578eae3..bf7ad51572aeaad8c92b46d079c2bf5d2fd91cdb 100644 (file)
@@ -9,6 +9,7 @@ package com.marcozanon.macaco.sql;
 import com.marcozanon.macaco.MObject;
 import com.marcozanon.macaco.text.MText;
 import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.LinkedList;
 
 public class MSqlTable extends MObject {
@@ -134,4 +135,20 @@ public class MSqlTable extends MObject {
                                                                       p);
     }
 
+    public MSqlStatementResults deleteRecords(LinkedHashSet idSet) throws MStatementSqlException {
+        if (null == idSet) {
+            throw new IllegalArgumentException("Invalid 'idSet': null.");
+        }
+        //
+        StringBuilder whereClause = new StringBuilder("(0)");
+        LinkedList<Object> p = new LinkedList<Object>();
+        for (Object id: idSet) {
+            whereClause.append(" OR (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)");
+            p.add(id);
+        }
+        return this.getConnectionReference().executePreparedStatement(" DELETE FROM \"" + this.getTable() + "\""
+                                                                    + " WHERE       (" + whereClause + ")",
+                                                                      p);
+    }
+
 }