public class JdbcDataSource extends DataSourceBase implements DataSourceProvider
A query or foreach tag can reference a var from another query or foreach tag using ${var.item}.. An XPath query can describe a node as well as an element. In this class a query defines a ResultSet and is only an element.
When using a var (<wr:forEach var="result"/>) that identifies a result set, you can use the following in a tag:
return ResultSet.getInt(1) > 0;
. This does not look at the select statement, it is the notEmpty="true" that
puts it in this mode.
Notes: statements are created using Connection.prepareStatement(select, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)
The TYPE_SCROLL_INSENSITIVE or TYPE_SCROLL_SENSITIVE setting is necessary in some jdbc drivers for ResultSet.isLast()
to function.Modifier and Type | Class and Description |
---|---|
static class |
JdbcDataSource.JdbcSelect |
Constructor and Description |
---|
JdbcDataSource(java.sql.Connection conn)
Create a DataSourceProvider that uses jdbc to access a SQL database.
|
JdbcDataSource(java.lang.String className,
java.lang.String url)
Create a DataSourceProvider that uses jdbc to access a SQL database.
|
JdbcDataSource(java.lang.String className,
java.lang.String url,
java.lang.String username,
java.lang.String password)
Create a DataSourceProvider that uses jdbc to access a SQL database.
|
Modifier and Type | Method and Description |
---|---|
void |
addSelectListener(JdbcSelectListener listener)
Adds a select Listener which is notified whenever a select has been executed.
|
void |
approveDenyModifySelect(BaseTag xmlTag)
Verifys that a tag select is approved by a user defined callback
Or denies by throwing a DatasourceException or modifies the select
|
void |
close()
Called when processing is complete.
|
java.sql.Connection |
getConnection() |
java.lang.String |
getDatasourceName()
returns the name of this type in the form "sql", "xml", etc.
|
java.util.Map |
getMap()
Returns the map of variables for this datasource.
|
int |
getParamMode()
Get the parameter substitution mode.
|
int |
getQueryMode(java.lang.String query,
BaseTag tag)
Returns the query mode for this select.
|
DataSourceNode |
getRootNode()
Returns the root node for this data set.
|
TagAttributes[] |
getTagAttributes()
Returns the allowed attributes for all tags.
|
void |
populateDatasourceException(DataSourceException exception,
BaseTag tag,
DataSourceNode[] stack)
Populates that properties in a DataSourceException via DataSourceException.setProperties().
|
void |
setDatasets(java.lang.Object[] datasets)
Set the datasets to use with this datasource.
|
void |
setMap(java.util.Map map)
Sets the map that is used for ${variable} substitution.
|
void |
setParamMode(int paramMode)
Set the parameter substitution mode.
|
void |
validateTag(BaseTag xmlTag)
Verifys that a tag has all required attributes and no unknown attributes.
|
convertToInputStream
public JdbcDataSource(java.lang.String className, java.lang.String url, java.lang.String username, java.lang.String password) throws DataConnectionException
className
- The classname for the jdbc driver. An example would be sun.jdbc.odbc.JdbcOdbcDriverurl
- The url of the of the database. An example would be jdbc:odbc:sampledbusername
- The username to log in to the database. This can be an empty string.password
- Thepassword to log in to the database. This can be an empty string.DataConnectionException
- thrown if anything goes wrong.public JdbcDataSource(java.lang.String className, java.lang.String url) throws DataConnectionException
className
- The classname for the jdbc driver. An example would be sun.jdbc.odbc.JdbcOdbcDriverurl
- The url of the of the database. An example would be jdbc:odbc:sampledbDataConnectionException
- thrown if anything goes wrong.public JdbcDataSource(java.sql.Connection conn) throws DataConnectionException
conn
- A connection to the sql database to use as the datasource.DataConnectionException
public java.lang.String getDatasourceName()
getDatasourceName
in interface DataSourceProvider
public TagAttributes[] getTagAttributes()
getTagAttributes
in interface DataSourceProvider
public void validateTag(BaseTag xmlTag) throws TagException, DataSourceException
validateTag
in interface DataSourceProvider
xmlTag
- The tag to checkTagException
- thrown if illegal parameters passed in.DataSourceException
public void approveDenyModifySelect(BaseTag xmlTag) throws DataSourceException
approveDenyModifySelect
in interface DataSourceProvider
xmlTag
- The tag to checkDataSourceException
- thrown if illegal parameters passed in.public void populateDatasourceException(DataSourceException exception, BaseTag tag, DataSourceNode[] stack)
populateDatasourceException
in interface DataSourceProvider
exception
- The exception to populate.tag
- The tag we're processing. null if no tag.stack
- The node stack at the time of the exception. null if not relevant.public int getParamMode()
getParamMode
in interface DataSourceProvider
public void setParamMode(int paramMode)
setParamMode
in interface DataSourceProvider
paramMode
- the parameter substitution mode.public void setMap(java.util.Map map)
setMap
in interface DataSourceProvider
map
- The map of string/value pairs.public java.util.Map getMap()
getMap
in interface DataSourceProvider
public void setDatasets(java.lang.Object[] datasets)
setDatasets
in interface DataSourceProvider
datasets
- The datasets to use. Can be null to turn off datasets. This is a JdbcDataset[] but because of
how the .NET engine is structured, we need to declare it as an object.public DataSourceNode getRootNode()
getRootNode
in interface DataSourceProvider
public void close() throws DataSourceException
close
in interface DataSourceProvider
DataSourceException
- Could not retrieve the data. Generally wraps a SqlException or XpathException.public int getQueryMode(java.lang.String query, BaseTag tag) throws DataSourceException
getQueryMode
in interface DataSourceProvider
query
- The select to evaluate.tag
- The tag this select is for. This may be null.DataSourceException
public java.sql.Connection getConnection()
public void addSelectListener(JdbcSelectListener listener)
Copyright © 2017 Windward Reports - All Rights Reserved. We are java reporting software