清除 OrientDB 数据库
Clear OrientDB database
给定一个 com.orientechnologies.orient.core.db.ODatabase<T>
对象,清除数据库(即擦除每个对象但尊重现有架构)的最佳编程方式是什么(没有 sql,没有控制台脚本)?
根据 Alessandro 的评论和 rmuller 对 的回答,我构建了一个 java 辅助方法。
db.getMetadata().getSchema().getClasses().stream()
.filter(oClass -> !oClass.getName().startsWith(ORIENTDB_CLASS_PREFIX)) //
.forEach(oClass -> {
try {
oClass.truncate();
} catch (IOException e) {
LOGGER.warn("Not possible to truncate class " + oClass.getName(), e);
}
});
给定一个 com.orientechnologies.orient.core.db.ODatabase<T>
对象,清除数据库(即擦除每个对象但尊重现有架构)的最佳编程方式是什么(没有 sql,没有控制台脚本)?
根据 Alessandro 的评论和 rmuller 对
db.getMetadata().getSchema().getClasses().stream()
.filter(oClass -> !oClass.getName().startsWith(ORIENTDB_CLASS_PREFIX)) //
.forEach(oClass -> {
try {
oClass.truncate();
} catch (IOException e) {
LOGGER.warn("Not possible to truncate class " + oClass.getName(), e);
}
});