提交 85e74dd1 authored 作者: noelgrandin's avatar noelgrandin

Bug: Changes to the database structure did not result in the Session query cache being invalidated.

上级 101d72e0
...@@ -22,8 +22,10 @@ Change Log ...@@ -22,8 +22,10 @@ Change Log
</li><li>Issue 467: OSGi Class Loader (ability to create reference to class </li><li>Issue 467: OSGi Class Loader (ability to create reference to class
in other ClassLoader, for example in another OSGi bundle). in other ClassLoader, for example in another OSGi bundle).
</li><li>Fix bug in unique and non-unique hash indexes which manifested as incorrect results </li><li>Fix bug in unique and non-unique hash indexes which manifested as incorrect results
when the search key was a different cardinal type from the table index key. when the search key was a different cardinal type from the table index key.
e.g. where the one was INT and the other was LONG e.g. where the one was INT and the other was LONG
</li><li>Bug: Changes to the database structure did not result
in the Session query cache being invalidated.
</li></ul> </li></ul>
<h2>Version 1.3.173 (2013-07-28)</h2> <h2>Version 1.3.173 (2013-07-28)</h2>
......
...@@ -110,6 +110,7 @@ public class Session extends SessionWithState { ...@@ -110,6 +110,7 @@ public class Session extends SessionWithState {
private int objectId; private int objectId;
private final int queryCacheSize; private final int queryCacheSize;
private SmallLRUCache<String, Command> queryCache; private SmallLRUCache<String, Command> queryCache;
private long modificationMetaID = -1;
private Transaction transaction; private Transaction transaction;
private long startStatement = -1; private long startStatement = -1;
...@@ -416,7 +417,13 @@ public class Session extends SessionWithState { ...@@ -416,7 +417,13 @@ public class Session extends SessionWithState {
if (queryCacheSize > 0) { if (queryCacheSize > 0) {
if (queryCache == null) { if (queryCache == null) {
queryCache = SmallLRUCache.newInstance(queryCacheSize); queryCache = SmallLRUCache.newInstance(queryCacheSize);
modificationMetaID = database.getModificationMetaId();
} else { } else {
long newModificationMetaID = database.getModificationMetaId();
if (newModificationMetaID != modificationMetaID) {
queryCache.clear();
modificationMetaID = newModificationMetaID;
}
command = queryCache.get(sql); command = queryCache.get(sql);
if (command != null && command.canReuse()) { if (command != null && command.canReuse()) {
command.reuse(); command.reuse();
......
...@@ -68,9 +68,12 @@ public class TestQueryCache extends TestBase { ...@@ -68,9 +68,12 @@ public class TestQueryCache extends TestBase {
private void testClearingCacheWithTableStructureChanges() throws Exception { private void testClearingCacheWithTableStructureChanges() throws Exception {
Connection conn = getConnection("queryCache;QUERY_CACHE_SIZE=10"); Connection conn = getConnection("queryCache;QUERY_CACHE_SIZE=10");
conn.createStatement().executeUpdate("CREATE TABLE TEST(col1 bigint, col2 varchar(255))"); assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, conn).prepareStatement("SELECT * FROM TEST");
conn.prepareStatement("SELECT * FROM TEST"); Statement stat = conn.createStatement();
conn.createStatement().executeUpdate("DROP TABLE TEST"); stat.executeUpdate("CREATE TABLE TEST(col1 bigint, col2 varchar(255))");
PreparedStatement prep = conn.prepareStatement("SELECT * FROM TEST");
prep.close();
stat.executeUpdate("DROP TABLE TEST");
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, conn).prepareStatement("SELECT * FROM TEST"); assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, conn).prepareStatement("SELECT * FROM TEST");
conn.close(); conn.close();
} }
......
...@@ -57,7 +57,7 @@ public class TestSQLInjection extends TestBase { ...@@ -57,7 +57,7 @@ public class TestSQLInjection extends TestBase {
stat.execute("CALL 123"); stat.execute("CALL 123");
assertThrows(ErrorCode.LITERALS_ARE_NOT_ALLOWED, stat). assertThrows(ErrorCode.LITERALS_ARE_NOT_ALLOWED, stat).
execute("CALL 'Hello'"); execute("CALL 'Hello'");
assertThrows(ErrorCode.SYNTAX_ERROR_1, stat). assertThrows(ErrorCode.LITERALS_ARE_NOT_ALLOWED, stat).
execute("CALL $$Hello World$$"); execute("CALL $$Hello World$$");
stat.execute("SET ALLOW_LITERALS NONE"); stat.execute("SET ALLOW_LITERALS NONE");
try { try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论