edu.ucsb.nceas.metacat

## Class DBUtil

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

-     public class DBUtil
      extends java.lang.Object

  A suite of utility classes for querying DB

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `NONEEXIST`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DBUtil()` Construct an instance of the utility class

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `findDataSetDocIdForGivenDocument(java.lang.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
    `static java.util.Vector<java.lang.String>` | `getAllDocids(java.lang.String scope)` get the latest Accession Number from a particular scope
    `static java.util.Vector<java.lang.String>` | `getAllDocidsByType(java.lang.String doctype, boolean includeRevs)` return all docids with a given doctype on all servers
    `static java.util.Vector<java.lang.String>` | `getAllDocidsByType(java.lang.String doctype, boolean includeRevs, int serverLocation)` return all docids with a given doctype for a given server
    `java.lang.String` | `getCurrentRevisionAndDocTypeForGivenDocument(java.lang.String givenDocId)` Method to get current revision and doctype for a given docid The output will look like "rev;doctype"
    `static int` | `getLatestRevisionInDocumentTable(java.lang.String docIdWithoutRev)` 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
    `java.lang.String` | `getMaxDocid(java.lang.String scope)` get the latest Accession Number from a particular scope
    `static int` | `getMaxRevFromRevisionTable(java.lang.String docIdWithoutRev)` Method to return max rev number in xml_revision for given docid.
    `static java.util.Vector<java.lang.Integer>` | `getRevListFromRevisionTable(java.lang.String docIdWithoutRev)` Method to return a rev list in xml_revision for given docid.
    `boolean` | `idExists(java.lang.String docid)` return true if the given docid is registered in either the xml_documents or xml_revisions table
    `static void` | `main(java.lang.String[] args)` main routine used for testing.
    `java.lang.String` | `readDoctypes()` read all doctypes from db connection in XML format select all Public Id from xml_catalog table
    `java.lang.String` | `readDTDSchema(java.lang.String doctype)` read DTD or Schema file from Metacat's XML catalog system

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### NONEEXIST

          public static final int NONEEXIST

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DBUtil

          public DBUtil()

      Construct an instance of the utility class

  - ### Method Detail

    - #### main

          public static void main(java.lang.String[] args)

      main routine used for testing.

      Usage: java DBUtil <-dt|-dg>

      Parameters:
        `-dt` - for selecting all doctypes -dg for selecting DataGuide

    - #### readDoctypes

          public java.lang.String readDoctypes()
                                        throws java.sql.SQLException

      read all doctypes from db connection in XML format select all Public Id from xml_catalog table
      Throws:
        `java.sql.SQLException`

    - #### readDTDSchema

          public java.lang.String readDTDSchema(java.lang.String doctype)
                                         throws java.sql.SQLException,
                                                java.net.MalformedURLException,
                                                java.io.IOException,
                                                edu.ucsb.nceas.utilities.PropertyNotFoundException

      read DTD or Schema file from Metacat's XML catalog system
      Throws:
        `java.sql.SQLException`
        `java.net.MalformedURLException`
        `java.io.IOException`
        `edu.ucsb.nceas.utilities.PropertyNotFoundException`

    - #### getMaxDocid

          public java.lang.String getMaxDocid(java.lang.String scope)
                                       throws java.sql.SQLException

      get the latest Accession Number from a particular scope
      Throws:
        `java.sql.SQLException`

    - #### idExists

          public boolean idExists(java.lang.String docid)
                           throws java.sql.SQLException

      return true if the given docid is registered in either the xml_documents or xml_revisions table
      Throws:
        `java.sql.SQLException`

    - #### getAllDocidsByType

          public static java.util.Vector<java.lang.String> getAllDocidsByType(java.lang.String doctype,
                                                                              boolean includeRevs)
                                                                       throws java.sql.SQLException

      return all docids with a given doctype on all servers
      Throws:
        `java.sql.SQLException`

    - #### getAllDocidsByType

          public static java.util.Vector<java.lang.String> getAllDocidsByType(java.lang.String doctype,
                                                                              boolean includeRevs,
                                                                              int serverLocation)
                                                                       throws java.sql.SQLException

      return all docids with a given doctype for a given server
      Throws:
        `java.sql.SQLException`

    - #### getAllDocids

          public static java.util.Vector<java.lang.String> getAllDocids(java.lang.String scope)
                                                                 throws java.sql.SQLException

      get the latest Accession Number from a particular scope
      Throws:
        `java.sql.SQLException`

    - #### findDataSetDocIdForGivenDocument

          public static java.lang.String findDataSetDocIdForGivenDocument(java.lang.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 java.lang.String getCurrentRevisionAndDocTypeForGivenDocument(java.lang.String givenDocId)
                                                                        throws java.sql.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:
        `java.sql.SQLException`

    - #### getMaxRevFromRevisionTable

          public static int getMaxRevFromRevisionTable(java.lang.String docIdWithoutRev)
                                                throws java.sql.SQLException

      Method to return max rev number in xml_revision for given docid.
      Parameters:
        `docId` -
      Returns:
        integer that holds max revision number
      Throws:
        `java.sql.SQLException`

    - #### getRevListFromRevisionTable

          public static java.util.Vector<java.lang.Integer> getRevListFromRevisionTable(java.lang.String docIdWithoutRev)
                                                                                 throws java.sql.SQLException

      Method to return a rev list in xml_revision for given docid.
      Parameters:
        `docId` -
      Returns:
        is a vector which contains Integer object
      Throws:
        `java.sql.SQLException`

    - #### getLatestRevisionInDocumentTable

          public static int getLatestRevisionInDocumentTable(java.lang.String docIdWithoutRev)
                                                      throws java.sql.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:
        `java.sql.SQLException`

Copyright © 2020 Regents of the University of California. All Rights Reserved.