params.put(PORT.key, port);
params.put(USER.key, username);
params.put(PASSWD.key, password);
params.put(DATABASE.key, database);
BasicDataSource dataSource = null;
Connection connection = null;
try {
dataSource = factory.createDataSource(params);
connection = dataSource.getConnection();
Statement statement = connection.createStatement();
if (!hasWritableTable(
"SYSSPATIAL.spatial_ref_sys", "SRID", statement)) { //$NON-NLS-1$
error = "The 'srid' table is either missing or not accessible; the Teradata datastore cannot work without the srid table. Please talk to your database administrator.";
return;
}
// Pair is schema, table name
List<Pair<String, String>> tableNames = new ArrayList<Pair<String, String>>();
ResultSet resultSet = statement
.executeQuery("SELECT F_TABLE_NAME,f_geometry_column FROM SYSSPATIAL.GEOMETRY_COLUMNS ORDER BY F_TABLE_NAME;");
while (resultSet.next()) {
String schema = database; //$NON-NLS-1$
String table = resultSet.getString(1); //$NON-NLS-1$
if (hasWritableTable(database+"."+table, resultSet.getString(2), statement)) { //$NON-NLS-1$
tableNames.add(Pair.create(schema, table));
}
}
if(tableNames.size() > 0) {
Collection<TableDescriptor> results = lookupGeometryColumn(
tableNames, connection);
tables.addAll(results);
}
statement.close();
} catch (SQLException e) {
error = "An error occurred when querying the database about the data it contains. Please talk to the administrator: "
+ e.getMessage();
} catch (IOException io) {
error = "An error occurred when querying the database about the data it contains. Please talk to the administrator: "
+ io.getMessage();
} finally {
if (connection != null) {
connection.close();
}
if (dataSource != null) {
dataSource.close();
}
}
}