org.springframework.orm.ojb.support
Class LocalDataSourceConnectionFactory

java.lang.Object
  extended byorg.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl
      extended byorg.apache.ojb.broker.accesslayer.ConnectionFactoryNotPooledImpl
          extended byorg.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl
              extended byorg.springframework.orm.ojb.support.LocalDataSourceConnectionFactory
All Implemented Interfaces:
org.apache.ojb.broker.accesslayer.ConnectionFactory
Direct Known Subclasses:
TransactionAwareDataSourceConnectionFactory

public class LocalDataSourceConnectionFactory
extends org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl

OJB connection factory that delegates to Spring-managed DataSource beans.

Define the following entry in your OJB.properties to use this connection factory:

 ConnectionFactoryClass=org.springframework.orm.ojb.support.LocalDataSourceConnectionFactory
Interprets JCD aliases in OJB's JDBC connection descriptors as Spring bean names. For example, the following will delegate to the Spring bean named "myDataSource":
 <jdbc-connection-descriptor jcd-alias="myDataSource" default-connection="true" useAutoCommit="1"/>
Depends on LocalOjbConfigurer being defined as Spring bean, which will expose the Spring BeanFactory to the corresponding static field of this connection factory.

Consider using the subclass TransactionAwareDataSourceConnectionFactory instead, to let Spring's OJB access to participate in JDBC-based transactions managed outside of OJB (for example, by Spring's DataSourceTransactionManager), or to automatically apply transaction timeouts managed by PersistenceBrokerTransactionManager.

Since:
1.1
Author:
Juergen Hoeller
See Also:
LocalOjbConfigurer, TransactionAwareDataSourceConnectionFactory

Field Summary
protected static BeanFactory beanFactory
          This will hold the BeanFactory to retrieve DataSource beans from.
 
Constructor Summary
LocalDataSourceConnectionFactory()
           
 
Method Summary
protected  DataSource getDataSource(String jcdAlias)
          Return the DataSource to use for the given JCD alias.
 Connection lookupConnection(org.apache.ojb.broker.metadata.JdbcConnectionDescriptor jcd)
           
 
Methods inherited from class org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl
newConnectionFromDriverManager
 
Methods inherited from class org.apache.ojb.broker.accesslayer.ConnectionFactoryNotPooledImpl
getConnectionFromPool, returnConnectionToPool
 
Methods inherited from class org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl
getDbURL, initializeJdbcConnection, newConnectionFromDataSource, releaseAllResources, releaseConnection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

beanFactory

protected static BeanFactory beanFactory
This will hold the BeanFactory to retrieve DataSource beans from.

Constructor Detail

LocalDataSourceConnectionFactory

public LocalDataSourceConnectionFactory()
Method Detail

lookupConnection

public Connection lookupConnection(org.apache.ojb.broker.metadata.JdbcConnectionDescriptor jcd)
                            throws org.apache.ojb.broker.accesslayer.LookupException
Throws:
org.apache.ojb.broker.accesslayer.LookupException

getDataSource

protected DataSource getDataSource(String jcdAlias)
Return the DataSource to use for the given JCD alias.

This implementation fetches looks for a bean with the JCD alias name in the provided Spring BeanFactory.

Parameters:
jcdAlias - the JCD alias to retrieve a DataSource for
Returns:
the DataSource to use


Copyright (C) 2003-2004 The Spring Framework Project.