KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > standalone > backend > DatabaseBackendMetaDataTest


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): Mathieu Peltier.
22  * Contributor(s): Sara Bouchenak.
23  */

24
25 package org.objectweb.cjdbc.scenario.standalone.backend;
26
27 import java.sql.SQLException JavaDoc;
28
29 import org.objectweb.cjdbc.common.log.Trace;
30 import org.objectweb.cjdbc.common.sql.schema.DatabaseSchema;
31 import org.objectweb.cjdbc.controller.backend.DatabaseBackendMetaData;
32 import org.objectweb.cjdbc.controller.backend.DatabaseBackendSchemaConstants;
33 import org.objectweb.cjdbc.controller.connection.AbstractConnectionManager;
34 import org.objectweb.cjdbc.scenario.templates.NoTemplate;
35 import org.objectweb.cjdbc.scenario.tools.databases.AbstractDatabase;
36 import org.objectweb.cjdbc.scenario.tools.databases.RUBiSDatabase;
37 import org.objectweb.cjdbc.scenario.tools.databases.TPCWDatabase;
38 import org.objectweb.cjdbc.scenario.tools.mock.MockConnectionManager;
39
40 /**
41  * <code>DatabaseBackendMetaData</code> test class.
42  *
43  * @author <a HREF="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a>
44  * @see org.objectweb.cjdbc.controller.backend.DatabaseBackendMetaData
45  */

46 public class DatabaseBackendMetaDataTest extends NoTemplate
47 {
48
49   /**
50    * @see org.objectweb.cjdbc.controller.backend#createDatabaseSchema()
51    */

52   public void testCreateDatabaseSchema()
53   {
54     // legacy test
55
// ArrayList tables = metaData.getDatabaseSchema().getTables();
56
// int size = tables.size();
57
// System.out.println(size + " tables found");
58
// DatabaseTable table = null;
59
// DatabaseColumn column = null;
60
// ArrayList columns = null;
61
// int nbColumns;
62
// int i, j;
63
// for (i = 0; i < size; i++)
64
// {
65
// table = (DatabaseTable) tables.get(i);
66
// System.out.println("Table found: " + table.getName());
67
// columns = table.getColumns();
68
// nbColumns = columns.size();
69
// System.out.println(nbColumns + " columns found for this table");
70
// for (j = 0; j < nbColumns; j++)
71
// {
72
// column = (DatabaseColumn) columns.get(j);
73
// System.out.println(" Column found: " + column.getName());
74
// if (column.isUnique())
75
// System.out.println(" Is unique: true");
76
// System.out.println(" Column type: " + column.getType());
77
// }
78
// }
79
performTest(new RUBiSDatabase());
80     performTest(new TPCWDatabase());
81   }
82
83   /**
84    * Checks that the meta data of the given database.
85    *
86    * @param database the <code>AbstractDatabase</code> to test.
87    */

88   private void performTest(AbstractDatabase database)
89   {
90     AbstractConnectionManager cm = new MockConnectionManager(database);
91     Trace l = Trace.getLogger("org.objectweb.cjdbc.controller.backend.test");
92     DatabaseBackendMetaData metaData = new DatabaseBackendMetaData(cm, l,
93         DatabaseBackendSchemaConstants.DynamicPrecisionColumn, false,null);
94
95     DatabaseSchema schema = null;
96     try
97     {
98       schema = metaData.getDatabaseSchema();
99     }
100     catch (SQLException JavaDoc e)
101     {
102       fail("Failed to gather schema from database meta data (" + e + ")");
103     }
104     assertTrue(schema.isCompatibleWith(database.getSchema()));
105     assertTrue(database.getSchema().isCompatibleWith(schema));
106   }
107 }
108
Popular Tags