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 configured DataSourceConnectionInfo instance. If no DataSourceConnectionInfo instance is available, then no connection is established and no request can be done.
Author:
mmoquillon
  • Constructor Details

    • JdbcRequester

      public JdbcRequester(String componentInstanceId)
      Constructs a new JDBC requester for the specified component instance. It loads the DataSourceConnectionInfo 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 a JdbcConnectorRuntimeException is then thrown.
      Parameters:
      componentInstanceId - the unique identifier of a ConnecteurJDBC application instance.
  • Method Details

    • 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 underlying DataSourceConnectionInfo 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 the DataSourceConnectionInfo 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 a DataSourceConnectionInfo 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 a DataSourceConnectionInfo 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, a JdbcConnectorRuntimeException 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 invoking getTableNames() method. If an error occurs while requesting the data source, a JdbcConnectorRuntimeException 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 underlying DataSourceConnectionInfo instance. A JdbcConnectorRuntimeException 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 underlying DataSourceConnectionInfo 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. A JdbcConnectorRuntimeException 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.