Fix problems with depot being unable to create a table called domains on postgres.
This commit is contained in:
@@ -1022,25 +1022,25 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
|
||||
return ctx.invoke(new Fetcher.Trivial<TableMetaData>() {
|
||||
public TableMetaData invoke (PersistenceContext ctx, Connection conn,
|
||||
DatabaseLiaison dl) throws SQLException {
|
||||
return new TableMetaData(conn.getMetaData(), tableName);
|
||||
return new TableMetaData(conn.getMetaData(), dl, tableName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public TableMetaData (DatabaseMetaData meta, String tableName)
|
||||
public TableMetaData (DatabaseMetaData meta, DatabaseLiaison dl, String tableName)
|
||||
throws SQLException
|
||||
{
|
||||
tableExists = meta.getTables(null, null, tableName, null).next();
|
||||
tableExists = meta.getTables(null, dl.getSchemaName(), tableName, null).next();
|
||||
if (!tableExists) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResultSet rs = meta.getColumns(null, null, tableName, "%");
|
||||
ResultSet rs = meta.getColumns(null, dl.getSchemaName(), tableName, "%");
|
||||
while (rs.next()) {
|
||||
tableColumns.add(rs.getString("COLUMN_NAME"));
|
||||
}
|
||||
|
||||
rs = meta.getIndexInfo(null, null, tableName, false, false);
|
||||
rs = meta.getIndexInfo(null, dl.getSchemaName(), tableName, false, false);
|
||||
while (rs.next()) {
|
||||
String indexName = rs.getString("INDEX_NAME");
|
||||
Set<String> set = indexColumns.get(indexName);
|
||||
@@ -1060,7 +1060,7 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
|
||||
}
|
||||
}
|
||||
|
||||
rs = meta.getPrimaryKeys(null, null, tableName);
|
||||
rs = meta.getPrimaryKeys(null, dl.getSchemaName(), tableName);
|
||||
while (rs.next()) {
|
||||
pkName = rs.getString("PK_NAME");
|
||||
pkColumns.add(rs.getString("COLUMN_NAME"));
|
||||
|
||||
@@ -85,7 +85,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
||||
public boolean tableContainsColumn (Connection conn, String table, String column)
|
||||
throws SQLException
|
||||
{
|
||||
ResultSet rs = conn.getMetaData().getColumns(null, null, table, column);
|
||||
ResultSet rs = conn.getMetaData().getColumns(null, getSchemaName(), table, column);
|
||||
while (rs.next()) {
|
||||
String tname = rs.getString("TABLE_NAME");
|
||||
String cname = rs.getString("COLUMN_NAME");
|
||||
@@ -100,7 +100,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
||||
public boolean tableContainsIndex (Connection conn, String table, String index)
|
||||
throws SQLException
|
||||
{
|
||||
ResultSet rs = conn.getMetaData().getIndexInfo(null, null, table, false, true);
|
||||
ResultSet rs = conn.getMetaData().getIndexInfo(null, getSchemaName(), table, false, true);
|
||||
while (rs.next()) {
|
||||
String tname = rs.getString("TABLE_NAME");
|
||||
String iname = rs.getString("INDEX_NAME");
|
||||
@@ -298,6 +298,12 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
||||
return true;
|
||||
}
|
||||
|
||||
// from DatabaseLiaison
|
||||
public String getSchemaName ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// from DatabaseLiaison
|
||||
public abstract String tableSQL (String table);
|
||||
|
||||
|
||||
@@ -203,6 +203,11 @@ public interface DatabaseLiaison
|
||||
public boolean dropTable (Connection conn, String name)
|
||||
throws SQLException;
|
||||
|
||||
/**
|
||||
* Get the schema name to pass to DatabaseMetaData calls, which may be null.
|
||||
*/
|
||||
public String getSchemaName ();
|
||||
|
||||
/**
|
||||
* Returns the proper SQL to identify a table. Some databases require table names to be quoted.
|
||||
*/
|
||||
|
||||
@@ -119,6 +119,14 @@ public class PostgreSQLLiaison extends BaseLiaison
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSchemaName ()
|
||||
{
|
||||
// TODO: is this global to all postgres? Should this be discovered by asking
|
||||
// DatabaseMetaData.getSchemas()?
|
||||
return "public";
|
||||
}
|
||||
|
||||
// from DatabaseLiaison
|
||||
public String columnSQL (String column)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user