The processing of Dbunit to MSSQLSERVER self-growth primary key

Source: Internet
Author: User
Tags config key mssql mssqlserver sql return
Server|sqlserver

Package com.sourceware.test;

/*******************************************************************************
* Copyright (c), 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 are 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> title: Message Service </p>
*
* <p> Description: Message Service Platform </p>
*
* <p> Copyright: Ningbo Zhongke Information Industry Co., Ltd. Copyright (c) 2004</p>
*
* <p> Company: Ningbo Zhongke Information Industry Co., Ltd. </p>
*
* @author Wu Fengbin (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 to 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;
}

}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.