Project

General

Profile

« Previous | Next » 

Revision 5333

Added by berkley almost 14 years ago

adding a system to track system metadata documents for dataone

View differences:

IdentifierManager.java
277 277
        
278 278
        return guid;
279 279
    }
280
    
281
    /**
282
     * insert a system metadata id for a local id
283
     * 
284
     * @param guid the id to insert
285
     * @param localId the systemMetadata object to get the local id for
286
     */
287
    public void createSystemMetadataMapping(String guid, String localId)
288
    {
289
      int serialNumber = -1;
290
        DBConnection dbConn = null;
291
        try {
292

  
293
            // Parse the localId into scope and rev parts
294
            AccessionNumber acc = new AccessionNumber(localId, "NOACTION");
295
            String docid = acc.getDocid();
296
            int rev = (new Integer(acc.getRev()).intValue());
297

  
298
            // Get a database connection from the pool
299
            dbConn = 
300
                DBConnectionPool.getDBConnection("Identifier.createMapping");
301
            serialNumber = dbConn.getCheckOutSerialNumber();
302

  
303
            // Execute the insert statement
304
            String query = "insert into systemMetadata (guid, docid, rev) values (?, ?, ?)";            
305
            PreparedStatement stmt = dbConn.prepareStatement(query);
306
            stmt.setString(1, guid);
307
            stmt.setString(2, docid);
308
            stmt.setInt(3, rev);
309
            int rows = stmt.executeUpdate();
310

  
311
            stmt.close();
312
        } catch (SQLException e) {
313
            logMetacat.error("SQL error while creating a mapping to the system metadata identifier: " 
314
                    + e.getMessage());
315
        } catch (NumberFormatException e) {
316
            logMetacat.error("NumberFormat error while creating a mapping to the system metadata identifier: " 
317
                    + e.getMessage());
318
        } catch (AccessionNumberException e) {
319
            logMetacat.error("AccessionNumber error while creating a mapping to the system metadata identifier: " 
320
                    + e.getMessage());
321
        } finally {
322
            // Return database connection to the pool
323
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
324
        }
325
    }
280 326
}

Also available in: Unified diff