继博文IBATIS存活空间续--SI(SpringIbatis)实现之后,本博文给出SI(SpringIbatis)实现中的LOB问题,尤其是CLOB,根据相关资料,简单地给出两种解决方案!
问题一:SI中的LOB问题
SI中的LOB配置在com/si/dao/core/lob.xml中,采用默认的处理器,可按需修改。lob.xml中内容如下:
<!-- 默认的DefaultLobHandler -->
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true" />
<!-- 特定的OracleLobHandler-->
<!-- 以c3p0数据库连接池为例,其它类型的数据库连接池仅需更换相应的jdbcExtractor类即可 -->
<!--
<bean id="jdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor" />
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
<property name="nativeJdbcExtractor" ref="jdbcExtractor"/>
</bean>
-->
问题二:关于LOB解决之道:(针对Oracle9i或更高版本)
注:主要是CLOB问题,CLOB资料http://developer.51cto.com/art/200907/136699.htm
方案一:采用spring的DefaultLobHandler
前提:Oracle 9i或更高版本,ojdgc14或更高版本驱动JAR
(推荐10g以上驱动,如ojdbc5-11.1.0.6.0-Produc.jar或ojdbc14-10.2.0.4.0.jar)
优点:完全透明化,(遵循最佳实践parameterClass&resultMap)
不足:只是对Oracle的CLOB只能支持到最大值4000字符
备注:原则上说,DefaultLobHandler不支持Oracle9i,且对Oracle10g仅有限支持;关于此点限制应该是指对CLOB的支持,因为在Oracle9i中我应用的BLOB操作无任何问题,而CLOB当时没太在意,不知是否存在4k字符的限制,若有,请采用方案二。
在xSpring.xml中样例
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true" />
<!-- 配置sqlMapClient -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="lobHandler" ref="lobHandler"/>
<property name="configLocation" value="classpath:ibatis.xml" />
</bean>
在ibatis.xml中的全局配置
<typeHandler jdbcType="BLOB" javaType="[B" callback="org.springframework.orm.ibatis.support.BlobByteArrayTypeHandler"/>
<typeHandler jdbcType="CLOB" javaType="java.lang.String" callback="org.springframework.orm.ibatis.support.ClobStringTypeHandler"/>
方案二:采用spring的OracleLobHandler
前提:Oracle 9i或更高版本,ojdgc14或更高版本驱动JAR
优点:完全透明化,解决CLOB最大值为4k字符的限制(遵循最佳实践parameterClass&resultMap)
不足:需要根据数据库连接的类型选择不同的本地SQL执行器,如Spring2.5.6中支持的:
①直接JDBC:SimpleNativeJdbcExtractor或Jdbc4NativeJdbcExtractor(若采用jdbc4 api)
②c3p0数据库连接池:CommonsDbcpNativeJdbcExtractor
③dhcp数据库连接池:C3P0NativeJdbcExtractor
④xprool数据库连接池:XAPoolNativeJdbcExtractor
⑤jboss数据库连接池:JBossNativeJdbcExtractor
⑥weblogic数据库连接池:WebLogicNativeJdbcExtractor
⑦websphere数据库连接池:WebSphereNativeJdbcExtractor
在xSpring.xml中样例
<bean id="jdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor" />
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
<property name="nativeJdbcExtractor" ref="jdbcExtractor"/>
</bean>
<!-- 配置sqlMapClient -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="lobHandler" ref="lobHandler"/>
<property name="configLocation" value="classpath:ibatis.xml" />
</bean>
在ibatis.xml中的全局配置(同上)
以下是参考资料,来自于Spring2.5.6的源码
pakage org.springframework.orm.ibatis.support;
/**
* iBATIS TypeHandler implementation for byte arrays that get mapped to BLOBs.
* Retrieves the LobHandler to use from SqlMapClientFactoryBean at config time.
*
* <p>Can also be defined in generic iBATIS mappings, as DefaultLobCreator will
* work with most JDBC-compliant database drivers. In this case, the field type
* does not have to be BLOB: For databases like MySQL and MS SQL Server, any
* large enough binary type will work.
*
* @author Juergen Hoeller
* @since 1.1.5
* @see org.springframework.orm.ibatis.SqlMapClientFactoryBean#setLobHandler
*/
public class BlobByteArrayTypeHandler extends AbstractLobTypeHandler {
//...
}
/**
* iBATIS TypeHandler implementation for arbitrary objects that get serialized to BLOBs.
* Retrieves the LobHandler to use from SqlMapClientFactoryBean at config time.
*
* <p>Can also be defined in generic iBATIS mappings, as DefaultLobCreator will
* work with most JDBC-compliant database drivers. In this case, the field type
* does not have to be BLOB: For databases like MySQL and MS SQL Server, any
* large enough binary type will work.
*
* @author Juergen Hoeller
* @since 1.1.5
* @see org.springframework.orm.ibatis.SqlMapClientFactoryBean#setLobHandler
*/
public class BlobSerializableTypeHandler extends AbstractLobTypeHandler {
//...
}
/**
* iBATIS TypeHandler implementation for Strings that get mapped to CLOBs.
* Retrieves the LobHandler to use from SqlMapClientFactoryBean at config time.
*
* <p>Particularly useful for storing Strings with more than 4000 characters in an
* Oracle database (only possible via CLOBs), in combination with OracleLobHandler.
*
* <p>Can also be defined in generic iBATIS mappings, as DefaultLobCreator will
* work with most JDBC-compliant database drivers. In this case, the field type
* does not have to be BLOB: For databases like MySQL and MS SQL Server, any
* large enough binary type will work.
*
* @author Juergen Hoeller
* @since 1.1.5
* @see org.springframework.orm.ibatis.SqlMapClientFactoryBean#setLobHandler
*/
public class ClobStringTypeHandler extends AbstractLobTypeHandler {
//...
}
package org.springframework.jdbc.support.lob;
/**
* Default implementation of the {@link LobHandler} interface. Invokes
* the direct accessor methods that <code>java.sql.ResultSet</code>
* and <code>java.sql.PreparedStatement</code> offer.
*
* <p>This LobHandler should work for any JDBC driver that is JDBC compliant
* in terms of the spec's suggestions regarding simple BLOB and CLOB handling.
* This does not apply to Oracle 9i, and only to a limited degree to Oracle 10g!
* As a consequence, use {@link OracleLobHandler} for accessing Oracle BLOBs/CLOBs.
*
* <p>Some JDBC drivers require values with a BLOB/CLOB target column to be
* explicitly set through the JDBC <code>setBlob</code> / <code>setClob</code>
* API: for example, PostgreSQL's driver. Switch the {@link #setWrapAsLob "wrapAsLob"}
* property to "true" when operating against such a driver.
*
* <p>On JDBC 4.0, this LobHandler also supports streaming the BLOB/CLOB content
* via the <code>setBlob</code> / <code>setClob</code> variants that take a stream
* argument directly. Consider switching the {@link #setStreamAsLob "streamAsLob"}
* property to "true" when operating against a fully compliant JDBC 4.0 driver.
*
* <p>See the {@link LobHandler} javadoc for a summary of recommendations.
*
* @author Juergen Hoeller
* @since 04.12.2003
* @see #setStreamAsLob
* @see java.sql.ResultSet#getBytes
* @see java.sql.ResultSet#getBinaryStream
* @see java.sql.ResultSet#getString
* @see java.sql.ResultSet#getAsciiStream
* @see java.sql.ResultSet#getCharacterStream
* @see java.sql.PreparedStatement#setBytes
* @see java.sql.PreparedStatement#setBinaryStream
* @see java.sql.PreparedStatement#setString
* @see java.sql.PreparedStatement#setAsciiStream
* @see java.sql.PreparedStatement#setCharacterStream
*/
public class DefaultLobHandler extends AbstractLobHandler {
//...
}
/**
* {@link LobHandler} implementation for Oracle databases. Uses proprietary API
* to create <code>oracle.sql.BLOB</code> and <code>oracle.sql.CLOB</code>
* instances, as necessary when working with Oracle's JDBC driver.
* Note that this LobHandler requires Oracle JDBC driver 9i or higher!
*
* <p>While most databases are able to work with {@link DefaultLobHandler},
* Oracle just accepts Blob/Clob instances created via its own proprietary
* BLOB/CLOB API, and additionally doesn't accept large streams for
* PreparedStatement's corresponding setter methods. Therefore, you need
* to use a strategy like this LobHandler implementation.
*
* <p>Needs to work on a native JDBC Connection, to be able to cast it to
* <code>oracle.jdbc.OracleConnection</code>. If you pass in Connections from a
* connection pool (the usual case in a J2EE environment), you need to set an
* appropriate {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor}
* to allow for automatical retrieval of the underlying native JDBC Connection.
* LobHandler and NativeJdbcExtractor are separate concerns, therefore they
* are represented by separate strategy interfaces.
*
* <p>Coded via reflection to avoid dependencies on Oracle classes.
* Even reads in Oracle constants via reflection because of different Oracle
* drivers (classes12, ojdbc14) having different constant values! As this
* LobHandler initializes Oracle classes on instantiation, do not define this
* as eager-initializing singleton if you do not want to depend on the Oracle
* JAR being in the class path: use "lazy-init=true" to avoid this issue.
*
* @author Juergen Hoeller
* @since 04.12.2003
* @see #setNativeJdbcExtractor
* @see oracle.sql.BLOB
* @see oracle.sql.CLOB
*/
public class OracleLobHandler extends AbstractLobHandler {
//...
}
分享到:
相关推荐
Oracle数据库中LOB的调优.pdf
oracle dbms_lob
LOB语料库 创建时间: 1970年代初 创建单位:英国Lancaster大学和挪威Oslo大学以及Bergen大学 规模层级: 100万词次 基本情况:研究当代英国英语,与美国英语对比,使用了TAGIT系统,以统计方式建立换算几率矩阵,提高标注...
Oracle的LOB(CLOB)大字段以及(SYS_LOB$$)清理.txt
sybase IQ LOB手册,这个功能能让你在IQ中村图片和视频
本文档主要介绍如何对LOB字段进行处理本文档主要介绍如何对LOB字段进行处理
OCI中有关LOB相关函数使用的样例程序
Oracle LOB字段处理工具是一款简单的lob字段处理工具
通过spring存blob和clob数据到sybase数据库中,压缩包里包含了三种方式,(1)spring+hibernate,切面事务(aop),存lob数据,(2)spring+hibernate存lob数据,(3)spring+jdbc存lob数据。
LOB语料库是模仿Brown语料库的比例建立起来的英国英语语料库,其预料搜集自1961年英国英语出版物上的文本,共500篇,每篇大约2000个单词,合计100万单词。Brown语料库带词性标记,LOB语料库不带词性标记。
前端开源库-lobLOB,LOB API包装
分享一个来自官方的对Oracle LOB字段的性能调优。
测试oracle数据库中,lob字段在不同参数条件下,删除数据后占用空间的情况。 测试1 测试disable storage in row下的lob字段 测试2 测试非disable storage in row模式下 该模式为默认模式,既小于4k的数据不会存在lob...
Oracle中LOB字段的存储管理和优化.pdf
ORACLE LOB大对象处理.doc ORACLE LOB大对象处理.doc
NULL 博文链接:https://sosuny.iteye.com/blog/446112
lob笔记.doclob笔记.doclob笔记.doc
oracle dbms_lob 智能大对象(Blob、Clob)
包含了官方权威说明。而且有LOB字段的日常维护总结,方便大家交流学习。
详细解释lob字段在DB2中的存储及处理过程, 主要基于IBM Z平台。