|
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.Database
public class Database
This class is a layer between a DBMS or any other data source and i-net Clear Reports. It compensate the differences between the different DBMS. This class is the default implementation and should work with any SQL99 compatible database. The major information are:
We first describe how data for the main report is fetched:
MaxConnections-1 connections.
So please set MaxConnections to an appropriate value. For example if you have a report which consumes a database connection and 5 sub-reports where each sub-report also consume one database connection set the value MaxConnections=6. However, if your reports use more than 2 or 3 sub-reports, you should better change the layout of your report.
| Constructor Summary | |
|---|---|
Database()
Create a default Database class instance. |
|
| Method Summary | |
|---|---|
java.lang.String |
convertModOperation(java.lang.String dividend,
java.lang.String divisor)
Returns a valid sql expression to evaluate the remainder of an division. |
java.lang.String |
convertStringToSQLSyntax(java.lang.String s,
boolean isFunctionParam)
This function transfoms a java String to a SQL String representation. |
java.lang.String |
convertToBoolean(boolean value)
Returns the representation of a boolean value in the query language of the database. |
java.lang.String |
convertToBoolean(java.lang.String fieldReference,
boolean invert)
If required, this function modifies a field reference to convert the value of the field to a boolean. |
java.lang.String |
convertToDate(java.lang.String date)
Returns a valid sql expression to convert the given parameter to a Time data type. |
java.lang.String |
convertToDate(java.lang.String year,
java.lang.String month,
java.lang.String day)
Returns a valid sql expression to convert the given parameters to a Date data type. |
java.lang.String |
convertToDouble(java.lang.String parameter)
Returns a valid sql expression to convert the given parameter to a Double data type. |
java.lang.String |
convertToInt(java.lang.String parameter)
Returns a valid sql expression to convert the given parameter to a Integer data type. |
java.lang.String |
convertToString(java.lang.String parameter)
Returns a valid sql expression to convert the given parameter to a String data type. |
java.lang.String |
convertToTime(java.lang.String time)
Returns a valid sql expression to convert the given parameter to a Time data type. |
java.lang.String |
convertToTime(java.lang.String hour,
java.lang.String minute,
java.lang.String sec)
Returns a valid sql expression to convert the given parameters to a Time data type. |
java.lang.String |
convertToTimeStamp(java.lang.String year,
java.lang.String month,
java.lang.String day,
java.lang.String hour,
java.lang.String minute,
java.lang.String sec)
Returns a valid sql expression to convert the given parameters to a Timestamp data type. |
protected void |
findColumnLabels(TableSource tableSource)
Tries to find column labels for the columns of the provided TableSource. |
java.lang.String |
getAddOp()
Overwrite this method if the used database uses another sign than "+" as add operator. |
java.lang.String |
getAliasToken()
Returns the SQL keyword that is required to define an alias name in a SQL statement. |
java.sql.ResultSet |
getColumns(Datasource ds,
java.lang.String catalog,
java.lang.String owner,
java.lang.String tablename)
Overwrite getTables and getColumns if you want to use your own Database class to design a report with i-net Designer. |
protected int |
getCursorType(int dataType)
Returns the SQL data type for a cursor if the stored procedure parameter is a cursor. |
java.lang.String |
getIdentifierQuoteString()
Returns the string used to quote SQL identifiers. |
int |
getMaxAliasNameLength()
Returns the maximum length of the alias name. |
void |
getReportData(Engine engine,
java.lang.String dataSourceConfigurationName)
Delivers the data of the report. |
boolean |
getReportDataPerInstance()
Override this method only if you use subreport(s) and you will set the data for the report with the getReportData method (useJdbcDriver = false). |
protected java.lang.String |
getSqlIdentifier(DatabaseTables dbTables,
java.lang.String identifier,
boolean escapeEverything)
Returns the SQL identifier regarding the settings of getIdentifierQuoteString(), escapeEverything and
needQuote(String). |
java.sql.ResultSet |
getTables(Datasource ds,
java.lang.String catalog)
Overwrite getTables and getColumns if you want to use your own Database class to design a report with i-net Designer. |
protected void |
initTransient()
Init transient variables after serialize. |
boolean |
isEscapeEverything()
Returns the value of the flag escapeEverything. |
boolean |
isUseOrderBy()
Indicates whether an ORDER BY clause is allowed for the sql statement. |
boolean |
isUseParenthesiseForJoin()
Indicates whether parentheses are allowed in FROM clause of the sql statement. |
boolean |
isUseQuoteLowerCase()
Indicates whether table names and column names have to be quoted This property can be necessary for Oracle databases for example, if table/column where created with quotes and lower case characters. |
boolean |
isUseSQL92syntax()
Indicates whether the SQL statement can contain the join condition in SQL92 syntax or not. |
boolean |
isUseWhereClause()
Indicates whether the SQL statement can contain the WHERE clause or not. |
protected boolean |
needQuote(java.lang.String identifier)
Returns if the supplied SQL identifier needs to be put in quotes. |
protected java.lang.String[] |
parseSourceName(java.lang.String sqlSource)
Splits the provided name of a SQL source (name of a table, view or stored procedure) into three parts. |
protected java.sql.PreparedStatement |
prepareStatement(TableSource tableSource)
Returns a PreparedStatement for execution of the stored procedure represented by the provided TableSource. |
protected void |
scanIdentifierQuoteString(Datasource dc)
This method will detect which String should be used to quote database identifiers for the supplied Datasource. |
void |
setAliasToken(java.lang.String aliasToken)
This method is for adapt the sql statement for a specific database. |
void |
setIdentifierQuoteString(java.lang.String quoteString)
This method is for adapt the sql statement for a specific database. |
void |
setUseEscapeEverything(boolean escapeEvreything)
This method is for adapt the sql statement for a specific database. |
void |
setUseOrderBy(boolean useOrderBy)
This method is for adapt the sql statement for a specific database. |
void |
setUseParenthesiseForJoin(boolean useParenthesiseForJoin)
This method is for adapt the sql statement for a specific database. |
void |
setUseQuoteLowerCase(boolean useQuoteLowerCase)
This method is for adapt the sql statement for a specific database. |
void |
setUseSQL92syntax(boolean useSQL92syntax)
This method is for adapt the sql statement for a specific database. |
void |
setUseWhereClause(boolean useWhereClause)
This method is for adapt the sql statement for a specific database. |
java.lang.String |
sqlConcat(java.lang.Object leftOperant,
java.lang.Object rightOperant)
Returns a valid sql statement concatenating two expressions. |
protected java.lang.String |
toSQL92(java.lang.String function,
Field field)
Creates a SQL92 expression with function and one parameter. |
boolean |
useJdbcDriver()
Override this method to specify if the engine should use a JDBC driver or if you want to use setData(). |
| Constructor Detail |
|---|
public Database()
| Method Detail |
|---|
protected void initTransient()
protected void scanIdentifierQuoteString(Datasource dc)
throws java.sql.SQLException,
ReportException
DatabaseMetaData.getIdentifierQuoteString(). The identifier
quote string detected should be applied to this Database using
setIdentifierQuoteString(String).
dc - The Datasource providing the connection information.
java.sql.SQLException - If a SQL error occurred during request of database
meta data.
ReportException - If an error occurred during establishing a
database connection.protected java.lang.String[] parseSourceName(java.lang.String sqlSource)
[[catalog.]schema.]name.
The array returned contains these three parts each part set to
null if not set.
sqlSource - The name of the SQL source which may contain catalog
or schema qualifier.
null if no catalog is setnull if no schema is setnull)protected boolean needQuote(java.lang.String identifier)
identifier - The SQL identifier to be checked.
protected java.lang.String getSqlIdentifier(DatabaseTables dbTables,
java.lang.String identifier,
boolean escapeEverything)
getIdentifierQuoteString(), escapeEverything and
needQuote(String). If getIdentifierQuoteString()
is empty the provided identifier will be returned without modification.
If escapeEverything returns true the whole identifier provided should be
put in the quotes returned by getIdentifierQuoteString().
Otherwise each part of the SQL identifier will be checked with
needQuote(String) and put in quotes if necessary. The
identifier can consist of catalog, schema and name like this:
[[catalog.]schema.]name.
dbTables - The DatabaseTables object of the report which uses the
provided SQL identifier.identifier - The identifier which should be prepared for SQL.escapeEverything - True if the complete sql identifier should
be quoted false otherwise
protected java.sql.PreparedStatement prepareStatement(TableSource tableSource)
throws java.sql.SQLException,
ReportException
tableSource - The TableSource representing a stored procedure to
prepare a statement for.
java.sql.SQLException - If a SQL error occurred during creation of the
PreparedStatement.
ReportException - If the connection for the report could not be
established.public boolean useJdbcDriver()
public boolean getReportDataPerInstance()
public void getReportData(Engine engine,
java.lang.String dataSourceConfigurationName)
throws ReportException
engine - The reference to your enginedataSourceConfigurationName - A string describing the connection configuration
ReportException - If an error occurred during data fetching.public java.lang.String getAddOp()
public java.lang.String sqlConcat(java.lang.Object leftOperant,
java.lang.Object rightOperant)
leftOperant + getAddOp() + rightOperant" concat("+leftOperant+","+rightOperant+") "
leftOperant - the left operandrightOperant - the right operand
getAddOp()
public java.sql.ResultSet getColumns(Datasource ds,
java.lang.String catalog,
java.lang.String owner,
java.lang.String tablename)
throws java.sql.SQLException,
ReportException
DatabaseMetaDataFactory.
public ResultSet getColumns(Datasource ds, String cat, String own, String tab) throws SQLException {
if(tab.equalsIgnoreCase("customers"))
return DatabaseMetaDataFactory.getColumns(new String[] {"customerid", "companyname", "address"},new int[] {Types.VARCHAR, Types.VARCHAR, Types.VARCHAR});
else
throw new SQLException("unknown table "+tab);
}
ds - The Datasource containing the Connection.catalog - The catalog/database set in login dialog of i-net Designer.owner - The table owner or null.tablename - The table name.
java.sql.SQLException - This SQLException will be showen in a message box in i-net Designer.
java.sql.SQLException - if a database access error occurs
ReportException - if the creation of a Connection failed.useJdbcDriver(),
getColumns(Datasource, String, String, String),
DatabaseMetaDataFactory.getTables(String[], String)
public java.sql.ResultSet getTables(Datasource ds,
java.lang.String catalog)
throws java.sql.SQLException,
ReportException
DatabaseMetaDataFactory.
public ResultSet getTables(Datasource ds, String catalog)throws SQLException {
return DatabaseMetaDataFactory.getTables(new String[]{"customers"});
}
ds - The current Datasource containg the Connection.catalog - The catalog/database set in login dialog of i-net Designer.
java.sql.SQLException - if a database access error occurs
ReportException - if the creation of a Connection failed.useJdbcDriver(),
getColumns(Datasource, String, String, String),
DatabaseMetaDataFactory.getTables(String[], String)protected int getCursorType(int dataType)
dataType - The original SQL data type for the stored procedure
parameter which should be used as cursor.
public int getMaxAliasNameLength()
18 as the default value. Databases which allow alias names
to have more than 18 characters can overwrite this method and return a
higher value.
public java.lang.String convertToString(java.lang.String parameter)
throws ReportException
return "{fn CONVERT( "+parameter+", SQL_CHAR ) }";return "Cstr("+parameter+")";
parameter - set in ToText(parameter)
ReportException - if that convert function is not possible in the database.
In this case the function will be evaluated by i-net Clear Reports.
public java.lang.String convertToInt(java.lang.String parameter)
throws ReportException
return "{fn CONVERT( "+parameter+", SQL_INTEGER ) }";return "Cint("+parameter+")";
parameter - set in Int(parameter),Truncate(parameter)
ReportException - if that convert function is not possible in the database.
In this case the function will be evaluated by i-net Clear Reports.
public java.lang.String convertToDouble(java.lang.String parameter)
throws ReportException
return "{fn CONVERT( "+parameter+", SQL_DOUBLE ) }";return "Cdbl("+parameter+")";
parameter - set in Cdbl(parameter),ToNumber(parameter)
ReportException - if that convert function is not possible in the database.
In this case the function will be evaluated by i-net Clear Reports.
public java.lang.String convertToTime(java.lang.String time)
throws ReportException
return "{fn CONVERT( "+parameter+", SQL_TIME ) }";return "to_date('1970-01-01 '||"+hour+"||'/'||"+minute+"||'/'||"+sec+",'yyyy-mm-dd HH24/MI/SS')";
time - parameter set in TimeValue(parameter),CTime(parameter)
ReportException - if that convert function is not possible in the database.
In this case the function will be evaluated by i-net Clear Reports.
public java.lang.String convertToDate(java.lang.String date)
throws ReportException
return "{fn CONVERT( "+parameter+", SQL_TIME ) }";return "to_date('1970-01-01 '||"+hour+"||'/'||"+minute+"||'/'||"+sec+",'yyyy-mm-dd HH24/MI/SS')";
date - parameter set in TimeValue(parameter),CTime(parameter)
ReportException - if that convert function is not possible in the database.
In this case the function will be evaluated by i-net Clear Reports.
public java.lang.String convertToDate(java.lang.String year,
java.lang.String month,
java.lang.String day)
throws ReportException
"convert(datetime, right( '0000' + convert(varchar,"+year+"),4) + right( '00' + convert(varchar,"+month+"), 2) + right( '00' + convert(varchar,"+day+"), 2))""to_date("+year+"||'/'||"+month+"||'/'||"+day+",'YYYY/mm/dd')"
year - The year of the date to convert.month - The month of the date to convert.day - The day of the date to convert.
ReportException - if that convert function is not possible in the database.
In this case the function will be evaluated by i-net Clear Reports.
public java.lang.String convertToTime(java.lang.String hour,
java.lang.String minute,
java.lang.String sec)
throws ReportException
"convert(datetime, right( '00' + convert(varchar,"+hour+"),2)+ ':'+ right( '00' + convert(varchar,"+minute+"), 2) +':'+ right( '00' + convert(varchar,"+sec+"),2),8)""to_date('1970-01-01 '||"+hour+"||'/'||"+minute+"||'/'||"+sec+",'yyyy-mm-dd HH24/MI/SS')"
hour - The hour of the time to convert.minute - The minute of the time to convert.sec - The second of the time to convert.
ReportException - if that convert function is not possible in the database.
In this case the function will be evaluated by i-net Clear Reports.
public java.lang.String convertToTimeStamp(java.lang.String year,
java.lang.String month,
java.lang.String day,
java.lang.String hour,
java.lang.String minute,
java.lang.String sec)
throws ReportException
"convert(datetime, right( '0000' + convert(varchar,"+year+"),4) + '-' + right( '00' + convert(varchar,"+month+"), 2) + '-' +right( '00' + convert(varchar,"+day+"),2)+' '+right( '00' + convert(varchar,"+hour+"),2)+ ':'+ right( '00' + convert(varchar,"+minute+"), 2) +':'+ right( '00' + convert(varchar,"+sec+"),2),20)"
year - The year of the date to convert.month - The month of the date to convert.day - The day of the date to convert.hour - The hour of the time to convert.minute - The minute of the time to convert.sec - The second of the time to convert.
ReportException - if that convert function is not possible in the database.
In this case the function will be evaluated by i-net Clear Reports.
public java.lang.String convertModOperation(java.lang.String dividend,
java.lang.String divisor)
throws ReportException
dividend+"%"+divisor
Example solution for Oracle Server:"mod("+dividend+","+divisor+")"
dividend - The dividend of the mod operation to convert.divisor - The divisor of the mod operation to convert.
ReportException - if that convert function is not possible in the database.
In this case the function will be evaluated by i-net Clear Reports.
public java.lang.String convertStringToSQLSyntax(java.lang.String s,
boolean isFunctionParam)
hello will transformed to 'hello'.Hello 'World' will transformed to 'Hello ''World'''.Hello 'World' will transformed to N'Hello ''World'''.
s - The String that have to transformed to SQL representation.isFunctionParam - Shows that this flag is a constant parameter to be used by a function. This is important for
parameters which can not be written as multi-language parameters. For example, the first parameter of the function
TIMESTAMPADD cannot be a multi-language parameter for a Microsoft SQL Server database.
public boolean isUseOrderBy()
Datasource.getDatabase(),
DatabaseTables.getDatasourceCount(),
setUseOrderBy(boolean)public void setUseOrderBy(boolean useOrderBy)
useOrderBy - Whether the sql statement can have an ORDER BY clause or not.Datasource.getDatabase(),
DatabaseTables.getDatasourceCount(),
isUseOrderBy()public boolean isUseParenthesiseForJoin()
Datasource.getDatabase(),
DatabaseTables.getDatasourceCount(),
setUseParenthesiseForJoin(boolean)public void setUseParenthesiseForJoin(boolean useParenthesiseForJoin)
useParenthesiseForJoin - Whether the sql statement can have parentheses in FROM clause or not.Datasource.getDatabase(),
DatabaseTables.getDatasourceCount(),
isUseParenthesiseForJoin()public boolean isUseQuoteLowerCase()
Datasource.getDatabase(),
DatabaseTables.getDatasourceCount(),
setUseQuoteLowerCase(boolean)public void setUseQuoteLowerCase(boolean useQuoteLowerCase)
useQuoteLowerCase - Whether table names and column names have to be quoted.Datasource.getDatabase(),
DatabaseTables.getDatasourceCount(),
isUseParenthesiseForJoin()public boolean isUseSQL92syntax()
setUseSQL92syntax(boolean)public void setUseSQL92syntax(boolean useSQL92syntax)
useSQL92syntax - Whether the SQL statement can contain the join condition in SQL92 syntax or not.isUseSQL92syntax()public boolean isUseWhereClause()
Datasource.getDatabase(),
DatabaseTables.getDatasourceCount(),
setUseWhereClause(boolean)public void setUseWhereClause(boolean useWhereClause)
useWhereClause - True if the database supports WHERE clauses
false otherwiese.Datasource.getDatabase(),
DatabaseTables.getDatasourceCount(),
isUseWhereClause()public java.lang.String getAliasToken()
setAliasToken(String)public void setAliasToken(java.lang.String aliasToken)
aliasToken - The keyword used to define an alias name.getAliasToken()public java.lang.String getIdentifierQuoteString()
setIdentifierQuoteString(String)public void setIdentifierQuoteString(java.lang.String quoteString)
" character.
quoteString - The string which should be used to quote the SQL
identifiers.getIdentifierQuoteString()public boolean isEscapeEverything()
setUseEscapeEverything(boolean)public void setUseEscapeEverything(boolean escapeEvreything)
"atable" in catalog "aCatalog".select ... from "aCatalog.aTable"
escapeEvreything - True if the complete sql identifier should
be quoted false otherwise.isEscapeEverything()protected void findColumnLabels(TableSource tableSource)
TableSource.getDatasource().getConnection())
If any column label is found overriding classes should update the
database field with the
column lable using DatabaseField.setColumnLabel(String).
tableSource - The TableSource to find the column labels for.
protected java.lang.String toSQL92(java.lang.String function,
Field field)
function - the functionfield - the parameter field
public java.lang.String convertToBoolean(boolean value)
value - the boolean value to convert
public java.lang.String convertToBoolean(java.lang.String fieldReference,
boolean invert)
fieldReference - the plain field reference for the column which is supposed to contain a boolean valueinvert - set whether to invert the value of the field
|
i-net Clear Reports | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||