1 |
775
|
bojilova
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Purpose: An 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$'
|
10 |
|
|
* '$Date$'
|
11 |
|
|
* '$Revision$'
|
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 OracleAdapter extends AbstractDatabase {
|
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 |
|
|
* When record is inserted in the table and insert trigger gets
|
43 |
|
|
* a nextval from that sequence, select currval of that sequence
|
44 |
|
|
* can return the generated key in the same db connection.
|
45 |
|
|
*
|
46 |
|
|
* @param conn db connection in which the unique id was generated
|
47 |
|
|
* @param tableName the name of table which unique id was generate
|
48 |
|
|
* @exception SQLException <br/> any SQLException that can be thrown
|
49 |
|
|
* during the db operation
|
50 |
|
|
* @return return the generated unique id as a long type
|
51 |
|
|
*/
|
52 |
|
|
public long getUniqueID(Connection conn, String tableName)
|
53 |
|
|
throws SQLException {
|
54 |
|
|
long uniqueid = 0;
|
55 |
|
|
Statement stmt = conn.createStatement();
|
56 |
|
|
stmt.execute("SELECT " + tableName + "_id_seq.currval FROM dual");
|
57 |
|
|
ResultSet rs = stmt.getResultSet();
|
58 |
|
|
if ( rs.next() ) {
|
59 |
|
|
uniqueid = rs.getLong(1);
|
60 |
|
|
}
|
61 |
|
|
stmt.close();
|
62 |
|
|
//System.out.println("Unique ID: " + uniqueid);
|
63 |
|
|
return uniqueid;
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
/**
|
67 |
|
|
* The Oracle's function name that gets the current date and time
|
68 |
|
|
* from the database server: "sysdate"
|
69 |
|
|
*
|
70 |
|
|
* @return return the current date and time function name: "sysdate"
|
71 |
|
|
*/
|
72 |
|
|
public String getDateTimeFunction() {
|
73 |
|
|
|
74 |
|
|
//System.out.println("The date and time function: " + "sysdate");
|
75 |
|
|
return "sysdate";
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
/**
|
79 |
|
|
* The Oracle's function name that is used to return non-NULL value
|
80 |
|
|
*
|
81 |
|
|
* @return return the non-NULL function name: "nvl"
|
82 |
|
|
*/
|
83 |
|
|
public String getIsNULLFunction() {
|
84 |
|
|
|
85 |
|
|
return "nvl";
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
/**
|
89 |
|
|
* The Oracles's string delimiter character: single quote (')
|
90 |
|
|
*
|
91 |
|
|
* @return return the string delimiter: single quote (')
|
92 |
|
|
*/
|
93 |
|
|
public String getStringDelimiter() {
|
94 |
|
|
|
95 |
|
|
return "'";
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
}
|