com.ihr.xbrl.store

## Class StorageService

- java.lang.Object
- - com.ihr.xbrl.database.common.XBRLDatabaseAccessApp
  - - com.ihr.xbrl.store.StorageService

- All Implemented Interfaces:
    HasEnableDisableOpenMenus, StorageEventListener
  Direct Known Subclasses:
    ExtractionEngine, RSS_Storage_SEC

      public class StorageService
      extends XBRLDatabaseAccessApp
      implements HasEnableDisableOpenMenus, StorageEventListener

  This class is a storage service for XBRL documents to the XBRL Database.

  The idea is that a job to store a DTS is created by an external application and submitted to this service. The service creates a new thread in order to deal with the database.

  This class contains handlers for all required interfaces during the storage phase

  Author:
    Ignacio

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `StorageService.StorageStatus` The Enum StorageStatus.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StorageService(DatabaseManagerBase dbm, RegisterExtraClasses[] extra, java.util.Properties props, boolean hasGUI)` It must be public because of the way it should be initialized due to the HasURIResolverParameter interface.
    `StorageService(RegisterExtraClasses[] extra, java.util.Properties props, boolean hasGUI)` It must be public because of the way it should be initialized due to the HasURIResolverParameter interface.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Releases memory in the caches reserved by the surrounding processors.
    `void` | `disableOpen()` Called when menus has to be set to "disabled" state.
    `void` | `documentStoredEvent(StorageEvent evt)` Document stored event.
    `void` | `doStoreDTS(java.lang.String instanceUriOnDatabase, XBRLDocument document, org.hibernate.Session parameter, boolean inNewThread, boolean bForUpdate, org.apache.log4j.Level logLevel, StorageEventListener[] listeners)` Starts the storage of a DTS into the database in an unattended new thread.
    `void` | `doStoreDTS(java.net.URI[] uris, java.lang.String dtsName, DbUtil dbUtil, HasStoreUserQuestions app, HasEnableDisableOpenMenus appEnableDisable, HasLoadingBar appLoadingBar, HasErrorsHandler errHandler, HasLogPanel appLogPanel, boolean inNewThread, boolean bForUpdate, StorageEventListener[] listeners)` Starts the storage of a DTS into the database in an unattended new thread.
    `void` | `doStoreDTS(XBRLDocument document, org.hibernate.Session parameter, boolean inNewThread, boolean bForUpdate, org.apache.log4j.Level logLevel, StorageEventListener[] listeners)` Starts the storage of a DTS into the database in an unattended new thread.
    `void` | `enableOpen()` Called when menus has to be set to "enables" state.
    `java.lang.String` | `getLastMessage(StoreXBRLThread th)` Gets the last message.
    `int` | `getPercentage(StoreXBRLThread th)` Gets the percentage.
    `static StorageService` | `getService(RegisterExtraClasses[] extra, java.util.Properties props, boolean hasGUI)` Obtains the instance of the static service class that manages storage of information into the XBRL database.
    `java.lang.String` | `getStackTrace(StoreXBRLThread th)` Gets the stack trace.
    `StorageService.StorageStatus` | `getStatus(StoreXBRLThread th)` Gets the status.
    `java.util.Collection<StoreXBRLThread>` | `getStorageThreads()` Access to the collection of active threads.
    `java.lang.String` | `getTooltipMessage(StoreXBRLThread th)` Gets the tooltip message.
    `boolean` | `isStored(java.net.URI uri, org.hibernate.Session dbSession)` Returns true if the document with URI is already stored in the database.

    - ### Methods inherited from class com.ihr.xbrl.database.common.XBRLDatabaseAccessApp

      `getDbUtil, getStatus, showDbSettings`

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

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

- - ### Constructor Detail

    - #### StorageService

          public StorageService(RegisterExtraClasses[] extra,
                        java.util.Properties props,
                        boolean hasGUI)

      It must be public because of the way it should be initialized due to the HasURIResolverParameter interface.
      Parameters:
        `extra` - is an array of RegisterExtraClasses objects
        `props` - additional Properties object for the connection to the database
        `hasGUI` - this is true if the service can open a window to the end user. false otherwise.
      See Also:
        `RegisterExtraClasses`

    - #### StorageService

          public StorageService(DatabaseManagerBase dbm,
                        RegisterExtraClasses[] extra,
                        java.util.Properties props,
                        boolean hasGUI)

      It must be public because of the way it should be initialized due to the HasURIResolverParameter interface.
      Parameters:
        `dbm` - the database manager base to use with alternate configuration to connect to the database
        `extra` - is an array of RegisterExtraClasses objects
        `props` - additional Properties object for the connection to the database and to the pojo generarion process
        `hasGUI` - this is true if the service can open a window to the end user. false otherwise.
      See Also:
        `RegisterExtraClasses`

  - ### Method Detail

    - #### getService

          public static StorageService getService(RegisterExtraClasses[] extra,
                                  java.util.Properties props,
                                  boolean hasGUI)

      Obtains the instance of the static service class that manages storage of information into the XBRL database.

      The parameters are optional and both can be null.

      Parameters:
        `extra` - array of RegisterExtraClasses instances. The RegisterExtraClasses interface allows for extending the database model for additional objects
        `props` - extra properties that will be added to the connection to the database and to the pojo generarion process
        `hasGUI` - this is true if the service can open a window to the end user. false otherwise.
      Returns:
        the StorageSerice instance. The first time this method is called the service will be initialized with the supplied parameters. on subsequent calls the parameters are ignored. Note the constructor of the StorageService is public this allows you applications to configure multiple storage services if this is needed.
      See Also:
        `RegisterExtraClasses`

    - #### doStoreDTS

          public void doStoreDTS(XBRLDocument document,
                        org.hibernate.Session parameter,
                        boolean inNewThread,
                        boolean bForUpdate,
                        org.apache.log4j.Level logLevel,
                        StorageEventListener[] listeners)

      Starts the storage of a DTS into the database in an unattended new thread. The process can be interrogated doing calls to this object.

      NOTE: The second parameter is the database session. It MUST be configured with Flush.COMMIT in order to work properly. typically you would do:

                  Session session = StorageService.getService(null,null).getDbUtil().getSessionFactory(null).openSession();
                  session.setFlushMode(FlushMode.COMMIT);
                  StorageService.getService(null,null).doStoreDTS(instance,session,true,false);

      Parameters:
        `document` - XBRLDocument to be stored
        `parameter` - the database session already opened
        `inNewThread` - if this argument is false, the storage will not create a new thread
        `bForUpdate` - if this parameter is true and the document already exists in the database, the document content will be updated. (only for XBRL reports)
        `logLevel` - the log level
        `listeners` - the listeners

    - #### doStoreDTS

          public void doStoreDTS(java.lang.String instanceUriOnDatabase,
                        XBRLDocument document,
                        org.hibernate.Session parameter,
                        boolean inNewThread,
                        boolean bForUpdate,
                        org.apache.log4j.Level logLevel,
                        StorageEventListener[] listeners)

      Starts the storage of a DTS into the database in an unattended new thread. The process can be interrogated doing calls to this object.

      NOTE: The second parameter is the database session. It MUST be configured with Flush.COMMIT in order to work properly. typically you would do:

                  Session session = StorageService.getService(null,null).getDbUtil().getSessionFactory(null).openSession();
                  session.setFlushMode(FlushMode.COMMIT);
                  StorageService.getService(null,null).doStoreDTS(instance,session,true,false);

      Parameters:
        `instanceUriOnDatabase` - this is the URI of the instance document in the database. Also, the URI will be used as base uri for transformation of locally referenced taxonomies and linkbases
        `document` - XBRLDocument to be stored
        `parameter` - the database session already opened
        `inNewThread` - if this argument is false, the storage will not create a new thread
        `bForUpdate` - if this parameter is true and the document already exists in the database, the document content will be updated. (only for XBRL reports)
        `logLevel` - the log level
        `listeners` - the listeners

    - #### doStoreDTS

          public void doStoreDTS(java.net.URI[] uris,
                        java.lang.String dtsName,
                        DbUtil dbUtil,
                        HasStoreUserQuestions app,
                        HasEnableDisableOpenMenus appEnableDisable,
                        HasLoadingBar appLoadingBar,
                        HasErrorsHandler errHandler,
                        HasLogPanel appLogPanel,
                        boolean inNewThread,
                        boolean bForUpdate,
                        StorageEventListener[] listeners)

      Starts the storage of a DTS into the database in an unattended new thread. The process can be interrogated doing calls to this object.

      NOTE: The second parameter is the database session. It MUST be configured with Flush.COMMIT in order to work properly. typically you would do:

                  Session session = StorageService.getService(null,null).getDbUtil().getSessionFactory(null).openSession();
                  session.setFlushMode(FlushMode.COMMIT);
                  StorageService.getService(null,null).doStoreDTS(instance,session,true,false);

      Parameters:
        `uris` - this is an array of URIs of documents to store. Also, the URI will be used as base uri for transformation of locally referenced taxonomies and linkbases
        `dtsName` - the dts name
        `dbUtil` - instance of the DbUtil to use
        `app` - implementation of the HasStoreUserQuestions interface
        `appEnableDisable` - implementation of the HasEnableDisableOpenMenus interface
        `appLoadingBar` - implementation of the HasLoadingBar interface
        `errHandler` - implementation of the HasErrorsHandler interface
        `appLogPanel` - implementation of the HasLogPanel interface
        `inNewThread` - if this argument is false, the storage will not create a new thread
        `bForUpdate` - if this parameter is true and the document already exists in the database, the document content will be updated. (only for XBRL reports)
        `listeners` - the listeners

    - #### clear

          public void clear()

      Releases memory in the caches reserved by the surrounding processors. If the processor is the static service, the static service is set to null. This also removes all information about terminated storage processes already finished either with OK status and ERROR status
      Since:
        2.8.1

    - #### disableOpen

          public void disableOpen()

      Description copied from interface: `HasEnableDisableOpenMenus`
      Called when menus has to be set to "disabled" state.
      Specified by:
        `disableOpen` in interface `HasEnableDisableOpenMenus`

    - #### enableOpen

          public void enableOpen()

      Description copied from interface: `HasEnableDisableOpenMenus`
      Called when menus has to be set to "enables" state.
      Specified by:
        `enableOpen` in interface `HasEnableDisableOpenMenus`

    - #### documentStoredEvent

          public void documentStoredEvent(StorageEvent evt)

      Description copied from interface: `StorageEventListener`
      Document stored event.
      Specified by:
        `documentStoredEvent` in interface `StorageEventListener`
      Parameters:
        `evt` - the evt

    - #### isStored

          public boolean isStored(java.net.URI uri,
                         org.hibernate.Session dbSession)

      Returns true if the document with URI is already stored in the database.
      Parameters:
        `uri` - the uri
        `dbSession` - the db session
      Returns:
        boolean value true means yes, it is stored

    - #### getStorageThreads

          public java.util.Collection<StoreXBRLThread> getStorageThreads()

      Access to the collection of active threads. Some of them may already have finished working
      Returns:
        the storage threads

    - #### getStatus

          public StorageService.StorageStatus getStatus(StoreXBRLThread th)

      Gets the status.
      Parameters:
        `th` - the th
      Returns:
        the status

    - #### getStackTrace

          public java.lang.String getStackTrace(StoreXBRLThread th)

      Gets the stack trace.
      Parameters:
        `th` - the th
      Returns:
        the stack trace

    - #### getLastMessage

          public java.lang.String getLastMessage(StoreXBRLThread th)

      Gets the last message.
      Parameters:
        `th` - the th
      Returns:
        the last message

    - #### getTooltipMessage

          public java.lang.String getTooltipMessage(StoreXBRLThread th)

      Gets the tooltip message.
      Parameters:
        `th` - the th
      Returns:
        the tooltip message

    - #### getPercentage

          public int getPercentage(StoreXBRLThread th)

      Gets the percentage.
      Parameters:
        `th` - the th
      Returns:
        the percentage