de.esprit.netsuite.server.chreq

## Class DataSourceManager

- java.lang.Object
- - de.esprit.common.util.DumpableObject
  - - de.esprit.appsuite.launch.AbstractApplicationObject<S>
    - - de.esprit.netsuite.server.AbstractServerObject<ServerContext>
      - - de.esprit.netsuite.server.chreq.DataSourceManager

- All Implemented Interfaces:
    ApplicationObject<ServerContext>, CloseableComponent, SimpleLogSupport, Dumpable, ServerObject<ServerContext>, java.lang.AutoCloseable

      public class DataSourceManager
      extends AbstractServerObject<ServerContext>
      implements CloseableComponent

  This class maintains a pool of connected DataSource objects which can be selected by name. The selected DataSource is the current one that is used by DBObjects. Only one DataSource can be selected at a time.
  Author:
    Rainer Buesch

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DataSourceManager(ServerContext serverCtx)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Closes and removes all DataSources in the pool
    `boolean` | `close(java.lang.String dataSourceName)` Closes and removes the given DataSource by name
    `int` | `connect()` Reads the srv_datasource.cfg file and fills the pool with according connected DataSource Objects.
    `DataSourceEntry` | `findDataSourceEntry(java.lang.String dsName)` Finds the DataSourceEntry by name
    `java.sql.Connection` | `getCurrentConnection()` Returns a connection of the currently selected connection pool.
    `DataSourceEntry` | `getCurrentDataSource()`
    `DBConnectionPool` | `getDataSource(java.lang.String dataSourceName)` Returns the corresponding DBConnectionPool or null if not found
    `DataSourceEntry[]` | `getDataSourceEntries()` Returns the list of currently configured DataSourceEntries
    `DBConnectionPool[]` | `getDataSources()`
    `java.util.List<ServerCredential>` | `getDefinedCredentials()`
    `int` | `getSize()` Returns the number of configured DataSources
    `boolean` | `hasDefinedCredentials()`
    `ResourceLock` | `lockExclusive(SessionId sessId)`
    `ResourceLock` | `lockShared(SessionId sessId)`
    `void` | `releaseLock(SessionId sessId, ResourceLock lock)`
    `DataSourceEntry` | `resetToDefaultDataSource(SessionId sessId)` Resets to the default DataSource which is the first one configured in the config file.
    `DataSourceEntry` | `resetToPreviousDataSource(SessionId sessId)` Resets to the previously selected DataSource.
    `DataSourceEntry` | `selectDataSource(SessionId sessId, java.lang.String dataSourceName)` Selects the DataSource by name.

    - ### Methods inherited from class de.esprit.netsuite.server.AbstractServerObject

      `getServerConfig, getServerContext, getServerParams, getServerStartup, getStatisticManager, toString`

    - ### Methods inherited from class de.esprit.appsuite.launch.AbstractApplicationObject

      `getApplicationContext, getLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannel`

    - ### Methods inherited from class de.esprit.common.util.DumpableObject

      `configureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, createDumpHeader, toDumpString, toDumpString, toString`

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

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

- - ### Constructor Detail

    - #### DataSourceManager

          public DataSourceManager(ServerContext serverCtx)
                            throws java.lang.Exception

      Throws:
        `java.lang.Exception`

  - ### Method Detail

    - #### getDefinedCredentials

          public java.util.List<ServerCredential> getDefinedCredentials()

    - #### hasDefinedCredentials

          public boolean hasDefinedCredentials()

    - #### findDataSourceEntry

          public DataSourceEntry findDataSourceEntry(java.lang.String dsName)

      Finds the DataSourceEntry by name
      Returns:
        the DataSourceEntry or null if not found

    - #### lockShared

          public ResourceLock lockShared(SessionId sessId)
                                  throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### lockExclusive

          public ResourceLock lockExclusive(SessionId sessId)
                                     throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### releaseLock

          public void releaseLock(SessionId sessId,
                         ResourceLock lock)
                           throws NotLockOwnerException

      Throws:
        `NotLockOwnerException`

    - #### connect

          public int connect()
                      throws java.lang.Exception

      Reads the srv_datasource.cfg file and fills the pool with according connected DataSource Objects. The first configured DataSource becomes the current one.
      Throws:
        `java.lang.Exception`

    - #### getSize

          public int getSize()

      Returns the number of configured DataSources

    - #### close

          public void close()

      Closes and removes all DataSources in the pool
      Specified by:
        `close` in interface `java.lang.AutoCloseable`

    - #### close

          public boolean close(java.lang.String dataSourceName)

      Closes and removes the given DataSource by name

    - #### getDataSourceEntries

          public DataSourceEntry[] getDataSourceEntries()

      Returns the list of currently configured DataSourceEntries

    - #### getDataSources

          public DBConnectionPool[] getDataSources()

    - #### getDataSource

          public DBConnectionPool getDataSource(java.lang.String dataSourceName)
                                         throws InvalidDataSourceException

      Returns the corresponding DBConnectionPool or null if not found
      Throws:
        `InvalidDataSourceException`

    - #### selectDataSource

          public DataSourceEntry selectDataSource(SessionId sessId,
                                         java.lang.String dataSourceName)
                                           throws InvalidDataSourceException,
                                                  ResourceLockedException

      Selects the DataSource by name. The sessionId may be null if the server itself calls this method.
      Throws:
        `InvalidDataSourceException` - if the data source name does not exist
        `ResourceLockedException`

    - #### getCurrentDataSource

          public DataSourceEntry getCurrentDataSource()

      Returns:
        the currently selected DataSourceEntry, null if none is configured

    - #### getCurrentConnection

          public java.sql.Connection getCurrentConnection()

      Returns a connection of the currently selected connection pool. Note that this connection MUST be returned to the pool after usage by calling its close() method.
      Returns:
        a SQL Connection , null if none is configured

    - #### resetToDefaultDataSource

          public DataSourceEntry resetToDefaultDataSource(SessionId sessId)
                                                   throws InvalidDataSourceException,
                                                          ResourceLockedException

      Resets to the default DataSource which is the first one configured in the config file.
      Returns:
        the selected default DataSourceEntry, null if none is configured
      Throws:
        `InvalidDataSourceException`
        `ResourceLockedException`

    - #### resetToPreviousDataSource

          public DataSourceEntry resetToPreviousDataSource(SessionId sessId)
                                                    throws InvalidDataSourceException,
                                                           ResourceLockedException

      Resets to the previously selected DataSource. If the datasource selection never changed it is identical to the current datasource.
      Returns:
        the selected default DataSourceEntry, null if none is configured
      Throws:
        `InvalidDataSourceException`
        `ResourceLockedException`

Copyright © 2013 EsprIT-Systems. All Rights Reserved.