-->

蒙德里安OLAP连接管理(Mondrian OLAP connection management)

2019-10-18 04:18发布

什么是管理蒙德里安数据库连接推荐的模式?

我使用蒙德里安在斯卡拉/播放框架的Web应用程序库。 例如:

var connection
try {
  connection = DriverManager.getConnection(connection_string).unwrap(classOf[OlapConnection])
  val result = connection.createStatement.executeOlapQuery(mdx)
  // ... use the result ...
} finally {
  if (connection) connection.close
}

正在呼吁close在finally块正确的方法?

如何配置一个连接池?

什么是终止长时间运行的查询建议的方法? 是否有可能监视查询的进展如何?

Answer 1:

在finally块中调用close()方法可以确保连接变得非常封闭的,所以它的任何资源做正确的事。

我会写它像

val connection = DriverManager.getConnection(connection_string).unwrap(classOf[OlapConnection])
try {
    [...]
} finally {
    connection.close
}

摆脱变种 。 但是,这仍然是“势在必行的风格”,所以我会用

def withResource[T <: { def close() }, R](resource: T)(code: (T) => R): R = {
  try {
    code(resource)
  } finally {
    import scala.language.reflectiveCalls
    resource.close()
  }
}

和...一起

withResource(DriverManager.getConnection(...)) {
  conn =>
    [...]
}

摆脱的try / catch其杂波了你的代码。 更重要的是,你不能忘记关闭。 这适用于它提供了一个close()方法的任何类。 如果你把withResource()方法的特点,你可以在你的类混吧。

至于连接池,还有就是这里的另一个线程 。

对于长时间运行OLAP查询...他们应该不会跑很长。 与Essbase的或帕罗奥经验表明,这些查询是旁边的“实时”。 如果你深入唯一的问题可能是大量的数据被传输到客户端。 当你阅读的结果,你可以使用输入的数据为手段,以实现进度显示。 OLAP数据库是非常快。 反正你可以把查询在后台线程,这样的代码是不可阻挡,但应该没有必要与OLAP做到这一点。 只要管数据到前端尽可能快的,这是客户端(Excel的插件)的工作方式。



文章来源: Mondrian OLAP connection management