* This sets up a Bitronix PoolingDataSource.
*
* @return PoolingDataSource that has been set up but _not_ initialized.
*/
public static PoolingDataSource setupPoolingDataSource(Properties dsProps, String datasourceName) {
PoolingDataSource pds = new PoolingDataSource();
// The name must match what's in the persistence.xml!
pds.setUniqueName(datasourceName);
pds.setClassName(dsProps.getProperty("className"));
pds.setMaxPoolSize(Integer.parseInt(dsProps.getProperty("maxPoolSize")));
pds.setAllowLocalTransactions(Boolean.parseBoolean(dsProps
.getProperty("allowLocalTransactions")));
for (String propertyName : new String[] { "user", "password" }) {
pds.getDriverProperties().put(propertyName, dsProps.getProperty(propertyName));
}
String driverClass = dsProps.getProperty("driverClassName");
if (driverClass.startsWith("org.h2")) {
if( ! TEST_MARSHALLING ) {
h2Server.start();
}
for (String propertyName : new String[] { "url", "driverClassName" }) {
pds.getDriverProperties().put(propertyName, dsProps.getProperty(propertyName));
}
} else {
pds.setClassName(dsProps.getProperty("className"));
if (driverClass.startsWith("oracle")) {
pds.getDriverProperties().put("driverType", "thin");
pds.getDriverProperties().put("URL", dsProps.getProperty("url"));
} else if (driverClass.startsWith("com.ibm.db2")) {
// http://docs.codehaus.org/display/BTM/JdbcXaSupportEvaluation#JdbcXaSupportEvaluation-IBMDB2
pds.getDriverProperties().put("databaseName", dsProps.getProperty("databaseName"));
pds.getDriverProperties().put("driverType", "4");
pds.getDriverProperties().put("serverName", dsProps.getProperty("serverName"));
pds.getDriverProperties().put("portNumber", dsProps.getProperty("portNumber"));
} else if (driverClass.startsWith("com.microsoft")) {
for (String propertyName : new String[] { "serverName", "portNumber", "databaseName" }) {
pds.getDriverProperties().put(propertyName, dsProps.getProperty(propertyName));
}
pds.getDriverProperties().put("URL", dsProps.getProperty("url"));
pds.getDriverProperties().put("selectMethod", "cursor");
pds.getDriverProperties().put("InstanceName", "MSSQL01");
} else if (driverClass.startsWith("com.mysql")) {
for (String propertyName : new String[] { "databaseName", "serverName", "portNumber", "url" }) {
pds.getDriverProperties().put(propertyName, dsProps.getProperty(propertyName));
}
} else if (driverClass.startsWith("com.sybase")) {
for (String propertyName : new String[] { "databaseName", "portNumber", "serverName" }) {
pds.getDriverProperties().put(propertyName, dsProps.getProperty(propertyName));
}
pds.getDriverProperties().put("REQUEST_HA_SESSION", "false");
pds.getDriverProperties().put("networkProtocol", "Tds");
} else if (driverClass.startsWith("org.postgresql")) {
for (String propertyName : new String[] { "databaseName", "portNumber", "serverName" }) {
pds.getDriverProperties().put(propertyName, dsProps.getProperty(propertyName));
}
} else {
throw new RuntimeException("Unknown driver class: " + driverClass);
}
}