小编Mar*_*lke的帖子

H2数据库>如何在运行时压缩/真空?

标题

在我的一个项目中,我正在使用带文件存储的h2数据库.

根据h2 db 文档

"自动重复使用数据库文件中的空白空间.关闭数据库时,默认情况下数据库会自动压缩最多200毫秒."

每次删除或更新行时都会创建空白空间.不幸的是,在运行时,数据库文件不断增长.

讨论中,建议备份数据库,然后再次还原.但是,我正在寻找一种在运行时压缩/清空数据库的解决方案,而无需关闭.有没有办法做到这一点?

当然,可以选择迁移到像Postgres这样的数据库.但是我的项目应该很容易安装,因此有必要将其集成到安装程序中.通常,添加专用数据库会增加一些开销.

java h2

8
推荐指数
0
解决办法
4578
查看次数

使用注释验证构造函数参数或方法参数,并让它们自动抛出异常

我正在验证构造函数和方法参数,因为我想要软件,特别是它的模型部分,要快速失败.

因此,构造函数代码通常看起来像这样

public MyModelClass(String arg1, String arg2, OtherModelClass otherModelInstance) {
    if(arg1 == null) {
        throw new IllegalArgumentsException("arg1 must not be null");
    }
    // further validation of constraints...
    // actual constructor code...
}
Run Code Online (Sandbox Code Playgroud)

有没有办法用注释驱动的方法做到这一点?就像是:

public MyModelClass(@NotNull(raise=IllegalArgumentException.class, message="arg1 must not be null") String arg1, @NotNull(raise=IllegalArgumentException.class) String arg2, OtherModelClass otherModelInstance) {

    // actual constructor code...
}
Run Code Online (Sandbox Code Playgroud)

在我看来,这将使实际代码更具可读性.

了解有注释以支持IDE验证(如现有的@NotNull注释).

非常感谢您的帮助.

java annotations exception

2
推荐指数
1
解决办法
2861
查看次数

标签 统计

java ×2

annotations ×1

exception ×1

h2 ×1