diff --git a/src/main/java/io/ebeaninternal/server/persist/ExeUpdateSql.java b/src/main/java/io/ebeaninternal/server/persist/ExeUpdateSql.java index 51fc4a35e..7e265033a 100644 --- a/src/main/java/io/ebeaninternal/server/persist/ExeUpdateSql.java +++ b/src/main/java/io/ebeaninternal/server/persist/ExeUpdateSql.java @@ -143,17 +143,26 @@ public class ExeUpdateSql { } } - String firstWord = sql.substring(0, pos[0]); - String secWord = sql.substring(pos[0] + 1, pos[1]); - String thirdWord; - if (pos[2] == 0) { - // there is nothing after the table name - thirdWord = sql.substring(pos[1] + 1); - } else { - thirdWord = sql.substring(pos[1] + 1, pos[2]); - } + if (spaceCount < 2) { + // unknown so no automatic L2 cache invalidation performed (so it should instead) + // be done explicitly via the server.externalModification() method + request.setType(SqlType.SQL_UNKNOWN, null, "UnknownSql"); - determineType(firstWord, secWord, thirdWord, request); + } else { + // try to determine if it is insert, update or delete and the table involved + // such that we can automatically manage L2 cache + String firstWord = sql.substring(0, pos[0]); + String secWord = sql.substring(pos[0] + 1, pos[1]); + String thirdWord; + if (pos[2] == 0) { + // there is nothing after the table name + thirdWord = sql.substring(pos[1] + 1); + } else { + thirdWord = sql.substring(pos[1] + 1, pos[2]); + } + + determineType(firstWord, secWord, thirdWord, request); + } } } diff --git a/src/test/java/org/tests/update/TestSqlUpdateInTxn.java b/src/test/java/org/tests/update/TestSqlUpdateInTxn.java index 017ea8b2e..3ede3004d 100644 --- a/src/test/java/org/tests/update/TestSqlUpdateInTxn.java +++ b/src/test/java/org/tests/update/TestSqlUpdateInTxn.java @@ -20,6 +20,21 @@ public class TestSqlUpdateInTxn extends BaseTestCase { assertThat(sqlUpdate.getSql()).isEqualTo(sql.trim()); } + @Test + public void test_twoWordSql() { + + if (isH2()) { + // 2 word syntax ... means no automatic determination of the type of change + // and table effected (so no automatic L2 cache invalidation) + String sql = "CHECKPOINT SYNC"; + + SqlUpdate sqlUpdate = Ebean.createSqlUpdate(sql); + sqlUpdate.execute(); + + assertThat(sqlUpdate.getSql()).isEqualTo(sql.trim()); + } + } + @Test public void testSqlUpdateWithWhitespace() {