具有自定义函数别名的 H2 数据库定义为:
create alias to_date as $$
java.util.Date toDate(java.lang.String dateString, java.lang.String pattern) {
try {
return new java.text.SimpleDateFormat(javaPattern).parse(dateString);
} catch(java.text.ParseException e) {
throw new java.lang.RuntimeException(e);
}
}
$$;
H2初始化为:
jdbc:h2:mem:testdb;INIT=runscript from 'classpath:create_alias.sql
这用于测试,在 Jenkins 实例上同时为多个项目执行。有时此类测试会失败并出现以下错误:
Could not get JDBC Connection; nested exception is org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "javac: file not found: org/h2/dynamic/TO_DATE.java
Usage: javac <options> <source files>
use -help for a list of possible options
"; SQL statement:
create alias to_date as $$
java.util.Date toDate(java.lang.String dateString, java.lang.String pattern) {
....
我的猜测是 org.h2.util.SourceCompiler 假设当时只有一个 h2 实例在运行,并将生成的 Java 源写入“java.io.tmpdir”,该源在同一帐户下运行的所有进程之间共享. 我建议进行以下修复:
Index: SourceCompiler.java
===================================================================
--- SourceCompiler.java (revision 5086)
+++ SourceCompiler.java (working copy)
@@ -40,7 +40,15 @@
*/
final HashMap<String, Class<?>> compiled = New.hashMap();
- private final String compileDir = Utils.getProperty("java.io.tmpdir", ".");
+ private final String compileDir;
+
+ {
+ // use random folder under java.io.tmpdir so multiple h2 could compile at the same time
+ // without overwriting each other files
+ File tmp = File.createTempFile("h2tmp", ".tmp");
+ tmp.mkdir();
+ compileDir = tmp.getAbsolutePath();
+ }
static {
Class<?> clazz;
我应该打开支持票还是有解决此问题的方法?