DISCLAIMER: I'm writing this question at work (from memory) when my code is at home on another PC which I might not be able to access tonight. I'm writing the question now while it is fresh in my memory so apologies for any mistakes.
QUESTION : I am writing a web app in Tomee that connects to a MySQL database. I have successfully created a datasource in Tomee as shown below:
<Resource auth="Container"
driverClassName="com.mysql.jdbc.Driver"
maxActive="100"
maxIdle="30"
maxWait="10000"
name="jdbc/TestDB"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/java"
username="u5ser"
password="p4ssword"/>
This works very well but does rely on this Data Source being configured in any/all instances of Tomcat/Tomee that I deploy my code in. Ultimately I'd like to be able to deploy this code in other containers like Glassfish or Weblogic or other Tomcat's/Tomee's. AKA I'd like the Data Source present in the War file.
With this in mind, is there a way of writing my own Datasource in Java (MyDataSource.class) and bundling this into the WAR file and initializing it with a WebListener.
Essentially : I'd like to know how to code the XML above into my own DataSource (even if this isn't the recommended way - I'm just experimenting really).
Also, a consideration is that I would like to code this so that I can read from a properties file and make aspects of the Data Source configurable.
I've found several examples on the Web but it is the maxActive, maxIdle, maxWait bits that I'm after so that I can create a connection pool in code. These seem to be missing.
Any help is appreciated.