Klasse Datasource
java.lang.Object
com.inet.report.Datasource
- Alle implementierten Schnittstellen:
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
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:
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));
- Seit:
- 5.0
- Siehe auch:
-
Methodenübersicht
Modifikator und TypMethodeBeschreibungvoidaddConnectionProperty(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.voidClose a cached connection if there once and return it to the pool if it is a pooled connection.booleanFOR INTERNAL USE ONLY Checks to see if there are only tables and/or views (not commands or stored procedures) in this connection.@Nonnull TableSourcecreateTableSource(String databaseIdentifier) Creates a new TableSource object that belongs to this Datasource.createTableSource(String databaseIdentifier, String aliasName) Creates a new TableSource object that belongs to this Datasource, or returns a TableSource with the given name if one already existscreateTableSourceCommand(String aliasName, String sql) Creates a new TableSource object based on a sql command.createTableSourceCommand(String aliasName, String sql, boolean quoteStringPrompts) Creates a new TableSource object based on a sql command.booleanString[]Returns a String array of alias names from all TableSources of this Datasource.Returns the value of the connection property catalog.Returns the Connection used to request data from the datasource.
If there exists already a valid Connection, this one will be returned.Returns the properties passed to JDBC driver to create the Connection.
Next to the driver properties the Properties object conains values internal used.Returns the DataFactory instance which should be used for the connection configured by this Datasource.If this Datasource is based on a DataSourceConfiguration and the configuration exists, the DataSourceConfiguration object will be returned.@Nonnull StringIf this Datasource is based on a DataSourceConfiguration and the configuration exists, the name of the DataSourceConfiguration object will be returned.getHost()Returns the value of the connection property host.Returns the value of the connection property password.Returns the value of the connection property schema.getSql(boolean keepPromptNames) FOR INTERNAL USE ONLY Returns a list of SQL statements for retrieving the data for this datasource.getTableSource(int idx) Returns the TableSource of the specified index.getTableSource(String alias) Returns the TableSource identified with the alias.intReturns the number of registered table sources.getTableSourceIfExist(String alias) Returns the TableSource identified with the alias.getUrl()Returns the Connection URL for the JDBC driver.Returns the value of the connection property user.booleanChecks to see if a connection has been set and whether this connection is valid for this data source.booleanisUsed()Returns the tables or sql field of this data source are used in the report.voidremoveConnectionProperty(String property) Removes the passed property from list of connection properties.voidRemoves the TableSource from the report.removeTableSourceAt(int idx) Removes the TableSource from the report.voidsetCatalog(String dsCatalog) Sets the database name that will be used to connect to the data source.voidsetConnection(@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.voidsetDataFactory(DataFactory newFactory) Allows to set an user defined DataFactory class that controls the access to the database or data.voidDefines that this Datasource bases on a data source configuration.voidsetDataSourceConfigurationName(String dataSourceConfigurationName) Defines that this Datasource bases on a data source configuration.voidSets the host name that will be used to connect to the data source.voidsetPassword(String dsPassword) Sets the password that will be used to connect to the data source.voidSets the schema that will be used to select a table, view or stored procedure.voidSets the JDBC driver URL that will be used to create a Connection to the data source.voidsetUsername(String dsUsername) Sets the user name that will be used to connect to the data source.@Nonnull StringtoString()Returns a string representation of this Datasource.
-
Methodendetails
-
toString
Returns a string representation of this Datasource. The returnedStringwill contain the index of this Datasource in the list of Datasources in DatabaseTables, the configured host, user name and dll. -
getConnection
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.- Gibt zurück:
- The pysical connection to the datasource or null if the Database.useJdbcDriver() return false.
- Löst aus:
ReportException- If creating a Connection failed.- Seit:
- 5.0
- Siehe auch:
-
closeConnection
public void closeConnection()Close a cached connection if there once and return it to the pool if it is a pooled connection.- Seit:
- 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.- Gibt zurück:
- false if the Connection is null or closed.
- Seit:
- 5.0
- Siehe auch:
-
setConnection
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.- Parameter:
newConnection- the Connection to the data source.- Seit:
- 5.0
-
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().- Gibt zurück:
String- the value of the connection property catalog.- Seit:
- 5.0
- Siehe auch:
-
setCatalog
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 viaDatasource.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().- Parameter:
dsCatalog- name of the catalog- Seit:
- 5.0
- Siehe auch:
-
getDataSourceConfiguration
If this Datasource is based on a DataSourceConfiguration and the configuration exists, the DataSourceConfiguration object will be returned.- Gibt zurück:
- 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.
- Seit:
- 6.0
- Siehe auch:
-
getDataSourceConfigurationName
If this Datasource is based on a DataSourceConfiguration and the configuration exists, the name of the DataSourceConfiguration object will be returned.- Gibt zurück:
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.- Seit:
- 6.0
- Siehe auch:
-
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().- Gibt zurück:
String- the value of the connection property host.- Seit:
- 5.0
- Siehe auch:
-
setHost
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 viaDatasource.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().- Parameter:
dsHost- name of the host- Seit:
- 5.0
- Siehe auch:
-
getPassword
Returns the value of the connection property password.- Gibt zurück:
String- the value of the connection property password.- Seit:
- 5.0
- Siehe auch:
-
setPassword
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.- Parameter:
dsPassword- the password for user authentication- Seit:
- 5.0
- Siehe auch:
-
getSchema
Returns the value of the connection property schema.- Gibt zurück:
String- the value of the connection property schema.- Seit:
- 5.0
- Siehe auch:
-
setSchema
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".- Parameter:
dsSchema- The schema name of the data source.- Seit:
- 5.0
- Siehe auch:
-
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().- Gibt zurück:
String- the value of the connection property user.- Seit:
- 5.0
- Siehe auch:
-
setUsername
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().- Parameter:
dsUsername- the user name for the user authentication- Seit:
- 5.0
- Siehe auch:
-
getTableSource
Returns the TableSource of the specified index.- Parameter:
idx- The index number of the TableSource. First TableSource has index 0.- Gibt zurück:
- The TableSource of the specified index.
- Seit:
- 5.0
- Siehe auch:
-
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().- Gibt zurück:
String- the Connection URL for the JDBC driver.- Seit:
- 5.0
- Siehe auch:
-
setUrl
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().- Parameter:
dsUrl- the Connection URL for the JDBC driver. The String can contaion placeholders- Seit:
- 5.0
- Siehe auch:
-
getTableSource
Returns the TableSource identified with the alias. Throws exception if table source was not found.- Parameter:
alias- Alias of the TableSource to be retrieved.- Gibt zurück:
- TableSource identified with the alias.
- Löst aus:
ReportException- If the Datasource does not contain a TableSource with the alias.- Seit:
- 5.0
- Siehe auch:
-
getTableSourceIfExist
Returns the TableSource identified with the alias.- Parameter:
alias- alias of the TableSource to be retrieved.- Gibt zurück:
- TableSource identified with the alias or
nullif TableSource was not found. - Seit:
- 10.0
-
getAliasList
Returns a String array of alias names from all TableSources of this Datasource.- Gibt zurück:
- A StringList of all aliases in the connection.
- Seit:
- 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.- Gibt zurück:
- true, if there are only tables and/or views
- Seit:
- 5.0
-
removeTableSource
Removes the TableSource from the report.- Parameter:
ts- The TableSource to be removed.- Löst aus:
ReportException- If any column of the TableSource is used in the report.- Seit:
- 6.0
-
removeTableSourceAt
Removes the TableSource from the report.- Parameter:
idx- The index of the TableSource to be removed.- Gibt zurück:
- The removed TableSource
- Löst aus:
ReportException- If any column of the TableSource is used in the report.- Seit:
- 6.0
-
getTableSourceCount
public int getTableSourceCount()Returns the number of registered table sources.- Gibt zurück:
- the number of registered table sources.
- Seit:
- 6.0
-
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.- Gibt zurück:
- A DataFactory instance matching the configured connection of this Datasource.
- Seit:
- 13.0
-
setDataFactory
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.- Parameter:
newFactory- The user defined DataFactory class.- Seit:
- 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- Parameter:
databaseIdentifier- The name of the table, view or stored procedure.aliasName- The alias name of the TableSource.- Gibt zurück:
- The created TableSource Object or the TableSource with the same alias name.
- Löst aus:
ReportException- when the alias name is not allowed or DatabaseIdentifier is not correct- Seit:
- 5.0
-
createTableSourceCommand
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 ofTableSource.- Parameter:
aliasName- An alias name for the command to create.sql- The SQL statement which should be used by the created command.- Gibt zurück:
- The created TableSource Object
- Löst aus:
ReportException- when AnAliasName is not allowed or empty- Seit:
- 6.0
- Siehe auch:
-
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 ofTableSource.- Parameter:
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- Gibt zurück:
- The created TableSource Object
- Löst aus:
ReportException- when AnAliasName is not allowed or empty- Seit:
- 11.2
- Siehe auch:
-
createTableSource
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.- Parameter:
databaseIdentifier- The original name of a table or stored procedure.- Gibt zurück:
- The created TableSource Object.
- Löst aus:
ReportException- when aDatabaseIdentifier is not correct- Seit:
- 6.0
- Siehe auch:
-
getSql
FOR INTERNAL USE ONLY Returns a list of SQL statements for retrieving the data for this datasource.- Parameter:
keepPromptNames- Whether or not to keep prompt names in the SQL statement or to replace them with the prompt's value- Gibt zurück:
- list of SQL statements, or an empty list if this datasource is not SQL-based
- Löst aus:
ReportException- if the report is in an invalid stateSQLException- if there occures a problem on requesting the DatabaseMetaData
-
addConnectionProperty
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.- Parameter:
property- The name of the property.value- The value of the property.- Seit:
- 6.5
-
removeConnectionProperty
Removes the passed property from list of connection properties.- Parameter:
property- The property to removed from connection Properties.- Seit:
- 6.5
- Siehe auch:
-
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_".- Gibt zurück:
- The properties passed to JDBC driver to create the connection.
- Seit:
- 6.5
- Siehe auch:
-
setDataSourceConfigurationName
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.- Parameter:
dataSourceConfigurationName- the data source configuration name- Seit:
- 9.0
- Siehe auch:
-
setDataSourceConfiguration
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.- Parameter:
dsc- the new configuration- Seit:
- 9.0
- Siehe auch:
-
isUsed
Returns the tables or sql field of this data source are used in the report.- Gibt zurück:
- the flag
- Löst aus:
ReportException- if engine is finished or no report is set.- Seit:
- 11.0
-
equals
-