mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 15:33:09 +00:00
Fix DS-2427 for 5.1 by consolidating problematic code into DatabaseUtils.getSchemaName() so that it can be replaced easily in future. Also cleaned up config comments
This commit is contained in:
@@ -66,14 +66,12 @@ db.password=dspace
|
|||||||
#db.username=dspace
|
#db.username=dspace
|
||||||
#db.password=dspace
|
#db.password=dspace
|
||||||
|
|
||||||
# Schema name - if your database contains multiple schemas, you can avoid problems with
|
# Schema name - if your database contains multiple schemas, you can avoid
|
||||||
# retrieving the definitions of duplicate object names by specifying
|
# problems with retrieving the definitions of duplicate object names by
|
||||||
# the schema name here that is used for DSpace by uncommenting the following entry
|
# specifying the schema name that is used for DSpace.
|
||||||
|
# ORACLE USAGE NOTE: In Oracle, schema is equivalent to "username". This means
|
||||||
# NOTE: this configuration option is for PostgreSQL only. For Oracle, schema is equivalent
|
# specifying a "db.schema" is often unnecessary (i.e. you can leave it blank),
|
||||||
# to user name. DSpace depends on the PostgreSQL understanding of schema. If you are using
|
# UNLESS your Oracle DB Account (in db.username) has access to multiple schemas.
|
||||||
# Oracle, just leave this this value blank.
|
|
||||||
|
|
||||||
db.schema =
|
db.schema =
|
||||||
|
|
||||||
# Maximum number of DB connections in pool
|
# Maximum number of DB connections in pool
|
||||||
|
@@ -15,7 +15,6 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.ResultSetMetaData;
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.SQLWarning;
|
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.sql.Time;
|
import java.sql.Time;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
@@ -35,8 +34,6 @@ import javax.sql.DataSource;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.core.ConfigurationManager;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.flywaydb.core.Flyway;
|
|
||||||
import org.flywaydb.core.api.MigrationInfo;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -1237,10 +1234,6 @@ public class DatabaseManager
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String schema = canonicalize(ConfigurationManager.getProperty("db.schema"));
|
|
||||||
if(StringUtils.isBlank(schema)){
|
|
||||||
schema = null;
|
|
||||||
}
|
|
||||||
String catalog = null;
|
String catalog = null;
|
||||||
|
|
||||||
int dotIndex = table.indexOf('.');
|
int dotIndex = table.indexOf('.');
|
||||||
@@ -1254,6 +1247,9 @@ public class DatabaseManager
|
|||||||
|
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
|
|
||||||
|
// Get current database schema name
|
||||||
|
String schema = DatabaseUtils.getSchemaName(connection);
|
||||||
|
|
||||||
DatabaseMetaData metadata = connection.getMetaData();
|
DatabaseMetaData metadata = connection.getMetaData();
|
||||||
Map<String, ColumnInfo> results = new HashMap<String, ColumnInfo>();
|
Map<String, ColumnInfo> results = new HashMap<String, ColumnInfo>();
|
||||||
|
|
||||||
|
@@ -873,8 +873,10 @@ public class DatabaseUtils
|
|||||||
* Get the Database Schema Name in use by this Connection, so that it can
|
* Get the Database Schema Name in use by this Connection, so that it can
|
||||||
* be used to limit queries in other methods (e.g. tableExists()).
|
* be used to limit queries in other methods (e.g. tableExists()).
|
||||||
* <P>
|
* <P>
|
||||||
* For PostgreSQL, schema is simply what is configured in db.schema or "public"
|
* NOTE: Once we upgrade to using Apache Commons DBCP / Pool version 2.0,
|
||||||
* For Oracle, schema is actually the database *USER* or owner.
|
* this method WILL BE REMOVED in favor of java.sql.Connection's new
|
||||||
|
* "getSchema()" method.
|
||||||
|
* http://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html#getSchema()
|
||||||
*
|
*
|
||||||
* @param connection
|
* @param connection
|
||||||
* Current Database Connection
|
* Current Database Connection
|
||||||
@@ -886,27 +888,29 @@ public class DatabaseUtils
|
|||||||
String schema = null;
|
String schema = null;
|
||||||
DatabaseMetaData meta = connection.getMetaData();
|
DatabaseMetaData meta = connection.getMetaData();
|
||||||
|
|
||||||
// Determine our DB type
|
// Check the configured "db.schema" FIRST for the value configured there
|
||||||
|
schema = ConfigurationManager.getProperty("db.schema");
|
||||||
|
|
||||||
|
// If unspecified, determine "sane" defaults based on DB type
|
||||||
|
if(StringUtils.isBlank(schema))
|
||||||
|
{
|
||||||
String dbType = DatabaseManager.findDbKeyword(meta);
|
String dbType = DatabaseManager.findDbKeyword(meta);
|
||||||
|
|
||||||
if(dbType.equals(DatabaseManager.DBMS_POSTGRES))
|
if(dbType.equals(DatabaseManager.DBMS_POSTGRES))
|
||||||
{
|
{
|
||||||
// Get the schema name from "db.schema"
|
// For PostgreSQL, the default schema is named "public"
|
||||||
schema = ConfigurationManager.getProperty("db.schema");
|
// See: http://www.postgresql.org/docs/9.0/static/ddl-schemas.html
|
||||||
|
|
||||||
// If unspecified, default schema is "public"
|
|
||||||
if(StringUtils.isBlank(schema)){
|
|
||||||
schema = "public";
|
schema = "public";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (dbType.equals(DatabaseManager.DBMS_ORACLE))
|
else if (dbType.equals(DatabaseManager.DBMS_ORACLE))
|
||||||
{
|
{
|
||||||
// Schema is actually the user account
|
// For Oracle, default schema is actually the user account
|
||||||
// See: http://stackoverflow.com/a/13341390
|
// See: http://stackoverflow.com/a/13341390
|
||||||
schema = meta.getUserName();
|
schema = meta.getUserName();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
schema = null;
|
schema = null;
|
||||||
|
}
|
||||||
|
|
||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
|
@@ -63,9 +63,9 @@ db.password = ${db.password}
|
|||||||
# Schema name - if your database contains multiple schemas, you can avoid
|
# Schema name - if your database contains multiple schemas, you can avoid
|
||||||
# problems with retrieving the definitions of duplicate object names by
|
# problems with retrieving the definitions of duplicate object names by
|
||||||
# specifying the schema name that is used for DSpace.
|
# specifying the schema name that is used for DSpace.
|
||||||
# NOTE: this configuration option is for PostgreSQL only. For Oracle, schema
|
# ORACLE USAGE NOTE: In Oracle, schema is equivalent to "username". This means
|
||||||
# is equivalent to user name. DSpace depends on the PostgreSQL understanding
|
# specifying a "db.schema" is often unnecessary (i.e. you can leave it blank),
|
||||||
# of schema. If you are using Oracle, just leave this this value blank.
|
# UNLESS your Oracle DB Account (in db.username) has access to multiple schemas.
|
||||||
db.schema = ${db.schema}
|
db.schema = ${db.schema}
|
||||||
|
|
||||||
## Connection pool parameters
|
## Connection pool parameters
|
||||||
|
Reference in New Issue
Block a user