Class: Olap::Connection
- Inherits:
-
Object
- Object
- Olap::Connection
- Defined in:
- lib/olap4r/connection.rb
Instance Method Summary collapse
-
#children_lookup(cube_unique_name, member = nil, recursive = false) ⇒ Object
Returns list of member children.
-
#cubes ⇒ Object
Returns list of all cubes.
-
#dimensions(cube_unique_name) ⇒ Object
Returns list of all dimensions for cube.
-
#drillthrough(query) ⇒ Object
Executes drillthrough MDX query.
-
#execute(query) ⇒ Object
Executes regular MDX query.
-
#initialize(connection_string) ⇒ Connection
constructor
Returns new OLAP connection.
-
#measures(cube_unique_name) ⇒ Object
Returns list of all measures for cube.
Constructor Details
#initialize(connection_string) ⇒ Connection
Returns new OLAP connection.
Attributes
-
connection_string
- OLAP connection string.
Examples
To create new connection provide a JDBC connection string:
@olap = Olap::Connection.new "jdbc:mondrian:JdbcDrivers=com.mysql.jdbc.Driver;Jdbc=jdbc:mysql://127.0.0.1/olap?user=olap&password=olap;Catalog=file:/home/olap/schemas/Olap.xml;"
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/olap4r/connection.rb', line 21 def initialize(connection_string) begin driver = connection_string.match(/\Ajdbc\:([A-Za-z]+)\:/)[1] rescue NoMethodError raise Olap::InvalidConnectionStringException.new end begin raise @connection = DriverManager.get_connection connection_string rescue begin driver_class = Olap.const_get("#{driver.capitalize}") driver = driver_class.jdbc_driver properties = java.util.Properties.new @connection = driver_initialize(driver).connect(connection_string, properties) rescue NameError => e raise Olap::InvalidOlapDriverException.new end end end |
Instance Method Details
#children_lookup(cube_unique_name, member = nil, recursive = false) ⇒ Object
Returns list of member children
Attributes
-
cube_unique_name
- Cube name -
member
- Root member element -
recursive
- Recursive lookup
118 119 120 121 122 123 124 125 126 |
# File 'lib/olap4r/connection.rb', line 118 def children_lookup(cube_unique_name, member = nil, recursive = false) return dimensions cube_unique_name if member.nil? if member.split(".").length == 1 cube(cube_unique_name).get_dimensions.reject { |dimension| dimension.get_unique_name != member }.first.get_hierarchies.map { |hierarchy| hierarchy.get_root_members.map { |member| dimension(member, recursive)} }.flatten else children cube(cube_unique_name).send(:lookup_member, Java::OrgOlap4jMdx::IdentifierNode.parse_identifier(member).get_segment_list()), recursive end end |
#cubes ⇒ Object
Returns list of all cubes.
65 66 67 68 69 70 71 72 |
# File 'lib/olap4r/connection.rb', line 65 def cubes @cubes ||= @connection.get_olap_schema.get_cubes.map do |cube| { :unique_name => cube.get_unique_name, :name => cube. } end end |
#dimensions(cube_unique_name) ⇒ Object
Returns list of all dimensions for cube.
Attributes
-
cube_unique_name
- Cube name
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/olap4r/connection.rb', line 97 def dimensions(cube_unique_name) @dimensions = {} if @dimensions.nil? @dimensions[cube_unique_name] ||= cube(cube_unique_name).get_dimensions.map do |dimension| { :unique_name => dimension.get_unique_name, :name => dimension., :children => true, :type => dimension.get_dimension_type.to_s.downcase.to_sym } end end |
#drillthrough(query) ⇒ Object
Executes drillthrough MDX query.
Attributes
-
query
- MDX Query.
59 60 61 |
# File 'lib/olap4r/connection.rb', line 59 def drillthrough(query) RowSet.new @connection.create_statement.execute_query(query.to_s) end |
#execute(query) ⇒ Object
Executes regular MDX query.
Attributes
-
query
- MDX Query.
49 50 51 |
# File 'lib/olap4r/connection.rb', line 49 def execute(query) CellSet.new @connection.create_statement.execute_olap_query(query.to_s) end |
#measures(cube_unique_name) ⇒ Object
Returns list of all measures for cube.
Attributes
-
cube_unique_name
- Cube name
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/olap4r/connection.rb', line 80 def measures(cube_unique_name) @measures = {} if @measures.nil? @measures[cube_unique_name] ||= cube(cube_unique_name).get_measures.map do |measure| { :unique_name => measure.get_unique_name, :name => measure. } end end |