[metacat-cvs] metacat/src/edu/ucsb/nceas/metacat AccessionNumber.java AccessionNumberGeneratedException.java
Matthew Jones
jones at ecoinformatics.org
Fri Nov 18 16:44:23 PST 2005
jones 05/11/18 16:44:23
Modified: src/edu/ucsb/nceas/metacat AccessionNumber.java
Removed: src/edu/ucsb/nceas/metacat
AccessionNumberGeneratedException.java
Log:
Cleaned up AccessionNumber class to get rid of unused methods. It seems the entire accession_number table is no longer used but has not been deleted from the build. Will do in subsequent commit.
Revision Changes Path
1.35 +6 -174 metacat/src/edu/ucsb/nceas/metacat/AccessionNumber.java
Index: AccessionNumber.java
===================================================================
RCS file: /cvs/metacat/src/edu/ucsb/nceas/metacat/AccessionNumber.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- AccessionNumber.java 24 Aug 2004 22:35:02 -0000 1.34
+++ AccessionNumber.java 19 Nov 2005 00:44:23 -0000 1.35
@@ -7,9 +7,9 @@
* Authors: Jivka Bojilova, Matt Jones
* Release: @release@
*
- * '$Author: sgarg $'
- * '$Date: 2004/08/24 22:35:02 $'
- * '$Revision: 1.34 $'
+ * '$Author: jones $'
+ * '$Date: 2005/11/19 00:44:23 $'
+ * '$Revision: 1.35 $'
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,8 +28,9 @@
package edu.ucsb.nceas.metacat;
-import java.net.*;
-import java.sql.*;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import edu.ucsb.nceas.dbadapter.AbstractDatabase;
@@ -45,7 +46,6 @@
private static final AbstractDatabase dbAdapter = MetaCatUtil.dbAdapter;
- //private Connection conn = null;
private String sitecode = null;
private String sep = null;
private String docid = null;
@@ -54,23 +54,10 @@
/**
* Construct an AccessionNumber
*/
- //public AccessionNumber ()
- //throws SQLException, ClassNotFoundException
- //{
- // Open a connection to the database from here
- //this((new MetaCatUtil()).openDBConnection());
- //}
-
- /**
- * Construct an AccessionNumber
- *
- * @param conn the db connection to read from and write Accession# to
- */
- public AccessionNumber ()
+ private AccessionNumber ()
{
this.sitecode = MetaCatUtil.getOption("sitecode");
this.sep = MetaCatUtil.getOption("accNumSeparator");
- //this.conn = conn;
}
/** NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT
@@ -173,129 +160,6 @@
}
}
- /**
- * Generate an Accession Number of form <sidecode>.<uniqueid>.<revisionid>
- * where <revisionid> is always 1.
- *
- * @param docid <sitecode>.<uniqueid> part of Accession Number
- * @param action INSERT, UPDATE or DELETE action
- */
- public String generate(String docid, String action)
- throws AccessionNumberException, SQLException
- {
- return generate(docid, "1", action);
- }
-
- /**
- * Generate an Accession Number of form <sidecode>.<uniqueid>.<revisionid>
- *
- * @param docid <sitecode>.<uniqueid> part of Accession Number
- * @param rev <revisionid> of Accession Number
- * @param action INSERT, UPDATE or DELETE action
- */
- public String generate(String docid, String rev, String action)
- throws AccessionNumberException, SQLException
- {
- try {
- // INSERT
- if ( action.equals("INSERT")) {
-
- // get a new docid
- if ( docid == null ) {
- String sitecode = getSitecode();
- String uniqueid = getUniqueID(sitecode);
-
- return sitecode + sep + uniqueid;
-
- // docid is used; throw an exception to prevent the insertion
- } else if ( accNumberUsed(docid) ) {
- throw new AccessionNumberException
- ("Accession number " + docid + " is already in use");
- // rev is <> 1; throw an exception to prevent the insertion
- } else if ( !rev.equals("1") ) {
- throw new AccessionNumberException
- ("Revision number must be 1");
- // docid is not used and rev=1; return it
- } else {
- return docid;
- }
-
- // UPDATE or DELETE
- } else if ( action.equals("UPDATE") || action.equals("DELETE")) {
-
- // Accession# is not provided; throw an exception to prevent the action
- if ( docid == null ) {
- throw new AccessionNumberException("Accession number is required");
-
- // Accession# is not current (not in xml_documents); throw an exception
- } else if ( !accNumberIsCurrent(docid) ) {
- throw new AccessionNumberException
- ("Document not found for Accession number " + docid);
-
- // Revision number is not the recent one; throw an exception
- } else if ( !rev.equals(getLastRevision(docid)) ) {
- throw new AccessionNumberException
- ("Revision number must be the recent");
-
- // Accession# is current (present in xml_documents); return it
- } else {
- return docid;
- }
- }
-
- } catch (SQLException e) {
- throw new SQLException
- ("Error on AccessionNumber.generate(): " + e.getMessage());
- }
-
- // never comes here
- throw new
- AccessionNumberException("Fatal Error in accession number generation");
- }
-
- // get local sitecode
- private String getSitecode()
- {
- return this.sitecode;
- }
-
- // get Unique ID from DB sequence
- private String getUniqueID (String sitecode) throws SQLException
- {
- String uniqueid;
- String sysdate = dbAdapter.getDateTimeFunction();
- DBConnection conn = null;
- int serialNumber = -1;
- try {
- PreparedStatement pstmt = null;
-
- //check out DBConnection
- conn=DBConnectionPool.getDBConnection("AccessionNumber.getUniqueID");
- serialNumber=conn.getCheckOutSerialNumber();
- pstmt = conn.prepareStatement
- ("INSERT INTO accession_number (site_code, date_created) " +
- "VALUES (?, " + sysdate + ")");
- pstmt.setString(1, sitecode);
- pstmt.execute();
- pstmt.close();
-
- uniqueid = "" + dbAdapter.getUniqueID(conn.getConnections(),
- "accession_number");
- //because we only count the connection usage one when it check in
- //but it use twice. So we need to increase one
- conn.increaseUsageCount(1);
-
- } catch (SQLException e) {
- throw new
- SQLException("Error on AccessionNumber.getUniqueID(): "+e.getMessage());
- }
- finally
- {
- DBConnectionPool.returnDBConnection(conn, serialNumber);
- }
- return uniqueid;
- }
-
/** check for existence of Accesssion Number xml_acc_numbers table */
public static boolean accNumberUsed ( String accNumber )
throws SQLException {
@@ -435,38 +299,6 @@
{
DBConnectionPool.returnDBConnection(conn,serialNumber);
}
- return rev;
- }
-
- // get the next revision number for docid
- private String getNextRevision(String docid) throws SQLException
- {
- String rev = "";
- DBConnection conn = null;
- int serialNumber = -1;
- try {
- PreparedStatement pstmt = null;
- //check out DBConnection
- conn=DBConnectionPool.getDBConnection("AccessionNumber.getNextRevision");
- serialNumber=conn.getCheckOutSerialNumber();
- pstmt = conn.prepareStatement
- ("SELECT rev+1 FROM xml_documents WHERE docid='" + docid + "'");
- pstmt.execute();
-
- ResultSet rs = pstmt.getResultSet();
- boolean hasRow = rs.next();
- rev = rs.getString(1);
- pstmt.close();
-
- } catch (SQLException e) {
- throw new SQLException(
- "Error on AccessionNumber.getNextRevision(): " + e.getMessage());
- }
- finally
- {
- DBConnectionPool.returnDBConnection(conn, serialNumber);
- }
-
return rev;
}
More information about the Metacat-cvs
mailing list