/* // $Id: //guest/julian_hyde/mondrian/src/main/mondrian/rolap/RolapConnection.java#2 $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. // (C) Copyright 2001-2002 Kana Software, Inc. and others. // All Rights Reserved. // You must accept the terms of that agreement to use this software. // // jhyde, 26 July, 2001 */ package mondrian.rolap; import mondrian.olap.*; import java.util.HashMap; import java.util.Properties; import java.util.Locale; import java.sql.*; import java.io.PrintWriter; /** * todo: * * @author jhyde * @since 26 July, 2001 * @version $Id: //guest/julian_hyde/mondrian/src/main/mondrian/rolap/RolapConnection.java#2 $ **/ public class RolapConnection extends ConnectionBase { Util.PropertyList connectInfo; java.sql.Connection jdbcConnection; HashMap mapNameToCube; HashMap mapSharedHierarchyToReader; /** Contains {@link HierarchyUsage}s for all hierarchy and fact-table * combinations. **/ HashMap hierarchyUsages; String jdbcConnectString; String catalogName; public RolapConnection(Util.PropertyList connectInfo) { try { this.connectInfo = connectInfo; this.jdbcConnectString = connectInfo.get("Jdbc"); this.catalogName = connectInfo.get("Catalog"); String provider = connectInfo.get("Provider"); Util.assert(provider.equalsIgnoreCase("mondrian")); this.jdbcConnection = java.sql.DriverManager.getConnection( jdbcConnectString); this.mapNameToCube = new HashMap(); this.mapSharedHierarchyToReader = new HashMap(); this.hierarchyUsages = new HashMap(); if (catalogName != null) { try { java.net.URL url = new java.net.URL(catalogName); mondrian.xom.Parser xmlParser = mondrian.xom.XOMUtil.createDefaultParser(); MondrianDef.Schema xmlSchema = new MondrianDef.Schema( xmlParser.parse(url)); loadSchema(xmlSchema); } catch (mondrian.xom.XOMException e) { throw new Error(e.getMessage()); } catch (java.io.IOException e) { throw new Error(e.getMessage()); } } } catch (SQLException e) { throw Util.getRes().newInternal( e, "while creating RolapConnection (" + connectInfo.toString() + ")"); } } // implement Connection protected Cube lookupCube(String cube) { return (RolapCube) mapNameToCube.get(cube); } public void close() { try { if (jdbcConnection != null) { jdbcConnection.close(); } } catch (SQLException e) { // ignore } } public String getConnectString() { return connectInfo.toString(); } public String getCatalogName() { return catalogName; } public String[] listCubeNames() { throw new Error("unsupported"); } public Locale getLocale() { return Locale.US; } public Result execute(Query query) { return new RolapResult(query); } public void loadSchema(MondrianDef.Schema xmlSchema) { for (int i = 0; i < xmlSchema.cubes.length; i++) { MondrianDef.Cube xmlCube = xmlSchema.cubes[i]; RolapCube cube = new RolapCube(this, xmlSchema, xmlCube); if (false && xmlCube.name.equals("Sales")) { cube = new RolapCube(this); } mapNameToCube.put(xmlCube.name, cube); } for (int i = 0; i < xmlSchema.virtualCubes.length; i++) { MondrianDef.VirtualCube xmlVirtualCube = xmlSchema.virtualCubes[i]; RolapCube cube = new RolapCube(this, xmlSchema, xmlVirtualCube); mapNameToCube.put(xmlVirtualCube.name, cube); } } public static RolapConnection makeFoodMartConnection( String connectString, String catalogName) { try { Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver"); } catch (ClassNotFoundException e) { throw new Error(e.toString()); } boolean flush = true; RolapUtil.debugOut = new PrintWriter(System.out, flush); Util.PropertyList connectInfo = new Util.PropertyList(); connectInfo.put("Jdbc", "jdbc:odbc:DSN=FoodMart2"); connectInfo.put("Provider", "mondrian"); connectInfo.put("Catalog", "http://code/bb/main/common/java/mondrian/rolap/FoodMart.xml"); return new RolapConnection(connectInfo); } /** * An <code>Extender</code> is a user-supplied class which extends the * system in some way. The <code>Extender</code> interfaces allows it to * describe itself, and receive parameters. **/ interface Extender { String getDescription(); ExtenderParameter[] getParameterDescriptions(); void initialize(Properties properties); }; /** * An <code>ExtenderParameter</code> describes a parameter of an {@link * Extender}. **/ static class ExtenderParameter { String name; Class clazz; String description; }; static class SqlQuery { // todo: replace {select, selectCount} with a StringList; etc. StringBuffer select = new StringBuffer(), from = new StringBuffer(), where = new StringBuffer(), groupBy = new StringBuffer(), having = new StringBuffer(); int selectCount = 0, fromCount = 0, whereCount = 0, groupByCount = 0, havingCount = 0; void addFromQuery(String query, String alias) { from.append( (fromCount++ == 0 ? " from " : ", ") + query + " as " + RolapUtil.doubleQuoteForSql(alias)); } void addFromTable(String schema, String table, String alias) { addFromQuery( RolapUtil.doubleQuoteForSql(schema, table), alias); } void addJoin(String type, String query, String alias, String condition) { Util.assert(fromCount > 0); from.append( " " + type + " join " + query + " as " + RolapUtil.doubleQuoteForSql(alias) + " on " + condition); } void addSelect(String expression) { select.append( (selectCount++ == 0 ? "select " : ", ") + expression); } void addWhere(String expression) { where.append( (whereCount++ == 0 ? " where " : " and ") + expression); } void addGroupBy(String expression) { groupBy.append( (groupByCount++ == 0 ? " group by " : ", ") + expression); } void addHaving(String expression) { having.append( (havingCount++ == 0 ? " having " : " and ") + expression); } public String toString() { return select.toString() + from.toString() + where.toString() + groupBy.toString() + having.toString(); } }; static abstract class SqlRelation { String alias; abstract SqlRelation find(String alias); }; static class SqlTable extends SqlRelation { String name; public String toString() { return RolapUtil.doubleQuoteForSql(name) + " as " + RolapUtil.doubleQuoteForSql(alias); } SqlRelation find(String alias) { if (this.alias.equals(alias)) { return this; } else { return null; } } }; static class SqlJoin extends SqlRelation { SqlRelation left, right; String type, on; SqlJoin( SqlRelation left, String type, SqlRelation right, String on, String alias) { this.left = left; this.type = type; this.right = right; this.on = on; this.alias = alias; } public String toString() { return "(" + left.toString() + " " + type + " join " + right.toString() + " on " + on + ") as " + RolapUtil.doubleQuoteForSql(alias); } SqlRelation find(String alias) { SqlRelation rel = left.find(alias); if (rel != null) { return rel; } return right.find(alias); } }; interface MemberCache extends MemberReader { }; } // End RolapConnection.java
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 1603 | Julian Hyde |
mondrian: Add Andreas' taglib; Rename 'mondrian.rolap.Util.assert' to 'assertTrue', because 'assert' is a keyword in jdk 1.4; Fix 'NON EMPTY'; JUnit framework for tests; Add Oracle dataset. |
||
#3 | 1576 | Julian Hyde |
mondrian: fix dataset (add column customer.ordinal); create dataset for oracle; get queries working on oracle; get format strings working; refactor out new packages mondrian.rolap.agg and mondrian.rolap.sql. |
||
#2 | 1496 | Julian Hyde |
Mondrian: Qualify table names with schemas. Add 'Hierarchy.schema', 'Cube.factSchema','Hierarchy.table' attributes. MondrianDef is now generated (so we need boot.jar). |
||
#1 | 1453 | Julian Hyde | mondrian: first source check-in |