Mondrian OLAP连接管理 [英] Mondrian OLAP connection management

查看:114
本文介绍了Mondrian OLAP连接管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

管理Mondrian数据库连接的推荐模式是什么?

What is the recommended pattern for managing Mondrian database connections?

我将Mondrian用作Scala/Play Framework Web应用程序中的库.例如:

I am using Mondrian as a library in a Scala/Play Framework web application. For example:

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是正确的方法吗?

Is calling close in a finally block the right approach?

如何配置连接池?

建议终止长时间运行的查询的方法是什么?是否可以监视查询进度?

What is the recommended approach for terminating a long running query? Is it possible to monitor the progress of query?

推荐答案

在finally块中调用close()可确保连接真正关闭,因此对任何资源而言都是正确的做法.

Calling close() in a finally block makes sure that the connection gets really closed, so it's the right thing to do for any resource.

我会这样写

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

摆脱 var .但这仍然是命令式",所以我会使用

to get rid of the var. But this is still "imperative style", so I would use

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()方法置于特征中,则可以将其混合在类中.

to get rid of the try/catch which clutters up your code. What is more, you cannot forget to close. This is applicable to any class which offers a close() method. If you put the withResource() method in a trait, you can mix it in your classes.

关于连接池,这里还有一个线程是另一个线程.

As for the connection pool, there is another thread here.

对于长时间运行的OLAP查询...应该不会运行很长时间. Essbase或Palo的经验表明,这些查询仅次于实时".如果您进行深入研究,唯一的问题可能是要传输到客户端的大量数据.在读取结果时,可以将传入数据用作实现进度显示的一种方式. OLAP数据库的速度非常快.无论如何,您都可以将查询放在后台线程中,以使代码不受阻塞,但是使用OLAP无需这样做.只需尽快将数据通过管道传输到您的前端,这就是客户端(Excel插件)的工作方式.

As for long running OLAP queries ... they are supposed not to run very long. Experience with Essbase or Palo show that these queries are next to "real time". If you drill down the only problem might be the large amount of data to be transferred to the client. While you read the result, you could use the incoming data as a means to implement a progress display. OLAP databases are incredibly fast. Anyway you could put the query in a background thread, so that the code is non-blocking, but there should be no need to do this with OLAP. Just pipe the data into your frontend as fast as possible, that's the way the clients (Excel plugins) work.

这篇关于Mondrian OLAP连接管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