Oops; over-zealous copy-paste in the spec. The example should have read as follows:
DataSource dataSource; // a data source using a connection pool
Connection connection = dataSource.getConnection();
OlapWrapper wrapper = (OlapWrapper) connection;
OlapConnection olapConnection = wrapper.unwrap(OlapConnection.class);
OlapStatement statement = olapConnection.createOlapStatement();
For the data source, use an implementation which allocates connections using DriverManager.getConnection and stores the results in a pool. You don't need anything olap4j-specific.
The implementation of the data source was left as an exercise to the reader (!). For instance, if you were using apache-commons-DBCP, you would combine PoolingDataSource with DriverManagerConnectionFactory, like this:
GenericObjectPool connectionPool =
new GenericObjectPool(null);
ConnectionFactory connectionFactory =
new DriverManagerConnectionFactory(
"jdbc:mondrian:local:Jdbc=jdbc:odbc:MondrianFoodMart;" +
"Catalog=/WEB-INF/queries/FoodMart.xml;" +
"Role='California manager'")
PoolableConnectionFactory poolableConnectionFactory =
new PoolableConnectionFactory(
connectionFactory,connectionPool,null,null,false,true);
PoolingDataSource dataSource =
new PoolingDataSource(connectionPool);
Just thinking out loud here. Maybe this will be useful to someone else.
A connection pool must exist independently of any web app on the app server.
So an appserver can't define a connection pool to a service that resides inside a web app eg an in process mondrian instance.
So if I want to define a connection pool in my app server, the mondrian service has to also exist independently of the web app and independently of the app server as well.
I could create a connection pool inside the web app itself, but that sounds like more work than just running a seperate standalone mondrian instance.
Does mondrian have a facility for running as an independent service?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When you use mondrian in-process, say in an app server, it automatically uses the same instance of mondrian whenever it can. It uses a pool of schemas stored in a static map and if two apps in the same JVM ask for connections to a schema with the same URI they will share a cache etc.
So, you don't need to worry about that aspect of pooling when you use mondrian. A connection pool layer will cache at a slightly higher level, and save a few steps in the process of creating a connection.
Julian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"DataSource dataSource; // a data source using a connection pool
Connection connection =
DriverManager.createConnection(
"jdbc:mondrian:local:Jdbc=jdbc:odbc:MondrianFoodMart;" +
"Catalog=/WEB-INF/queries/FoodMart.xml;" +
"Role='California manager'");
OlapConnection olapConnection =
connection.unwrap(OlapConnection.class);
OlapStatement statement = olapConnection.createOlapStatement();"
-- 2.2.1
Please forgive my ignorance.
How does the above connection come from a connection pool?
I have a dataSource that is retrived like so:
Context ctx = new InitialContext();
DataSource dataSource = (DataSource)ctx.lookup("jdbc/myJDBCResource");
How do I get an olapConnection to an in process mondrian instance with the above dataSource used as the fact table?
Maybe I am asking the wrong question...
How do I setup a connection pool to an in process mondrian instance in Glassfish?
On a side note I think I found a few errata in the spec (http://www.olap4j.org/olap4j_fs.html#Connection_pooling)
DriverManager.createConnection(...) //should be getConnection(...)?
^^^^^^
OlapStatement statement = olapConnection.createOlapStatement() //should be createStatement()?
^^^^
Oops. Right on both counts. I've corrected the spec.
Julian
On a side note I think I found a few errata in the spec (http://www.olap4j.org/olap4j_fs.html#Connection_pooling)
DriverManager.createConnection(...) //should be getConnection(...)?
__^^^^^^
OlapStatement statement = olapConnection.createOlapStatement() //should be createStatement()?
_______^^^^
Oops; over-zealous copy-paste in the spec. The example should have read as follows:
DataSource dataSource; // a data source using a connection pool
Connection connection = dataSource.getConnection();
OlapWrapper wrapper = (OlapWrapper) connection;
OlapConnection olapConnection = wrapper.unwrap(OlapConnection.class);
OlapStatement statement = olapConnection.createOlapStatement();
For the data source, use an implementation which allocates connections using DriverManager.getConnection and stores the results in a pool. You don't need anything olap4j-specific.
The implementation of the data source was left as an exercise to the reader (!). For instance, if you were using apache-commons-DBCP, you would combine PoolingDataSource with DriverManagerConnectionFactory, like this:
GenericObjectPool connectionPool =
new GenericObjectPool(null);
ConnectionFactory connectionFactory =
new DriverManagerConnectionFactory(
"jdbc:mondrian:local:Jdbc=jdbc:odbc:MondrianFoodMart;" +
"Catalog=/WEB-INF/queries/FoodMart.xml;" +
"Role='California manager'")
PoolableConnectionFactory poolableConnectionFactory =
new PoolableConnectionFactory(
connectionFactory,connectionPool,null,null,false,true);
PoolingDataSource dataSource =
new PoolingDataSource(connectionPool);
See http://commons.apache.org/dbcp/apidocs/org/apache/commons/dbcp/package-summary.html for more examples of DBCP.
Julian
Just thinking out loud here. Maybe this will be useful to someone else.
A connection pool must exist independently of any web app on the app server.
So an appserver can't define a connection pool to a service that resides inside a web app eg an in process mondrian instance.
So if I want to define a connection pool in my app server, the mondrian service has to also exist independently of the web app and independently of the app server as well.
I could create a connection pool inside the web app itself, but that sounds like more work than just running a seperate standalone mondrian instance.
Does mondrian have a facility for running as an independent service?
When you use mondrian in-process, say in an app server, it automatically uses the same instance of mondrian whenever it can. It uses a pool of schemas stored in a static map and if two apps in the same JVM ask for connections to a schema with the same URI they will share a cache etc.
So, you don't need to worry about that aspect of pooling when you use mondrian. A connection pool layer will cache at a slightly higher level, and save a few steps in the process of creating a connection.
Julian