ng sql = "update f_topic set post_count = :count where id = :topicId"; SqlUpdate update = new SqlUpdate(sql); update.setParameter("count", 1); update.setParameter("topicId", 50); int modifiedCount = Ebean.execute(update);
Note that when the SqlUpdate is executed via Ebean.execute() the sql is parsed to determine if it is an update, delete or insert. In addition the table modified is deduced. If isAutoTableMod() is true, then this is then added to the TransactionEvent and cache invalidation etc is maintained. This means you don't need to use the Ebean.externalModification() method as this has already been done.
You can sql.setAutoTableMod(false); to stop the automatic table modification
EXAMPLE: Using JDBC batching with SqlUpdate
String data = "This is a simple test of the batch processing" + " mode and the transaction execute batch method"; String[] da = data.split(" "); String sql = "insert into junk (word) values (?)"; SqlUpdate sqlUpdate = Ebean.createSqlUpdate(sql); Transaction t = Ebean.beginTransaction(); t.setBatchMode(true); t.setBatchSize(3); try { for (int i = 0; i < da.length; i++) { sqlUpdate.setParameter(1, da[i]); sqlUpdate.execute(); } // NB: commit implicitly flushes the batch Ebean.commitTransaction(); } finally { Ebean.endTransaction(); }
@see com.avaje.ebean.CallableSql
@see com.avaje.ebean.Ebean#execute(SqlUpdate)