|
i-net Clear Reports | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.inet.report.DatabaseTables
public class DatabaseTables
The class DatabaseTables is the starting point if you want to configure everything has to do
with databases, tables, connections, table joins and so on.
The DatabaseTables contains a list of Datasource objects and a list of Join objects.
A Datasource handles the connection to the database and it contains the table, stored procedures and sql commands
that are used in the report. A Join is for linking tables, stored procedures and sql commands with each other.
The following example shows how to define a Datasource for a database.
To create the Datasource a Data Source Configuration is used. You can define such a Data Source Configurations with the Data Source Manager in i-net Designer.
Also, you can define it via API DataSourceConfigurationManager.createDataSourceConfiguration(String, int).
(eng is your reference to a new Engine instance.)
DatabaseTables dbTables = eng.getDatabaseTables();
Datasource dsToNortwind = dbTables.createDatasource("myNorthwindDataSourceConfiguration");
Now you can define a table that is required for the report:
TableSource tsOrders = dsNortwind.createTableSource("Orders");
tsOrders.addColumn("OrderID",Field.NUMBER);
tsOrders.addColumn("CustomerID",Field.STRING);
tsOrders.addColumn("EmployeeID",Field.NUMBER);
tsOrders.addColumn("OrderDate",Field.DATETIME);
tsOrders.addColumn("Freight",Field.CURRENCY);
//and so on for each column (or at least for each required column)
To create a link between two tables you can call addJoin(String, String, String, String, int, int) or addJoin(TableSource, DatabaseField, TableSource, DatabaseField, int, int).
For example:
TableSource tsOrders = dsNortwind.createTableSource("Orders");
tsOrders.addColumn("OrderID",Field.NUMBER);
tsOrders.addColumn("CustomerID",Field.STRING);
//...
TableSource tsCustomers = dsNortwind.createTableSource("Customers");
tsOrders.addColumn("CustomerID",Field.STRING);
//...
Join aJoin = dbTables.addJoin(tsOrders,tsOrders.getDatabaseField("CustomerID"),tsCustomers,tsCustomers.getDatabaseField("CustomerID"),DatabaseTables.JOINTYPE_INNER,DatabaseTables.JOINLINK_EQUALS);
To insert columns into an empty report you should do something like that:
Fields fields = eng.getFields();
DatabaseField dbField = null;
FieldElement fElem = null;
Area dArea = eng.getArea("D");
Section dSec = dArea.getSection(0);
dbField = tsOrders.getDatabaseField("OrderID");
fElem = dSec.addFieldElement(dbField, 100, 100, 2000, 500);
dbField = tsOrders.getDatabaseField("CustomerID");
fElem = dSec.addFieldElement(dbField, 3000, 100, 2000, 500);
dbField = tsOrders.getDatabaseField("OrderDate");
fElem = dSec.addFieldElement(dbField, 100, 100, 2000, 500);
dbField = tsOrders.getDatabaseField("Freight");
fElem = dSec.addFieldElement(dbField, 6000, 100, 2000, 500);
A further way to get a data source is to use query files (generated by CrystalReports). With method readDbFromQuery(java.net.URL)
you can let read your pre designed data source from a query file.
DatabaseTables dataSources = eng.getDatabaseTables();
dataSources.readDbFromQuery(new java.net.URL("file:C:/i-net Clear Reports/xyz.qry"));
This class is part of the RDC.
Datasource,
TableSource,
Join,
DataSourceConfigurationManager,
DataSourceConfiguration,
Serialized Form| Field Summary | |
|---|---|
static int |
JOINLINK_EQUALS
Use this value to set an "=" link between two table columns. |
static int |
JOINLINK_GREATER_EQUALS_THAN
Use this value to set an ">=" link between two table columns. |
static int |
JOINLINK_GREATER_THAN
Use this value to set an ">" link between two table columns. |
static int |
JOINLINK_LESS_EQUALS_THAN
Use this value to set an "<=" link between two table columns. |
static int |
JOINLINK_LESS_THAN
Use this value to set an "<" link between two table columns. |
static int |
JOINLINK_NOT_EQUALS
Use this value to set an "<>" link between two table columns. |
static int |
JOINTYPE_FULL_OUTER
Use this value for creating an full outer join. |
static int |
JOINTYPE_INNER
Use this value for creating an inner join. |
static int |
JOINTYPE_LEFT_OUTER
Use this value for creating an left outer join. |
static int |
JOINTYPE_RIGHT_OUTER
Use this value for creating an right outer join. |
| Method Summary | |
|---|---|
Join |
addJoin(java.lang.String fromTableAlias,
java.lang.String fromColumn,
java.lang.String toTableAlias,
java.lang.String toColumn,
int joinType,
int linkType)
Adds a join into report. |
Join |
addJoin(TableSource fromTableSource,
DatabaseField fromColumn,
TableSource toTableSource,
DatabaseField toColumn,
int joinType,
int linkType)
Adds a join into report. |
static java.lang.String |
changeWhereToNoRows(java.lang.String sqlStatement)
Returns the sql statement with WHERE condition 1=0 to avoid the db returning any data. |
Datasource |
createDatasource(java.lang.String dataSourceConfigurationName)
Creates a Datasource that uses a DataSourceConfiguration to create a database connection. |
java.lang.String[] |
getAllAvailableColumns()
Returns all columns that are available for this report. |
java.lang.String[] |
getColumnNames(java.lang.String alias)
Returns a String[] with the column names. |
int[] |
getColumnTypes(java.lang.String alias)
Returns an int[] with the types of columns. |
Datasource |
getDatasource(int idx)
Returns the data source at position idx. |
Datasource |
getDatasource(java.lang.String name)
Returns the datasource by name. |
int |
getDatasourceCount()
Returns how many data sources are known. |
java.util.Vector |
getJoinsEntries()
Returns a Vector with an entry for each join. |
java.util.Vector |
getJoinsView()
Returns a Vector with an entry for each join, i.e. |
int |
getSqlAliasCount()
Returns the count of aliases. |
java.lang.String[] |
getSqlAliasNames()
Returns a String[] with the names of the sql aliases used in this report. |
java.lang.String[] |
getSqlSourcesView()
Returns a String[] with the names of all TableSources used in this report. |
TableSource |
getTablesource(java.lang.String alias)
Returns the TableSource with that alias name. |
boolean |
isSavePassword()
Returns if the password should be saved. |
static int |
mapSqlTypeToCCType(int sqlType)
Conversion between the java.sql.Types data types of a database table column and the internal representation of data types in RDC. |
void |
readDbFromQuery(java.net.URL url)
Use this method if you have already designed a query file. |
void |
removeDatasource(Datasource ds)
Removes a datasource connection from the known connections. |
void |
removeJoin(java.lang.String fromTableAlias,
java.lang.String fromColumn,
java.lang.String toTableAlias,
java.lang.String toColumn)
Removes a join from report if exists. |
void |
removeJoin(TableSource fromTableSource,
DatabaseField fromColumn,
TableSource toTableSource,
DatabaseField toColumn)
Removes a link of a join from the report if it exists. |
void |
removeSqlSource(java.lang.String alias)
Removes a sql source from report (a table or a stored procedure), if exists. |
void |
setSavePassword(boolean save)
Sets if the password for this report should be saved in the xml file (report template). |
| Field Detail |
|---|
public static final int JOINTYPE_INNER
addJoin(String, String, String, String, int, int),
Constant Field Valuespublic static final int JOINTYPE_RIGHT_OUTER
addJoin(String, String, String, String, int, int),
Constant Field Valuespublic static final int JOINTYPE_LEFT_OUTER
addJoin(String, String, String, String, int, int),
Constant Field Valuespublic static final int JOINTYPE_FULL_OUTER
addJoin(String, String, String, String, int, int),
Constant Field Valuespublic static final int JOINLINK_EQUALS
addJoin(String, String, String, String, int, int),
Constant Field Valuespublic static final int JOINLINK_GREATER_THAN
addJoin(String, String, String, String, int, int),
Constant Field Valuespublic static final int JOINLINK_GREATER_EQUALS_THAN
addJoin(String, String, String, String, int, int),
Constant Field Valuespublic static final int JOINLINK_LESS_THAN
addJoin(String, String, String, String, int, int),
Constant Field Valuespublic static final int JOINLINK_LESS_EQUALS_THAN
addJoin(String, String, String, String, int, int),
Constant Field Valuespublic static final int JOINLINK_NOT_EQUALS
addJoin(String, String, String, String, int, int),
Constant Field Values| Method Detail |
|---|
public void setSavePassword(boolean save)
throws ReportException
save - The password will be saved only if this is true.
ReportException - will thrown if Engine is invalid or finished.isSavePassword(),
Datasource.getUsername(),
Datasource.getPassword(),
Datasource.setPassword(String)public boolean isSavePassword()
setSavePassword(boolean),
Datasource.getUsername(),
Datasource.getPassword(),
Datasource.setPassword(String)public static java.lang.String changeWhereToNoRows(java.lang.String sqlStatement)
sqlStatement - the original statement
public void removeSqlSource(java.lang.String alias)
throws ReportException
alias - The alias name of the sql source, i.e. "Customer" or "Credit_Limit".
ReportException - If there is no TableSource (that means table, view
or stored procedure) in the report with the given alias or a stored procedure
should be removed which uses prompt fields for their parameter(s) and at
least one parameter could not be removed as it is still used in the report.public java.lang.String[] getSqlSourcesView()
Datasource.createTableSource(String),
Datasource.createTableSource(String, String),
removeSqlSource(String)public java.lang.String[] getSqlAliasNames()
Engine e = new Engine();
e.setReportFile("file:c:/MyReport.rpt");
DatabaseTables dt = e.getDatabaseTables();
String[] aliasNames = dt.getSqlAliasNames();
for (int i=0;i<aliasNames.length;i++) {
System.out.println(aliasNames[i]);
}
Datasource.createTableSource(String),
Datasource.createTableSource(String, String),
removeSqlSource(String)public int getSqlAliasCount()
public java.lang.String[] getColumnNames(java.lang.String alias)
alias - the alias name of the TableSource to return the column names of
getSqlAliasNames()public int[] getColumnTypes(java.lang.String alias)
alias - The sql source alias.
Field.NUMBER,
Field.BOOLEAN,
Field.DATE,
Field.DATETIME,
Field.TIME,
Field.STRING
public Join addJoin(java.lang.String fromTableAlias,
java.lang.String fromColumn,
java.lang.String toTableAlias,
java.lang.String toColumn,
int joinType,
int linkType)
throws ReportException
fromTableAlias - The name of the table the join starts, i.e. CustomertoTableAlias - The name of the table the join ends, i.e. Employee_AddressfromColumn - The name of the column the join starts, i.e. CitytoColumn - The name of the column the join starts, i.e. CityjoinType - The join type. Possible values:linkType - The link type for the column link. Possible values:ReportException - will be thrown if join is not valid.
ReportException - if the same join already exists
public Join addJoin(TableSource fromTableSource,
DatabaseField fromColumn,
TableSource toTableSource,
DatabaseField toColumn,
int joinType,
int linkType)
throws ReportException
fromTableSource - The TableSource from which the join starts.toTableSource - The TableSource the join ends.fromColumn - The column of the fromTableSource that is linked with a column of the toTableSource.toColumn - The column of the toTableSource that is linked with a column of the fromTableSource.joinType - The join type. Possible values:linkType - The link type for the column link. Possible values:ReportException - will be thrown if join is not valid or if the same join already exists
java.lang.IllegalArgumentException - If the passed joinType or linkType is invalid.getTablesource(String),
Datasource.createTableSource(String,String),
TableSource.getDatabaseField(String)
public void removeJoin(java.lang.String fromTableAlias,
java.lang.String fromColumn,
java.lang.String toTableAlias,
java.lang.String toColumn)
throws ReportException
fromTableAlias - The name of the table the join starts, i.e. "Customer".fromColumn - The name of the column the join starts, i.e. "City".toTableAlias - The name of the table the join ends, i.e. "Employee_Addresses".toColumn - Tha name of the column the join ends, i.e. "City".
ReportException - will thrown if parameters are invalid.
public void removeJoin(TableSource fromTableSource,
DatabaseField fromColumn,
TableSource toTableSource,
DatabaseField toColumn)
fromTableSource - The from TableSource of the join.fromColumn - The column of the from TableSource of the join.toTableSource - The to TableSource of the join.toColumn - The column of the to TableSource of the join.
java.lang.IllegalArgumentException - If one of the parameters is
null or if the columns can not be found in the given TableSources.public java.util.Vector getJoinsView()
addJoin(String, String, String, String, int, int),
removeJoin(String, String, String, String)public java.util.Vector getJoinsEntries()
JoinJoin,
addJoin(String, String, String, String, int, int),
removeJoin(String, String, String, String)
public void readDbFromQuery(java.net.URL url)
throws ReportException
url - The URL to the query file. Note that the query file has to be located
in the same directory as the report.
ReportException - is thrown if query file was not found.public static int mapSqlTypeToCCType(int sqlType)
sqlType - One of the types defined in java.sql.Types.
Field.NUMBER,
Field.BOOLEAN,
Field.DATE,
Field.DATETIME,
Field.TIME,
Field.STRINGpublic java.lang.String[] getAllAvailableColumns()
getSqlAliasNames(),
getColumnNames(String)
public TableSource getTablesource(java.lang.String alias)
throws ReportException
alias - Alias of data source to be retrieved.
ReportException - If no TableSource exists with the alias name.The alias name is case insensitive per default. It is case sensitive if the database property "useQuoteLowerCase" is set on true.
public void removeDatasource(Datasource ds)
throws ReportException
ds - Datasource to remove.
ReportException - If trying to remove a connection which is used by the report.public Datasource getDatasource(int idx)
idx - Position of data source to be returned. The first Datasource has index 0.
public Datasource getDatasource(java.lang.String name)
getDatasource(int) with 0.
name - the name
public int getDatasourceCount()
public Datasource createDatasource(java.lang.String dataSourceConfigurationName)
throws ReportException
dataSourceConfigurationName - the name of the global datasource configuration.
ReportException - if there is no known DataSourceConfiguration with passed name.DataSourceConfiguration,
DataSourceConfigurationManager,
Datasource
|
i-net Clear Reports | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||