mondrian.olap.DriverManager Java Examples

The following examples show how to use mondrian.olap.DriverManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MondrianApp.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static Connection getConnection(String propertiesFileName) throws FileNotFoundException, IOException
{
	if (propertiesFileName == null) {
		throw new RuntimeException("connection properties file not set");
	}
	ConnectionData data = getConnectionData(propertiesFileName);
	Connection connection = null;
	if (data.isEnabled())
	{
		connection = 
			DriverManager.getConnection(
				"Provider=mondrian;" + 
				"JdbcDrivers=" + data.getJdbcDrivers() + ";" +
				"Jdbc=" + data.getJdbcUrl() + ";" +
				"JdbcUser=" + data.getJdbcUser() + ";" +
				"JdbcPassword=" + data.getJdbcPassword() + ";" +
				"Catalog=" + data.getCatalogUri() + ";", 
				null
				);
	}
	return connection;
}
 
Example #2
Source File: MondrianDataAdapterService.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void contributeParameters(Map<String, Object> parameters)
		throws JRException {
	MondrianDataAdapter mda = getJdbcDataAdapter();
	if (mda != null) {
		Util.PropertyList props = new Util.PropertyList();
		props.put("Catalog", mda.getCatalogURI());
		props.put("Provider", "mondrian");
		props.put("Locale", Locale.getDefault().getLanguage());

		connection = DriverManager.getConnection(props, null,
				new SimpleSQLDataSource(this));

		parameters
				.put(JRMondrianQueryExecuterFactory.PARAMETER_MONDRIAN_CONNECTION,
						connection);
	}
}
 
Example #3
Source File: SsasToMondrianTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void loadConvertedSchemaInMondrian() throws Exception {
  // temp file to hold conversion output
  File tmpFile = File.createTempFile("output_foodmart_", ".xml"); //$NON-NLS-1$ //$NON-NLS-2$

  // do conversion on SSAS dump of foodmart
  List<Document> docs = ConversionUtil.generateMondrianDocsFromSSASSchema(getClass().getResourceAsStream(
      "/analysis_server_output.xml")); //$NON-NLS-1$

  // save conversion to file
  FileUtils.writeStringToFile(tmpFile, docs.get(0).asXML());

  // load file into Mondrian
  String connectString = getTestProperty("test.mondrian.foodmart.connectString", //$NON-NLS-1$
      getTestProperty("test.mondrian.foodmart.connectString.provider"), //$NON-NLS-1$
      getTestProperty("test.mondrian.foodmart.connectString.jdbc"), //$NON-NLS-1$
      getTestProperty("test.mondrian.foodmart.connectString.username"), //$NON-NLS-1$
      getTestProperty("test.mondrian.foodmart.connectString.password"), //$NON-NLS-1$
      tmpFile.getPath());

  DriverManager.getConnection(connectString, null).getSchema();
}
 
Example #4
Source File: DataSourceService.java    From youkefu with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param cube
 * @throws Exception
 */
public Connection service(String xml) throws Exception {
	Connection dataSourceObject = null ;
	StringBuffer strb = new StringBuffer();
	Util.PropertyList properties = Util.parseConnectString(strb.append("Provider=mondrian;")
				.append(
			       "Catalog=").append(xml).append(";").toString());
	if(properties!=null){
		dataSourceObject = DriverManager.getConnection(properties,null , dataSource) ;
	}
	return dataSourceObject ;
}
 
Example #5
Source File: DefaultMondrianConnectionProvider.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Connection createConnection( final Properties properties, final DataSource dataSource )
  throws ReportDataFactoryException {
  logger.debug( "Creating Mondrian connection: " + Util.parseConnectString( computeConnectionString( properties ) ) );
  return DriverManager
    .getConnection( Util.parseConnectString( computeConnectionString( properties ) ), null, dataSource );
}
 
