001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2007-2012 Pentaho 008// All Rights Reserved. 009*/ 010package mondrian.olap4j; 011 012import mondrian.olap.Hierarchy; 013import mondrian.olap.OlapElement; 014import mondrian.olap.Role; 015 016import org.olap4j.OlapException; 017import org.olap4j.impl.*; 018import org.olap4j.metadata.*; 019 020import java.util.*; 021 022/** 023 * Implementation of {@link org.olap4j.metadata.Schema} 024 * for the Mondrian OLAP engine. 025 * 026 * @author jhyde 027 * @since May 24, 2007 028 */ 029class MondrianOlap4jSchema 030 extends MondrianOlap4jMetadataElement 031 implements Schema, Named 032{ 033 final MondrianOlap4jCatalog olap4jCatalog; 034 final String schemaName; 035 final mondrian.olap.Schema schema; 036 037 /** 038 * Creates a MondrianOlap4jSchema. 039 * 040 * <p>The name of the schema is not necessarily the same as 041 * schema.getName(). If schema was loaded in a datasources.xml file, the 042 * name it was given there (in the <Catalog> element) trumps the name 043 * in the catalog.xml file. 044 * 045 * @param olap4jCatalog Catalog containing schema 046 * @param schemaName Name of schema 047 * @param schema Mondrian schema 048 */ 049 MondrianOlap4jSchema( 050 MondrianOlap4jCatalog olap4jCatalog, 051 String schemaName, 052 mondrian.olap.Schema schema) 053 { 054 this.olap4jCatalog = olap4jCatalog; 055 this.schemaName = schemaName; 056 this.schema = schema; 057 } 058 059 public Catalog getCatalog() { 060 return olap4jCatalog; 061 } 062 063 public NamedList<Cube> getCubes() throws OlapException { 064 NamedList<MondrianOlap4jCube> list = 065 new NamedListImpl<MondrianOlap4jCube>(); 066 final MondrianOlap4jConnection olap4jConnection = 067 olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; 068 for (mondrian.olap.Cube cube 069 : olap4jConnection.getMondrianConnection() 070 .getSchemaReader().getCubes()) 071 { 072 list.add(olap4jConnection.toOlap4j(cube)); 073 } 074 return Olap4jUtil.cast(list); 075 } 076 077 public NamedList<Dimension> getSharedDimensions() throws OlapException { 078 final MondrianOlap4jConnection olap4jConnection = 079 olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; 080 final SortedSet<MondrianOlap4jDimension> dimensions = 081 new TreeSet<MondrianOlap4jDimension>( 082 new Comparator<MondrianOlap4jDimension>() { 083 public int compare( 084 MondrianOlap4jDimension o1, 085 MondrianOlap4jDimension o2) 086 { 087 return o1.getName().compareTo(o2.getName()); 088 } 089 } 090 ); 091 final Role role = olap4jConnection.getMondrianConnection().getRole(); 092 for (Hierarchy hierarchy : schema.getSharedHierarchies()) { 093 if (role.canAccess(hierarchy)) { 094 dimensions.add( 095 olap4jConnection.toOlap4j(hierarchy.getDimension())); 096 } 097 } 098 NamedList<MondrianOlap4jDimension> list = 099 new NamedListImpl<MondrianOlap4jDimension>(); 100 list.addAll(dimensions); 101 return Olap4jUtil.cast(list); 102 } 103 104 public Collection<Locale> getSupportedLocales() throws OlapException { 105 return Collections.emptyList(); 106 } 107 108 public String getName() { 109 return schemaName; 110 } 111 112 /** 113 * Shorthand for catalog.database.connection.getLocale(). 114 * Not part of the olap4j api; do not make public. 115 * 116 * @return Locale of current connection 117 */ 118 final Locale getLocale() { 119 return olap4jCatalog.olap4jDatabase.getOlapConnection().getLocale(); 120 } 121 122 protected OlapElement getOlapElement() { 123 return null; 124 } 125} 126 127// End MondrianOlap4jSchema.java