KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > tools > testlet > CreateTableTestLet


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.scenario.tools.testlet;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.ResultSet JavaDoc;
29
30 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase;
31
32 /**
33  * Execute a Create table statement using the given connection, and then checks
34  * on the given virtual database that the proper table can be retrieved.
35  *
36  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
37  * @version 1.0
38  */

39 public class CreateTableTestLet extends AbstractConnectionTestLet
40 {
41
42   /**
43    * Creates a new <code>CreateTableTestLet</code> object
44    *
45    * @param con connection to use for testing
46    */

47   public CreateTableTestLet(Connection JavaDoc con)
48   {
49     super(con);
50     config.put(TABLE_NAME, "newtable" + System.currentTimeMillis());
51     config.put(IGNORE_CASE, "true");
52     config.put(TABLE_METADATA_COLUMNS, new String JavaDoc[]{"TABLE"});
53     config.put(ITERATION, "" + 1);
54   }
55
56   /**
57    * @see org.objectweb.cjdbc.scenario.tools.testlet.AbstractTestLet#execute()
58    */

59   public void execute() throws Exception JavaDoc
60   {
61     String JavaDoc myTableName = (String JavaDoc) config.get(TABLE_NAME);
62     VirtualDatabase mainVdb = (VirtualDatabase) config.get(VIRTUAL_DATABASE);
63     if (mainVdb == null)
64       throw new TestLetException("No virtual database defined");
65
66     int iteration = Integer.parseInt((String JavaDoc) config.get(ITERATION));
67
68     for (int i = 0; i < iteration; i++)
69     {
70       String JavaDoc tableName = myTableName + i;
71       String JavaDoc createQuery = "CREATE TABLE " + tableName
72           + "(ID INTEGER NOT NULL PRIMARY KEY,NAME VARCHAR(255),COST DECIMAL)";
73
74       jdbcConnection.createStatement().executeUpdate(createQuery);
75       ResultSet JavaDoc set = jdbcConnection.getMetaData().getTables(null, "%", tableName,
76           (String JavaDoc[]) config.get(TABLE_METADATA_COLUMNS));
77       assertTrue("No results after create table", set.next());
78       String JavaDoc table = set.getString(3);
79       if (ignoreCase())
80         assertTrue(table.equalsIgnoreCase(tableName));
81       else
82         assertTrue(table.equals(tableName));
83     }
84   }
85 }
Popular Tags