So I'm using BoneCP and creating my datasource in Spring:
<bean id="baseDataSource" abstract="true" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<property name="driverClass" value="#{T(io.bigsense.spring.MySpring).dbDriver('${dbms}')}" />
<property name="jdbcUrl" value="#{T(io.bigsense.spring.MySpring).dbConnectionString('${dbms}','${dbHostname}','${dbDatabase}','${dbPort}')}" />
<property name="maxConnectionsPerPartition" value="${dbPoolMaxPerPart}"/>
<property name="minConnectionsPerPartition" value="${dbPoolMinPerPart}"/>
<property name="partitionCount" value="${dbPoolPartitions}"/>
<property name="acquireIncrement" value="5"/>
<property name="statementsCacheSize" value="100"/>
<property name="releaseHelperThreads" value="3"/>
</bean>
Most of those values come from a property file. In this particular case, the driverClass
is org.postgresql.Driver
and my jdbcUrl
is jdbc:postgresql://[hostname]:[port]/[database]
returned from some custom functions.
I have postgis installed on my postgres-9.4 instance and I've found documentation that states that in order to send Geography objects to Postgres via JDBC, you need to add the data types to the connection:
import java.sql.*;
import java.util.*;
import java.lang.*;
import org.postgis.*;
...
java.sql.Connection conn;
try {
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost:5432/database";
conn = DriverManager.getConnection(url, "postgres", "");
((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry")
; ((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d");
My question is, how do I do this with my BoneCP setup? If I do a getConnection()
from my BoneCP data source, I can't case it to a org.postgresql.PGConnection
because its type is actually that of com.jolbox.bonecp.ConnectionHandle
.
How do I setup PostGIS datatypes with the underlying Postgres drivers when using a BoneCP data source defined in a Spring application context?
I discovered the answer. I need to use the postgis
DriverWrapper
class: http://postgis.refractions.net/documentation/javadoc/org/postgis/DriverWrapper.html