Project

General

Profile

« Previous | Next » 

Revision 1140

Added by Jing Tao over 22 years ago

Change back to using Connection. The DBConnection will be store in a cvs branch.

View differences:

src/edu/ucsb/nceas/metacat/AccessionNumber.java
244 244
  {
245 245
    String uniqueid;
246 246
    String sysdate = dbAdapter.getDateTimeFunction();
247
    DBConnection conn = null;
248
    int serialNumber = -1;
247
    
249 248
    try {
250
      PreparedStatement pstmt = null;
251
      
252
      //check out DBConnection
253
      conn=DBConnectionPool.getDBConnection("AccessionNumber.getUniqueID");
254
      serialNumber=conn.getCheckOutSerialNumber();
249
      PreparedStatement pstmt;
255 250
      pstmt = conn.prepareStatement
256 251
              ("INSERT INTO accession_number (site_code, date_created) " +
257 252
               "VALUES (?, " + sysdate + ")");
......
259 254
      pstmt.execute();
260 255
      pstmt.close();
261 256
      
262
      uniqueid = "" + dbAdapter.getUniqueID(conn.getConnections(),
263
                                                          "accession_number");
264
      //because we only count the connection usage one when it check in
265
      //but it use twice. So we need to increase one
266
      conn.increaseUsageCount(1);
257
      uniqueid = "" + dbAdapter.getUniqueID(conn, "accession_number");
267 258

  
268 259
    } catch (SQLException e) {
269 260
      throw new 
270 261
      SQLException("Error on AccessionNumber.getUniqueID(): "+e.getMessage());
271 262
    }
272
    finally
273
    {
274
      DBConnectionPool.returnDBConnection(conn, serialNumber);
275
    }
263

  
276 264
    return uniqueid;
277 265
  }
278 266

  
......
281 269
                  throws SQLException {
282 270
        
283 271
    boolean hasAccNumber = false;
284
    DBConnection conn = null;
285
    int serialNumber = -1;
286 272
        
287 273
    try {
288
      PreparedStatement pstmt = null;
289
      //check out DBConnection
290
      conn=DBConnectionPool.getDBConnection("AccessionNumber.accNumberUsed");
291
      serialNumber=conn.getCheckOutSerialNumber();
274
      PreparedStatement pstmt;
292 275
      pstmt = conn.prepareStatement(
293 276
                "SELECT 'x' FROM xml_documents " + 
294 277
                "WHERE docid = ? " +
......
305 288
    } catch (SQLException e) {
306 289
      throw new SQLException
307 290
      ("Error on AccessionNumber.accNumberUsed(accNumber): " + e.getMessage());
308
    }
309
    finally
310
    {
311
      DBConnectionPool.returnDBConnection(conn, serialNumber);
312
    }
291
    }    
313 292
        
314 293
    return hasAccNumber;
315 294
  }    
......
318 297
  private boolean accNumberIsCurrent(String accNumber) throws SQLException {
319 298
        
320 299
    boolean hasCurrentAccNumber = false;
321
    DBConnection conn = null;
322
    int serialNumber = -1;
323 300
        
324 301
    try {
325
      PreparedStatement pstmt = null;
326
      //check out DBConnection
327
      conn=DBConnectionPool.getDBConnection("AccessionNumber.accNumberIsCurre");
328
      serialNumber=conn.getCheckOutSerialNumber();
302
      PreparedStatement pstmt;
329 303
      pstmt = conn.prepareStatement(
330 304
                "SELECT 'x' FROM xml_documents " + 
331 305
                "WHERE docid = ?");
......
339 313
      throw new SQLException(
340 314
          "Error on AccessionNumber.accNumberIsCurrent(String accNumber): " +
341 315
          e.getMessage());
342
    }
343
    finally
344
    {
345
      DBConnectionPool.returnDBConnection(conn, serialNumber);
346
    }
316
    }    
347 317
  
348 318
    return hasCurrentAccNumber;
349 319
  }    
......
352 322
  private String getLastRevision(String docid) throws SQLException
353 323
  {
354 324
    String rev = "";
355
    DBConnection conn = null;
356
    int serialNumber = -1;
357 325
    
358 326
    try {
359
      PreparedStatement pstmt = null;
360
      //check out DBConnection
361
      conn=DBConnectionPool.getDBConnection("AccessionNumber.getLastRevision");
362
      serialNumber=conn.getCheckOutSerialNumber();
327
      PreparedStatement pstmt;
363 328
      pstmt = conn.prepareStatement
364 329
              ("SELECT rev FROM xml_documents WHERE docid='" + docid + "'");
365 330
      pstmt.execute();
......
373 338
      throw new SQLException(
374 339
      "Error on AccessionNumber.getLastRevision(): " + e.getMessage());
375 340
    }
376
    finally
377
    {
378
      DBConnectionPool.returnDBConnection(conn,serialNumber);
379
    }
380 341

  
381 342
    return rev;
382 343
  }
......
389 350
  private int getLastRevisionNumber(String docId) throws SQLException
390 351
  {
391 352
    int rev = 1;
392
    DBConnection conn =null;
393
    int serialNumber = -1;
394 353
    
395 354
    try {
396
      PreparedStatement pStmt = null;
397
      //check out DBConnection
398
      conn=DBConnectionPool.getDBConnection("AccessionNumber.getLastRevisionN");
399
      serialNumber=conn.getCheckOutSerialNumber();
400
      
355
      PreparedStatement pStmt;
401 356
      pStmt = conn.prepareStatement
402 357
              ("SELECT rev FROM xml_documents WHERE docid='" + docId + "'");
403 358
      pStmt.execute();
......
411 366
      throw new SQLException(
412 367
      "Error on AccessionNumber.getLastRevision(): " + e.getMessage());
413 368
    }
414
    finally
415
    {
416
      DBConnectionPool.returnDBConnection(conn,serialNumber);
417
    }
369

  
418 370
    return rev;
419 371
  }
420 372
  
......
422 374
  private String getNextRevision(String docid) throws SQLException
423 375
  {
424 376
    String rev = "";
425
    DBConnection conn = null;
426
    int serialNumber = -1;
377
    
427 378
    try {
428
      PreparedStatement pstmt = null;
429
      //check out DBConnection
430
      conn=DBConnectionPool.getDBConnection("AccessionNumber.getNextRevision");
431
      serialNumber=conn.getCheckOutSerialNumber();
379
      PreparedStatement pstmt;
432 380
      pstmt = conn.prepareStatement
433 381
              ("SELECT rev+1 FROM xml_documents WHERE docid='" + docid + "'");
434 382
      pstmt.execute();
......
442 390
      throw new SQLException(
443 391
      "Error on AccessionNumber.getNextRevision(): " + e.getMessage());
444 392
    }
445
    finally
446
    {
447
      DBConnectionPool.returnDBConnection(conn, serialNumber);
448
    }
449 393

  
450 394
    return rev;
451 395
  }

Also available in: Unified diff