|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.orm.ibatis.SqlMapClientFactoryBean
public class SqlMapClientFactoryBean
FactoryBean that creates an iBATIS Database Layer SqlMapClient as singleton in the current bean factory, possibly for use with SqlMapClientTemplate.
Allows to specify a DataSource at the SqlMapClient level. This is preferable to per-DAO DataSource references, as it allows for lazy loading and avoids repeated DataSource references.
NOTE: The SqlMapClient/SqlMapSession API is the API of iBATIS SQL Maps 2. With SQL Maps 1.x, the SqlMap/MappedStatement API has to be used.
setConfigLocation(org.springframework.core.io.Resource)
,
setDataSource(javax.sql.DataSource)
,
SqlMapClientTemplate.setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient)
,
JdbcAccessor.setDataSource(javax.sql.DataSource)
Constructor Summary | |
---|---|
SqlMapClientFactoryBean()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware). |
protected void |
applyTransactionConfig(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient,
com.ibatis.sqlmap.engine.transaction.TransactionConfig transactionConfig)
Apply the given iBATIS TransactionConfig to the SqlMapClient. |
static LobHandler |
getConfigTimeLobHandler()
Return the LobHandler for the currently configured iBATIS SqlMapClient, to be used by TypeHandler implementations like ClobStringTypeHandler. |
Object |
getObject()
Return an instance (possibly shared or independent) of the object managed by this factory. |
Class |
getObjectType()
Return the type of object that this FactoryBean creates, or null
if not known in advance. |
boolean |
isSingleton()
Is the bean managed by this factory a singleton or a prototype? |
void |
setConfigLocation(Resource configLocation)
Set the location of the iBATIS SqlMapClient config file. |
void |
setDataSource(DataSource dataSource)
Set the DataSource to be used by iBATIS SQL Maps. |
void |
setLobHandler(LobHandler lobHandler)
Set the LobHandler to be used by the SqlMapClient. |
void |
setSqlMapClientProperties(Properties sqlMapClientProperties)
Set optional properties to be passed into the SqlMapClientBuilder, as alternative to a <properties> tag in the sql-map-config.xml
file. |
void |
setTransactionConfigClass(Class transactionConfigClass)
Set the iBATIS TransactionConfig class to use. |
void |
setTransactionConfigProperties(Properties transactionConfigProperties)
Set properties to be passed to the TransactionConfig instance used by this SqlMapClient. |
void |
setUseTransactionAwareDataSource(boolean useTransactionAwareDataSource)
Set whether to use a transaction-aware DataSource for the SqlMapClient, i.e. whether to automatically wrap the passed-in DataSource with Spring's TransactionAwareDataSourceProxy. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SqlMapClientFactoryBean()
Method Detail |
---|
public static LobHandler getConfigTimeLobHandler()
This instance will be set before initialization of the corresponding SqlMapClient, and reset immediately afterwards. It is thus only available during configuration.
public void setConfigLocation(Resource configLocation)
public void setSqlMapClientProperties(Properties sqlMapClientProperties)
<properties>
tag in the sql-map-config.xml
file. Will be used to resolve placeholders in the config file.
setConfigLocation(org.springframework.core.io.Resource)
,
SqlMapClientBuilder.buildSqlMapClient(java.io.Reader, java.util.Properties)
public void setDataSource(DataSource dataSource)
If specified, this will override corresponding settings in the SqlMapClient properties. Usually, you will specify DataSource and transaction configuration either here or in SqlMapClient properties.
Specifying a DataSource for the SqlMapClient rather than for each individual DAO allows for lazy loading, for example when using PaginatedList results.
With a DataSource passed in here, you don't need to specify one for each DAO. Passing the SqlMapClient to the DAOs is enough, as it already carries a DataSource. Thus, it's recommended to specify the DataSource at this central location only.
Thanks to Brandon Goodin from the iBATIS team for the hint on how to make this work with Spring's integration strategy!
setTransactionConfigClass(java.lang.Class)
,
setTransactionConfigProperties(java.util.Properties)
,
SqlMapTransactionManager.getDataSource()
,
JdbcAccessor.setDataSource(javax.sql.DataSource)
,
SqlMapClientTemplate.queryForPaginatedList(java.lang.String, int)
public void setUseTransactionAwareDataSource(boolean useTransactionAwareDataSource)
Default is "true": When the SqlMapClient performs direct database operations outside of Spring's SqlMapClientTemplate (for example, lazy loading or direct SqlMapClient access), it will still participate in active Spring-managed transactions.
As a further effect, using a transaction-aware DataSource will apply remaining transaction timeouts to all created JDBC Statements. This means that all operations performed by the SqlMapClient will automatically participate in Spring-managed transaction timeouts.
Turn this flag off to get raw DataSource handling, without Spring transaction checks. Operations on Spring's SqlMapClientTemplate will still detect Spring-managed transactions, but lazy loading or direct SqlMapClient access won't.
setDataSource(javax.sql.DataSource)
,
TransactionAwareDataSourceProxy
,
DataSourceTransactionManager
,
SqlMapClientTemplate
,
SqlMapClient
public void setTransactionConfigClass(Class transactionConfigClass)
com.ibatis.sqlmap.engine.transaction.external.ExternalTransactionConfig
.
Will only get applied when using a Spring-managed DataSource. An instance of this class will get populated with the given DataSource and initialized with the given properties.
The default ExternalTransactionConfig is appropriate if there is external transaction management that the SqlMapClient should participate in: be it Spring transaction management, EJB CMT or plain JTA. This should be the typical scenario. If there is no active transaction, SqlMapClient operations will execute SQL statements non-transactionally.
JdbcTransactionConfig or JtaTransactionConfig is only necessary when using the iBATIS SqlMapTransactionManager API instead of external transactions. If there is no explicit transaction, SqlMapClient operations will automatically start a transaction for their own scope (in contrast to the external transaction mode, see above).
It is strongly recommended to use iBATIS SQL Maps with Spring transaction management (or EJB CMT). In this case, the default ExternalTransactionConfig is fine. Lazy loading and SQL Maps operations without explicit transaction demarcation will execute non-transactionally.
Even with Spring transaction management, it might be desirable to specify JdbcTransactionConfig: This will still participate in existing Spring-managed transactions, but lazy loading and operations without explicit transaction demaration will execute in their own auto-started transactions. However, this is usually not necessary.
setDataSource(javax.sql.DataSource)
,
setTransactionConfigProperties(java.util.Properties)
,
TransactionConfig
,
ExternalTransactionConfig
,
com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransactionConfig
,
com.ibatis.sqlmap.engine.transaction.jta.JtaTransactionConfig
,
SqlMapTransactionManager
public void setTransactionConfigProperties(Properties transactionConfigProperties)
TransactionConfig.initialize(java.util.Properties)
,
ExternalTransactionConfig
,
com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransactionConfig
,
com.ibatis.sqlmap.engine.transaction.jta.JtaTransactionConfig
public void setLobHandler(LobHandler lobHandler)
getConfigTimeLobHandler()
,
TypeHandler
,
ClobStringTypeHandler
,
BlobByteArrayTypeHandler
,
BlobSerializableTypeHandler
public void afterPropertiesSet() throws Exception
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
Exception
- in the event of misconfiguration (such
as failure to set an essential property) or if initialization fails.protected void applyTransactionConfig(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient, com.ibatis.sqlmap.engine.transaction.TransactionConfig transactionConfig)
Default implementation casts to ExtendedSqlMapClient, retrieves the maximum number of concurrent transactions from the SqlMapExecutorDelegate, and sets an iBATIS TransactionManager with the given TransactionConfig.
sqlMapClient
- the SqlMapClient to apply the TransactionConfig totransactionConfig
- the iBATIS TransactionConfig to applyExtendedSqlMapClient
,
SqlMapExecutorDelegate.getMaxTransactions()
,
SqlMapExecutorDelegate.setTxManager(com.ibatis.sqlmap.engine.transaction.TransactionManager)
public Object getObject()
FactoryBean
If this method returns null
, the factory will consider
the FactoryBean as not fully initialized and throw a corresponding
FactoryBeanNotInitializedException.
getObject
in interface FactoryBean
null
;
a null
value will be considered as an indication of
incomplete initialization)FactoryBeanNotInitializedException
public Class getObjectType()
FactoryBean
null
if not known in advance. This allows to check for specific types
of beans without instantiating objects, for example on autowiring.
For a singleton, this should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too.
This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available.
NOTE: Autowiring will simply ignore FactoryBeans that return
null
here. Therefore it is highly recommended to implement
this method properly, using the current state of the FactoryBean.
getObjectType
in interface FactoryBean
null
if not known at the time of the callListableBeanFactory.getBeansOfType(java.lang.Class)
public boolean isSingleton()
FactoryBean
getObject()
always return the same object
(a reference that can be cached)?
NOTE: If a FactoryBean indicates to hold a singleton object,
the object returned from getObject()
might get cached
by the owning BeanFactory. Hence, do not return true
unless the FactoryBean always exposes the same reference.
The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there.
isSingleton
in interface FactoryBean
FactoryBean.getObject()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |