|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface DataSourceConfig
If you use the ConfigurableDataSource then this interface needs to be implemented in customer projects to return the proper values to connect to the database.
The connectionId
parameter can be used to distinguish
between different databases.
There are 3 ways to configure a DataSource
getJndiResourceName(String)
getJndiResourceName(String)
returns null
. In this case you must specify the getConnectionClassName(String)
to contain the class name of a DataSource, e.g.
"";com.mchange.v2.c3p0.ComboPooledDataSource"";
and return additional configuration via getConnectionProperties(String)
.
getJndiResourceName(String)
returns null
. In this case you must specify the getConnectionClassName(String)
to contain the class name of a javax.sql.Driver, e.g.
"";org.hsqldb.jdbcDriver"";
and return additional configuration via getConnectionProperties(String)
.
Instead of configuring any hardcoded DataSource provider, JDBC driver or JNDI location of the DataSource you just configure our ConfigurableDataSource in your persistence.xml. This class is an implementation of DataSource and acts as kind of a proxy to determine the underlying database configuration for your usage scenarios.
A possible persistence.xml configuration would look like the following:
<persistence 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_1_0.xsd" version="1.0"> <persistence-unit name="test" > <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> <class>org.apache.myfaces.extensions.cdi.jpa.test.TestEntity</class> <properties> <property name="openjpa.ConnectionDriverName" value="org.apache.myfaces.extensions.cdi.jpa.impl.datasource.ConfigurableDataSource"/> <property name="openjpa.ConnectionProperties" value="connectionId=core"/> </properties> </persistence-unit> </persistence>
Method Summary | |
---|---|
String |
getConnectionClassName(String connectionId)
|
Properties |
getConnectionProperties(String connectionId)
|
String |
getJdbcConnectionUrl(String connectionId)
This will only get used if getConnectionClassName(String) is a javax.sql.Driver. |
String |
getJndiResourceName(String connectionId)
Return the JNDI resource name if the DataSource should get retrieved via JNDI. |
Method Detail |
---|
String getJndiResourceName(String connectionId)
null
.
And the JDBC connection properties must get set via
getConnectionClassName(String)
and getConnectionProperties(String)
.
connectionId
- used to distinguish between different databases.
null
if a native
JDBC connection should get used.String getConnectionClassName(String connectionId)
connectionId
- used to distinguish between different databases.
null
if getJndiResourceName(String)
is not being usedProperties getConnectionProperties(String connectionId)
connectionId
- used to distinguish between different databases.
null
if getJndiResourceName(String)
is not being usedString getJdbcConnectionUrl(String connectionId)
getConnectionClassName(String)
is a javax.sql.Driver.
Foor Datasources, the underlying connection url must get configured via
getConnectionProperties(String)
.
connectionId
- used to distinguish between different databases.
null
if getJndiResourceName(String)
is not being used
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |