Project

General

Profile

« Previous | Next » 

Revision 171

Added by bojilova about 24 years ago

added missed conn.close()

View differences:

src/edu/ucsb/nceas/metacat/AccessionNumber.java
21 21
 */
22 22
public class AccessionNumber  {
23 23
    
24
    /**
25
     * This method gets Accession Number (if any), check for uniqueness 
26
     * and register it into new db connection
27
     * @param accNumber - accession # if provided or null if not
28
     * @param action - INSERT, UPDATE or DELETE.
29
     * When "INSERT" and accession # provided is not unique, get next one.
30
     * If it is unique, use it.
31
     * When "INSERT" and accession # is null, get a new one.
32
     * When "UPDATE", accession # is required. 
33
     * When "DELETE", accession # is required. 
34
     */
24 35
    public static String generate (String accNumber, String action) 
25 36
        throws ClassNotFoundException, StringIndexOutOfBoundsException, 
26 37
               SQLException
......
59 70
                    return put(conn, defaultGlobalName, null, sep);
60 71
                else
61 72
                    return put(conn, globalName, localId, sep);
73
                    
74
            conn.close();        
62 75

  
63 76
        } catch (SQLException e) {
64 77
            System.out.println(
......
70 83
        return null;        
71 84
    }    
72 85

  
86
    /** put unique accession # into db connection */
73 87
    private static String put (Connection conn, String globalName, 
74 88
                String localId, String sep) 
75 89
                throws SQLException
......
79 93
        try {
80 94
            if ( localId == null ) 
81 95
                l = new Integer(get(conn, globalName) + 1); 
82
            else if ( !unique(conn, globalName, localId) )
96
            else if ( exist(conn, globalName, localId) )
83 97
                l = new Integer(get(conn, globalName) + 1); 
84 98
            else
85 99
                l = new Integer(localId); 
......
93 107
            pstmt.setString(2,l.toString());
94 108
            pstmt.execute();
95 109
            
110
            pstmt.close();
111
            
96 112
        } catch (SQLException e) {
97 113
            System.out.println(
98 114
                   "Error on AccessionNumber.put(conn, globalName, localId): " 
......
103 119
    }
104 120

  
105 121
    /** check for existance of Accesssion Number */
106
    private static boolean unique (Connection conn, String globalName, 
122
    private static boolean exist (Connection conn, String globalName, 
107 123
                String localId) throws SQLException
108 124
    {
109 125
        
......
130 146
        return hasAccNumber;
131 147
    }    
132 148
    
133
    //** get the last in order local ID by a given global name */
149
    /** get the last in order local ID by a given global name */
134 150
    private static int get (Connection conn, String globalName) 
135 151
                throws SQLException
136 152
    {

Also available in: Unified diff