Skip to content

Commit fd8b7bc

Browse files
committed
SQLファイルのキャッシュを削除するためのメソッドを追加
1 parent 88dadda commit fd8b7bc

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/main/java/org/seasar/doma/jdbc/GreedyCacheSqlFileRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,8 @@ protected SqlFile getSqlFileWithCacheControl(Method method, String path,
4545
return current != null ? current : file;
4646
}
4747

48+
@Override
49+
public void clearCache() {
50+
sqlFileMap.clear();
51+
}
4852
}

src/main/java/org/seasar/doma/jdbc/SqlFileRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,9 @@ public interface SqlFileRepository {
7979
*/
8080
SqlFile getSqlFile(Method method, String path, Dialect dialect);
8181

82+
/**
83+
* SQLファイルのキャッシュを削除します。
84+
*/
85+
default void clearCache() {
86+
}
8287
}

src/test/java/org/seasar/doma/jdbc/GreedyCacheSqlFileRepositoryTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,18 @@ public void testGetSqlFile_postgres() throws Exception {
6666
SqlFile sqlFile = repository.getSqlFile(method, path, dialect);
6767
assertEquals(path, sqlFile.getPath());
6868
}
69+
70+
public void testClearCache() throws Exception {
71+
StandardDialect dialect = new StandardDialect();
72+
String path = "META-INF/" + getClass().getName().replace(".", "/")
73+
+ ".sql";
74+
GreedyCacheSqlFileRepository repository = new GreedyCacheSqlFileRepository();
75+
SqlFile sqlFile = repository.getSqlFile(method, path, dialect);
76+
assertNotNull(sqlFile);
77+
repository.clearCache();
78+
SqlFile sqlFile2 = repository.getSqlFile(method, path, dialect);
79+
assertNotSame(sqlFile, sqlFile2);
80+
assertEquals(path, sqlFile.getPath());
81+
}
82+
6983
}

0 commit comments

Comments
 (0)