Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'rsim/master'

Conflicts:
	lib/mondrian/olap/schema.rb
  • Loading branch information...
commit cb22a07e35f3fbb595b836ee705aca695d87e9ae 2 parents 8d05ee5 + 16a596a
@eeng authored
View
BIN  lib/mondrian/jars/mondrian.jar
Binary file not shown
View
14 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
View
14 lib/mondrian/olap/cube.rb
@@ -12,6 +12,8 @@ def initialize(connection, raw_cube)
@raw_cube = raw_cube
end
+ attr_reader :raw_cube
+
def name
@name ||= @raw_cube.getName
end
@@ -55,7 +57,7 @@ def initialize(cube, raw_dimension)
@raw_dimension = raw_dimension
end
- attr_reader :cube
+ attr_reader :cube, :raw_dimension
def name
@name ||= @raw_dimension.getName
@@ -104,6 +106,8 @@ def initialize(dimension, raw_hierarchy)
@raw_hierarchy = raw_hierarchy
end
+ attr_reader :raw_hierarchy
+
def name
@name ||= @raw_hierarchy.getName
end
@@ -167,6 +171,8 @@ def initialize(hierarchy, raw_level)
@raw_level = raw_level
end
+ attr_reader :raw_level
+
def name
@name ||= @raw_level.getName
end
@@ -207,6 +213,8 @@ def initialize(raw_member)
@raw_member = raw_member
end
+ attr_reader :raw_member
+
def name
@raw_member.getName
end
@@ -223,6 +231,10 @@ def calculated?
@raw_member.isCalculated
end
+ def calculated_in_query?
+ @raw_member.isCalculatedInQuery
+ end
+
def visible?
@raw_member.isVisible
end
View
5 lib/mondrian/olap/schema.rb
@@ -61,7 +61,8 @@ class Cube < SchemaElement
:cache,
# Whether element is enabled - if true, then the Cube is realized otherwise it is ignored.
:enabled
- elements :table, :view, :dimension, :measure, :calculated_member, :named_set
+ # always render xml fragment as the first element in XML output (by default it is added at the end)
+ elements :xml, :table, :view, :dimension, :measure, :calculated_member, :named_set
end
class Table < SchemaElement
@@ -115,7 +116,7 @@ class Hierarchy < SchemaElement
# that all members have entirely unique rows, allowing SQL GROUP BY clauses to be completely eliminated from the query.
:unique_key_level_name
data_dictionary_names :primary_key, :primary_key_table # values in XML will be uppercased when using Oracle driver
- elements :table, :join, :property, :level
+ elements :table, :join, :view, :property, :level
end
class Join < SchemaElement
View
19 lib/mondrian/olap/schema_element.rb
@@ -54,6 +54,7 @@ def self.elements(*names)
@elements.concat(names)
names.each do |name|
+ next if name == :xml
attr_reader pluralize(name).to_sym
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{name}(name=nil, attributes = {}, &block)
@@ -90,16 +91,26 @@ def add_to_xml(xml, options)
xml.send(tag_name(self.class.name), @content, xmlized_attributes(options))
else
xml.send(tag_name(self.class.name), xmlized_attributes(options)) do
+ xml_fragments_added = false
self.class.elements.each do |element|
- instance_variable_get("@#{pluralize(element)}").each {|item| item.add_to_xml(xml, options)}
- end
- @xml_fragments.each do |xml_fragment|
- xml.send(:insert, Nokogiri::XML::DocumentFragment.parse(xml_fragment))
+ if element == :xml
+ add_xml_fragments(xml)
+ xml_fragments_added = true
+ else
+ instance_variable_get("@#{pluralize(element)}").each {|item| item.add_to_xml(xml, options)}
+ end
end
+ add_xml_fragments(xml) unless xml_fragments_added
end
end
end
+ def add_xml_fragments(xml)
+ @xml_fragments.each do |xml_fragment|
+ xml.send(:insert, Nokogiri::XML::DocumentFragment.parse(xml_fragment))
+ end
+ end
+
private
def xmlized_attributes(options)
View
4 spec/cube_spec.rb
@@ -282,6 +282,10 @@
@cube.member('[Customers].[Non-USA]').should be_calculated
end
+ it "should not be calculated in query when calculated member defined in schema" do
+ @cube.member('[Customers].[Non-USA]').should_not be_calculated_in_query
+ end
+
it "should not be calculated when normal member" do
@cube.member('[Customers].[USA]').should_not be_calculated
end
View
26 spec/schema_definition_spec.rb
@@ -450,6 +450,32 @@
</Schema>
XML
end
+
+ it "should render embedded cube XML defintion before additional calculated member to XML" do
+ @schema.define do
+ cube 'Sales' do
+ xml <<-XML
+ <Table name="sales_fact_1997"/>
+ XML
+ calculated_member 'Profit' do
+ dimension 'Measures'
+ formula '[Measures].[Store Sales] - [Measures].[Store Cost]'
+ format_string '#,##0.00'
+ end
+ end
+ end
+ @schema.to_xml.should be_like <<-XML
+ <?xml version="1.0"?>
+ <Schema name="default">
+ <Cube name="Sales">
+ <Table name="sales_fact_1997"/>
+ <CalculatedMember dimension="Measures" formatString="#,##0.00" name="Profit">
+ <Formula>[Measures].[Store Sales] - [Measures].[Store Cost]</Formula>
+ </CalculatedMember>
+ </Cube>
+ </Schema>
+ XML
+ end
end
describe "Aggregates" do
Please sign in to comment.
Something went wrong with that request. Please try again.