public class DatabaseTables
extends java.lang.Object
implements java.io.Serializable
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.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");
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)
addJoin(String, String, String, String, int, int)
or addJoin(TableSource, DatabaseField, TableSource, DatabaseField, int, int)
.
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);
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);
Datasource
,
TableSource
,
Join
,
DataSourceConfigurationManager
,
DataSourceConfiguration
,
Serialized FormModifier and Type | Field and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
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<java.lang.String> |
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 |
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).
|
public static final int JOINTYPE_INNER
public static final int JOINTYPE_RIGHT_OUTER
public static final int JOINTYPE_LEFT_OUTER
public static final int JOINTYPE_FULL_OUTER
public static final int JOINLINK_EQUALS
public static final int JOINLINK_GREATER_THAN
public static final int JOINLINK_GREATER_EQUALS_THAN
public static final int JOINLINK_LESS_THAN
public static final int JOINLINK_LESS_EQUALS_THAN
public static final int JOINLINK_NOT_EQUALS
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 statementpublic 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( Engine.NO_EXPORT );
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 ofgetSqlAliasNames()
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 existspublic 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 existsjava.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<java.lang.String> getJoinsView()
addJoin(String, String, String, String, int, int)
,
removeJoin(String, String, String, String)
public java.util.Vector getJoinsEntries()
Join
Join
,
addJoin(String, String, String, String, int, int)
,
removeJoin(String, String, String, String)
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.STRING
public 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 namepublic int getDatasourceCount()
@Nonnull 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
Copyright © 1999-2020 by i-net software GmbH