Package org.silverpeas.components.mydb.model

## Class MyDBConnectionInfo

- java.lang.Object
- - org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity<E,​I>
  - - org.silverpeas.core.persistence.datasource.model.jpa.BasicJpaEntity<MyDBConnectionInfo,​org.silverpeas.core.persistence.datasource.model.identifier.UniqueIntegerIdentifier>
    - - org.silverpeas.components.mydb.model.MyDBConnectionInfo

- All Implemented Interfaces:
    `Serializable`, `org.silverpeas.core.persistence.datasource.model.IdentifiableEntity`

      @Entity
      public class MyDBConnectionInfo
      extends org.silverpeas.core.persistence.datasource.model.jpa.BasicJpaEntity<MyDBConnectionInfo,​org.silverpeas.core.persistence.datasource.model.identifier.UniqueIntegerIdentifier>

  Information about a connexion to a data source. Such information is the name of the data source and the credentials required to access that data source.
  Author:
    mmoquillon
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `MyDBConnectionInfo()` |
    `` | `MyDBConnectionInfo​(String dataSource, String instanceId)` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `checkConnection()` | Checks the connection with the remote data source referred in this `MyDBConnectionInfo` instance.
    `boolean` | `equals​(Object o)` |
    `static MyDBConnectionInfo` | `getById​(String id)` |
    `int` | `getDataMaxNumber()` | Gets the maximum number of data to return when requesting the data source.
    `String` | `getDataSourceName()` | Gets the JNDI name of the data source targeted by this connection information.
    `String` | `getDefaultTableName()` | Gets the name of the table to load with this connexion information.
    `static List<MyDBConnectionInfo>` | `getFromComponentInstance​(String instanceId)` |
    `String` | `getInstanceId()` | Gets the unique identifier of the component instance this connection info belongs to.
    `String` | `getLogin()` | Gets the user identifier used in the data source authentication.
    `String` | `getPassword()` | Gets the password associated with the login to connect the data source.
    `int` | `hashCode()` |
    `boolean` | `isDefaultTableNameDefined()` | Is the name of the default table to load is defined?
    `boolean` | `isDefined()` | Is this connection information defined?
    `Connection` | `openConnection()` | Opens a connection to the data source targeted by this connection information.
    `void` | `remove()` | Removes this connection information from the persistence context.
    `static void` | `removeFromComponentInstance​(String instanceId)` |
    `void` | `save()` | Saves or updates this connection information into the persistence context in order to be able to retrieve it later.
    `void` | `setDataMaxNumber​(int maxNumber)` | Sets the maximum number of data to select when requesting the data source.
    `void` | `setDataSourceName​(String dataSourceName)` | Sets a new data source by its JNDI name to this connection info.
    `void` | `setDefaultTableName​(String tableName)` | Sets the name of the default table to load with this connection information.
    `void` | `setLoginAndPassword​(String login, String password)` | Sets the login and the password required to open a connection to the targeted data source.
    `MyDBConnectionInfo` | `withDataMaxNumber​(int maxNumber)` | Sets the maximum number of data to select when requesting the data source and returns this connection information.
    `MyDBConnectionInfo` | `withDataSourceName​(String dataSourceName)` | Sets a new data source by its JNDI name to this connection info.
    `MyDBConnectionInfo` | `withDefaultTableName​(String tableName)` | Sets the default table to defaultTable from the database with this connection information and returns the later.
    `MyDBConnectionInfo` | `withLoginAndPassword​(String login, String password)` |
    `MyDBConnectionInfo` | `withoutAnyDefaultTable()` |

    - ### Methods inherited from class org.silverpeas.core.persistence.datasource.model.jpa.BasicJpaEntity

      `performBeforePersist, performBeforeRemove, performBeforeUpdate`

    - ### Methods inherited from class org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity

      `getId, getNativeId, isPersisted, setId`

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

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

