Re: Why =?UTF-8?B?Q2Fu4oCZdCBZb3UgSW1wb3J0IFBhY2thZ2VzPw==?=
Arne Vajh??j wrote:
Preferable no database specific code at all. The JDBC API
provides many features to support that.
In those very rare cases where that is not possible, then
a class per database and a configuration/DI way of loading
those.
Sometimes it pays to push deployment issues out to XML files and indirect
resource managers like JNDI.
For example, Tomcat uses context.xml and related files to configure JDBC/JNDI
access, and this works quite nicely with JPA (Java Persistence API).
http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html
Full-blown Java EE app servers have such mechanisms also.
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="fooPu" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:/comp/env/jdbc/foosrc</non-jta-data-source>
<class>com.lewscanon.foo.entity.Person</class>
<class>com.lewscanon.foo.entity.Address</class>
<class>com.lewscanon.foo.entity.Avatar</class>
<class>com.lewscanon.foo.entity.Etc</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/foo" reloadable="true" >
<Resource auth="Container" name="jdbc/foosrc" type="javax.sql.DataSource"
url="jdbc:postgresql://127.0.0.1:5432/foo"
driverClassName="org.postgresql.Driver"
username="groucho" password="swordfish"
maxActive="20" maxIdle="2" maxWait="-1"
/>
</Context>
--
Lew
Honi soit qui mal y pense.