Project

General

Profile

« Previous | Next » 

Revision 758

Added by bojilova almost 23 years ago

Changed the order of generating and getting Unique ID for
xml_nodes.nodeid and for uniqueid part of the accession#
because of SQl Server capabilities:
first let the db to generate unique id on insert (by db trigger and sequence or by IDENTITY key),
then get that unique id for further use by the application.
Used to be the opposite for these 2 unique id generations.

View differences:

AccessionNumber.java
108 108
        // get a new docid
109 109
        if ( docid == null ) {
110 110
          String sitecode = getSitecode();
111
          // NOT USED; USED DBAdapter.getUniqueID() instead
112
          //String uniqueid = getUniqueID();
113
          String uniqueid = "" + dbAdapter.getUniqueID(conn,"xml_documents");
111
          String uniqueid = getUniqueID(sitecode);
114 112

  
115 113
          return sitecode + sep + uniqueid;
116 114

  
......
167 165
  }
168 166

  
169 167
  // get Unique ID from DB sequence
170
  private String getUniqueID () throws SQLException
168
  private String getUniqueID (String sitecode) throws SQLException
171 169
  {
172 170
    String uniqueid;
171
    String sysdate = dbAdapter.getDateTimeFunction();
173 172
    
174 173
    try {
175 174
      PreparedStatement pstmt;
176 175
      pstmt = conn.prepareStatement
177
              ("SELECT accnum_uniqueid_seq.nextval FROM dual");
176
              ("INSERT INTO accession_number (site_code, date_created) " +
177
               "VALUES (?, " + sysdate + ")");
178
      pstmt.setString(1, sitecode);
178 179
      pstmt.execute();
179

  
180
      ResultSet rs = pstmt.getResultSet();
181
      boolean hasRow = rs.next();
182
      uniqueid = rs.getString(1);
183 180
      pstmt.close();
184 181
      
182
      uniqueid = "" + dbAdapter.getUniqueID(conn, "accession_number");
183

  
185 184
    } catch (SQLException e) {
186 185
      throw new 
187 186
      SQLException("Error on AccessionNumber.getUniqueID(): "+e.getMessage());

Also available in: Unified diff