KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > ProbeTable


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: ProbeTable.java,v 1.2 2002/10/17 21:00:57 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import java.sql.Connection JavaDoc;
14 import java.sql.DatabaseMetaData JavaDoc;
15 import java.sql.ResultSet JavaDoc;
16 import java.sql.SQLException JavaDoc;
17 import javax.jdo.JDODataStoreException;
18
19
20 class ProbeTable extends BaseTable
21 {
22     public ProbeTable(StoreManager storeMgr)
23     {
24         super(storeMgr);
25
26         name = new TableIdentifier(dba, "deleteMe" + System.currentTimeMillis());
27     }
28
29
30     public void initialize()
31     {
32         assertIsUninitialized();
33
34         dba.getMapping(newColumn(int.class, "unused"));
35
36         state = TABLE_STATE_INITIALIZED;
37     }
38
39
40     public String JavaDoc findSchemaName(Connection JavaDoc conn) throws SQLException JavaDoc
41     {
42         String JavaDoc schemaName = null;
43         DatabaseMetaData JavaDoc dmd = conn.getMetaData();
44
45         ResultSet JavaDoc rs = dmd.getTables(null, null, name.getSQLIdentifier(), null);
46
47         try
48         {
49             if (!rs.next())
50                 throw new JDODataStoreException("Cannot find probe table " + name);
51
52             schemaName = rs.getString(2);
53         }
54         finally
55         {
56             rs.close();
57         }
58
59         return schemaName;
60     }
61 }
62
Popular Tags