Example #6
Source File: MondrianHelper.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings( "deprecation" )
public void openQuery() throws KettleDatabaseException {

  connection = null;
  String realRole = space.environmentSubstitute( role );

  if ( databaseMeta.getAccessType() == DatabaseMeta.TYPE_ACCESS_JNDI ) {
    DataSource dataSource = ( new DatabaseUtil() ).getNamedDataSource( databaseMeta.getDatabaseName() );
    mondrian.olap.Util.PropertyList propList = new mondrian.olap.Util.PropertyList();
    propList.put( "Provider", "mondrian" );
    propList.put( "Catalog", space.environmentSubstitute( catalog ) );

    if ( !Utils.isEmpty( realRole ) ) {
      propList.put( "Role", realRole );
    }

    connection = DriverManager.getConnection( propList, null, dataSource );
  } else {

    String connectString =
      "Provider=mondrian;"
        + "Jdbc='" + space.environmentSubstitute( databaseMeta.getURL() ) + "';" + "Catalog='"
        + space.environmentSubstitute( catalog ) + "';" + "JdbcDrivers="
        + space.environmentSubstitute( databaseMeta.getDriverClass() ) + ";";

    if ( !Utils.isEmpty( databaseMeta.getUsername() ) ) {
      connectString += "JdbcUser=" + space.environmentSubstitute( databaseMeta.getUsername() ) + ";";
    }
    String password = databaseMeta.getPassword();
    if ( !Utils.isEmpty( password ) ) {
      String realPassword = Utils.resolvePassword( space, password );
      connectString += "JdbcPassword=" + space.environmentSubstitute( realPassword ) + ";";
    }

    if ( !Utils.isEmpty( realRole ) ) {
      connectString += "Role=" + realRole + ";";
    }

    connection = DriverManager.getConnection( connectString, null );

  }

  query = connection.parseQuery( queryString );
  result = connection.execute( query );
}
 
Example #7
Source File: MondrianSchemaLoader.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public List<ValidationMessage> validateSchema( Map<Parameter, Object> parameterValues ) {
  String connectString =
    (String) parameterValues.get(
      MondrianSchemaLoaderParameter.connectString );
  String cubeName =
    (String) parameterValues.get(
      MondrianSchemaLoaderParameter.cube );

  PropertyList propertyList = Util.parseConnectString( connectString );

  String jdbcDrivers = propertyList.get( "JdbcDrivers" );
  if ( StringUtils.isBlank( jdbcDrivers ) ) {
    throw new RuntimeException( "missing 'JdbcDrivers' in connect string" );
  }

  Boolean integratedSecurity = Boolean.parseBoolean( propertyList.get( "integratedSecurity" ) );

  String jdbc = getJdbcConnectionString( propertyList, integratedSecurity );
  if ( StringUtils.isBlank( jdbcDrivers ) ) {
    throw new RuntimeException( "missing 'Jdbc' in connect string" );
  }

  String catalog = propertyList.get( "Catalog" );
  if ( StringUtils.isBlank( jdbcDrivers ) ) {
    throw new RuntimeException( "missing 'Catalog' in connect string" );
  }

  String jdbcUser = propertyList.get( "JdbcUser" );

  String jdbcPassword = propertyList.get( "JdbcPassword" );

  List<ValidationMessage> messages = new ArrayList<ValidationMessage>();

  try {
    List<MondrianSchemaValidator> validators = loadValidators( parameterValues );

    Class.forName( jdbcDrivers ); //$NON-NLS-1$

    java.sql.Connection conn;

    if ( integratedSecurity ) {
      conn = java.sql.DriverManager.getConnection( jdbc );
    } else {
      conn = java.sql.DriverManager.getConnection( jdbc, jdbcUser, jdbcPassword );
    }

    messages = ValidationHelper.validateCube( catalog, cubeName, conn, validators ); //$NON-NLS-1$

    conn.close();
  } catch ( Exception e ) {
    if ( logger.isErrorEnabled() ) {
      logger.error( "an exception occurred", e );
    }
    ValidationMessage msg =
      new ValidationMessage( ValidationMessage.Type.ERROR, e.getClass().getName() + ": " + e.getLocalizedMessage() );
    messages.add( msg );
  }
  return messages;
}