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 protectedMyDBConnectionInfo()MyDBConnectionInfo(String dataSource, String instanceId)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckConnection()Checks the connection with the remote data source referred in thisMyDBConnectionInfoinstance.booleanequals(Object o)intgetDataMaxNumber()Gets the maximum number of data to return when requesting the data source.StringgetDataSourceName()Gets the JNDI name of the data source targeted by this connection information.StringgetDefaultTableName()Gets the name of the table to load with this connexion information.static List<MyDBConnectionInfo>getFromComponentInstance(String instanceId)StringgetLogin()Gets the user identifier used in the data source authentication.StringgetPassword()Gets the password associated with the login to connect the data source.inthashCode()booleanisDefaultTableNameDefined()Is the name of the default table to load is defined?booleanisDefined()Is this connection information defined?ConnectionopenConnection()Opens a connection to the data source targeted by this connection information.static voidremoveFromComponentInstance(String instanceId)voidsave()Saves or updates this connection information into the persistence context in order to be able to retrieve it later.voidsetDataMaxNumber(int maxNumber)Sets the maximum number of data to select when requesting the data source.voidsetDataSourceName(String dataSourceName)Sets a new data source by its JNDI name to this connection info.voidsetDefaultTableName(String tableName)Sets the name of the default table to load with this connection information.voidsetLoginAndPassword(String login, String password)Sets the login and the password required to open a connection to the targeted data source.MyDBConnectionInfowithDataMaxNumber(int maxNumber)Sets the maximum number of data to select when requesting the data source and returns this connection information.MyDBConnectionInfowithDataSourceName(String dataSourceName)Sets a new data source by its JNDI name to this connection info.MyDBConnectionInfowithDefaultTableName(String tableName)Sets the default table to defaultTable from the database with this connection information and returns the later.MyDBConnectionInfowithLoginAndPassword(String login, String password)MyDBConnectionInfowithoutAnyDefaultTable()-
Methods inherited from class org.silverpeas.core.persistence.datasource.model.jpa.BasicJpaEntity
performBeforePersist, performBeforeRemove, performBeforeUpdate
-
-
-
-
Method Detail
-
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 myDB application instance and the name of the data source is defined.- Returns:
- true if the connection is defined. False otherwise.
-
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.
-
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.
-
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:
equalsin classorg.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity<MyDBConnectionInfo,org.silverpeas.core.persistence.datasource.model.identifier.UniqueIntegerIdentifier>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classorg.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity<MyDBConnectionInfo,org.silverpeas.core.persistence.datasource.model.identifier.UniqueIntegerIdentifier>
-
checkConnection
public void checkConnection() throws MyDBExceptionChecks the connection with the remote data source referred in thisMyDBConnectionInfoinstance.If the connection cannot be established with the data source, a
MyDBExceptionexception 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 thisMyDBConnectionInfoinstance.
-
-