- - ### Constructor Detail

    - #### MyDBConnectionInfo

          protected MyDBConnectionInfo()

    - #### MyDBConnectionInfo

          public MyDBConnectionInfo​(String dataSource,
                                    String instanceId)

  - ### Method Detail

    - #### getById

          public static MyDBConnectionInfo getById​(String id)

    - #### getFromComponentInstance

          public static List<MyDBConnectionInfo> getFromComponentInstance​(String instanceId)

    - #### removeFromComponentInstance

          public static void removeFromComponentInstance​(String instanceId)

    - #### isDefined

          public boolean isDefined()

      Is this connection information defined? Information about a connection to a data source is defined if both it is related to a ConnecteurJDBC application instance and the name of the data source is defined.
      Returns:

    - #### withDefaultTableName

          public MyDBConnectionInfo withDefaultTableName​(String tableName)

      Sets the default table to defaultTable from the database with this connection information and returns the later.
      Parameters:
        `tableName` - the name of the table to load by default.
      Returns:
        itself.

    - #### withoutAnyDefaultTable

          public MyDBConnectionInfo withoutAnyDefaultTable()

    - #### withDataMaxNumber

          public MyDBConnectionInfo withDataMaxNumber​(int maxNumber)

      Sets the maximum number of data to select when requesting the data source and returns this connection information.
      Parameters:
        `maxNumber` - the maximum number of data to return. 0 means all.
      Returns:
        itself.

    - #### withLoginAndPassword

          public MyDBConnectionInfo withLoginAndPassword​(String login,
                                                         String password)

    - #### withDataSourceName

          public MyDBConnectionInfo withDataSourceName​(String dataSourceName)

      Sets a new data source by its JNDI name to this connection info.
      Parameters:
        `dataSourceName` - the JNDI name of the data source to connect to.
      Returns:
        itself.

    - #### getDataSourceName

          public String getDataSourceName()

      Gets the JNDI name of the data source targeted by this connection information.
      Returns:
        the JNDI name of the data source.

    - #### getInstanceId

          public String getInstanceId()

      Gets the unique identifier of the component instance this connection info belongs to.
      Returns:
        the unique identifier of the component instance.

    - #### getLogin

          public String getLogin()

      Gets the user identifier used in the data source authentication.
      Returns:
        the login.

    - #### getPassword

          public String getPassword()

      Gets the password associated with the login to connect the data source.
      Returns:
        the password.

    - #### getDefaultTableName

          public String getDefaultTableName()

      Gets the name of the table to load with this connexion information.
      Returns:
        the name of the default table.

    - #### getDataMaxNumber

          public int getDataMaxNumber()

      Gets the maximum number of data to return when requesting the data source.
      Returns:
        the maximum number of data to consider. 0 means all.

    - #### isDefaultTableNameDefined

          public boolean isDefaultTableNameDefined()

      Is the name of the default table to load is defined?
      Returns:
        true if the name of a default table is set, false otherwise.

    - #### setDataSourceName

          public void setDataSourceName​(String dataSourceName)

      Sets a new data source by its JNDI name to this connection info.
      Parameters:
        `dataSourceName` - the JNDI name of the data source to connect to.

    - #### setLoginAndPassword

          public void setLoginAndPassword​(String login,
                                          String password)

      Sets the login and the password required to open a connection to the targeted data source.
      Parameters:
        `login` - a login.
        `password` - the password associated with the login.

    - #### setDefaultTableName

          public void setDefaultTableName​(String tableName)

      Sets the name of the default table to load with this connection information.
      Parameters:
        `tableName` - the name of a table in the database.

    - #### setDataMaxNumber

          public void setDataMaxNumber​(int maxNumber)

      Sets the maximum number of data to select when requesting the data source.
      Parameters:
        `maxNumber` - the maximum number of data to return. 0 means all.

    - #### save

          public void save()

      Saves or updates this connection information into the persistence context in order to be able to retrieve it later.

    - #### remove

          public void remove()

      Removes this connection information from the persistence context.

    - #### openConnection

          public Connection openConnection()
                                    throws MyDBException

      Opens a connection to the data source targeted by this connection information.
      Returns:
        a connection against the data source referred by this object.
      Throws:
        `MyDBException`

    - #### equals

          public boolean equals​(Object o)

      Overrides:
        `equals` in class `org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity<MyDBConnectionInfo,​org.silverpeas.core.persistence.datasource.model.identifier.UniqueIntegerIdentifier>`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity<MyDBConnectionInfo,​org.silverpeas.core.persistence.datasource.model.identifier.UniqueIntegerIdentifier>`

    - #### checkConnection

          public void checkConnection()
                               throws MyDBException

      Checks the connection with the remote data source referred in this `MyDBConnectionInfo` instance.

      If the connection cannot be established with the data source, a `MyDBException` exception is thrown. This occurs when:

      - no connection information is set for the underlying component instance,
      - the connection information isn't correct,
      - the connection information is correct but the connection with the data source fails at this time.
      Throws:
        `MyDBException` - if the connection cannot be established with the data source referred by this `MyDBConnectionInfo` instance.