edu.ucsb.nceas.metacat.dataone.quota

## Class QuotaDBManager

- java.lang.Object
- - edu.ucsb.nceas.metacat.dataone.quota.QuotaDBManager

-     public class QuotaDBManager
      extends java.lang.Object

  Represents a class to manipulate the usages table for the quota service in the postgresql database
  Author:
    tao

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `DATEREPORTED`
    `static java.lang.String` | `INSTANCEID`
    `static java.lang.String` | `NODEID`
    `static java.lang.String` | `OBJECT`
    `static java.lang.String` | `QUANTITY`
    `static java.lang.String` | `QUOTAID`
    `static java.lang.String` | `QUOTASUBJECT`
    `static java.lang.String` | `QUOTATYPE`
    `static java.lang.String` | `REQUESTOR`
    `static java.lang.String` | `STATUS`
    `static java.lang.String` | `TABLE`
    `static java.lang.String` | `USAGELOCALID`
    `static java.lang.String` | `USAGEREMOTEID`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `QuotaDBManager()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `createUsage(org.dataone.bookkeeper.api.Usage usage, java.util.Date date)` Create a usage record in the usages table with the given date as the reported date If the date is null, it will create a usage record without the reported date
    `static java.sql.ResultSet` | `getUnReportedUsages()` Get the result set from the table which haven't been reported to the bookkeeper server.
    `static int` | `lookupRemoteUsageId(int quotaId, java.lang.String instanceId)` Find the remote usage id in the local database for the given quota id and instance id
    `static void` | `setReportedDateAndRemoteId(int localId, java.util.Date date, int remoteId)` Set the reported date and remote id for a given usage local id

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

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

- - ### Field Detail

    - #### TABLE

          public static final java.lang.String TABLE

      See Also:
        Constant Field Values

    - #### USAGELOCALID

          public static final java.lang.String USAGELOCALID

      See Also:
        Constant Field Values

    - #### USAGEREMOTEID

          public static final java.lang.String USAGEREMOTEID

      See Also:
        Constant Field Values

    - #### QUOTAID

          public static final java.lang.String QUOTAID

      See Also:
        Constant Field Values

    - #### INSTANCEID

          public static final java.lang.String INSTANCEID

      See Also:
        Constant Field Values

    - #### QUANTITY

          public static final java.lang.String QUANTITY

      See Also:
        Constant Field Values

    - #### STATUS

          public static final java.lang.String STATUS

      See Also:
        Constant Field Values

    - #### DATEREPORTED

          public static final java.lang.String DATEREPORTED

      See Also:
        Constant Field Values

    - #### OBJECT

          public static final java.lang.String OBJECT

      See Also:
        Constant Field Values

    - #### NODEID

          public static final java.lang.String NODEID

      See Also:
        Constant Field Values

    - #### QUOTASUBJECT

          public static final java.lang.String QUOTASUBJECT

      See Also:
        Constant Field Values

    - #### QUOTATYPE

          public static final java.lang.String QUOTATYPE

      See Also:
        Constant Field Values

    - #### REQUESTOR

          public static final java.lang.String REQUESTOR

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### QuotaDBManager

          public QuotaDBManager()

  - ### Method Detail

    - #### createUsage

          public static void createUsage(org.dataone.bookkeeper.api.Usage usage,
                                         java.util.Date date)
                                  throws java.sql.SQLException

      Create a usage record in the usages table with the given date as the reported date If the date is null, it will create a usage record without the reported date
      Parameters:
        `usage` - the usage will be record into the db table
        `date` - the reported date associated with the usage. If it is null, the reported date will be blank in the table
      Throws:
        `java.sql.SQLException`

    - #### setReportedDateAndRemoteId

          public static void setReportedDateAndRemoteId(int localId,
                                                        java.util.Date date,
                                                        int remoteId)
                                                 throws java.sql.SQLException

      Set the reported date and remote id for a given usage local id
      Parameters:
        `localId` - the local id of the usage will be set
        `date` - the date to report to the bookkeeper server
        `remoteId` - the remote id will be set
      Throws:
        `java.sql.SQLException`

    - #### getUnReportedUsages

          public static java.sql.ResultSet getUnReportedUsages()
                                                        throws java.sql.SQLException

      Get the result set from the table which haven't been reported to the bookkeeper server. The indication is the reported date is null in the usages table
      Returns:
        the result set which usages which haven't been reported to the bookkeeper server
      Throws:
        `java.sql.SQLException`

    - #### lookupRemoteUsageId

          public static int lookupRemoteUsageId(int quotaId,
                                                java.lang.String instanceId)
                                         throws java.sql.SQLException

      Find the remote usage id in the local database for the given quota id and instance id
      Parameters:
        `quotaId` - the quota id associated with the usage
        `instanceId` - the instance id associated with the usage
      Returns:
        the remote usage id. If it is -1, which means there is no remote usage id found.
      Throws:
        `java.sql.SQLException`

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