1 |
4335
|
daigle
|
/**
|
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.service;
|
28 |
|
|
|
29 |
|
|
import org.apache.log4j.Logger;
|
30 |
|
|
|
31 |
|
|
import edu.ucsb.nceas.dbadapter.AbstractDatabase;
|
32 |
|
|
|
33 |
|
|
public class DatabaseService implements ServiceInterface {
|
34 |
|
|
|
35 |
|
|
private static DatabaseService databaseService = null;
|
36 |
|
|
private static AbstractDatabase dbAdapter;
|
37 |
|
|
private static Logger logMetacat = Logger.getLogger(DatabaseService.class);
|
38 |
|
|
|
39 |
|
|
/**
|
40 |
|
|
* private constructor since this is a singleton
|
41 |
|
|
*/
|
42 |
|
|
private DatabaseService() {
|
43 |
|
|
// Determine our db adapter class and create an instance of that class
|
44 |
|
|
try {
|
45 |
|
|
dbAdapter = (AbstractDatabase) createObject(PropertyService.getProperty("database.adapter"));
|
46 |
|
|
} catch (Exception e) {
|
47 |
|
|
logMetacat.error("Could not create dbAdaptor" + e.getMessage());
|
48 |
|
|
e.printStackTrace();
|
49 |
|
|
}
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
/**
|
53 |
|
|
* Get the single instance of AuthAdmin.
|
54 |
|
|
*
|
55 |
|
|
* @return the single instance of AuthAdmin
|
56 |
|
|
*/
|
57 |
|
|
public static DatabaseService getInstance() {
|
58 |
|
|
if (databaseService == null) {
|
59 |
|
|
databaseService = new DatabaseService();
|
60 |
|
|
}
|
61 |
|
|
return databaseService;
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
/**
|
65 |
|
|
* Instantiate a class using the name of the class at runtime
|
66 |
|
|
*
|
67 |
|
|
* @param className the fully qualified name of the class to instantiate
|
68 |
|
|
*/
|
69 |
|
|
public static Object createObject(String className) throws Exception {
|
70 |
|
|
|
71 |
|
|
Object object = null;
|
72 |
|
|
try {
|
73 |
|
|
Class classDefinition = Class.forName(className);
|
74 |
|
|
object = classDefinition.newInstance();
|
75 |
|
|
} catch (InstantiationException e) {
|
76 |
|
|
throw e;
|
77 |
|
|
} catch (IllegalAccessException e) {
|
78 |
|
|
throw e;
|
79 |
|
|
} catch (ClassNotFoundException e) {
|
80 |
|
|
throw e;
|
81 |
|
|
}
|
82 |
|
|
return object;
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
/**
|
86 |
|
|
* gets the database adapter
|
87 |
|
|
*
|
88 |
|
|
* @return AbstractDatabase object for this application's database adapter.
|
89 |
|
|
*/
|
90 |
|
|
public static AbstractDatabase getDBAdapter() {
|
91 |
|
|
return dbAdapter;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
}
|