J'ai rencontré quelques difficultés en utilisant DBCP 1.2.1, et vous devrez pour des raisons de "legacy" souvent travailler avec cette version de la librairie. A la suite je présente le code que l'on pourrait utiliser avec dbcp 1.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//inutile depuis le jdk 1.6 "jdbc:mondrian" provoque la registration du driver | |
//si celui-ci est dans le classpath, c'est pareil pour jdbc:mysql | |
//le driver mysql est automatiquement chargé depuis le classpath | |
//donc a décommenter si on est en dessous du jdk 1.6 | |
//Class.forName("mondrian.olap4j.MondrianOlap4jDriver"); | |
//Class.forName("com.mysql.jdbc.Driver"); | |
//le pool de connexion, PoolableConnectionFactory sera en charge des entrées et | |
//sortie des connexion dans le pool ces deux classes appartiennent à common-pool | |
GenericObjectPool connectionPool = new GenericObjectPool(null); | |
//la fabrique de connexion mondrian, cette classe sera passé à PoolableConnectionFactory | |
//pour creer des connexion et les faire entrer dans le connectionPool | |
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( | |
"jdbc:mondrian:Jdbc=jdbc:mysql://localhost/foodmart;JdbcUser=foodmart;JdbcPassword=foodmart;" | |
+ "Catalog=demo/FoodMart.xml;" | |
+ "Role='California manager'", new Properties()); | |
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( | |
connectionFactory, connectionPool, null, null, false, true); | |
//je triche pour obtenir l'accès à la connection décorée (ie la olap connection) | |
//DataSource dataSource = new PoolingDataSource(connectionPool); | |
PoolingDataSource dataSource = new PoolingDataSource(connectionPool); | |
//si je ne fais pas cela connection.getInnermostDelegate(); renvoie null | |
//attention cette méthode n'est pas accessible sur l'interface DataSource | |
dataSource.setAccessToUnderlyingConnectionAllowed(true); | |
Connection conn = dataSource.getConnection(); | |
//ce down cast est necessaire pour obtenir le proxy de base avec #getInnermostDelegate() | |
DelegatingConnection connection = (DelegatingConnection) conn; | |
//j'aurai ontenu org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to org.olap4j.OlapWrapper | |
//avec OlapWrapper wrapper = (OlapWrapper) conn; | |
OlapWrapper wrapper = (OlapWrapper) connection.getInnermostDelegate(); | |
OlapConnection olapConnection = wrapper.unwrap(OlapConnection.class); | |
OlapStatement statement = olapConnection.createStatement(); | |
CellSet cellSet = statement | |
.executeOlapQuery("SELECT {[Measures].[Unit Sales]} ON COLUMNS,\n" | |
+ " {[Product].Members} ON ROWS\n" + "FROM [Sales]"); | |
System.out.println(cellSet); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GenericObjectPool connectionPool = new GenericObjectPool(null); | |
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( | |
"jdbc:mondrian:Jdbc=jdbc:mysql://localhost/foodmart;JdbcUser=foodmart;JdbcPassword=foodmart;" | |
+ "Catalog=demo/FoodMart.xml;" | |
+ "Role='California manager'", new Properties()); | |
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( | |
connectionFactory, connectionPool, null, null, false, true); | |
DataSource dataSource = new PoolingDataSource(connectionPool); | |
Connection connection = dataSource.getConnection(); | |
//OlapWrapper wrapper = (OlapWrapper) connection; | |
OlapConnection olapConnection = connection.unwrap(OlapConnection.class); | |
OlapStatement statement = olapConnection.createStatement(); | |
CellSet cellSet = statement | |
.executeOlapQuery("SELECT {[Measures].[Unit Sales]} ON COLUMNS,\n" | |
+ " {[Product].Members} ON ROWS\n" + "FROM [Sales]"); | |
System.out.println(cellSet); |