Class Datasource

java.lang.Object
com.inet.report.Datasource
All Implemented Interfaces:
Serializable

public class Datasource extends Object implements Serializable
A datasource represents a connection to a database. To create the connection to the database, it needs connection properties like host, user name and password. Using setDataSourceConfiguration(DataSourceConfiguration) or setDataSourceConfigurationName(String) to configure the datasource by a DataSourceConfiguration.
To each Datasource some TableSource objects can be added. It is possible to use tables from different Datasources at the same time in the report design. These tables can be linked together and used in the report. The join process of tables from different databases will be took on i-net Clear Reports.

Code sample:

DatabaseTables dbTables = engine.getDatabaseTables();
Datasource ds = dbTables.createDatasource("<Data Source Configuration Name>");
//adding a TableSource to the Datasource
TableSource tabCustomers = ds.createTableSource("Order Details");
tabCustomers.addColumn("OrderId",Field.NUMBER);
tabCustomers.addColumn("ProductId",Field.NUMBER);
tabCustomers.addColumn("UnitPrice",Field.NUMBER);
tabCustomers.addColumn("Quantity",Field.NUMBER);
tabCustomers.addColumn("OrderId",Field.NUMBER);
tabCustomers.addColumn("Discount",Field.NUMBER);
//to receive the DatabaseField of column "OrderId call: tabOrderDetails.getDatabaseField(tabOrderDetails.getColumnName(0));


