日历
导航
常用链接
留言簿(2)
随笔档案
搜索
最新评论
阅读排行榜
评论排行榜
|
2006年5月9日
在查询时报下面的错误,使用的是hibernate,oracle数据库,并做了集群 WARN - SQL Error: 17002, SQLState: null ERROR - Io 异常:Software caused connection abort: recv failed 请问是什么原因造成的,谢谢!
参考hibernate对hql语句的解析,写了对SQL语句的解析,并生成相应的对象。主要为了自定义查询条件进行查询和对查询结果进行二次查询使用。目前只支持简单的sql语句的解析,不支持子查询的解析。在压缩包中只给出了解析程序,没有包括对应的查询对象。链接:程序源码。
项目要求能获得CONNECTION便于对数据库的操作,并要求能与spring中的事务处于同一事务中。实现: 1.定义SanHibernateTransactionManager类,继承spring中的
HibernateTransactionManager,便于获得HibernateTransactionObject。把这个类注入到spring容器中。
<
bean
id
="transactionManager"
class
="com.san.tools.hibernate.SanHibernateTransactionManager"
>
<
property
name
="sessionFactory"
>
<
ref
bean
="sessionFactory"
/>
</
property
>
</
bean
>
public class SanHibernateTransactionManager extends HibernateTransactionManager{
public Object getTransactionObj(){ return super.doGetTransaction(); } public boolean existsTransaction(Object transaction){ return super.isExistingTransaction(transaction); } public Session getSession(){ return SessionFactoryUtils.getSession(this.getSessionFactory(), true); } public Session getCurrentSession(){ HibernateTransactionObject obj = (HibernateTransactionObject)this.getTransactionObj(); return obj.getSessionHolder().getSession(); } } 2.开始事务。
public
void
beginTransaction()
throws
SQLException
{
//
TransactionDefinition.PROPAGATION_REQUIRED:支持当前的事务,如果不存在就创建一个新的。
DefaultTransactionDefinition transactionDef
=
new
DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
//
创建一个TransactionStatus
TransactionStatus transactionStatus
=
transactionManager.getTransaction(transactionDef);
//
取得绑定到当前线程上的session。从HibernateTransactionObject中获得,这里修改了spring中HibernateTransactionManager.java文件,
//
将private HibernateTransactionObject改为protected HibernateTransactionObject
Session session
=
transactionManager.getCurrentSession();
if
(session
!=
this
.session)
{ System.err.println(
"
session不是同一对象
"
); }
//
将transactionStatus保存到集合中
this
.transactionStatuss.add(transactionStatus);
this
.beginTransaction
=
true
; }
3.提交事务
public
void
commit()
throws
HibernateException,SQLException
{
//
循环TransactionStatus集合,直至第一个transactionStatus被提交时,才真正提交
for
(
int
i
=
transactionStatuss.size()
-
1
;i
>=
0
;i
--
)
{ DefaultTransactionStatus transactionStatus
=
(DefaultTransactionStatus)transactionStatuss.get(i); transactionManager.commit(transactionStatus); }
transactionStatuss.clear();
}
4.回滚事务
public void rollBack(){ for(int i = transactionStatuss.size() - 1;i >= 0;i--){ DefaultTransactionStatus transactionStatus = (DefaultTransactionStatus)transactionStatuss.get(i); transactionManager.rollback(transactionStatus); } transactionStatuss.clear(); } 贴出这段代码一是为了共享一点所得,二是希望能指出中间有什么不正确的地方(心里不是很有底 )
function doPrint(servlet, form) { var oWord = new ActiveXObject("Word.Application"); var oDoc = oWord.Documents.Add("",0,1); var strFields = form.elements["gFields"].value; var fields = strFields.split(","); oWord.Selection.TypeParagraph(); oWord.Selection.Style = oDoc.Styles("正文"); var wdPageBreak = 7; oWord.Selection.InsertBreak(wdPageBreak); //生成下一页,用于产生正文部分。当前页用于生成目录 for(var i=0;i<fields.length;i++){ form.elements["gFields"].value = fields[i]; var oRange = oWord.Selection.Range; pastObj(servlet,form,oWord); } oWord.Selection.TypeBackspace(); //去掉最后一页 oWord.Selection.HomeKey(6); //返回首页的第一行 oWord.Selection.Font.Bold = 9999998; //加粗 oWord.Selection.Font.Size = 16; //设置字体大小(3号) oWord.Selection.TypeText("目录"); oWord.Selection.ParagraphFormat.Alignment = 1; //居中 oWord.Selection.TypeParagraph(); //换行 oWord.Selection.Style = oDoc.Styles("正文"); //样式设为正文 oWord.Application.WindowState = 2; oWord.Application.WindowState = 0; //生成目录 oWord.ActiveDocument.TablesOfContents.add(oWord.Selection.Range,true,1,3,false,"",true,true,"",true,true,true); oWord.ActiveDocument.TablesOfContents(1).TabLeader = 1 oWord.ActiveDocument.TablesOfContents.Format = 0; oWord.Selection.Sections(1).Footers(1).PageNumbers.Add(2,true); //在页脚出生成页码 oWord.Application.Visible = true; //退出word //oWord.Quit(); oWord = null; } function pastObj(servlet, form,oWord){ var ajax = new AJAXInteraction(servlet, function(requestText) { if (requestText == "FAILED") { return; } else { var oDoc = oWord.ActiveDocument; var sele = oWord.Selection; sele.Style = oDoc.Styles("标题 1"); //设置样式为标题1 var tempObj = document.getElementById("content"); tempObj.innerHTML = requestText; var title = document.getElementById("title_"+form.elements["gFields"].value).value; oWord.Selection.TypeText(title); //取得单位名称,并设为标题 sele.TypeParagraph(); //换行 sele.Style = oDoc.Styles("正文"); //设置样式为正文 var arrs = requestText.split("^^^"); for(var i=0;i<arrs.length;i++){ var obj = document.getElementById("content"); obj.innerHTML = arrs[i]; var sel = document.body.createTextRange(); sel.moveToElementText(obj); sel.select(); sel.execCommand("Copy"); sele.paste(); var wdPageBreak = 7; sele.InsertBreak(wdPageBreak); //生成下一页 } //sele.TypeParagraph(); //sele.TypeText("测试1"); //sele.Style = oDoc.Styles("正文"); } }); ajax.doPost(getRequestBody(form)); }
摘要: 阅读全文
SpeedProductLoad.java
public
class
SpeedProductLoad
{
private
SpeedProduct product;
private
SpeedVehicleType vehicleType;
private
Double loaded;
private
Long lineNo;
public
SpeedProductLoad(SpeedProduct product,SpeedVehicleType vehicleType,Double loaded,Long lineNo)
{
this
.product
=
product;
this
.vehicleType
=
vehicleType;
this
.loaded
=
loaded;
this
.lineNo
=
lineNo; }
}
hbm中的映射: <map name="vehicleTypes" table="PRODUCT_VEHICLETYPE" lazy="true" inverse="false" cascade="all"> <key column="PRODUCT_ID"/> <index-many-to-many class="com.vtradex.speedtms.model.base.vehicle.SpeedVehicleType" column="VEHICLE_TYPE_ID"/> <element type="double" column="FULLYLOADED"/> </map> HQL语句:
SELECT new com.vtradex.speedtms.model.base.product.SpeedProductLoad(product,index(vehicleTypes),vehicleTypes,product.id) FROM SpeedProduct AS product LEFT JOIN FETCH product.vehicleTypes AS vehicleTypes WHERE 1=1 AND product.disabled=false /~code: AND product.code LIKE {code} ~/ /~name: AND product.name LIKE {name} ~/ /~company.id: AND product.company.id={company.id} ~/ /~product.uom: AND product.uom={product.uom} ~/ /~productType.id: AND product.productType.id={productType.id} ~/
|