Package com.inet.report
Class Datasource
- java.lang.Object
-
- com.inet.report.Datasource
-
- All Implemented Interfaces:
java.io.Serializable
public class Datasource extends java.lang.Object implements java.io.SerializableA datasource represents a connection to a database. To create the connection to the database, it needs connection properties like host, user name and password. UsingsetDataSourceConfiguration(DataSourceConfiguration)orsetDataSourceConfigurationName(String)to configure the datasource by aDataSourceConfiguration.
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:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddConnectionProperty(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.voidcloseConnection()Close a cached connection if there once and return it to the pool if it is a pooled connection.booleancontainsOnlyTables()FOR INTERNAL USE ONLY Checks to see if there are only tables and/or views (not commands or stored procedures) in this connection.TableSourcecreateTableSource(java.lang.String databaseIdentifier)Creates a new TableSource object that belongs to this Datasource.TableSourcecreateTableSource(java.lang.String databaseIdentifier, java.lang.String aliasName)Creates a new TableSource object that belongs to this Datasource, or returns a TableSource with the given name if one already existsTableSourcecreateTableSourceCommand(java.lang.String aliasName, java.lang.String sql)Creates a new TableSource object based on a sql command.TableSourcecreateTableSourceCommand(java.lang.String aliasName, java.lang.String sql, boolean quoteStringPrompts)Creates a new TableSource object based on a sql command.booleanequals(java.lang.Object obj)java.lang.String[]getAliasList()Returns a String array of alias names from all TableSources of this Datasource.java.lang.StringgetCatalog()Returns the value of the connection property catalog.java.sql.ConnectiongetConnection()Returns the Connection used to request data from the datasource.
If there exists already a valid Connection, this one will be returned.java.util.PropertiesgetConnectionProperties()Returns the properties passed to JDBC driver to create the Connection.
Next to the driver properties the Properties object conains values internal used.DataFactorygetDataFactory()Returns the DataFactory instance which should be used for the connection configured by this Datasource.DataSourceConfigurationgetDataSourceConfiguration()If this Datasource is based on a DataSourceConfiguration and the configuration exists, the DataSourceConfiguration object will be returned.java.lang.StringgetDataSourceConfigurationName()If this Datasource is based on a DataSourceConfiguration and the configuration exists, the name of the DataSourceConfiguration object will be returned.java.lang.StringgetHost()Returns the value of the connection property host.java.lang.StringgetPassword()Returns the value of the connection property password.java.lang.StringgetSchema()Returns the value of the connection property schema.java.util.List<java.lang.String>getSql(boolean keepPromptNames)FOR INTERNAL USE ONLY Returns a list of SQL statements for retrieving the data for this datasource.TableSourcegetTableSource(int idx)Returns the TableSource of the specified index.TableSourcegetTableSource(java.lang.String alias)Returns the TableSource identified with the alias.intgetTableSourceCount()Returns the number of registered table sources.TableSourcegetTableSourceIfExist(java.lang.String alias)Returns the TableSource identified with the alias.java.lang.StringgetUrl()Returns the Connection URL for the JDBC driver.java.lang.StringgetUsername()Returns the value of the connection property user.booleanhasValidConnection()Checks 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(java.lang.String property)Removes the passed property from list of connection properties.voidremoveTableSource(TableSource ts)Removes the TableSource from the report.TableSourceremoveTableSourceAt(int idx)Removes the TableSource from the report.voidsetCatalog(java.lang.String dsCatalog)Sets the database name that will be used to connect to the data source.voidsetConnection(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.voidsetDatabase(Database newDatabase)Deprecated.As of i-net Clear Reports 13.0, replaced bysetDataFactory(DataFactory)voidsetDataFactory(DataFactory newFactory)Allows to set an user defined DataFactory class that controls the access to the database or data.voidsetDataSourceConfiguration(DataSourceConfiguration dsc)Defines that this Datasource bases on a data source configuration.voidsetDataSourceConfigurationName(java.lang.String dataSourceConfigurationName)Defines that this Datasource bases on a data source configuration.voidsetHost(java.lang.String dsHost)Sets the host name that will be used to connect to the data source.voidsetPassword(java.lang.String dsPassword)Sets the password that will be used to connect to the data source.voidsetSchema(java.lang.String dsSchema)Sets the schema that will be used to select a table, view or stored procedure.voidsetUrl(java.lang.String dsUrl)Sets the JDBC driver URL that will be used to create a Connection to the data source.voidsetUsername(java.lang.String dsUsername)Sets the user name that will be used to connect to the data source.java.lang.StringtoString()Returns a string representation of this Datasource.
-
-
-
Method Detail
-
toString
public java.lang.String 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.- Overrides:
toStringin classjava.lang.Object- Returns:
- a
Stringrepresentation of this Datasource. - Since:
- 6.0
-
getConnection
public java.sql.Connection getConnection() throws ReportExceptionReturns 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:
hasValidConnection(),setConnection(Connection)
-
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:
getConnection()
-
setConnection
public void setConnection(@Nonnull 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.- Since:
- 5.0
-
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.- Since:
- 5.0
- 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 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().- Parameters:
dsCatalog- name of the catalog- Since:
- 5.0
- 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.
- Since:
- 6.0
- 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.- Since:
- 6.0
- 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.- Since:
- 5.0
- 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 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().- Parameters:
dsHost- name of the host- Since:
- 5.0
- 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.- Since:
- 5.0
- 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- Since:
- 5.0
- 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.- Since:
- 5.0
- 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.- Since:
- 5.0
- 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.- Since:
- 5.0
- 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. 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:
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.
- Since:
- 5.0
- 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.- Since:
- 5.0
- 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. 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:
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.- Since:
- 5.0
- 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
nullif 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.
- 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 bysetDataFactory(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(java.lang.String databaseIdentifier, java.lang.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(java.lang.String aliasName, 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 ofTableSource.- 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:
ReportProperties.setIgnoreFiltering(boolean),ReportProperties.setIgnoreSorting(boolean)
-
createTableSourceCommand
public TableSource createTableSourceCommand(java.lang.String aliasName, java.lang.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.- 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:
ReportProperties.setIgnoreFiltering(boolean),ReportProperties.setIgnoreSorting(boolean)
-
createTableSource
public TableSource createTableSource(java.lang.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:
TableSource,TableSource.addColumn(String, int)
-
getSql
public java.util.List<java.lang.String> getSql(boolean keepPromptNames) throws ReportException, java.sql.SQLExceptionFOR 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 statejava.sql.SQLException- if there occures a problem on requesting the DatabaseMetaData
-
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)
-
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)
-
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)
-
isUsed
public boolean isUsed() throws ReportExceptionReturns 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(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-