KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > test > core > Utils


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.test.core;
10
11 import java.io.FileInputStream JavaDoc;
12 import java.sql.Connection JavaDoc;
13 import java.sql.DriverManager JavaDoc;
14 import java.sql.SQLException JavaDoc;
15 import java.sql.Statement JavaDoc;
16
17 import org.dbunit.database.DatabaseConnection;
18 import org.dbunit.database.IDatabaseConnection;
19 import org.dbunit.dataset.IDataSet;
20 import org.dbunit.dataset.xml.FlatXmlDataSet;
21
22 /**
23  * @author <a HREF="theute@jboss.org">Thomas Heute </a>
24  * $Revision: 1.1 $
25  */

26 public class Utils
27 {
28
29    private static String JavaDoc url = "jdbc:mysql://localhost:3306/jbossportal?useServerPrepStmts=false";
30    private static String JavaDoc username = "portal";
31    private static String JavaDoc password = "portalpassword";
32    
33    public static IDataSet getDataSet(String JavaDoc file) throws Exception JavaDoc
34    {
35        return new FlatXmlDataSet(new FileInputStream JavaDoc(file));
36    }
37    
38    public static IDatabaseConnection getConnection() throws Exception JavaDoc
39    {
40        Class JavaDoc driverClass = Class.forName("org.gjt.mm.mysql.Driver");
41        Connection JavaDoc jdbcConnection = DriverManager.getConnection(
42                url, username, password);
43        return new DatabaseConnection(jdbcConnection);
44    }
45
46    public static void resetAutoIncrement() throws SQLException JavaDoc {
47       Connection JavaDoc jdbcConnection = DriverManager.getConnection(
48             url, username, password);
49       Statement JavaDoc stmt = jdbcConnection.createStatement();
50       stmt.execute("alter table jbp_roles auto_increment=1");
51    }
52 }
53
Popular Tags