Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A db adapter class for Oracle RDBMS.
4
 *  Copyright: 2000 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Jivka Bojilova
7
 *    Release: @release@
8
 *
9
 *   '$Author: harris $'
10
 *     '$Date: 2001-05-24 11:07:52 -0700 (Thu, 24 May 2001) $'
11
 * '$Revision: 753 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

    
28
package edu.ucsb.nceas.dbadapter;
29

    
30
import java.sql.*;
31

    
32
/**
33
 * The Oracle db adapter implementation.
34
 */
35
public class DBOracle extends DBAdapter {
36

    
37
  /**
38
   * The Oracle unique ID generator through use of sequences
39
   * The name of the sequence used to generate the unique id 
40
   * is made from the name of the table that uses the id by 
41
   * appending "_id_seq" to it.
42
   *
43
   * @param conn db connection in which to generate the unique id
44
   * @param tableName the name of table which unique id to generate
45
   * @exception SQLException <br/> any SQLException that can be thrown 
46
   *            during the db operation
47
   * @return return the generated unique id as a long type
48
   */
49
  public long getUniqueID(Connection conn, String tableName) 
50
                                         throws SQLException {
51
    long uniqueid = 0;
52
    Statement stmt = conn.createStatement();
53
    stmt.execute("SELECT " + tableName + "_id_seq.nextval FROM dual");
54
    ResultSet rs = stmt.getResultSet();
55
    if ( rs.next() ) {
56
      uniqueid = rs.getLong(1);
57
    }
58
    stmt.close();
59
    //System.out.println("Unique ID: " + uniqueid);    
60
    return uniqueid;
61
  }
62

    
63
  /**
64
   * The Oracle's function name that gets the current date and time
65
   * from the database server: "sysdate"
66
   *
67
   * @return return the current date and time function name: "sysdate"
68
   */
69
  public String getDateTimeFunction() {
70

    
71
    //System.out.println("The date and time function: " + "sysdate");    
72
    return "sysdate";
73
  }
74

    
75
  /**
76
   * The Oracles's string delimiter character: single quote (')
77
   *
78
   * @return return the string delimiter: single quote (')
79
   */
80
  public String getStringDelimiter() {
81

    
82
    return "'";
83
  }
84
  
85
}
86
    
(2-2/3)