001 /* 002 // $Id: //open/mondrian/src/main/mondrian/olap/DriverManager.java#26 $ 003 // This software is subject to the terms of the Common Public License 004 // Agreement, available at the following URL: 005 // http://www.opensource.org/licenses/cpl.html. 006 // Copyright (C) 2002-2002 Kana Software, Inc. 007 // Copyright (C) 2002-2007 Julian Hyde and others 008 // All Rights Reserved. 009 // You must accept the terms of that agreement to use this software. 010 // 011 // jhyde, 15 January, 2002 012 */ 013 014 package mondrian.olap; 015 import mondrian.rolap.RolapConnection; 016 import mondrian.rolap.RolapConnectionProperties; 017 import mondrian.spi.CatalogLocator; 018 import mondrian.spi.impl.CatalogLocatorImpl; 019 020 import javax.sql.DataSource; 021 022 /** 023 * The basic service for managing a set of OLAP drivers. 024 * 025 * @author jhyde 026 * @since 15 January, 2002 027 * @version $Id: //open/mondrian/src/main/mondrian/olap/DriverManager.java#26 $ 028 */ 029 public class DriverManager { 030 031 public DriverManager() { 032 } 033 034 /** 035 * Creates a connection to a Mondrian OLAP Engine 036 * using a connect string 037 * and a catalog locator. 038 * 039 * @param connectString Connect string of the form 040 * 'property=value;property=value;...'. 041 * See {@link mondrian.olap.Util#parseConnectString} for more details of the format. 042 * See {@link mondrian.rolap.RolapConnectionProperties} for a list of 043 * allowed properties. 044 * @param locator Use to locate real catalog url by a customized 045 * configuration value. If <code>null</code>, leave the catalog url 046 * unchanged. 047 * @return A {@link Connection} 048 * @post return != null 049 */ 050 public static Connection getConnection( 051 String connectString, 052 CatalogLocator locator) 053 { 054 Util.PropertyList properties = Util.parseConnectString(connectString); 055 return getConnection(properties, locator); 056 } 057 058 /** 059 * Creates a connection to a Mondrian OLAP Engine. 060 * 061 * @param properties Collection of properties which define the location 062 * of the connection. 063 * See {@link mondrian.rolap.RolapConnection} for a list of allowed properties. 064 * @param locator Use to locate real catalog url by a customized 065 * configuration value. If <code>null</code>, leave the catalog url 066 * unchanged. 067 * @return A {@link Connection} 068 * @post return != null 069 */ 070 public static Connection getConnection( 071 Util.PropertyList properties, 072 CatalogLocator locator) 073 { 074 return getConnection(properties, locator, null); 075 } 076 077 /** 078 * Creates a connection to a Mondrian OLAP Engine 079 * using a list of connection properties, 080 * a catalog locator, 081 * and a JDBC data source. 082 * 083 * @param properties Collection of properties which define the location 084 * of the connection. 085 * See {@link mondrian.rolap.RolapConnection} for a list of allowed properties. 086 * @param locator Use to locate real catalog url by a customized 087 * configuration value. If <code>null</code>, leave the catalog url 088 * unchanged. 089 * @param dataSource - if not null an external DataSource to be used 090 * by Mondrian 091 * @return A {@link Connection} 092 * @post return != null 093 */ 094 public static Connection getConnection( 095 Util.PropertyList properties, 096 CatalogLocator locator, 097 DataSource dataSource) 098 { 099 String provider = properties.get("PROVIDER", "mondrian"); 100 if (!provider.equalsIgnoreCase("mondrian")) { 101 throw Util.newError("Provider not recognized: " + provider); 102 } 103 if (locator != null) { 104 String catalog = properties.get( 105 RolapConnectionProperties.Catalog.name()); 106 properties.put( 107 RolapConnectionProperties.Catalog.name(), 108 locator.locate(catalog)); 109 } 110 return new RolapConnection(properties, dataSource); 111 } 112 } 113 114 // End DriverManager.java