...
There are a number of built-in implementations of UpdateScript which of UpdateScript which provide out-of-the-box single/atomic updates:
...
Code Block | ||
---|---|---|
| ||
UpdateableDataContext dataContext = ...; dataContext.executeUpdate(new UpdateScript() { public void run(UpdateCallback callback) { // INSERT INTO table (name,age) VALUES ('Polly the Sheep', -1) callback.insertInto(table).value("name", "Polly the Sheep").value("age", -1)).execute(); // UPDATE table SET age = 10 WHERE name = 'Polly the Sheep' callback.update(table).where("name").eq("Polly the Sheep").value("age", 10)).execute(); // DELETE FROM table WHERE name = 'Polly the Sheep' callback.deleteFrom(table).where("name").eq("Polly the Sheep")).execute(); }; }); |
Notice also that the UpdateScript interface the UpdateScript interface is a single-method-interface (SAM). This means that from Java 8 and forward, you should be able to provide a closure here instead of an anonymous inner class.