Project

General

Profile

« Previous | Next » 

Revision 184

cleaned up code for getting options from the properties file, made the database connection inthe MetaCatUtil class use the properties file for the conneciton info

View differences:

MetaCatUtil.java
13 13
import java.sql.Connection;
14 14
import java.sql.DriverManager;
15 15
import java.sql.SQLException;
16
import java.util.PropertyResourceBundle;
16 17

  
17 18
/**
18 19
 * A suite of utility classes for the metadata catalog server
19 20
 */
20 21
public class MetaCatUtil {
21 22

  
22
  static  String 	user = "jones";
23
  static  String 	password = "your-pw-goes-here";
24
  static  String 	defaultDB = "jdbc:oracle:thin:@localhost:1521:test";
23
  private PropertyResourceBundle options = null;
24
  private static String propertiesFile = "edu.ucsb.nceas.metacat.metacat";
25 25

  
26
  /**
27
   * Construct an instance of the utility class
28
   */
29
  public MetaCatUtil() {
30
    options = (PropertyResourceBundle)
31
          PropertyResourceBundle.getBundle(propertiesFile);
32
  }
33

  
26 34
  /** 
35
   * Utility method to establish a JDBC database connection using connection
36
   * info from the properties file
37
   */
38
  public Connection openDBConnection()
39
                throws SQLException, ClassNotFoundException {
40
    return openDBConnection(getOption("dbDriver"), getOption("defaultDB"),
41
                     getOption("user"), getOption("password"));
42
  }
43

  
44
  /** 
27 45
   * Utility method to establish a JDBC database connection 
28 46
   *
29 47
   * @param dbDriver the string representing the database driver
......
42 60
     Connection conn = DriverManager.getConnection( connection, user, password);
43 61
     return conn;
44 62
  }
63

  
64
  /** 
65
   * Utility method to get an option value from the properties file
66
   *
67
   * @param option_name the name of the option requested
68
   */
69
  public String getOption(String option_name) {
70
      // Get the configuration file information
71
      if (options == null) {
72
        options = (PropertyResourceBundle)
73
          PropertyResourceBundle.getBundle(propertiesFile);
74
      }
75
      String value = (String)options.handleGetObject(option_name);
76
      return value;
77
  }
45 78
}

Also available in: Unified diff