Class JdbcRequester
- java.lang.Object
-
- org.silverpeas.components.jdbcconnector.service.JdbcRequester
-
public class JdbcRequester extends Object
A requester of a remote enterprise data source by using the yet configuredDataSourceConnectionInfoinstance. If noDataSourceConnectionInfoinstance is available, then no connection is established and no request can be done.- Author:
- mmoquillon
-
-
Constructor Summary
Constructors Constructor Description JdbcRequester(String componentInstanceId)Constructs a new JDBC requester for the specified component instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckConnection()Checks the connection with the remote data source referred by the underlyingDataSourceConnectionInfoinstance used by this requester.List<String>getColumnNames(String tableName)Gets all the columns in the specified table.DataSourceConnectionInfogetCurrentConnectionInfo()Gets information about the current JDBC connection used to request the data source.List<String>getTableNames()Gets all the tables in the data source (only public tables and views are fetched).booleanisDataSourceDefined()Is there is a data source set with this requester?booleanisSQLRequestDefined()Is there is any default SQL request set with this requester?List<TableRow>request()Requests the data source by using the SQL query that was set with the current underlyingDataSourceConnectionInfoinstance.List<TableRow>request(String sqlQuery)Requests the data source with the specified SQL query.
-
-
-
Constructor Detail
-
JdbcRequester
public JdbcRequester(String componentInstanceId)
Constructs a new JDBC requester for the specified component instance. It loads theDataSourceConnectionInfoinstance that was persisted for the specified component instance in order to establish a connection with a remote data source. If there is more than one connection information registered, then we are in an unstable state for the given component instance and aJdbcConnectorRuntimeExceptionis then thrown.- Parameters:
componentInstanceId- the unique identifier of a ConnecteurJDBC application instance.
-
-
Method Detail
-
getCurrentConnectionInfo
public DataSourceConnectionInfo getCurrentConnectionInfo()
Gets information about the current JDBC connection used to request the data source.- Returns:
- a
DataSourceConnectionInfoinstance with all the information about the connection with the remote data source
-
checkConnection
public void checkConnection() throws JdbcConnectorExceptionChecks the connection with the remote data source referred by the underlyingDataSourceConnectionInfoinstance used by this requester.If the connection cannot be established with the data source, a
JdbcConnectorExceptionexception 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:
JdbcConnectorException- if the connection cannot be established with the data source referred by theDataSourceConnectionInfoinstance used by this requester.
-
isDataSourceDefined
public boolean isDataSourceDefined()
Is there is a data source set with this requester? A data source is set when there is aDataSourceConnectionInfoinstance defined for the component instance to which this requester is related.- Returns:
- true if there is a
DataSourceConnectionInfoinstance set with this requester. False otherwise.
-
isSQLRequestDefined
public boolean isSQLRequestDefined()
Is there is any default SQL request set with this requester? A request is set when there is aDataSourceConnectionInfoinstance defined for the component instance to which this request is related and a SQL query has been defined for that connection information.- Returns:
- true if there is a SQL query defined for the current underlying connection information.
-
getTableNames
public List<String> getTableNames()
Gets all the tables in the data source (only public tables and views are fetched). If an error occurs while requesting the data source, aJdbcConnectorRuntimeExceptionis thrown.- Returns:
- a list of table names.
-
getColumnNames
public List<String> getColumnNames(String tableName)
Gets all the columns in the specified table.- Parameters:
tableName- a name of a table. This name must have been get by invokinggetTableNames()method. If an error occurs while requesting the data source, aJdbcConnectorRuntimeExceptionis thrown.- Returns:
- a list of column names in the given table.
-
request
public List<TableRow> request() throws JdbcConnectorException
Requests the data source by using the SQL query that was set with the current underlyingDataSourceConnectionInfoinstance. AJdbcConnectorRuntimeExceptionis thrown if the data returned by the requesting fails to be read. If no request was set, then nothing is requested and hence nothing is returned.- Returns:
- a list of rows, each of them represented by a
TableRowinstance. If no SQL query is defined with the underlyingDataSourceConnectionInfoinstance, then an empty list is returned. - Throws:
JdbcConnectorException- if either no connection can be established or the requesting failed.
-
request
public List<TableRow> request(String sqlQuery) throws JdbcConnectorException
Requests the data source with the specified SQL query. AJdbcConnectorRuntimeExceptionis thrown if the data returned by the requesting fails to be read.- Returns:
- a list of rows, each of them represented by a
TableRowinstance. - Throws:
JdbcConnectorException- if either no connection can be established or the requesting failed.
-
-