mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
Merge pull request #635 from mwoodiupui/DS-2128
[DS-2128] Eliminate dspace.cfg:db.name
This commit is contained in:
@@ -43,9 +43,6 @@ default.language = en_US
|
||||
# DATABASE CONFIGURATION #
|
||||
##########################
|
||||
|
||||
# Database name ("oracle", or "postgres")
|
||||
db.name=postgres
|
||||
|
||||
# Uncomment the appropriate block below for your database.
|
||||
# postgres
|
||||
db.driver=org.postgresql.Driver
|
||||
|
@@ -1143,11 +1143,7 @@ public class LogAnalyser
|
||||
public static Integer getNumItems(Context context, String type)
|
||||
throws SQLException
|
||||
{
|
||||
boolean oracle = false;
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
{
|
||||
oracle = true;
|
||||
}
|
||||
boolean oracle = DatabaseManager.isOracle();
|
||||
|
||||
// FIXME: this method is clearly not optimised
|
||||
|
||||
|
@@ -9,6 +9,7 @@ package org.dspace.browse;
|
||||
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
|
||||
/**
|
||||
* Factory class to generate DAOs based on the configuration
|
||||
@@ -87,18 +88,13 @@ public class BrowseDAOFactory
|
||||
public static BrowseItemDAO getItemInstance(Context context)
|
||||
throws BrowseException
|
||||
{
|
||||
String db = ConfigurationManager.getProperty("db.name");
|
||||
if ("postgres".equals(db))
|
||||
if (! DatabaseManager.isOracle())
|
||||
{
|
||||
return new BrowseItemDAOPostgres(context);
|
||||
}
|
||||
else if ("oracle".equals(db))
|
||||
{
|
||||
return new BrowseItemDAOOracle(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BrowseException("The configuration for db.name is either invalid, or contains an unrecognised database");
|
||||
return new BrowseItemDAOOracle(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,18 +109,13 @@ public class BrowseDAOFactory
|
||||
public static BrowseDAOUtils getUtils(Context context)
|
||||
throws BrowseException
|
||||
{
|
||||
String db = ConfigurationManager.getProperty("db.name");
|
||||
if ("postgres".equals(db))
|
||||
if (! DatabaseManager.isOracle())
|
||||
{
|
||||
return new BrowseDAOUtilsPostgres();
|
||||
}
|
||||
else if ("oracle".equals(db))
|
||||
else
|
||||
{
|
||||
return new BrowseDAOUtilsOracle();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BrowseException("The configuration for db.name is either invalid, or contains an unrecognised database");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -32,16 +32,16 @@ import org.dspace.sort.OrderFormat;
|
||||
public class BrowseEngine
|
||||
{
|
||||
/** the logger for this class */
|
||||
private static Logger log = Logger.getLogger(BrowseEngine.class);
|
||||
private static final Logger log = Logger.getLogger(BrowseEngine.class);
|
||||
|
||||
/** the browse scope which is the basis for our browse */
|
||||
private BrowserScope scope;
|
||||
|
||||
/** the DSpace context */
|
||||
private Context context;
|
||||
private final Context context;
|
||||
|
||||
/** The Data Access Object for the browse tables */
|
||||
private BrowseDAO dao;
|
||||
private final BrowseDAO dao;
|
||||
|
||||
/** The Browse Index associated with the Browse Scope */
|
||||
private BrowseIndex browseIndex;
|
||||
@@ -49,7 +49,7 @@ public class BrowseEngine
|
||||
/**
|
||||
* Create a new instance of the Browse engine, using the given DSpace
|
||||
* Context object. This will automatically assign a Data Access Object
|
||||
* for the Browse Engine, based on the dspace.cfg setting for db.name
|
||||
* for the Browse Engine, based on the brand of the provided DBMS.
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @throws BrowseException
|
||||
|
@@ -12,7 +12,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
@@ -28,6 +27,7 @@ import org.dspace.discovery.SolrServiceIndexPlugin;
|
||||
import org.dspace.sort.OrderFormat;
|
||||
import org.dspace.sort.SortException;
|
||||
import org.dspace.sort.SortOption;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
import org.dspace.utils.DSpace;
|
||||
|
||||
/**
|
||||
@@ -68,19 +68,13 @@ public class SolrBrowseCreateDAO implements BrowseCreateDAO,
|
||||
public SolrBrowseCreateDAO(Context context) throws BrowseException
|
||||
{
|
||||
// For compatibility with previous versions
|
||||
String db = ConfigurationManager.getProperty("db.name");
|
||||
if ("postgres".equals(db))
|
||||
if (! DatabaseManager.isOracle())
|
||||
{
|
||||
dbCreateDAO = new BrowseCreateDAOPostgres(context);
|
||||
}
|
||||
else if ("oracle".equals(db))
|
||||
{
|
||||
dbCreateDAO = new BrowseCreateDAOOracle(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BrowseException(
|
||||
"The configuration for db.name is either invalid, or contains an unrecognised database");
|
||||
dbCreateDAO = new BrowseCreateDAOOracle(context);
|
||||
}
|
||||
|
||||
try
|
||||
|
@@ -285,7 +285,7 @@ public final class BitstreamInfoDAO extends DAOSupport
|
||||
{
|
||||
LOG.debug("updating missing bitstreams");
|
||||
conn = DatabaseManager.getConnection();
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
stmt = conn.prepareStatement(INSERT_MISSING_CHECKSUM_BITSTREAMS_ORACLE);
|
||||
}
|
||||
@@ -398,7 +398,7 @@ public final class BitstreamInfoDAO extends DAOSupport
|
||||
{
|
||||
|
||||
conn = DatabaseManager.getConnection();
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
prepStmt = conn.prepareStatement(GET_OLDEST_BITSTREAM_ORACLE);
|
||||
}
|
||||
@@ -445,7 +445,7 @@ public final class BitstreamInfoDAO extends DAOSupport
|
||||
try
|
||||
{
|
||||
conn = DatabaseManager.getConnection();
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
prepStmt = conn.prepareStatement(GET_OLDEST_BITSTREAM_DATE_ORACLE);
|
||||
}
|
||||
|
@@ -111,7 +111,7 @@ public class ChecksumHistoryDAO extends DAOSupport
|
||||
try
|
||||
{
|
||||
conn = DatabaseManager.getConnection();
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
stmt = conn.prepareStatement(INSERT_HISTORY_ORACLE);
|
||||
}
|
||||
@@ -183,7 +183,7 @@ public class ChecksumHistoryDAO extends DAOSupport
|
||||
PreparedStatement stmt = null;
|
||||
try
|
||||
{
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
stmt = conn.prepareStatement(INSERT_MISSING_HISTORY_BITSTREAMS_ORACLE);
|
||||
}
|
||||
|
@@ -180,7 +180,7 @@ public class ReporterDAO extends DAOSupport
|
||||
// create the connection and execute the statement
|
||||
conn = DatabaseManager.getConnection();
|
||||
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
prepStmt = conn.prepareStatement(DATE_RANGE_NOT_PROCESSED_BITSTREAMS_ORACLE);
|
||||
}
|
||||
|
@@ -531,11 +531,7 @@ public class Bitstream extends DSpaceObject
|
||||
*/
|
||||
void delete() throws SQLException
|
||||
{
|
||||
boolean oracle = false;
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
{
|
||||
oracle = true;
|
||||
}
|
||||
boolean oracle = DatabaseManager.isOracle();
|
||||
|
||||
// changed to a check on remove
|
||||
// Check authorisation
|
||||
|
@@ -8,7 +8,7 @@
|
||||
package org.dspace.content.dao;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -21,7 +21,7 @@ public class ItemDAOFactory
|
||||
{
|
||||
public static ItemDAO getInstance(Context context)
|
||||
{
|
||||
if (ConfigurationManager.getProperty("db.name").equalsIgnoreCase("oracle"))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
return new ItemDAOOracle(context);
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.GnuParser;
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.OptionGroup;
|
||||
@@ -60,13 +59,13 @@ public class EPerson extends DSpaceObject
|
||||
public static final int LANGUAGE = 5;
|
||||
|
||||
/** log4j logger */
|
||||
private static Logger log = Logger.getLogger(EPerson.class);
|
||||
private static final Logger log = Logger.getLogger(EPerson.class);
|
||||
|
||||
/** Our context */
|
||||
private Context myContext;
|
||||
private final Context myContext;
|
||||
|
||||
/** The row in the table representing this eperson */
|
||||
private TableRow myRow;
|
||||
private final TableRow myRow;
|
||||
|
||||
/** Flag set when data is modified, for events */
|
||||
private boolean modified;
|
||||
@@ -295,7 +294,7 @@ public class EPerson extends DSpaceObject
|
||||
queryBuf.append("LOWER(firstname) LIKE LOWER(?) OR LOWER(lastname) LIKE LOWER(?) OR LOWER(email) LIKE LOWER(?) ORDER BY lastname, firstname ASC ");
|
||||
|
||||
// Add offset and limit restrictions - Oracle requires special code
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
// First prepare the query to generate row numbers
|
||||
if (limit > 0 || offset > 0)
|
||||
@@ -431,7 +430,7 @@ public class EPerson extends DSpaceObject
|
||||
new Object[] {int_param,dbquery,dbquery,dbquery});
|
||||
|
||||
// use getIntColumn for Oracle count data
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
count = Long.valueOf(row.getIntColumn("epcount"));
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ public class Group extends DSpaceObject
|
||||
public static final int NAME = 1; // sort by NAME (default)
|
||||
|
||||
/** log4j logger */
|
||||
private static Logger log = Logger.getLogger(Group.class);
|
||||
private static final Logger log = Logger.getLogger(Group.class);
|
||||
|
||||
/** ID of Anonymous Group */
|
||||
public static final int ANONYMOUS_ID = 0;
|
||||
@@ -55,10 +55,10 @@ public class Group extends DSpaceObject
|
||||
public static final int ADMIN_ID = 1;
|
||||
|
||||
/** Our context */
|
||||
private Context myContext;
|
||||
private final Context myContext;
|
||||
|
||||
/** The row in the table representing this object */
|
||||
private TableRow myRow;
|
||||
private final TableRow myRow;
|
||||
|
||||
/** lists of epeople and groups in the group */
|
||||
private List<EPerson> epeople = new ArrayList<EPerson>();
|
||||
@@ -852,7 +852,7 @@ public class Group extends DSpaceObject
|
||||
queryBuf.append("SELECT * FROM epersongroup WHERE LOWER(name) LIKE LOWER(?) OR eperson_group_id = ? ORDER BY name ASC ");
|
||||
|
||||
// Add offset and limit restrictions - Oracle requires special code
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
// First prepare the query to generate row numbers
|
||||
if (limit > 0 || offset > 0)
|
||||
@@ -985,7 +985,7 @@ public class Group extends DSpaceObject
|
||||
|
||||
// use getIntColumn for Oracle count data
|
||||
Long count;
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
count = Long.valueOf(row.getIntColumn("gcount"));
|
||||
}
|
||||
|
@@ -27,8 +27,8 @@ import java.util.List;
|
||||
|
||||
public class HarvestedCollection
|
||||
{
|
||||
private Context context;
|
||||
private TableRow harvestRow;
|
||||
private final Context context;
|
||||
private final TableRow harvestRow;
|
||||
|
||||
public static final int TYPE_NONE = 0;
|
||||
public static final int TYPE_DMD = 1;
|
||||
@@ -238,7 +238,7 @@ public class HarvestedCollection
|
||||
public static Integer findOldestHarvest (Context c) throws SQLException {
|
||||
String query = "select collection_id from harvested_collection where harvest_type > ? and harvest_status = ? order by last_harvested asc limit 1";
|
||||
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
query = "select collection_id from harvested_collection where harvest_type > ? and harvest_status = ? and rownum <= 1 order by last_harvested asc";
|
||||
}
|
||||
@@ -263,7 +263,7 @@ public class HarvestedCollection
|
||||
public static Integer findNewestHarvest (Context c) throws SQLException {
|
||||
String query = "select collection_id from harvested_collection where harvest_type > ? and harvest_status = ? order by last_harvested desc limit 1";
|
||||
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
query = "select collection_id from harvested_collection where harvest_type > ? and harvest_status = ? and rownum <= 1 order by last_harvested desc";
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ import java.util.*;
|
||||
public class Harvest
|
||||
{
|
||||
/** log4j logger */
|
||||
private static Logger log = Logger.getLogger(Harvest.class);
|
||||
private static final Logger log = Logger.getLogger(Harvest.class);
|
||||
|
||||
/**
|
||||
* Obtain information about items that have been created, modified or
|
||||
@@ -173,7 +173,7 @@ public class Harvest
|
||||
if (!withdrawn)
|
||||
{
|
||||
// Exclude withdrawn items
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
if (DatabaseManager.isOracle())
|
||||
{
|
||||
query += " AND withdrawn=0 ";
|
||||
}
|
||||
|
@@ -7,6 +7,11 @@
|
||||
*/
|
||||
package org.dspace.storage.rdbms;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.DataSource;
|
||||
import org.apache.commons.dbcp.*;
|
||||
import org.apache.commons.pool.ObjectPool;
|
||||
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
|
||||
@@ -15,13 +20,8 @@ import org.apache.commons.pool.impl.GenericObjectPool;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DataSourceInit {
|
||||
private static Logger log = Logger.getLogger(DataSourceInit.class);
|
||||
private static final Logger log = Logger.getLogger(DataSourceInit.class);
|
||||
|
||||
private static DataSource dataSource = null;
|
||||
|
||||
@@ -94,12 +94,6 @@ public class DataSourceInit {
|
||||
//
|
||||
String validationQuery = "SELECT 1";
|
||||
|
||||
// Oracle has a slightly different validation query
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
{
|
||||
validationQuery = "SELECT 1 FROM DUAL";
|
||||
}
|
||||
|
||||
GenericKeyedObjectPoolFactory statementFactory = null;
|
||||
if (useStatementPool)
|
||||
{
|
||||
@@ -139,6 +133,16 @@ public class DataSourceInit {
|
||||
poolingDataSource.setPool(connectionPool);
|
||||
|
||||
dataSource = poolingDataSource;
|
||||
|
||||
// Set the proper validation query by DBMS brand.
|
||||
Connection connection = dataSource.getConnection();
|
||||
if ("oracle".equals(connection.getMetaData().getDatabaseProductName().toLowerCase()))
|
||||
{
|
||||
poolableConnectionFactory.setValidationQuery("SELECT 1 FROM DUAL");
|
||||
}
|
||||
connection.close();
|
||||
|
||||
// Ready to use
|
||||
return poolingDataSource;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@@ -26,18 +26,17 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.Level;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Executes SQL queries.
|
||||
@@ -48,8 +47,8 @@ import org.dspace.core.Context;
|
||||
*/
|
||||
public class DatabaseManager
|
||||
{
|
||||
/** log4j category */
|
||||
private static final Logger log = Logger.getLogger(DatabaseManager.class);
|
||||
/** logging category */
|
||||
private static final Logger log = LoggerFactory.getLogger(DatabaseManager.class);
|
||||
|
||||
/** True if initialization has been done */
|
||||
private static boolean initialized = false;
|
||||
@@ -59,23 +58,12 @@ public class DatabaseManager
|
||||
private static boolean isOracle = false;
|
||||
private static boolean isPostgres = false;
|
||||
|
||||
static
|
||||
{
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||
{
|
||||
isOracle = true;
|
||||
isPostgres = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
isOracle = false;
|
||||
isPostgres = true;
|
||||
}
|
||||
}
|
||||
|
||||
/** DataSource (retrieved from jndi */
|
||||
private static DataSource dataSource = null;
|
||||
|
||||
/** Name of the DBMS, as returned by its driver. */
|
||||
private static String dbms;
|
||||
|
||||
/** Name to use for the pool */
|
||||
private static String poolName = "dspacepool";
|
||||
|
||||
@@ -106,6 +94,13 @@ public class DatabaseManager
|
||||
|
||||
public static boolean isOracle()
|
||||
{
|
||||
try
|
||||
{
|
||||
initialize();
|
||||
} catch (SQLException ex)
|
||||
{
|
||||
log.error("Failed to initialize the database: ", ex);
|
||||
}
|
||||
return isOracle;
|
||||
}
|
||||
|
||||
@@ -988,21 +983,15 @@ public class DatabaseManager
|
||||
|
||||
// If the messages are bogus, give them a low priority
|
||||
if (isDrop || isNoResults)
|
||||
{
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug(msg, sqle);
|
||||
}
|
||||
}
|
||||
// Otherwise, we need to know!
|
||||
else
|
||||
{
|
||||
if (log.isEnabledFor(Level.WARN))
|
||||
{
|
||||
log.warn(msg, sqle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset SQL buffer
|
||||
sqlBuilder = new StringBuilder();
|
||||
@@ -1487,6 +1476,33 @@ public class DatabaseManager
|
||||
dataSource = DataSourceInit.getDatasource();
|
||||
}
|
||||
|
||||
// What brand of DBMS do we have?
|
||||
Connection connection = dataSource.getConnection();
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
dbms = meta.getDatabaseProductName();
|
||||
String dbms_lc = dbms.toLowerCase(Locale.ROOT);
|
||||
if (dbms_lc.contains("postgresql"))
|
||||
{
|
||||
isPostgres = true;
|
||||
log.info("DBMS is PostgreSQL");
|
||||
}
|
||||
else if (dbms_lc.contains("oracle"))
|
||||
{
|
||||
isOracle = true;
|
||||
log.info("DBMS is Oracle Database");
|
||||
}
|
||||
else if (dbms_lc.contains("h2")) // Used in testing
|
||||
{
|
||||
isOracle = true;
|
||||
log.info("DBMS is H2");
|
||||
}
|
||||
else
|
||||
{
|
||||
log.error("DBMS {} is unsupported", dbms);
|
||||
}
|
||||
log.info("DBMS driver version is '{}'", meta.getDatabaseProductVersion());
|
||||
connection.close();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
catch (SQLException se)
|
||||
@@ -1503,6 +1519,21 @@ public class DatabaseManager
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What is the name of our DBMS?
|
||||
*
|
||||
* @return name returned by the DBMS driver.
|
||||
*/
|
||||
public static String getDbName()
|
||||
{
|
||||
try {
|
||||
initialize();
|
||||
} catch (SQLException ex) {
|
||||
log.error("Failed to initialize the database: ", ex);
|
||||
}
|
||||
return dbms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over the given parameters and add them to the given prepared statement.
|
||||
* Only a select number of datatypes are supported by the JDBC driver.
|
||||
|
@@ -11,9 +11,9 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.utils.DSpace;
|
||||
|
||||
/**
|
||||
* Command-line executed class for initializing the DSpace database. This should
|
||||
@@ -25,7 +25,7 @@ import org.dspace.utils.DSpace;
|
||||
public class InitializeDatabase
|
||||
{
|
||||
/** log4j category */
|
||||
private static Logger log = Logger.getLogger(InitializeDatabase.class);
|
||||
private static final Logger log = Logger.getLogger(InitializeDatabase.class);
|
||||
|
||||
public static void main(String[] argv)
|
||||
{
|
||||
@@ -61,13 +61,13 @@ public class InitializeDatabase
|
||||
|
||||
/**
|
||||
* Attempt to get the named script, with the following rules:
|
||||
* etc/<db.name>/<name>
|
||||
* etc/<DBMS name>/<name>
|
||||
* etc/<name>
|
||||
* <name>
|
||||
*/
|
||||
private static FileReader getScript(String name) throws FileNotFoundException, IOException
|
||||
{
|
||||
String dbName = new DSpace().getConfigurationService().getProperty("db.name") ;
|
||||
String dbName = DatabaseManager.getDbName().toLowerCase(Locale.ROOT);
|
||||
|
||||
File myFile = null;
|
||||
|
||||
|
@@ -10,7 +10,6 @@ package org.dspace.xmlworkflow.storedcomponents;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.InProgressSubmission;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.LogManager;
|
||||
import org.dspace.storage.rdbms.TableRow;
|
||||
@@ -40,15 +39,15 @@ public class XmlWorkflowItem implements InProgressSubmission {
|
||||
/*
|
||||
* The current step in the workflow system in which this workflow item is present
|
||||
*/
|
||||
private static Logger log = Logger.getLogger(XmlWorkflowItem.class);
|
||||
private static final Logger log = Logger.getLogger(XmlWorkflowItem.class);
|
||||
|
||||
private Collection collection;
|
||||
|
||||
private Item item;
|
||||
|
||||
private TableRow wfRow;
|
||||
private final TableRow wfRow;
|
||||
|
||||
private Context ourContext;
|
||||
private final Context ourContext;
|
||||
|
||||
|
||||
public static XmlWorkflowItem create(Context context) throws AuthorizeException, IOException, SQLException {
|
||||
@@ -181,7 +180,7 @@ public class XmlWorkflowItem implements InProgressSubmission {
|
||||
query.append("WHERE collection_id=").append(collectionId);
|
||||
}
|
||||
int offset = (page - 1) * pagesize;
|
||||
if ("oracle".equals(ConfigurationManager.getProperty("db.name"))) {
|
||||
if (DatabaseManager.isOracle()) {
|
||||
// First prepare the query to generate row numbers
|
||||
if (pagesize > 0 || offset > 0) {
|
||||
query.insert(0, "SELECT /*+ FIRST_ROWS(n) */ rec.*, ROWNUM rnum FROM (");
|
||||
|
@@ -0,0 +1,684 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.storage.rdbms;
|
||||
|
||||
import org.dspace.AbstractUnitTest;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author mhwood
|
||||
*/
|
||||
public class DatabaseManagerTest
|
||||
extends AbstractUnitTest
|
||||
{
|
||||
|
||||
public DatabaseManagerTest()
|
||||
{
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass()
|
||||
{
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass()
|
||||
{
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of isOracle method, of class DatabaseManager.
|
||||
*/
|
||||
@Test
|
||||
public void testIsOracle()
|
||||
{
|
||||
System.out.println("isOracle");
|
||||
boolean expResult = true;
|
||||
boolean result = DatabaseManager.isOracle();
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of setConstraintDeferred method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testSetConstraintDeferred() throws Exception
|
||||
{
|
||||
System.out.println("setConstraintDeferred");
|
||||
Context context = null;
|
||||
String constraintName = "";
|
||||
DatabaseManager.setConstraintDeferred(context, constraintName);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of setConstraintImmediate method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testSetConstraintImmediate() throws Exception
|
||||
{
|
||||
System.out.println("setConstraintImmediate");
|
||||
Context context = null;
|
||||
String constraintName = "";
|
||||
DatabaseManager.setConstraintImmediate(context, constraintName);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of queryTable method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testQueryTable() throws Exception
|
||||
{
|
||||
System.out.println("queryTable");
|
||||
Context context = null;
|
||||
String table = "";
|
||||
String query = "";
|
||||
Object[] parameters = null;
|
||||
TableRowIterator expResult = null;
|
||||
TableRowIterator result = DatabaseManager.queryTable(context, table,
|
||||
query, parameters);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of query method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testQuery() throws Exception
|
||||
{
|
||||
System.out.println("query");
|
||||
Context context = null;
|
||||
String query = "";
|
||||
Object[] parameters = null;
|
||||
TableRowIterator expResult = null;
|
||||
TableRowIterator result = DatabaseManager.query(context, query,
|
||||
parameters);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of querySingle method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testQuerySingle() throws Exception
|
||||
{
|
||||
System.out.println("querySingle");
|
||||
Context context = null;
|
||||
String query = "";
|
||||
Object[] parameters = null;
|
||||
TableRow expResult = null;
|
||||
TableRow result = DatabaseManager.querySingle(context, query, parameters);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of querySingleTable method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testQuerySingleTable() throws Exception
|
||||
{
|
||||
System.out.println("querySingleTable");
|
||||
Context context = null;
|
||||
String table = "";
|
||||
String query = "";
|
||||
Object[] parameters = null;
|
||||
TableRow expResult = null;
|
||||
TableRow result = DatabaseManager.querySingleTable(context, table, query,
|
||||
parameters);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* Test of updateQuery method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testUpdateQuery() throws Exception
|
||||
{
|
||||
System.out.println("updateQuery");
|
||||
Context context = null;
|
||||
String query = "";
|
||||
Object[] parameters = null;
|
||||
int expResult = 0;
|
||||
int result = DatabaseManager.updateQuery(context, query, parameters);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of create method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testCreate() throws Exception
|
||||
{
|
||||
System.out.println("create");
|
||||
Context context = null;
|
||||
String table = "";
|
||||
TableRow expResult = null;
|
||||
TableRow result = DatabaseManager.create(context, table);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of find method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testFind() throws Exception
|
||||
{
|
||||
System.out.println("find");
|
||||
Context context = null;
|
||||
String table = "";
|
||||
int id = 0;
|
||||
TableRow expResult = null;
|
||||
TableRow result = DatabaseManager.find(context, table, id);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of findByUnique method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testFindByUnique() throws Exception
|
||||
{
|
||||
System.out.println("findByUnique");
|
||||
Context context = null;
|
||||
String table = "";
|
||||
String column = "";
|
||||
Object value = null;
|
||||
TableRow expResult = null;
|
||||
TableRow result = DatabaseManager.findByUnique(context, table, column,
|
||||
value);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of delete method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testDelete_3args() throws Exception
|
||||
{
|
||||
System.out.println("delete");
|
||||
Context context = null;
|
||||
String table = "";
|
||||
int id = 0;
|
||||
int expResult = 0;
|
||||
int result = DatabaseManager.delete(context, table, id);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of deleteByValue method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testDeleteByValue() throws Exception
|
||||
{
|
||||
System.out.println("deleteByValue");
|
||||
Context context = null;
|
||||
String table = "";
|
||||
String column = "";
|
||||
Object value = null;
|
||||
int expResult = 0;
|
||||
int result = DatabaseManager.deleteByValue(context, table, column, value);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getConnection method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetConnection() throws Exception
|
||||
{
|
||||
System.out.println("getConnection");
|
||||
Connection expResult = null;
|
||||
Connection result = DatabaseManager.getConnection();
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getDataSource method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetDataSource()
|
||||
{
|
||||
System.out.println("getDataSource");
|
||||
DataSource expResult = null;
|
||||
DataSource result = DatabaseManager.getDataSource();
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of freeConnection method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testFreeConnection()
|
||||
{
|
||||
System.out.println("freeConnection");
|
||||
Connection c = null;
|
||||
DatabaseManager.freeConnection(c);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of row method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testRow() throws Exception
|
||||
{
|
||||
System.out.println("row");
|
||||
String table = "";
|
||||
TableRow expResult = null;
|
||||
TableRow result = DatabaseManager.row(table);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of insert method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testInsert() throws Exception
|
||||
{
|
||||
System.out.println("insert");
|
||||
Context context = null;
|
||||
TableRow row = null;
|
||||
DatabaseManager.insert(context, row);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of update method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testUpdate() throws Exception
|
||||
{
|
||||
System.out.println("update");
|
||||
Context context = null;
|
||||
TableRow row = null;
|
||||
int expResult = 0;
|
||||
int result = DatabaseManager.update(context, row);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of delete method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testDelete_Context_TableRow() throws Exception
|
||||
{
|
||||
System.out.println("delete");
|
||||
Context context = null;
|
||||
TableRow row = null;
|
||||
int expResult = 0;
|
||||
int result = DatabaseManager.delete(context, row);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getColumnInfo method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetColumnInfo_String() throws Exception
|
||||
{
|
||||
System.out.println("getColumnInfo");
|
||||
String table = "";
|
||||
Collection<ColumnInfo> expResult = null;
|
||||
Collection<ColumnInfo> result = DatabaseManager.getColumnInfo(table);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getColumnInfo method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetColumnInfo_String_String() throws Exception
|
||||
{
|
||||
System.out.println("getColumnInfo");
|
||||
String table = "";
|
||||
String column = "";
|
||||
ColumnInfo expResult = null;
|
||||
ColumnInfo result = DatabaseManager.getColumnInfo(table, column);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getColumnNames method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetColumnNames_String() throws Exception
|
||||
{
|
||||
System.out.println("getColumnNames");
|
||||
String table = "";
|
||||
List<String> expResult = null;
|
||||
List<String> result = DatabaseManager.getColumnNames(table);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getColumnNames method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetColumnNames_ResultSetMetaData() throws Exception
|
||||
{
|
||||
System.out.println("getColumnNames");
|
||||
ResultSetMetaData meta = null;
|
||||
List<String> expResult = null;
|
||||
List<String> result = DatabaseManager.getColumnNames(meta);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of canonicalize method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testCanonicalize()
|
||||
{
|
||||
System.out.println("canonicalize");
|
||||
String table = "";
|
||||
String expResult = "";
|
||||
String result = DatabaseManager.canonicalize(table);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of loadSql method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testLoadSql_String() throws Exception
|
||||
{
|
||||
System.out.println("loadSql");
|
||||
String sql = "";
|
||||
DatabaseManager.loadSql(sql);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of loadSql method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testLoadSql_Reader() throws Exception
|
||||
{
|
||||
System.out.println("loadSql");
|
||||
Reader r = null;
|
||||
DatabaseManager.loadSql(r);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of process method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testProcess_ResultSet_String() throws Exception
|
||||
{
|
||||
System.out.println("process");
|
||||
ResultSet results = null;
|
||||
String table = "";
|
||||
TableRow expResult = null;
|
||||
TableRow result = DatabaseManager.process(results, table);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of process method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testProcess_3args() throws Exception
|
||||
{
|
||||
System.out.println("process");
|
||||
ResultSet results = null;
|
||||
String table = "";
|
||||
List<String> pColumnNames = null;
|
||||
TableRow expResult = null;
|
||||
TableRow result = DatabaseManager.process(results, table, pColumnNames);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getPrimaryKeyColumn method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetPrimaryKeyColumn_TableRow() throws Exception
|
||||
{
|
||||
System.out.println("getPrimaryKeyColumn");
|
||||
TableRow row = null;
|
||||
String expResult = "";
|
||||
String result = DatabaseManager.getPrimaryKeyColumn(row);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getPrimaryKeyColumn method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetPrimaryKeyColumn_String() throws Exception
|
||||
{
|
||||
System.out.println("getPrimaryKeyColumn");
|
||||
String table = "";
|
||||
String expResult = "";
|
||||
String result = DatabaseManager.getPrimaryKeyColumn(table);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getPrimaryKeyColumnInfo method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testGetPrimaryKeyColumnInfo() throws Exception
|
||||
{
|
||||
System.out.println("getPrimaryKeyColumnInfo");
|
||||
String table = "";
|
||||
ColumnInfo expResult = null;
|
||||
ColumnInfo result = DatabaseManager.getPrimaryKeyColumnInfo(table);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of shutdown method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testShutdown() throws Exception
|
||||
{
|
||||
System.out.println("shutdown");
|
||||
DatabaseManager.shutdown();
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of getDbName method, of class DatabaseManager.
|
||||
*/
|
||||
@Test
|
||||
public void testGetDbName()
|
||||
{
|
||||
System.out.println("getDbName");
|
||||
String expResult = "H2";
|
||||
String result = DatabaseManager.getDbName();
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of loadParameters method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testLoadParameters() throws Exception
|
||||
{
|
||||
System.out.println("loadParameters");
|
||||
PreparedStatement statement = null;
|
||||
Object[] parameters = null;
|
||||
DatabaseManager.loadParameters(statement, parameters);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of main method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testMain()
|
||||
{
|
||||
System.out.println("main");
|
||||
String[] args = null;
|
||||
DatabaseManager.main(args);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of applyOffsetAndLimit method, of class DatabaseManager.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testApplyOffsetAndLimit()
|
||||
{
|
||||
System.out.println("applyOffsetAndLimit");
|
||||
StringBuffer query = null;
|
||||
List<Serializable> params = null;
|
||||
int offset = 0;
|
||||
int limit = 0;
|
||||
DatabaseManager.applyOffsetAndLimit(query, params, offset, limit);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
*/
|
||||
}
|
@@ -14,7 +14,6 @@ import java.sql.Statement;
|
||||
import java.sql.Types;
|
||||
import java.util.List;
|
||||
|
||||
import mockit.Deencapsulation;
|
||||
import mockit.Mock;
|
||||
import mockit.MockUp;
|
||||
|
||||
@@ -36,10 +35,8 @@ public final class MockDatabaseManager
|
||||
// Set our logger to specify the Mock class, so we know which logs are from the "real" vs "mock" class
|
||||
private static final Logger log = Logger.getLogger(MockDatabaseManager.class);
|
||||
|
||||
// Get the values of private static variables 'isOracle' and 'isPostgres' from
|
||||
// DatabaseManager itself (by using Deencapsulation)
|
||||
private static final boolean isOracle = Deencapsulation.getField(DatabaseManager.class, "isOracle");
|
||||
private static final boolean isPostgres = Deencapsulation.getField(DatabaseManager.class, "isPostgres");
|
||||
/** Is our DBMS Oracle-like? */
|
||||
private static final boolean isOracle = DatabaseManager.isOracle();
|
||||
|
||||
/**
|
||||
* Override/Mock the default "setConstraintDeferred()" method in order to
|
||||
|
@@ -10,9 +10,12 @@ package org.dspace.xoai.services.impl.database;
|
||||
import com.lyncode.xoai.dataprovider.filter.Scope;
|
||||
import com.lyncode.xoai.dataprovider.filter.ScopedFilter;
|
||||
import com.lyncode.xoai.dataprovider.filter.conditions.Condition;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
@@ -22,11 +25,8 @@ import org.dspace.xoai.services.api.database.DatabaseQueryResolver;
|
||||
import org.dspace.xoai.services.api.xoai.DSpaceFilterResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DSpaceDatabaseQueryResolver implements DatabaseQueryResolver {
|
||||
private static Logger log = LogManager.getLogger(DSpaceDatabaseQueryResolver.class);
|
||||
private static final Logger log = LogManager.getLogger(DSpaceDatabaseQueryResolver.class);
|
||||
|
||||
@Autowired
|
||||
DSpaceFilterResolver filterResolver;
|
||||
@@ -61,10 +61,7 @@ public class DSpaceDatabaseQueryResolver implements DatabaseQueryResolver {
|
||||
}
|
||||
|
||||
query += " ORDER BY i.item_id";
|
||||
String db = configurationService.getProperty("db.name");
|
||||
boolean postgres = true;
|
||||
// Assuming Postgres as default
|
||||
if ("oracle".equals(db)) postgres = false;
|
||||
boolean postgres = ! DatabaseManager.isOracle();
|
||||
if (postgres)
|
||||
{
|
||||
query += " OFFSET ? LIMIT ?";
|
||||
|
@@ -13,7 +13,6 @@ import org.dspace.core.Context;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
import org.dspace.storage.rdbms.TableRowIterator;
|
||||
import org.dspace.xoai.exceptions.InvalidMetadataFieldException;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.services.api.database.EarliestDateResolver;
|
||||
import org.dspace.xoai.services.api.database.FieldResolver;
|
||||
import org.dspace.xoai.util.DateUtils;
|
||||
@@ -23,22 +22,15 @@ import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
public class DSpaceEarliestDateResolver implements EarliestDateResolver {
|
||||
private static Logger log = LogManager.getLogger(DSpaceEarliestDateResolver.class);
|
||||
private static final Logger log = LogManager.getLogger(DSpaceEarliestDateResolver.class);
|
||||
|
||||
@Autowired
|
||||
private FieldResolver fieldResolver;
|
||||
|
||||
@Autowired
|
||||
private ConfigurationService configurationService;
|
||||
|
||||
@Override
|
||||
public Date getEarliestDate(Context context) throws InvalidMetadataFieldException, SQLException {
|
||||
String query = "SELECT MIN(text_value) as value FROM metadatavalue WHERE metadata_field_id = ?";
|
||||
String db = configurationService.getProperty("db.name");
|
||||
boolean postgres = true;
|
||||
// Assuming Postgres as default
|
||||
if ("oracle".equals(db))
|
||||
postgres = false;
|
||||
boolean postgres = ! DatabaseManager.isOracle();
|
||||
|
||||
if (!postgres) {
|
||||
query = "SELECT MIN(TO_CHAR(text_value)) as value FROM metadatavalue WHERE metadata_field_id = ?";
|
||||
|
@@ -15,7 +15,6 @@ import java.util.Comparator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.avalon.framework.activity.Disposable;
|
||||
import org.apache.avalon.framework.service.ServiceException;
|
||||
import org.apache.avalon.framework.service.ServiceManager;
|
||||
@@ -42,10 +41,11 @@ import org.dspace.app.xmlui.wing.element.Table;
|
||||
import org.dspace.app.xmlui.wing.element.TextArea;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.AuthorizeManager;
|
||||
import org.dspace.harvest.HarvestedCollection;
|
||||
import org.dspace.harvest.OAIHarvester.HarvestScheduler;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.harvest.HarvestedCollection;
|
||||
import org.dspace.harvest.OAIHarvester.HarvestScheduler;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
@@ -510,7 +510,7 @@ public class ControlPanel extends AbstractDSpaceTransformer implements Serviceab
|
||||
dspace.addItem(notnull(ConfigurationManager.getProperty("dspace.name")));
|
||||
|
||||
dspace.addLabel(T_DB_NAME);
|
||||
dspace.addItem(notnull(ConfigurationManager.getProperty("db.name")));
|
||||
dspace.addItem(notnull(DatabaseManager.getDbName()));
|
||||
|
||||
dspace.addLabel(T_DB_URL);
|
||||
dspace.addItem(notnull(ConfigurationManager.getProperty("db.url")));
|
||||
|
@@ -50,9 +50,6 @@ default.language = ${default.language}
|
||||
|
||||
##### Database settings #####
|
||||
|
||||
# Database name ("oracle", or "postgres")
|
||||
db.name = ${db.name}
|
||||
|
||||
# URL for connecting to database
|
||||
db.url = ${db.url}
|
||||
|
||||
@@ -89,7 +86,7 @@ db.poolname = ${db.poolname}
|
||||
# Specify a configured database connection pool to be fetched from a
|
||||
# directory. This overrides the pool and driver settings above. If
|
||||
# none can be found, then DSpace will use the above settings to create a
|
||||
# pool. db.name should be specified regardless.
|
||||
# pool.
|
||||
#db.jndi = jdbc/dspace
|
||||
|
||||
##### Email settings ######
|
||||
|
@@ -7,9 +7,8 @@ Revision: 11-sep-04 dstuve
|
||||
Oracle Porting Notes for the Curious
|
||||
|
||||
Oracle is missing quite a number of cool features found in Postgres, so
|
||||
workarounds had to be found, most of which are hidden behind tests of
|
||||
the db.name configuration parameter in dspace.cfg. If the db.name is
|
||||
set to Oracle the workarounds are activated:
|
||||
workarounds had to be found, most of which are hidden behind tests in
|
||||
DatabaseManager. If Oracle is your DBMS, the workarounds are activated:
|
||||
|
||||
Oracle doesn't like ';' characters in JDBC SQL - they have all been removed
|
||||
from the DSpace source, including code in the .sql file reader to strip ;'s.
|
||||
@@ -18,8 +17,8 @@ browse code - LIMIT and OFFSET is used to limit browse results, and an
|
||||
Oracle-hack is used to limit the result set to a given size
|
||||
|
||||
Oracle has no boolean data type, so a new schema file was created that
|
||||
uses NUMBER(1) (AKA 'integers') and code is inserted everywhere to use 0 for false
|
||||
and 1 for true if the db.name is Oracle
|
||||
uses NUMBER(1) (AKA 'integers') and code is inserted everywhere to use 0 for
|
||||
false and 1 for true if DSpace is using Oracle.
|
||||
|
||||
Oracle doesn't have a TEXT data type either, so TEXT columns are defined
|
||||
as VARCHAR2 in the Oracle-specific schema.
|
||||
|
Reference in New Issue
Block a user