Class DBUtil

java.lang.Object
edu.ucsb.nceas.metacat.DBUtil

public class DBUtil extends Object
A suite of utility classes for querying DB
  • Field Details

  • Constructor Details

    • DBUtil

      public DBUtil()
      Construct an instance of the utility class
  • Method Details

    • main

      public static void main(String[] args)
      main routine used for testing.

      Usage: java DBUtil <-dt|-dg>

    • readDoctypes

      public String readDoctypes() throws SQLException
      read all doctypes from db connection in XML format select all Public Id from xml_catalog table
      Throws:
      SQLException
    • readDTDSchema

      public String readDTDSchema(String doctype) throws SQLException, MalformedURLException, IOException, edu.ucsb.nceas.utilities.PropertyNotFoundException
      read DTD or Schema file from Metacat's XML catalog system
      Throws:
      SQLException
      MalformedURLException
      IOException
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getMaxDocid

      public String getMaxDocid(String scope) throws SQLException
      get the latest Accession Number from a particular scope
      Throws:
      SQLException
    • idExists

      public boolean idExists(String docid) throws SQLException
      return true if the given docid is registered in either the xml_documents or xml_revisions table
      Throws:
      SQLException
    • getAllDocidsByType

      public static Vector<String> getAllDocidsByType(String doctype, boolean includeRevs) throws SQLException
      return all docids with a given doctype on all servers
      Throws:
      SQLException
    • getAllDocidsByType

      public static Vector<String> getAllDocidsByType(String doctype, boolean includeRevs, int serverLocation) throws SQLException
      return all docids with a given doctype for a given server
      Throws:
      SQLException
    • getAllDocids

      public static Vector<String> getAllDocids(String scope) throws SQLException
      get the latest Accession Number from a particular scope
      Throws:
      SQLException
    • findDataSetDocIdForGivenDocument

      public static String findDataSetDocIdForGivenDocument(String givenDocId)
      To a given docid, found a dataset docid which contains the the given docid This will be done by searching xml_relation table If couldn't find, null will be return
      Parameters:
      givenDocId - , the docid which we want to find
    • getCurrentRevisionAndDocTypeForGivenDocument

      public String getCurrentRevisionAndDocTypeForGivenDocument(String givenDocId) throws SQLException
      Method to get current revision and doctype for a given docid The output will look like "rev;doctype"
      Parameters:
      givenDocId - , the docid which we want
      Throws:
      SQLException
    • getMaxRevFromRevisionTable

      public static int getMaxRevFromRevisionTable(String docIdWithoutRev) throws SQLException
      Method to return max rev number in xml_revision for given docid.
      Parameters:
      docId -
      Returns:
      integer that holds max revision number
      Throws:
      SQLException
    • getRevListFromRevisionTable

      public static Vector<Integer> getRevListFromRevisionTable(String docIdWithoutRev) throws SQLException
      Method to return a rev list in xml_revision for given docid.
      Parameters:
      docId -
      Returns:
      is a vector which contains Integer object
      Throws:
      SQLException
    • getLatestRevisionInDocumentTable

      public static int getLatestRevisionInDocumentTable(String docIdWithoutRev) throws SQLException
      Get last revision number from database for a docid If couldn't find an entry, -1 will return The return value is integer because we want compare it to there new one
      Parameters:
      docid - . part of Accession Number
      Throws:
      SQLException