Index: src/edu/ucsb/nceas/dbadapter/DBAdapter.java
===================================================================
--- src/edu/ucsb/nceas/dbadapter/DBAdapter.java	(nonexistent)
+++ src/edu/ucsb/nceas/dbadapter/DBAdapter.java	(revision 746)
@@ -0,0 +1,125 @@
+/**
+ *  '$RCSfile$'
+ *    Purpose: An abstract class that encapsulates access to any RDBMS.
+ *             This allows to swap easily between databases without any
+ *             modification to the application.
+ *  Copyright: 2000 Regents of the University of California and the
+ *             National Center for Ecological Analysis and Synthesis
+ *    Authors: Jivka Bojilova
+ *    Release: @release@
+ *
+ *   '$Author$'
+ *     '$Date$'
+ * '$Revision$'
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+package edu.ucsb.nceas.dbadapter;
+
+import java.sql.*;
+import edu.ucsb.nceas.metacat.MetaCatUtil;
+
+/**
+ * Java offers uniform database access through the use of JDBC.
+ * But many databases still use different SQL implementations and 
+ * conventions. Thus this class offers extended programming interface
+ * that all subclasses should implement to gain access to different
+ * databases.
+ *
+ * To add a new database adapter class you must create a new class 
+ * DB<dbname> that extends edu.ucsb.nceas.dbadapter.DBAdapter (where
+ * dbname is the name of the database or database driver you wish to
+ * add to your application). DBAdapter is an abstract class, thus the
+ * subclasses need to implement the abstract methods.
+ */
+public abstract class DBAdapter {
+
+  /**
+   * Unique ID generator
+   *
+   * @param conn db connection in which to generate the unique id
+   * @param tableName the table which unique id to generate
+   * @exception SQLException <br/> any SQLException that can be thrown 
+   *            during the db operation
+   * @return return the generated unique id as a long type
+   */
+  public abstract long getUniqueID(Connection conn, String tableName) 
+                                                  throws SQLException;
+  /**
+   * The function name that gets the current date and time
+   * from the database server
+   *
+   * @return return the current date and time function name
+   */
+  public abstract String getDateString();
+
+  /**
+   * The character that the specific database implementation uses to 
+   * indicate string literals in SQL. This will usually be a single
+   * qoute (').
+   *
+   * @return return the string delimiter
+   */
+  public abstract String getStringDelimiter();
+  
+  /**
+   * Instantiate a class using the name of the class at runtime
+   *
+   * @param className the fully qualified name of the class to instantiate
+   */
+  static public Object createObject(String className) throws Exception {
+ 
+    Object object = null;
+    try {
+      Class classDefinition = Class.forName(className);
+      object = classDefinition.newInstance();
+    } catch (InstantiationException e) {
+      throw e;
+    } catch (IllegalAccessException e) {
+      throw e;
+    } catch (ClassNotFoundException e) {
+      throw e;
+    }
+    return object;
+  }
+
+  /**
+   * the main routine used to test the DBAdapter utility.
+   */
+  static public void main(String[] args) {
+    
+    // Determine our db adapter class and
+    // create an instance of that class
+    try {
+      MetaCatUtil util = new MetaCatUtil();
+      String dbAdapter = util.getOption("dbAdapter");
+      DBAdapter dbAdapterObj = (DBAdapter)createObject(dbAdapter);
+      
+      // test if they work correctly
+      String date = dbAdapterObj.getDateString();
+
+      Connection conn = util.openDBConnection();
+      long uniqueid = dbAdapterObj.getUniqueID(conn, "xml_catalog");
+      conn.close();
+      conn = null;
+
+    } catch (Exception e) {
+      System.out.println(e);
+    }
+  }
+  
+}
+    
\ No newline at end of file

Property changes on: src/edu/ucsb/nceas/dbadapter/DBAdapter.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: src/edu/ucsb/nceas/dbadapter/DBOracle.java
===================================================================
--- src/edu/ucsb/nceas/dbadapter/DBOracle.java	(nonexistent)
+++ src/edu/ucsb/nceas/dbadapter/DBOracle.java	(revision 746)
@@ -0,0 +1,86 @@
+/**
+ *  '$RCSfile$'
+ *    Purpose: A db adapter class for Oracle RDBMS.
+ *  Copyright: 2000 Regents of the University of California and the
+ *             National Center for Ecological Analysis and Synthesis
+ *    Authors: Jivka Bojilova
+ *    Release: @release@
+ *
+ *   '$Author$'
+ *     '$Date$'
+ * '$Revision$'
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+package edu.ucsb.nceas.dbadapter;
+
+import java.sql.*;
+
+/**
+ * The Oracle db adapter implementation.
+ */
+public class DBOracle extends DBAdapter {
+
+  /**
+   * The Oracle unique ID generator through use of sequences
+   * The name of the sequence used to generate the unique id 
+   * is made from the name of the table that uses the id by 
+   * appending "_id_seq" to it.
+   *
+   * @param conn db connection in which to generate the unique id
+   * @param tableName the name of table which unique id to generate
+   * @exception SQLException <br/> any SQLException that can be thrown 
+   *            during the db operation
+   * @return return the generated unique id as a long type
+   */
+  public long getUniqueID(Connection conn, String tableName) 
+                                         throws SQLException {
+    long uniqueid = 0;
+    Statement stmt = conn.createStatement();
+    stmt.execute("SELECT " + tableName + "_id_seq.nextval FROM dual");
+    ResultSet rs = stmt.getResultSet();
+    if ( rs.next() ) {
+      uniqueid = rs.getLong(1);
+    }
+    stmt.close();
+    //System.out.println("Unique ID: " + uniqueid);    
+    return uniqueid;
+  }
+
+  /**
+   * The Oracle's function name that gets the current date and time
+   * from the database server: "sysdate"
+   *
+   * @return return the current date and time function name: "sysdate"
+   */
+  public String getDateString() {
+
+    //System.out.println("Current date string: " + "sysdate");    
+    return "sysdate";
+  }
+
+  /**
+   * The Oracles's string delimiter character: single quote (')
+   *
+   * @return return the string delimiter: single quote (')
+   */
+  public String getStringDelimiter() {
+
+    return "'";
+  }
+  
+}
+    
\ No newline at end of file

Property changes on: src/edu/ucsb/nceas/dbadapter/DBOracle.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
