Permalink
Browse files

use JRuby class loader when establishing Mondrian connection

otherwise latest Mondrian version ClassResolver fails to load some Mondrian classes when using mondrian-olap inside OSGi container
  • Loading branch information...
1 parent cba41be commit 16a596a3f010ef78640cfae9e50b6becd97447e3 @rsim rsim committed Jan 18, 2013
Showing with 11 additions and 3 deletions.
  1. +11 −3 lib/mondrian/olap/connection.rb
@@ -31,9 +31,17 @@ def connect
conn_string = connection_string
- # TODO: removed workaround for Mondrian ServiceDiscovery
- # need to check if database dialects are always loaded by ServiceDiscovery detected class loader
- @raw_jdbc_connection = driver.connect(conn_string, props)
+ # latest Mondrian version added ClassResolver which uses current thread class loader to load some classes
+ # therefore need to set it to JRuby class loader to ensure that Mondrian classes are found
+ # (e.g. when running mondrian-olap inside OSGi container)
+ current_thread = Java::JavaLang::Thread.currentThread
+ class_loader = current_thread.getContextClassLoader
+ begin
+ current_thread.setContextClassLoader JRuby.runtime.jruby_class_loader
+ @raw_jdbc_connection = driver.connect(conn_string, props)
+ ensure
+ current_thread.setContextClassLoader(class_loader)
+ end
@raw_connection = @raw_jdbc_connection.unwrap(Java::OrgOlap4j::OlapConnection.java_class)
@raw_catalog = @raw_connection.getOlapCatalog

0 comments on commit 16a596a

Please sign in to comment.