Project

General

Profile

1
/**
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: sgarg $'
10
 *     '$Date: 2005-11-10 13:22:57 -0800 (Thu, 10 Nov 2005) $'
11
 * '$Revision: 2728 $'
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
import edu.ucsb.nceas.metacat.*;
32

    
33
/**
34
 * The Oracle db adapter implementation.
35
 */
36
public class OracleAdapter extends AbstractDatabase {
37

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

    
70
  /**
71
   * The Oracle's function name that gets the current date and time
72
   * from the database server: "sysdate"
73
   *
74
   * @return return the current date and time function name: "sysdate"
75
   */
76
  public String getDateTimeFunction() {
77

    
78
    //System.out.println("The date and time function: " + "sysdate");    
79
    return "sysdate";
80
  }
81

    
82
  /**
83
   * The Oracle's function name that is used to return non-NULL value
84
   *
85
   * @return return the non-NULL function name: "nvl"
86
   */
87
  public String getIsNULLFunction() {
88
    
89
    return "nvl";
90
  }
91

    
92
  /**
93
   * The Oracles's string delimiter character: single quote (')
94
   *
95
   * @return return the string delimiter: single quote (')
96
   */
97
  public String getStringDelimiter() {
98

    
99
    return "'";
100
  }
101

    
102
  /**
103
   * The Oracles's syntax for doing a left join
104
   * Add 'a.' in front of the fields for first table and
105
   * 'b.' in front of the fields for the second table
106
   * 
107
   * @param selectFields fields that you want to be selected
108
   * @param tableA first table in the join
109
   * @param tableB second table in the join
110
   * @param joinCriteria the criteria based on which the join will be made
111
   * @param nonJoinCriteria all other criterias
112
   * @return return the string for teh select query
113
   */
114
  public String getLeftJoinQuery(String selectFields, String tableA, 
115
		  String tableB, String joinCriteria, String nonJoinCriteria){
116

    
117
	  return "SELECT " + selectFields + " FROM " + tableA + " a, " 
118
	         + tableB + " b WHERE " + joinCriteria + "(+) " + " AND (" 
119
	         + nonJoinCriteria +")";
120
  }
121
  
122
  
123
  /**
124
   * Return a hard code string to get xml_document list in timed replcation
125
   */
126
  public String getReplicationDocumentListSQL()
127
  {
128
      String sql ="select a.docid, a.rev, a.doctype from xml_documents a, xml_revisions b where a.docid=b.docid(+) and  a.rev<=b.rev(+) and b.docid is null ";
129
      return sql;
130
  }
131
  
132
}
133
    
(2-2/4)