Package edu.ucsb.nceas.metacat.admin
Class DBAdmin
java.lang.Object
edu.ucsb.nceas.metacat.admin.MetacatAdmin
edu.ucsb.nceas.metacat.admin.DBAdmin
Control the display of the database configuration page and the processing
of the configuration values.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
Fields inherited from class edu.ucsb.nceas.metacat.admin.MetacatAdmin
FAILURE, IN_PROGRESS, SUCCESS
-
Method Summary
Modifier and TypeMethodDescriptionvoid
configureDatabase
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Handle configuration of the database the first time that Metacat starts or when it is explicitly called.static int
Performs a status check on the database.Get the version of the database as a stringstatic DBAdmin
Get the single instance of DBAdmin.Finds the version of the database for a database that does not have a dbVersion table yet.Get the list of the Java and Solr update class files which will run in the upgrade processCreates a list of database update script names by looking at the database version and the metacat version and then getting any script that is inbetween the two (inclusive of metacat version).loadSQLFromFile
(String sqlFileName) Very basic utility to read sql from a file and return a vector of the individual sql statements.void
runSQLFile
(String sqlFileName) Runs the commands in a sql script.void
Iterates through the list of scripts that need to be run to upgrade the database and calls runSQLFile on each.validateDBConnectivity
(String dbDriver, String connection, String user, String password) Validate connectivity to the database.validateOptions
(javax.servlet.http.HttpServletRequest request) Validate the most important configuration options submitted by the user.Methods inherited from class edu.ucsb.nceas.metacat.admin.MetacatAdmin
updateUpgradeStatus
-
Field Details
-
DB_DOES_NOT_EXIST
public static final int DB_DOES_NOT_EXIST- See Also:
-
TABLES_DO_NOT_EXIST
public static final int TABLES_DO_NOT_EXIST- See Also:
-
TABLES_EXIST
public static final int TABLES_EXIST- See Also:
-
VERSION_INACTIVE
public static final int VERSION_INACTIVE- See Also:
-
VERSION_ACTIVE
public static final int VERSION_ACTIVE- See Also:
-
-
Method Details
-
getInstance
Get the single instance of DBAdmin.- Returns:
- the single instance of DBAdmin
- Throws:
AdminException
-
configureDatabase
public void configureDatabase(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws AdminException Handle configuration of the database the first time that Metacat starts or when it is explicitly called. Collect necessary update information from the administrator.- Parameters:
request
- the http request informationresponse
- the http response to be sent back to the client- Throws:
AdminException
-
getDBStatus
public static int getDBStatus() throws SQLException, edu.ucsb.nceas.utilities.PropertyNotFoundExceptionPerforms a status check on the database.- Throws:
SQLException
edu.ucsb.nceas.utilities.PropertyNotFoundException
-
getDBVersion
Get the version of the database as a string- Throws:
AdminException
-
getUnRegisteredDBVersion
Finds the version of the database for a database that does not have a dbVersion table yet. Work backwards with various clues found in update scripts to find the version.- Throws:
AdminException
SQLException
-
validateDBConnectivity
public String validateDBConnectivity(String dbDriver, String connection, String user, String password) Validate connectivity to the database. Validation methods return a string error message if there is an issue. This allows the calling code to run several validations and compile the errors into a list that can be displayed on a web page if desired.- Parameters:
dbDriver
- the database driverconnection
- the jdbc connection stringuser
- the user namepassword
- the login password- Returns:
- a string holding error message if validation fails.
-
getUpdateScripts
Creates a list of database update script names by looking at the database version and the metacat version and then getting any script that is inbetween the two (inclusive of metacat version).- Throws:
AdminException
-
getUpdateClasses
Get the list of the Java and Solr update class files which will run in the upgrade process- Returns:
- the list of Java class files
- Throws:
AdminException
-
upgradeDatabase
Iterates through the list of scripts that need to be run to upgrade the database and calls runSQLFile on each.- Throws:
AdminException
-
runSQLFile
Runs the commands in a sql script. Individual commands are loaded into a string vector and run one at a time.- Parameters:
sqlFileName
- the name of the file holding the sql statements that need to get run.- Throws:
AdminException
SQLException
-
loadSQLFromFile
Very basic utility to read sql from a file and return a vector of the individual sql statements. This ignores any line that starts with /* or *. It strips anything following --. Sql is parsed by looking for lines that start with one of the following identifiers: INSERT, UPDATE, ALTER, CREATE, DROP, BEGIN and COMMIT. It then assumes that everything until the line that ends with ; is part of the sql, excluding comments.- Parameters:
sqlFileName
- the name of the file to read.- Returns:
- a vector holding the individual sql statements.
- Throws:
IOException
-
validateOptions
Validate the most important configuration options submitted by the user.- Specified by:
validateOptions
in classMetacatAdmin
- Returns:
- a vector holding error message for any fields that fail validation.
-