public class TableSource extends java.lang.Object implements java.io.Serializable, com.inet.report.ReferenceHolder, NodeParser
Add a table to the reportDatabaseTables dbTables = engine.getDatabaseTables(); Datasource ds = dbTables.createDatasource("pdssql.dll","localhost","","Northwind","sa","MyPassword"); //adding a TableSource to the Datasource TableSource tabOrderDetails = ds.createTableSource("Order Details"); tabOrderDetails.addColumn("OrderId",Field.NUMBER); tabOrderDetails.addColumn("ProductId",Field.NUMBER); tabOrderDetails.addColumn("UnitPrice",Field.NUMBER); tabOrderDetails.addColumn("Quantity",Field.NUMBER); tabOrderDetails.addColumn("OrderId",Field.NUMBER); tabOrderDetails.addColumn("Discount",Field.NUMBER); //to receive the DatabaseField of column "OrderId call: tabOrderDetails.getDatabaseField(tabOrderDetails.getColumnName(0));
Add a stored procedure to the report:TableSource sp_salesByYear = ds.createTableSource("Sales By Year"); //add the result columns to the stored procedure sp_salesByYear.addColumn("ShippedDate", Field.DATETIME); sp_salesByYear.addColumn("OrderID", Field.NUMBER); sp_salesByYear.addColumn("Subtotal", Field.NUMBER); sp_salesByYear.addColumn("Year", Field.STRING); //define the input parameter of the stored procedure String[] inputParamNames = new String[]{"Beginning_Date","Ending_Date"}; int[] inputParamTypes = new int[]{Field.DATETIME,Field.DATETIME}; sp_salesByYear.setInputParameter(inputParamNames,inputParamTypes);
Add a SQL command to the report:TableSource cmdOrderDetails = ds.createTableSource("Order Details"); //Hint:
If the Datasource of the TableSource can create a database Connection, you can use theDatasource.createTableSourceCommand(String, String)
adds the columns and DatabaseFields automatically. cmdOrderDetails.setSql("select * from \"Order Details\" where OrderId = {?OrderId}"); //add the required PromptField to the report cmdOrderDetails.setInputParameter( new String[]{"OrderId"}, new int[]{Field.NUMBER}); //add the result columns to the sql command cmdOrderDetails.addColumn("OrderId",Field.NUMBER); cmdOrderDetails.addColumn("ProductId",Field.NUMBER); cmdOrderDetails.addColumn("UnitPrice",Field.NUMBER); cmdOrderDetails.addColumn("Quantity",Field.NUMBER); cmdOrderDetails.addColumn("OrderId",Field.NUMBER); cmdOrderDetails.addColumn("Discount",Field.NUMBER);refresh()
to add a table or a stored procedure.DatabaseTables dbTables = engine.getDatabaseTables(); Datasource ds = dbTables.createDatasource("pdssql.dll","localhost","","Northwind","sa","MyPassword"); //adding a TableSource to the Datasource TableSource tabOrderDetails = ds.createTableSource("Order Details"); tabOrderDetails.refresh();//scans the table and adds all columns to TableSource
Modifier and Type | Field and Description |
---|---|
static int |
TYPE_COMMAND
Identifies a TableSource as a sql statement.
|
static java.lang.String |
TYPE_NAME_SYSTEM_TABLE
The name of system table data source returning from meta data.
|
static java.lang.String |
TYPE_NAME_TABLE
The name of table data source returning from meta data.
|
static java.lang.String |
TYPE_NAME_VIEW
The name of view data source returning from meta data.
|
static int |
TYPE_PROCEDURE
Identifies a TableSource as a stored procedure.
|
static int |
TYPE_TABLE_OR_VIEW
Identifies a TableSource as a table or a view.
|
Modifier and Type | Method and Description |
---|---|
void |
addColumn(java.lang.String columnName,
int columnType)
Adds a column to the table definition.
|
void |
addColumn(java.lang.String columnName,
int columnType,
java.lang.String columnLabel)
Adds a column with column description to the table definition.
|
void |
canRemoveColumn(java.lang.String columnName)
Checks the column of this table can be removed from the report.
|
void |
changeAliasReferences(java.lang.String newAlias)
Changes the alias name to newAlias.
|
static void |
checkAliasValidity(java.lang.String newAlias)
Checks the name for whether it is a valid name for this TableSource.
|
void |
checkExistsOnCurrentDatasource()
Sends a test statement to the data source to check if the TableSource is executable.
|
boolean |
equals(java.lang.Object o)
Checks whether the given Object is a TableSource object with the same alias name.
|
java.lang.String |
getAlias()
Returns the alias name.
|
int |
getColumnCount()
Returns the number of columns.
|
java.lang.String |
getColumnName(int idx)
Returns the column name of the selected column.
|
java.lang.String[] |
getColumnNames()
Returns an array of all column names.
|
int |
getColumnType(int idx)
Returns the column type of the selected column.
|
int[] |
getColumnTypes()
Returns an array of all column types.
|
DatabaseField |
getDatabaseField(int idx)
Returns the corresponding DatabaseField to that column index.
|
DatabaseField |
getDatabaseField(java.lang.String columnName)
Returns the corresponding DatabaseField to that column name.
|
DatabaseField[] |
getDatabaseFields()
Returns all DatabaseFields that belongs to this TableSource.
|
java.lang.String |
getDatabaseIdentifier()
Returns the original name of the table source.
|
Datasource |
getDatasource()
Returns the Datasource object, to which this TableSource belongs.
|
java.util.List<PromptField> |
getInputParameters()
Returns the list of
PromptField s which are used by this table source as store procedures parameter. |
boolean |
getQuoteStringPrompts()
Get the value if a string prompts in a SQL statement should be quoted or not.
|
java.sql.ResultSet |
getResultSet()
Returns the ResultSet of that TableSource.
|
java.lang.String |
getSql()
Returns the SQL command if it was set.
|
java.lang.String |
getSqlWithPromptFieldValues()
Returns the SQL command if it was set.
|
int |
getType()
Returns the type of that TableSource.
|
boolean |
isUsed()
Returns the columns of this report are used in the report or this table is used in a join.
|
void |
refresh()
Refreshs the columns of the TableSource by requesting meta information from the database.
|
void |
removeColumn(java.lang.String columnName)
Removes a specific column.
|
void |
setDatabaseIdentifierName(java.lang.String newDatabaseIdentifier)
Sets the identifier name of the TableSource.
|
void |
setInputParameter(java.lang.String[] paramNames,
int[] paramTypes)
Defines the input parameter for this TableSource.
|
void |
setInputParameter(java.lang.String[] paramNames,
int[] paramTypes,
java.lang.Object[] values)
Defines the input parameter for this TableSource.
|
void |
setInputParameter_TypesOfSQLType(java.lang.String[] paramNames,
int[] paramTypes)
Deprecated.
As of i-net Clear Reports 15, instead use
setInputParameter(String[], int[]) |
void |
setInputParameter_TypesOfSQLType(java.lang.String[] paramNames,
int[] paramTypes,
java.lang.Object[] values)
Deprecated.
As of i-net Clear Reports 15, instead use
setInputParameter(String[], int[], Object[]) |
void |
setLocation(java.lang.String location,
Datasource newDatasource)
Set the location information of the identifier.
|
void |
setQuoteStringPrompts(boolean value)
Set if a string prompts in a SQL statement should be quoted or not.
|
void |
setSql(java.lang.String newSql)
Sets the SQL statement and changes the type of this TableSource to
TYPE_COMMAND . |
java.lang.String |
toString()
Returns the alias name.
|
isDOMParser, parseDOM, parseElement, parseEndElement, parseText
public static final int TYPE_TABLE_OR_VIEW
getType()
,
Constant Field Valuespublic static final int TYPE_PROCEDURE
getType()
,
Constant Field Valuespublic static final int TYPE_COMMAND
getType()
,
Constant Field Valuespublic static final java.lang.String TYPE_NAME_TABLE
public static final java.lang.String TYPE_NAME_VIEW
public static final java.lang.String TYPE_NAME_SYSTEM_TABLE
public int getType() throws ReportException
ReportException
- if there occurs a problem while creating the ConnectionTYPE_COMMAND
,
TYPE_PROCEDURE
,
TYPE_TABLE_OR_VIEW
@Nonnull public java.sql.ResultSet getResultSet() throws ReportException, java.sql.SQLException
ReportException
- if there occur a problem on create the Connectionjava.sql.SQLException
- if there occur a problem on execute the Statement.public void checkExistsOnCurrentDatasource() throws ReportException
ReportException
- If the TableSource is not executable on the data source OR if creating the Connection to the data source failed.public void addColumn(java.lang.String columnName, int columnType) throws ReportException
columnName
- The column namecolumnType
- The i-net Clear Reports value typeReportException
- when columnType is not validField.NUMBER
,
Field.STRING
,
Field.TIME
,
Field.DATETIME
,
Field.DATE
,
Field.BOOLEAN
,
Field.BINARY
,
Field.CURRENCY
public void addColumn(java.lang.String columnName, int columnType, java.lang.String columnLabel) throws ReportException
columnName
- The column namecolumnType
- The i-net Clear Reports value typecolumnLabel
- additional information that can be used to explain abstract column namesReportException
- when columnType is not validField.NUMBER
,
Field.STRING
,
Field.TIME
,
Field.DATETIME
,
Field.DATE
,
Field.BOOLEAN
,
Field.BINARY
,
Field.CURRENCY
,
DatabaseField.getColumnLabel()
,
DatabaseField.setColumnLabel(String)
,
DatabaseField.hasColumnLabel()
public DatabaseField getDatabaseField(int idx)
idx
- A 0-based index of DatabaseField.addColumn(String, int)
,
getColumnNames()
,
getColumnCount()
public DatabaseField getDatabaseField(java.lang.String columnName)
columnName
- A column of this TableSource.addColumn(String, int)
,
getColumnNames()
public DatabaseField[] getDatabaseFields()
addColumn(String, int)
public java.lang.String getColumnName(int idx)
idx
- The 0-based index of a column name.getColumnCount()
,
addColumn(String, int)
,
getColumnType(int)
public java.lang.String[] getColumnNames()
public int[] getColumnTypes()
public int getColumnType(int idx) throws java.lang.IndexOutOfBoundsException
idx
- index of the columnjava.lang.IndexOutOfBoundsException
- - if index is out of range (index < 0 || index >= getColumnCount())getColumnCount()
,
addColumn(String, int)
,
getColumnName(int)
public void removeColumn(java.lang.String columnName) throws ReportException
columnName
- Column name to be removed.ReportException
- If the column is used in the report.getColumnNames()
public void canRemoveColumn(java.lang.String columnName) throws ReportException
columnName
- the short column nameReportException
- if the column is used and cannot be removedpublic static void checkAliasValidity(java.lang.String newAlias) throws ReportException
newAlias
- alias name to checkReportException
- if the name is not validpublic void changeAliasReferences(java.lang.String newAlias) throws ReportException
newAlias
- Alias to be setReportException
- If there is no such data source, or if there is a different problempublic void setDatabaseIdentifierName(java.lang.String newDatabaseIdentifier) throws ReportException
newDatabaseIdentifier
- The new identifier name of the TableSource.ReportException
- If the identifier name is empty.public int getColumnCount()
public java.lang.String getAlias()
getDatabaseIdentifier()
public java.lang.String getDatabaseIdentifier()
getAlias()
public void setLocation(java.lang.String location, Datasource newDatasource)
Example 1://old identifier name = "SCOTT.MYTABLE" tableSource.setLocation("OTHERSCHEMA.MYPACKAGE", anOtherDatasource); //the new identifier name = "OTHERSCHEMA.MYPACKAGE.MYTABLE"
Example 2://old identifier name = "SCOTT.MYTABLE" tableSource.setLocation(null,null); //the new identifier name = "MYTABLE"
location
- The location information of the identifier. Passing null
will not change the location. Set empty String to remove the location information.newDatasource
- Set an other Datasource if the TableSource has to move from one Datasource to the other. Passing null
will not move the TableSource.public java.lang.String toString()
toString
in class java.lang.Object
getAlias()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- Object to be checkedpublic java.lang.String getSql()
setSql(String)
public java.lang.String getSqlWithPromptFieldValues() throws ReportException
ReportException
- if SQL command contains invalid placeholder.setSql(String)
public void setSql(java.lang.String newSql)
TYPE_COMMAND
.newSql
- SQL Statement that will be used for this TableSourceaddColumn(String, int)
,
Datasource.createTableSourceCommand(String, String)
,
ReportProperties.setIgnoreFiltering(boolean)
,
ReportProperties.setIgnoreSorting(boolean)
public void setQuoteStringPrompts(boolean value)
value
- the new valuesetSql(String)
public boolean getQuoteStringPrompts()
public Datasource getDatasource()
public void setInputParameter(java.lang.String[] paramNames, int[] paramTypes) throws ReportException
paramNames
- The input parameter names.paramTypes
- The types of the input parameter. The type is a constant of class com.inet.report.Field.ReportException
- If type of parameter is unknown.Field.NUMBER
,
Field.STRING
,
Field.TIME
,
Field.DATETIME
,
Field.BOOLEAN
,
Field.BINARY
public void setInputParameter(java.lang.String[] paramNames, int[] paramTypes, java.lang.Object[] values) throws ReportException
String[] names = new String(){"costumerId","endDate"};
int[] types = new int(){Field.STRING,Field.DATE};
Object values = new Object("ALFKI",new Date(1999,11,11){};
//mySP has two input parameter and retunes a result set
TableSource ts = datasource.createTableSource("mySP");
//creates PromptFields for this procedure and set values
ts.setInputParameter_TypesOfSQLType(names,types,values);
//executes the SP to scan returned columns. The parameter for execution were set before.
ts.refresh();
paramNames
- The input parameter names.paramTypes
- paramTypes The types of the input parameter. The type is a constant of class com.inet.report.Field.values
- values The values for set parameter.ReportException
- If type of parameter is unknown.public java.util.List<PromptField> getInputParameters() throws ReportException
PromptField
s which are used by this table source as store procedures parameter.null
)ReportException
- will be thrown if the engine was invalid or finished@Deprecated public void setInputParameter_TypesOfSQLType(java.lang.String[] paramNames, int[] paramTypes) throws ReportException
setInputParameter(String[], int[])
String[] names = new String(){"costumerId","endDate"};
int[] types = new int(){Types.VARCHAR,Types.DATE};
//mySP has two input parameter and retunes a result set
TableSource ts = datasource.createTableSource("mySP");
//creates PromptFields for this procedure.
ts.setInputParameter_TypesOfSQLType(names,types,values);
//executes the SP to scan returned columns. The parameter for execution are sample values.
ts.refresh();
paramNames
- The input parameter names.paramTypes
- The types of the input parameter. The type is a constant of class java.sql.Types.ReportException
- if mapping from SQL type to Field type failed. If paramNames.length is different to paramTypes.length.@Deprecated public void setInputParameter_TypesOfSQLType(java.lang.String[] paramNames, int[] paramTypes, java.lang.Object[] values) throws ReportException
setInputParameter(String[], int[], Object[])
String[] names = new String(){"costumerId","endDate"};
int[] types = new int(){Types.VARCHAR,Types.DATE};
Object values = new Object("ALFKI",new Date(1999,11,11){};
//mySP has two input parameter and returns a result set
TableSource ts = datasource.createTableSource("mySP");
//creates PromptFields for this procedure and set values
ts.setInputParameter_TypesOfSQLType(names,types,values);
//executes the SP to scan returned columns. The parameter for execution were set before.
ts.refresh();
Code sample for a stored procedure with out cursor:
String[] names = new String(){"outcursor";"costumerId","endDate"};
int[] types = new int(){-10,Types.VARCHAR,Types.DATE};//-10 is out cursor , it is the standard value returned from oracle JDBC drivers
Object values = new Object("ALFKI",new Date(1999,11,11){};//no value for out cursor or other out values
//mySP2 has two input parameter and returns a result via out cursor
TableSource ts = datasource.createTableSource("mySP2");
//creates PromptFields for this procedure and set values
ts.setInputParameter_TypesOfSQLType(names,types,values);
//executes the SP to scan returned columns. The parameter for execution were set before.
ts.refresh();
paramNames
- The input parameter names.paramTypes
- The types of the input parameter. The type is a constant of class java.sql.Types. The values -10(type oracle cursor) and 1111(type other) will be ignored.values
- The values for set parameter. Do not set values for out parameter or cursor parameter.ReportException
- if mapping from SQL type to Field type failed. If paramNames.length is different to paramTypes.length.public void refresh() throws ReportException, java.sql.SQLException
TYPE_TABLE_OR_VIEW
, the following query will send to database to find out the columns of the table:"select * from "+this.getDatabaseIdentifier()+" where 1=0"
TYPE_COMMAND
will requested. An algorithm includes a "1=0" filter clause in the statement.
TYPE_PROCEDURE
, the result of the sp will requested.ReportException
- if a DatabaseField is used in report but the refering column does not exists on database.java.sql.SQLException
- if connecting to database failed or if requesting meta information failed.public boolean isUsed() throws ReportException
ReportException
- if engine is finished or no report is set.Copyright © 1999-2020 by i-net software GmbH