dbUnit对mssqlserver自增长主键的处理
2008-02-23 09:35:53来源:互联网 阅读 ()
package com.sourceware.test;
/*******************************************************************************
* Copyright (c) 2000, 2005 ZhongKe Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.source-ware.com/
*
* Contributors:
* ZhongKe Corporation - initial API and implementation
*******************************************************************************/
import Java.io.InputStream;
import java.sql.Connection;
import org.dbunit.DatabaseTestCase;
import org.dbunit.database.DatabaseConfig;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.XML.FlatXmlDataSet;
import org.dbunit.operation.DatabaseOperation;
import com.sourceware.sms.platform.dao.SMSDAO;
import org.springFramework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.ApplicationContext;
import javax.sql.DataSource;
/**
*
* <p>标题: 消息服务</p>
*
* <p>描述: 消息服务平台</p>
*
* <p>版权: 宁波中科信息产业有限公司 Copyright (c) 2004</p>
*
* <p>公司: 宁波中科信息产业有限公司</p>
*
* @author 吴锋彬(woowind@sina.com)
* @version 1.0
*/
public class BaseDatabaseTestCase
extends DatabaseTestCase {
static ApplicationContext appContext;
private final static String batchID =
"http://www.dbunit.org/features/batchedStatements";
static DataSource ds;
static {
appContext =
new ClassPathXmlApplicationContext("xml/sms-platform-context.xml");
ds = (DataSource) appContext.getBean("dataSource");
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
this.getConnection().close();
}
/* (non-Javadoc)
* @see org.dbunit.DatabaseTestCase#getConnection()
*/
protected IDatabaseConnection getConnection() throws Exception {
IDatabaseConnection iDataBaseConnection = new DatabaseConnection(ds.
getConnection());
DatabaseConfig config = iDataBaseConnection.getConfig();
//Enable Batched statements
if (!config.getFeature(batchID)) {
config.setFeature(batchID, true);
}
return iDataBaseConnection;
}
/* (non-Javadoc)
* @see org.dbunit.DatabaseTestCase#getDataSet()
*/
protected IDataSet getDataSet() throws Exception {
InputStream is = this.getClass().getClassLoader().getResourceAsStream(
"dataset/fmsDomain.xml");
return new FlatXmlDataSet(is);
}
protected DatabaseOperation getSetUpOperation() throws Exception {
return org.dbunit.ext.MSSQL.InsertIdentityOperation.INSERT;
}
protected DatabaseOperation getTearDownOperation() throws Exception {
return org.dbunit.ext.mssql.InsertIdentityOperation.CLEAN_INSERT;
}
}
上一篇: spring中使用JOTM作为数据源及TransactionManager
下一篇: Java Thread Programming 1.7 - Concurrent Access to Objects and Variables
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash