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 configuredDataSourceConnectionInfo
instance. If noDataSourceConnectionInfo
instance 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 void
checkConnection()
Checks the connection with the remote data source referred by the underlyingDataSourceConnectionInfo
instance used by this requester.List<String>
getColumnNames(String tableName)
Gets all the columns in the specified table.DataSourceConnectionInfo
getCurrentConnectionInfo()
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).boolean
isDataSourceDefined()
Is there is a data source set with this requester?boolean
isSQLRequestDefined()
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 underlyingDataSourceConnectionInfo
instance.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 theDataSourceConnectionInfo
instance 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 aJdbcConnectorRuntimeException
is 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
DataSourceConnectionInfo
instance with all the information about the connection with the remote data source
-
checkConnection
public void checkConnection() throws JdbcConnectorException
Checks the connection with the remote data source referred by the underlyingDataSourceConnectionInfo
instance used by this requester.If the connection cannot be established with the data source, a
JdbcConnectorException
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:
JdbcConnectorException
- if the connection cannot be established with the data source referred by theDataSourceConnectionInfo
instance 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 aDataSourceConnectionInfo
instance defined for the component instance to which this requester is related.- Returns:
- true if there is a
DataSourceConnectionInfo
instance 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 aDataSourceConnectionInfo
instance 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, aJdbcConnectorRuntimeException
is 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, aJdbcConnectorRuntimeException
is 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 underlyingDataSourceConnectionInfo
instance. AJdbcConnectorRuntimeException
is 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
TableRow
instance. If no SQL query is defined with the underlyingDataSourceConnectionInfo
instance, 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. AJdbcConnectorRuntimeException
is thrown if the data returned by the requesting fails to be read.- Returns:
- a list of rows, each of them represented by a
TableRow
instance. - Throws:
JdbcConnectorException
- if either no connection can be established or the requesting failed.
-
-