Since:
5.0
See Also:
  • Method Details

    • toString

      public String toString()
      Returns a string representation of this Datasource. The returned String will contain the index of this Datasource in the list of Datasources in DatabaseTables, the configured host, user name and dll.
      Overrides:
      toString in class Object
      Returns:
      a String representation of this Datasource.
      Since:
      6.0
    • getConnection

      public Connection getConnection() throws ReportException
      Returns the Connection used to request data from the datasource.
      If there exists already a valid Connection, this one will be returned. Otherwise a Connection will be created by the connection parameters dll, host, catalog ...

      Do not forget to close your connection if you do not need it anymore. Otherwise the Connection cannot be removed from the internal Connection pool.
      Returns:
      The pysical connection to the datasource or null if the Database.useJdbcDriver() return false.
      Throws:
      ReportException - If creating a Connection failed.
      Since:
      5.0
      See Also:
    • closeConnection

      public void closeConnection()
      Close a cached connection if there once and return it to the pool if it is a pooled connection.
      Since:
      12.0
    • hasValidConnection

      public boolean hasValidConnection()
      Checks to see if a connection has been set and whether this connection is valid for this data source.
      Returns:
      false if the Connection is null or closed.
      Since:
      5.0
      See Also:
    • setConnection

      public void setConnection(@Nonnull Connection newConnection)
      Sets the connection to the data source.
      If there already exists a valid connection, it will be closed and replaced by the set connection. The Database class will be changed if there are a default Database class for the DBMS of the connection available.
      Parameters:
      newConnection - the Connection to the data source.
      Since:
      5.0
    • getCatalog

      public String getCatalog()
      Returns the value of the connection property catalog.

      This method is only useful for reports designed with i-net Crystal-Clear 6 (or earlier versions) or Crystal Reports.
      To get properties of reports designed with newer i-net Clear Reports versions please see: getDataSourceConfiguration().
      Returns:
      String - the value of the connection property catalog.
      Since:
      5.0
      See Also:
    • setCatalog

      public void setCatalog(String dsCatalog)
      Sets the database name that will be used to connect to the data source. In the connection URL that is set in the crystalclear.properties file, the placeholder "{1}" will be replaced by the catalogname.

      Example configuration in the crystalclear.properties file :

      pdssql.dll=sql7 sql7.driver=com.inet.tds.TdsDriver
      sql7.url=jdbc:inetdae7:{0}?database={1}
      sql7.class=com.inet.report.DatabaseSqlServer
      sql7.supportsSQL92syntax=true
      sql7.supportsWhere=true

      If "localhost" was set for host and "northwind" was set as catalog, the resulting connection URL is the following:
      jdbc:inetdae7:localhost?database=northwind


      Note: if an connection URL was set via Datasource.setURL(String), this URL will be used directly without scanning for placeholders.

      Calling this function also has influence about where location of tables and stored procedures are expected. In case of Oracle database set catalog overwrites the package where stored procedures/functions are expected.

      This method is only useful for reports designed with i-net Crystal-Clear 6 (or earlier versions) or Crystal Reports.
      To set properties of reports designed with newer i-net Clear Reports versions please see: getDataSourceConfiguration().
      Parameters:
      dsCatalog - name of the catalog
      Since:
      5.0
      See Also:
    • getDataSourceConfiguration

      public DataSourceConfiguration getDataSourceConfiguration()
      If this Datasource is based on a DataSourceConfiguration and the configuration exists, the DataSourceConfiguration object will be returned.
      Returns:
      the DataSourceConfiguration object this Datasource bases on. null if DataSourceConfiguration definition don't exists/was deleted or if this Datasource was defined in classic way.
      Since:
      6.0
      See Also:
    • getDataSourceConfigurationName

      public String getDataSourceConfigurationName()
      If this Datasource is based on a DataSourceConfiguration and the configuration exists, the name of the DataSourceConfiguration object will be returned.
      Returns:
      String - the name of the DataSourceConfiguration this Datasopurce bases on. returns an empty String if DataSourceConfiguration definition don't exists/was deleted or if this Datasource was defined in classic way.
      Since:
      6.0
      See Also:
    • getHost

      public String getHost()
      Returns the value of the connection property host.

      This method is only useful for reports designed with i-net Crystal-Clear 6 (or earlier versions) or Crystal Reports.
      To get properties of reports designed with newer i-net Clear Reports versions please see: getDataSourceConfiguration().
      Returns:
      String - the value of the connection property host.
      Since:
      5.0
      See Also:
    • setHost

      public void setHost(String dsHost)
      Sets the host name that will be used to connect to the data source. In the connection URL that is set in the crystalclear.properties file, the placeholder "{0}" will be replaced by the host name.

      Example configuration in the crystalclear.properties file :

      pdssql.dll=sql7 sql7.driver=com.inet.tds.TdsDriver
      sql7.url=jdbc:inetdae7:{0}?database={1}
      sql7.class=com.inet.report.DatabaseSqlServer
      sql7.supportsSQL92syntax=true
      sql7.supportsWhere=true

      If "localhost" was set for host and "northwind" was set as catalog, the resulting connection URL is the following:
      jdbc:inetdae7:localhost?database=northwind


      Note: if an connection URL was set via Datasource.setURL(String), this URL will be used directly without scanning for placeholders.

      This method is only useful for reports designed with i-net Crystal-Clear 6 (or earlier versions) or Crystal Reports.
      To set properties of reports designed with newer i-net Clear Reports versions please see: getDataSourceConfiguration().
      Parameters:
      dsHost - name of the host
      Since:
      5.0
      See Also:
    • getPassword

      public String getPassword()
      Returns the value of the connection property password.
      Returns:
      String - the value of the connection property password.
      Since:
      5.0
      See Also:
    • setPassword

      public void setPassword(String dsPassword)
      Sets the password that will be used to connect to the data source. This method need to be used if there is no password saved in data source configuration or it should be used another password as the one that is saved in the data source configuration.
      Parameters:
      dsPassword - the password for user authentication
      Since:
      5.0
      See Also:
    • getSchema

      public String getSchema()
      Returns the value of the connection property schema.
      Returns:
      String - the value of the connection property schema.
      Since:
      5.0
      See Also:
    • setSchema

      public void setSchema(String dsSchema)
      Sets the schema that will be used to select a table, view or stored procedure.
      For Example if your report was design on "dbo.MyTable" and you want execute the report with "MySchema.MyTable" then you can set the schema "MySchema".
      Parameters:
      dsSchema - The schema name of the data source.
      Since:
      5.0
      See Also:
    • getUsername

      public String getUsername()
      Returns the value of the connection property user.

      This method is only useful for reports designed with i-net Crystal-Clear 6 (or earlier versions) or Crystal Reports.
      To get properties of reports designed with newer i-net Clear Reports versions please see: getDataSourceConfiguration().
      Returns:
      String - the value of the connection property user.
      Since:
      5.0
      See Also:
    • setUsername

      public void setUsername(String dsUsername)
      Sets the user name that will be used to connect to the data source. This method is only useful for reports designed with i-net Crystal-Clear 6 (or earlier versions) or Crystal Reports.
      To set properties of reports designed with newer i-net Clear Reports versions please see: getDataSourceConfiguration().
      Parameters:
      dsUsername - the user name for the user authentication
      Since:
      5.0
      See Also:
    • getTableSource

      public TableSource getTableSource(int idx)
      Returns the TableSource of the specified index.
      Parameters:
      idx - The index number of the TableSource. First TableSource has index 0.
      Returns:
      The TableSource of the specified index.
      Since:
      5.0
      See Also:
    • getUrl

      public String getUrl()
      Returns the Connection URL for the JDBC driver.

      This method is only useful for reports designed with i-net Crystal-Clear 6 (or earlier versions) or Crystal Reports.
      To get properties of reports designed with newer i-net Clear Reports versions please see: getDataSourceConfiguration().
      Returns:
      String - the Connection URL for the JDBC driver.
      Since:
      5.0
      See Also:
    • setUrl

      public void setUrl(String dsUrl)
      Sets the JDBC driver URL that will be used to create a Connection to the data source. This method is only useful for reports designed with i-net Crystal-Clear 6 (or earlier versions) or Crystal Reports.
      To set properties of reports designed with newer i-net Clear Reports versions please see: getDataSourceConfiguration().
      Parameters:
      dsUrl - the Connection URL for the JDBC driver. The String can contaion placeholders
      Since:
      5.0
      See Also:
    • getTableSource

      public TableSource getTableSource(String alias) throws ReportException
      Returns the TableSource identified with the alias. Throws exception if table source was not found.
      Parameters:
      alias - Alias of the TableSource to be retrieved.
      Returns:
      TableSource identified with the alias.
      Throws:
      ReportException - If the Datasource does not contain a TableSource with the alias.
      Since:
      5.0
      See Also:
    • getTableSourceIfExist

      public TableSource getTableSourceIfExist(String alias)
      Returns the TableSource identified with the alias.
      Parameters:
      alias - alias of the TableSource to be retrieved.
      Returns:
      TableSource identified with the alias or null if TableSource was not found.
      Since:
      10.0
    • getAliasList

      public String[] getAliasList()
      Returns a String array of alias names from all TableSources of this Datasource.
      Returns:
      A StringList of all aliases in the connection.
      Since:
      5.0
    • containsOnlyTables

      public boolean containsOnlyTables()
      FOR INTERNAL USE ONLY Checks to see if there are only tables and/or views (not commands or stored procedures) in this connection.
      Returns:
      true, if there are only tables and/or views
      Since:
      5.0
    • removeTableSource

      public void removeTableSource(TableSource ts) throws ReportException
      Removes the TableSource from the report.
      Parameters:
      ts - The TableSource to be removed.
      Throws:
      ReportException - If any column of the TableSource is used in the report.
      Since:
      6.0
    • removeTableSourceAt

      public TableSource removeTableSourceAt(int idx) throws ReportException
      Removes the TableSource from the report.
      Parameters:
      idx - The index of the TableSource to be removed.
      Returns:
      The removed TableSource
      Throws:
      ReportException - If any column of the TableSource is used in the report.
      Since:
      6.0
    • getTableSourceCount

      public int getTableSourceCount()
      Returns the number of registered table sources.
      Returns:
      the number of registered table sources.
      Since:
      6.0
    • getDataFactory

      public DataFactory getDataFactory()
      Returns the DataFactory instance which should be used for the connection configured by this Datasource. If not already loaded the DataFactory instance has to be created based on this Datasource.
      Returns:
      A DataFactory instance matching the configured connection of this Datasource.
      Since:
      13.0
    • setDatabase

      @Deprecated public void setDatabase(Database newDatabase)
      Deprecated.
      As of i-net Clear Reports 13.0, replaced by setDataFactory(DataFactory)
      Allows to set an user defined Database class that controls the access to the database. This has only an effect if no configuration or dll was set.
      Parameters:
      newDatabase - The user defined Database class.
      Since:
      5.0
    • setDataFactory

      public void setDataFactory(DataFactory newFactory)
      Allows to set an user defined DataFactory class that controls the access to the database or data. This has only an effect if no configuration or dll was set.
      Parameters:
      newFactory - The user defined DataFactory class.
      Since:
      13.0
    • createTableSource

      public TableSource createTableSource(String databaseIdentifier, String aliasName) throws ReportException
      Creates a new TableSource object that belongs to this Datasource, or returns a TableSource with the given name if one already exists
      Parameters:
      databaseIdentifier - The name of the table, view or stored procedure.
      aliasName - The alias name of the TableSource.
      Returns:
      The created TableSource Object or the TableSource with the same alias name.
      Throws:
      ReportException - when the alias name is not allowed or DatabaseIdentifier is not correct
      Since:
      5.0
    • createTableSourceCommand

      public TableSource createTableSourceCommand(String aliasName, String sql) throws ReportException
      Creates a new TableSource object based on a sql command. All columns and DatabaseFields will be added automatically. Therefore the method need to connect to the data source. To define a TableSource command without a data source connection, please have a look a the sample code in the API documentation of TableSource.
      Parameters:
      aliasName - An alias name for the command to create.
      sql - The SQL statement which should be used by the created command.
      Returns:
      The created TableSource Object
      Throws:
      ReportException - when AnAliasName is not allowed or empty
      Since:
      6.0
      See Also:
    • createTableSourceCommand

      public TableSource createTableSourceCommand(String aliasName, String sql, boolean quoteStringPrompts) throws ReportException
      Creates a new TableSource object based on a sql command. All columns and DatabaseFields will be added automatically. Therefore the method need to connect to the data source. To define a TableSource command without a data source connection, please have a look a the sample code in the API documentation of TableSource.
      Parameters:
      aliasName - An alias name for the command to create.
      sql - The SQL statement which should be used by the created command.
      quoteStringPrompts - true, string prompts are quote, false no quote is added at runtime and SQL injection is possible
      Returns:
      The created TableSource Object
      Throws:
      ReportException - when AnAliasName is not allowed or empty
      Since:
      11.2
      See Also:
    • createTableSource

      @Nonnull public TableSource createTableSource(String databaseIdentifier) throws ReportException
      Creates a new TableSource object that belongs to this Datasource. The TableSource can represent a table, a stored procedure or a SQL query. The alias name of the TableSource will be created automatically.
      Parameters:
      databaseIdentifier - The original name of a table or stored procedure.
      Returns:
      The created TableSource Object.
      Throws:
      ReportException - when aDatabaseIdentifier is not correct
      Since:
      6.0
      See Also:
    • getSql

      public List<String> getSql(boolean keepPromptNames) throws ReportException, SQLException
      FOR INTERNAL USE ONLY Returns a list of SQL statements for retrieving the data for this datasource.
      Parameters:
      keepPromptNames - Whether or not to keep prompt names in the SQL statement or to replace them with the prompt's value
      Returns:
      list of SQL statements, or an empty list if this datasource is not SQL-based
      Throws:
      ReportException - if the report is in an invalid state
      SQLException - if there occures a problem on requesting the DatabaseMetaData
    • addConnectionProperty

      public void addConnectionProperty(String property, String value)
      This method allows you to add JDBC driver specific properties that are pass to the JDBC driver to create a JDBC Connection Object.
      The JDBC API already defines "user" and "password" as possible connection properties.
      JDBC driver often knows further properties.
      For example MS SQL Server JDBC driver i-net SPRINTA allows you to set:
      a query timeout with property "queryTimeout"
      or the property "instance", if the driver has to connect to an other MS SQL Server instance on a host.
      Parameters:
      property - The name of the property.
      value - The value of the property.
      Since:
      6.5
    • removeConnectionProperty

      public void removeConnectionProperty(String property)
      Removes the passed property from list of connection properties.
      Parameters:
      property - The property to removed from connection Properties.
      Since:
      6.5
      See Also:
    • getConnectionProperties

      public Properties getConnectionProperties()
      Returns the properties passed to JDBC driver to create the Connection.
      Next to the driver properties the Properties object conains values internal used. The parameter that are used by i-net Clear Reports starts with "datasource_".
      Returns:
      The properties passed to JDBC driver to create the connection.
      Since:
      6.5
      See Also:
    • setDataSourceConfigurationName

      public void setDataSourceConfigurationName(String dataSourceConfigurationName)
      Defines that this Datasource bases on a data source configuration. All information to create the Connection will be used from that configuration. All information stored in this object are not used then.
      Parameters:
      dataSourceConfigurationName - the data source configuration name
      Since:
      9.0
      See Also:
    • setDataSourceConfiguration

      public void setDataSourceConfiguration(DataSourceConfiguration dsc)
      Defines that this Datasource bases on a data source configuration. All information to create the Connection will be used from that configuration. All information stored in this object are not used then.
      Parameters:
      dsc - the new configuration
      Since:
      9.0
      See Also:
    • isUsed

      public boolean isUsed() throws ReportException
      Returns the tables or sql field of this data source are used in the report.
      Returns:
      the flag
      Throws:
      ReportException - if engine is finished or no report is set.
      Since:
      11.0
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object