1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A Class that implements database utility 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-08-22 16:23:38 -0700 (Fri, 22 Aug 2008) $'
|
10
|
* '$Revision: 4297 $'
|
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.database;
|
28
|
|
29
|
import org.apache.log4j.Logger;
|
30
|
|
31
|
import edu.ucsb.nceas.dbadapter.AbstractDatabase;
|
32
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
33
|
import edu.ucsb.nceas.metacat.shared.BaseService;
|
34
|
import edu.ucsb.nceas.metacat.shared.ServiceException;
|
35
|
|
36
|
public class DatabaseService extends BaseService {
|
37
|
|
38
|
private static DatabaseService databaseService = null;
|
39
|
private static AbstractDatabase dbAdapter;
|
40
|
private static Logger logMetacat = Logger.getLogger(DatabaseService.class);
|
41
|
|
42
|
/**
|
43
|
* private constructor since this is a singleton
|
44
|
*/
|
45
|
private DatabaseService() {
|
46
|
// Determine our db adapter class and create an instance of that class
|
47
|
try {
|
48
|
dbAdapter = (AbstractDatabase) createObject(PropertyService.getProperty("database.adapter"));
|
49
|
} catch (Exception e) {
|
50
|
logMetacat.error("Could not create dbAdaptor" + e.getMessage());
|
51
|
e.printStackTrace();
|
52
|
}
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* Get the single instance of DatabaseService.
|
57
|
*
|
58
|
* @return the single instance of DatabaseService
|
59
|
*/
|
60
|
public static DatabaseService getInstance() {
|
61
|
if (databaseService == null) {
|
62
|
databaseService = new DatabaseService();
|
63
|
}
|
64
|
return databaseService;
|
65
|
}
|
66
|
|
67
|
public boolean refreshable() {
|
68
|
return false;
|
69
|
}
|
70
|
|
71
|
public void doRefresh() throws ServiceException {
|
72
|
return;
|
73
|
}
|
74
|
|
75
|
public void stop() throws ServiceException {
|
76
|
return;
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* Instantiate a class using the name of the class at runtime
|
81
|
*
|
82
|
* @param className the fully qualified name of the class to instantiate
|
83
|
*/
|
84
|
public static Object createObject(String className) throws Exception {
|
85
|
|
86
|
Object object = null;
|
87
|
try {
|
88
|
Class classDefinition = Class.forName(className);
|
89
|
object = classDefinition.newInstance();
|
90
|
} catch (InstantiationException e) {
|
91
|
throw e;
|
92
|
} catch (IllegalAccessException e) {
|
93
|
throw e;
|
94
|
} catch (ClassNotFoundException e) {
|
95
|
throw e;
|
96
|
}
|
97
|
return object;
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* gets the database adapter
|
102
|
*
|
103
|
* @return AbstractDatabase object for this application's database adapter.
|
104
|
*/
|
105
|
public AbstractDatabase getDBAdapter() {
|
106
|
return dbAdapter;
|
107
|
}
|
108
|
|
109
|
}
|