01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.postgis;
17:
18: import java.sql.Connection;
19: import java.sql.SQLException;
20: import java.sql.Statement;
21:
22: import javax.sql.DataSource;
23:
24: import org.geotools.data.jdbc.ConnectionPool;
25: import org.geotools.data.jdbc.JDBCUtils;
26:
27: /**
28: * A few methods shared by multiple classes
29: *
30: * @author aaime
31: *
32: */
33: public class SqlTestUtils {
34:
35: protected static void dropTable(DataSource pool, String tableName,
36: boolean geomColumns) throws SQLException {
37: Connection conn = null;
38: Statement st = null;
39: try {
40: conn = pool.getConnection();
41: st = conn.createStatement();
42: if (geomColumns)
43: st
44: .execute("DELETE FROM GEOMETRY_COLUMNS WHERE F_TABLE_NAME = '"
45: + tableName + "'");
46: st.execute("DROP TABLE " + tableName + " CASCADE");
47: } catch (SQLException e) {
48: // no problem, the drop may fail
49: System.out.println(e.getMessage());
50: } finally {
51: JDBCUtils.close(st);
52: JDBCUtils.close(conn, null, null);
53: }
54: }
55:
56: protected static void execute(DataSource pool, String sql)
57: throws SQLException {
58: Connection conn = null;
59: Statement st = null;
60: try {
61: conn = pool.getConnection();
62: st = conn.createStatement();
63: st.execute(sql);
64: conn.commit();
65: } finally {
66: JDBCUtils.close(st);
67: JDBCUtils.close(conn, null, null);
68: }
69: }
70:
71: }
|