Project

General

Profile

« Previous | Next » 

Revision 750

Added by harris almost 23 years ago

The Postgres implementation of the dbadapter package, still needs testing and
the getDate... method just returns the db function to return the date; to retreive the
current time is a second function so we may want to add a second method to return the
current time.

View differences:

src/edu/ucsb/nceas/dbadapter/DBPostgresql.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A db adapter class for Postgresql 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 DBPostgresql extends DBAdapter {
36

  
37
  /**
38
   * The Postgresql unique ID /sequence generator
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 from which to generate the unique id
44
   * @param tableName the name of table which unique id to generate
45
   * @exception SQLException 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 nextval('" + tableName + "_id_seq')");
54
    ResultSet rs = stmt.getResultSet();
55
    if ( rs.next() ) 
56
		{
57
      uniqueid = rs.getLong(1);
58
    }
59
    stmt.close();
60
    //System.out.println("Unique ID: " + uniqueid);    
61
    return uniqueid;
62
  }
63

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

  
72
    //System.out.println("Current date string: " + "sysdate");    
73
    return "current_date";
74
		//for current time use current_time
75
  }
76

  
77
  /**
78
   * Postgresql's string delimiter character: single quote (')
79
   *
80
   * @return return the string delimiter: single quote (')
81
   */
82
  public String getStringDelimiter() {
83

  
84
    return "'";
85
  }
86
  
87
}
88
    
0 89

  

Also available in: Unified diff