i-net Clear Reports

com.inet.report
Class Datasource

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

public class Datasource
extends java.lang.Object
implements java.io.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));


See Also:
Serialized Form

Method Summary
 void addConnectionProperty(java.lang.String property, java.lang.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.
 TableSource createTableSource(java.lang.String aDatabaseIdentifier, java.lang.String anAliasName)
          Creates a new TableSource object that belongs to this Datasource, or returns a TableSource with the given name if one already exists
 TableSource createTableSource(java.lang.String aDatabaseIdentifier)
          Creates a new TableSource object that belongs to this Datasource.
 TableSource createTableSourceCommand(java.lang.String AnAliasName, java.lang.String sql)
          Creates a new TableSource object based on a sql command.
 java.lang.String[] getAliasList()
          Returns a String array of alias names from all TableSources of this Datasource.
 java.lang.String getCatalog()
          Returns the value of the connection property catalog.
 java.sql.Connection getConnection()
          Returns the Connection used to request data from the datasource.
 java.util.Properties getConnectionProperties()
          Returns the properties passed to JDBC driver to create the Connection.
 DataSourceConfiguration getDataSourceConfiguration()
          If this Datasource is based on a DataSourceConfiguration and the configuration exists, the DataSourceConfiguration object will be returned.
 java.lang.String getDataSourceConfigurationName()
          If this Datasource is based on a DataSourceConfiguration and the configuration exists, the name of the DataSourceConfiguration object will be returned.
 Database getDatabase()
          Returns the Database instance which should be used for the connection configured by this Datasource.
 java.lang.String getHost()
          Returns the value of the connection property host.
 java.lang.String getPassword()
          Returns the value of the connection property password.
 java.lang.String getSchema()
          Returns the value of the connection property schema.
 TableSource getTableSource(int idx)
          Returns the TableSource of the specified index.
 TableSource getTableSource(java.lang.String alias)
          Returns the TableSource identified with the alias.
 int getTableSourceCount()
          Returns the number of registered table sources.
 TableSource getTableSourceIfExist(java.lang.String alias)
          Returns the TableSource identified with the alias.
 java.lang.String getUrl()
          Returns the Connection URL for the JDBC driver.
 java.lang.String getUsername()
          Returns the value of the connection property user.
 boolean hasValidConnection()
          Checks to see if a connection has been set and whether this connection is valid for this data source.
 boolean isUsed()
          Returns the tables or sql field of this data source are used in the report.
 void removeConnectionProperty(java.lang.String property)
          Removes the passed property from list of connection properties.
 void removeTableSource(TableSource ts)
          Removes the TableSource from the report.
 TableSource removeTableSourceAt(int idx)
          Removes the TableSource from the report.
 boolean requestPasswordIfNeeded(java.awt.Frame owner)
          Check whether a password is available for this DataSource.
 void setCatalog(java.lang.String dsCatalog)
          Sets the database name that will be used to connect to the data source.
 void setConnection(java.sql.Connection newConnection)
          Sets the connection to the data source.
 void setConnection(java.sql.Connection newConnection, java.util.Properties configuration)
          Deprecated. As of i-net Crystal-Clear 10.0 because this works for reports created with i-net Crystal-Clear version 6 or older, replaced by setConnection(Connection). To change the properties, you should modify the datasource configuration with the Datasource Manager.
 void setDataSourceConfiguration(DataSourceConfiguration dsc)
          Defines that this Datasource bases on a data source configuration.
 void setDataSourceConfigurationName(java.lang.String dataSourceConfigurationName)
          Defines that this Datasource bases on a data source configuration.
 void setDatabase(Database newDatabase)
          Allows to set an user defined Database class that controls the access to the database.
 void setHost(java.lang.String dsHost)
          Sets the host name that will be used to connect to the data source.
 void setPassword(java.lang.String dsPassword)
          Sets the password that will be used to connect to the data source.
 void setSchema(java.lang.String dsSchema)
          Sets the schema that will be used to select a table, view or stored procedure.
 void setUrl(java.lang.String dsUrl)
          Sets the JDBC driver URL that will be used to create a Connection to the data source.
 void setUsername(java.lang.String dsUsername)
          Sets the user name that will be used to connect to the data source.
 void setup(java.lang.String dataSourceConfigurationName)
          Deprecated. As of i-net Crystal-Clear 9.0, replaced by setDataSourceConfigurationName(String)
 void setup(DataSourceConfiguration dsc)
          Deprecated. As of i-net Crystal-Clear 9.0, replaced by setup(String)
 java.lang.String toString()
          Returns a string representation of this Datasource.
 

Method Detail

toString

public java.lang.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 java.lang.Object
Returns:
a String representation of this Datasource.
Since:
6.0

getConnection

public java.sql.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.
See Also:
hasValidConnection(), setConnection(Connection)

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.
See Also:
getConnection()

setConnection

public void setConnection(java.sql.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.

setConnection

@Deprecated
public void setConnection(java.sql.Connection newConnection,
                                     java.util.Properties configuration)
Deprecated. As of i-net Crystal-Clear 10.0 because this works for reports created with i-net Crystal-Clear version 6 or older, replaced by setConnection(Connection). To change the properties, you should modify the datasource configuration with the Datasource Manager.

This method is equal to setConnection(Connection). This method allows you to set the database configuration for the set Connection. The set Properties overwrite the "setConnection" configuration of whole i-net Clear Reports. So every Connection set after this call will get this configuration. Thats why it is recommended to set all properties listed below. possible keys for the configuration properties: "setConnection.alias"
"setConnection.identifierQuoteString"
"setConnection.supportsSQL92syntax"
"setConnection.supportsParenthesiseInJoin"
"setConnection.supportsWhere"
"setConnection.supportsOrderBy"
"setConnection.quoteLowerCase"
"setConnection.escapeEverything"

Parameters:
newConnection - the Connection to the data source.
configuration - The i-net Clear Reports connection properties which should be used for the supplied connection.
Since:
6.0
See Also:
setConnection(Connection)

getCatalog

public java.lang.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.
See Also:
setCatalog(String)

setCatalog

public void setCatalog(java.lang.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
See Also:
getCatalog(), setDll(String), setHost(String), setSchema(String), setUsername(String), setPassword(String)

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.
See Also:
setDataSourceConfigurationName(String), DatabaseTables.createDatasource(String)

getDataSourceConfigurationName

public java.lang.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.
See Also:
setDataSourceConfigurationName(String), DatabaseTables.createDatasource(String)

getHost

public java.lang.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.
See Also:
setHost(String)

setHost

public void setHost(java.lang.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
See Also:
getHost(), setDll(String), setCatalog(String), setSchema(String), setUsername(String), setPassword(String)

getPassword

public java.lang.String getPassword()
Returns the value of the connection property password.

Returns:
String - the value of the connection property password.
See Also:
setPassword(String)

setPassword

public void setPassword(java.lang.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
See Also:
getPassword(), setDll(String), setCatalog(String), setSchema(String), setUsername(String), setHost(String)

getSchema

public java.lang.String getSchema()
Returns the value of the connection property schema.

Returns:
String - the value of the connection property schema.
See Also:
setSchema(String)

setSchema

public void setSchema(java.lang.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.
See Also:
getSchema(), setDll(String), setCatalog(String), setPassword(String), setUsername(String), setHost(String)

getUsername

public java.lang.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.
See Also:
setUsername(String)

setUsername

public void setUsername(java.lang.String dsUsername)
Sets the user 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 "{2}" will be replaced by the user name.
It is not absolutely required to use a placeholder for set the user name. The user name can also be set directly for create a Connection.

Example configuration in the crystalclear.properties file :

pdssql.dll=sql7 sql7.driver=com.inet.tds.TdsDriver
sql7.url=jdbc:inetdae7:localhost?database={1}&user={2}&password=MyPassword
sql7.class=com.inet.report.DatabaseSqlServer
sql7.supportsSQL92syntax=true
sql7.supportsWhere=true

If "sa" was set for user name and "northwind" was set as catalog, the resulting connection URL is the following:
jdbc:inetdae7:localhost?database=northwind&user=sa&password=MyPassword


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:
dsUsername - the user name for the user authentication
See Also:
getUsername(), setHost(String), setDll(String), setCatalog(String), setSchema(String), setPassword(String)

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.
See Also:
getTableSourceCount()

getUrl

public java.lang.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.
See Also:
setUrl(String)

setUrl

public void setUrl(java.lang.String dsUrl)
Sets the JDBC driver URL that will be used to create a Connection to the data source. If a URL was set, the Datasource does not use the predefined URL from crystalclear.properties file.
Example:
jdbc:inetora:{0}?user=scott&password=tiger
{0}
then will be replaced by the host set for this database.

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
See Also:
getUrl(), setUsername(String), setPassword(String), setDll(String)

getTableSource

public TableSource getTableSource(java.lang.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.
See Also:
getTableSourceIfExist(String)

getTableSourceIfExist

public TableSource getTableSourceIfExist(java.lang.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 java.lang.String[] getAliasList()
Returns a String array of alias names from all TableSources of this Datasource.

Returns:
A StringList of all aliases in the connection.

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

getDatabase

public Database getDatabase()
Returns the Database instance which should be used for the connection configured by this Datasource. If not already loaded the Database instance has to be created based on this Datasource.

Returns:
A Database instance matching the configured connection of this Datasource.

setDatabase

public void setDatabase(Database newDatabase)
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.

createTableSource

public TableSource createTableSource(java.lang.String aDatabaseIdentifier,
                                     java.lang.String anAliasName)
                              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:
aDatabaseIdentifier - The name of the table, view or stored procedure.
anAliasName - 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

createTableSourceCommand

public TableSource createTableSourceCommand(java.lang.String AnAliasName,
                                            java.lang.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:
AnAliasName - 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:
ReportProperties.setIgnoreFiltering(boolean), ReportProperties.setIgnoreSorting(boolean)

createTableSource

public TableSource createTableSource(java.lang.String aDatabaseIdentifier)
                              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:
aDatabaseIdentifier - 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:
TableSource, TableSource.addColumn(String, int)

addConnectionProperty

public void addConnectionProperty(java.lang.String property,
                                  java.lang.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(java.lang.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:
addConnectionProperty(String, String)

getConnectionProperties

public java.util.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:
addConnectionProperty(String, String), removeConnectionProperty(String)

setup

@Deprecated
public void setup(java.lang.String dataSourceConfigurationName)
Deprecated. As of i-net Crystal-Clear 9.0, replaced by setDataSourceConfigurationName(String)

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
See Also:
DataSourceConfigurationManager.getDataSourceConfigurationNames(), DataSourceConfigurationManager.createDataSourceConfiguration(String, int), getDataSourceConfiguration(), getDataSourceConfigurationName(), setDataSourceConfiguration(DataSourceConfiguration)

setDataSourceConfigurationName

public void setDataSourceConfigurationName(java.lang.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:
DataSourceConfigurationManager.getDataSourceConfigurationNames(), DataSourceConfigurationManager.createDataSourceConfiguration(String, int), getDataSourceConfiguration(), getDataSourceConfigurationName(), setDataSourceConfiguration(DataSourceConfiguration)

setup

@Deprecated
public void setup(DataSourceConfiguration dsc)
Deprecated. As of i-net Crystal-Clear 9.0, replaced by setup(String)

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
See Also:
setDataSourceConfigurationName(String)

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:
setDataSourceConfigurationName(String)

requestPasswordIfNeeded

public boolean requestPasswordIfNeeded(java.awt.Frame owner)
Check whether a password is available for this DataSource. If no password is available a password dialog is opened to request a password from the user.

Parameters:
owner - An owner Frame for the password dialog which will be displayed.
Returns:
true if password is valid; false if Password Dialog was cancel

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

i-net Clear Reports

Copyright © 1999-2011 by i-net software GmbH