Revision 747
Added by bojilova almost 23 years ago
MetaCatUtil.java | ||
---|---|---|
37 | 37 |
import java.util.Hashtable; |
38 | 38 |
import java.util.Enumeration; |
39 | 39 |
|
40 |
import edu.ucsb.nceas.dbadapter.DBAdapter; |
|
41 |
|
|
40 | 42 |
/** |
41 | 43 |
* A suite of utility classes for the metadata catalog server |
42 | 44 |
*/ |
43 | 45 |
public class MetaCatUtil { |
44 | 46 |
|
45 |
private PropertyResourceBundle options = null;
|
|
46 |
private String propertiesFile = "edu.ucsb.nceas.metacat.metacat";
|
|
47 |
private Hashtable connectionPool = new Hashtable();
|
|
47 |
public static DBAdapter dbAdapter;
|
|
48 |
private static PropertyResourceBundle options = null;
|
|
49 |
private static String propertiesFile = "edu.ucsb.nceas.metacat.metacat";
|
|
48 | 50 |
private static boolean debug = false; |
49 | 51 |
|
52 |
private Hashtable connectionPool = new Hashtable(); |
|
53 |
|
|
54 |
/** |
|
55 |
* Determine our db adapter class and create an instance of that class |
|
56 |
*/ |
|
57 |
static { |
|
58 |
try { |
|
59 |
dbAdapter = (DBAdapter)createObject(getOption("dbAdapter")); |
|
60 |
} catch (Exception e) { |
|
61 |
System.err.println("Error in MetaCatUtil static block:" + e.getMessage()); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
// CONSTRUCTORS NOT NEEDED |
|
66 |
// /** |
|
67 |
// * Construct an instance of the utility class |
|
68 |
// */ |
|
69 |
// public MetaCatUtil() { |
|
70 |
// |
|
71 |
// options = (PropertyResourceBundle) |
|
72 |
// PropertyResourceBundle.getBundle(propertiesFile); |
|
73 |
// } |
|
74 |
// |
|
75 |
// /** |
|
76 |
// * This constructor allows the usage of a different properties file |
|
77 |
// * @param propFile the properties file that you wish to use. |
|
78 |
// */ |
|
79 |
// public MetaCatUtil(String propFile) { |
|
80 |
// |
|
81 |
// propertiesFile = propFile; |
|
82 |
// } |
|
83 |
|
|
50 | 84 |
/** |
51 |
* Construct an instance of the utility class |
|
85 |
* Instantiate a class using the name of the class at runtime |
|
86 |
* |
|
87 |
* @param className the fully qualified name of the class to instantiate |
|
52 | 88 |
*/ |
53 |
public MetaCatUtil() { |
|
54 |
options = (PropertyResourceBundle) |
|
89 |
public static Object createObject(String className) throws Exception { |
|
90 |
|
|
91 |
Object object = null; |
|
92 |
try { |
|
93 |
Class classDefinition = Class.forName(className); |
|
94 |
object = classDefinition.newInstance(); |
|
95 |
} catch (InstantiationException e) { |
|
96 |
throw e; |
|
97 |
} catch (IllegalAccessException e) { |
|
98 |
throw e; |
|
99 |
} catch (ClassNotFoundException e) { |
|
100 |
throw e; |
|
101 |
} |
|
102 |
return object; |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Utility method to get an option value from the properties file |
|
107 |
* |
|
108 |
* @param optionName the name of the option requested |
|
109 |
*/ |
|
110 |
public static String getOption(String optionName) { |
|
111 |
// Get the configuration file information |
|
112 |
if (options == null) { |
|
113 |
options = (PropertyResourceBundle) |
|
55 | 114 |
PropertyResourceBundle.getBundle(propertiesFile); |
115 |
} |
|
116 |
String value = (String)options.handleGetObject(optionName); |
|
117 |
return value; |
|
56 | 118 |
} |
57 |
|
|
58 |
/** |
|
59 |
* This constructor allows the usage of a different properties file |
|
60 |
* @param propFile the properties file that you wish to use. |
|
119 |
|
|
120 |
/** |
|
121 |
* Utility method to get an option value from a properties file |
|
122 |
* |
|
123 |
* @param optionName the name of the option requested |
|
124 |
* @param propFile the name of the file where to get the properties from |
|
61 | 125 |
*/ |
62 |
public MetaCatUtil(String propFile) |
|
63 |
{ |
|
64 |
propertiesFile = propFile; |
|
126 |
public String getOption(String optionName, String propFile) { |
|
127 |
// Get the configuration file information |
|
128 |
PropertyResourceBundle options = (PropertyResourceBundle) |
|
129 |
PropertyResourceBundle.getBundle(propFile); |
|
130 |
String value = (String)options.handleGetObject(optionName); |
|
131 |
return value; |
|
65 | 132 |
} |
66 | 133 |
|
67 | 134 |
/** |
... | ... | |
95 | 162 |
return conn; |
96 | 163 |
} |
97 | 164 |
|
98 |
/** |
|
99 |
* Utility method to get an option value from the properties file |
|
100 |
* |
|
101 |
* @param option_name the name of the option requested |
|
102 |
*/ |
|
103 |
public String getOption(String option_name) { |
|
104 |
// Get the configuration file information |
|
105 |
if (options == null) { |
|
106 |
options = (PropertyResourceBundle) |
|
107 |
PropertyResourceBundle.getBundle(propertiesFile); |
|
108 |
} |
|
109 |
String value = (String)options.handleGetObject(option_name); |
|
110 |
return value; |
|
111 |
} |
|
112 |
|
|
113 | 165 |
/* Utility method to create and return a pool of Connection objects */ |
114 | 166 |
public Hashtable getConnectionPool() |
115 | 167 |
throws SQLException, ClassNotFoundException { |
Also available in: Unified diff
- changed to use the DBAdapter uniform interface for all apperance of "sysdate"
and uniqueid generation from sequence
MetaCatUtil:
- reads from metacat.properties the dbadapter class implemented the interface
and creates an instance of that class (in static public variable named dbAdapter) for use.
So all the classes in the application can access the dbadapter obj by:
MetaCatUtil.dbAdapter