我开始Flyway在我当前的项目中使用数据库迁移,我非常喜欢它.我目前在TEST-Environment中使用PROD-和Derby中的Oracle.
很快,我确实遇到了数据库特定的sql命令的问题,例如
ALTER TABLE T1 MODIFY F1 VARCHAR(256); 关于Oracle vs. ALTER TABLE T1 ALTER F1 SET DATA TYPE VARCHAR(256); 在德比.我看不到编写"供应商中立的alter table modify column datatype"sql的方法.
使用Flyway解决这个问题的最佳方法是什么?
我尝试拦截对方法的调用,并使用Byte Buddy调用Java 8 lambda表达式AgentBuilder,如下所示:
static {
final Instrumentation inst = ByteBuddyAgent.install();
new AgentBuilder.Default()
.type(ElementMatchers.nameContainsIgnoreCase("foo"))
.transform((builder, typeDescription) ->
builder.method(ElementMatchers.any())
.intercept(MethodDelegation.to(LogInterceptor.class)))
.installOn(inst);
}
public static class LogInterceptor {
@RuntimeType
public static Object log(@SuperCall Callable<?> superCall) throws Exception {
System.out.println("yeah...");
return superCall.call();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Byte Buddy v0.7.1.
它可以拦截以下Runnable(匿名类):
FunnyFramework.callMeLater(new Runnable() {
@Override
public void run() {
System.out.println("Hello from inner class");
}
});
Run Code Online (Sandbox Code Playgroud)
当然,对对象的任何调用都定义为普通(非匿名)类.但拦截不适用于lambda表达式:
FunnyFramework.callMeLater(() -> {
System.out.println("Hello from lambda");
});
Run Code Online (Sandbox Code Playgroud)
我怎样才能拦截lambda表达式调用?据我所知,在Byte Buddy中没有LambdaInterceptor这样的东西.