Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that implements database administrative methods 
4
 *  Copyright: 2008 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Michael Daigle
7
 * 
8
 *   '$Author: daigle $'
9
 *     '$Date: 2008-07-11 10:10:53 -0700 (Fri, 11 Jul 2008) $'
10
 * '$Revision: 4109 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

    
27
package edu.ucsb.nceas.metacat.util;
28

    
29
import java.util.Map;
30
import java.util.TreeSet;
31
import java.util.Vector;
32

    
33
import org.apache.log4j.Logger;
34

    
35
import edu.ucsb.nceas.metacat.DBVersion;
36
import edu.ucsb.nceas.metacat.service.PropertyService;
37
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
38

    
39
public class DatabaseUtil {
40
	
41
	private static Logger logMetacat = Logger.getLogger(DatabaseUtil.class);
42

    
43
	/**
44
	 * private constructor - all methods are static so there is no no need to
45
	 * instantiate.
46
	 */
47
	private DatabaseUtil() {}
48
	
49
	/**
50
	 * Reports whether database is fully configured.
51
	 * 
52
	 * @return a boolean that is true if database is not unconfigured and false
53
	 *         otherwise
54
	 */
55
	public static boolean isDatabaseConfigured() throws UtilException {
56
		String databaseConfiguredString = PropertyService.UNCONFIGURED;
57
		try {
58
			databaseConfiguredString = 
59
				PropertyService.getProperty("configutil.databaseConfigured");
60
		} catch (PropertyNotFoundException pnfe) {
61
			throw new UtilException("Could not determine if database is configured: "
62
					+ pnfe.getMessage());
63
		}
64
		return !databaseConfiguredString.equals(PropertyService.UNCONFIGURED);
65
	}	
66
	
67
	/**
68
	 * Gets the available upgrade versions for metacat by getting a list of 
69
	 * upgrade script from properties in metacat.properties that start with 
70
	 * "database.upgradeVersion". It then creats a DBVersion object for each 
71
	 * upgrade version.
72
	 * 
73
	 * @return a TreeSet of DBVersion objects holding individual version information
74
	 */
75
	public static TreeSet<DBVersion> getUpgradeVersions() throws PropertyNotFoundException {
76
		
77
		TreeSet<DBVersion> versionSet = new TreeSet<DBVersion>();
78
		
79
		Vector<String> upgradeVersionKeys = PropertyService.getPropertyNamesByGroup("database.upgradeVersion");
80
		for (String upgradeVersionKey : upgradeVersionKeys) {
81
			String upgradeVersionId = upgradeVersionKey.substring(24);
82
			logMetacat.debug("Creating DBVersion object for version: " + upgradeVersionId);
83
			DBVersion dbVersion = new DBVersion(upgradeVersionId);
84
			versionSet.add(dbVersion);
85
		}
86

    
87
		return versionSet;
88
	}
89
	
90
	/**
91
	 * Gets the available upgrade versions for metacat by getting a list of 
92
	 * upgrade script from properties in metacat.properties that start with 
93
	 * "database.upgradeVersion". It then creats a DBVersion object for each 
94
	 * upgrade version.
95
	 * 
96
	 * @return a TreeSet of DBVersion objects holding individual version information
97
	 */
98
	public static Map<String, String> getScriptSuffixes() throws PropertyNotFoundException {
99
		
100
		return PropertyService.getPropertiesByGroup("database.scriptsuffix");
101
	}
102
}
(1-1/11)