ReportMill 10 API

com.reportmill.datasource
Class RMJDBCDataSource

java.lang.Object
  extended by com.reportmill.datasource.RMDataSource
      extended by com.reportmill.datasource.RMJDBCDataSourceBasic
          extended by com.reportmill.datasource.RMJDBCDataSource
All Implemented Interfaces:
RMBindSource, java.lang.Cloneable

public class RMJDBCDataSource
extends RMJDBCDataSourceBasic

This datasource uses a relational database to model an entity-relationship diagram. Every table in the database is represented by an RMEntity. Relationships are represented by RMJoin objects. All relationships are evaluated lazily - when a key crosses a relationship, the datasource does a fetch from the database of the new entities. By default, at the topmost level, there is a dataset key for every entity. A statement like "myDatasoure.getDataset().get("MOVIES")" will fetch in all the rows from the MOVIES table. Queries can be done by defining subqueries at the relationship level or by explicitly setting a query string at the datasource level. In order to have relationships between entities in the e-r diagram, the schema needs to have been defined using RMSchema.


Field Summary
 
Fields inherited from class com.reportmill.datasource.RMJDBCDataSourceBasic
_statement
 
Constructor Summary
RMJDBCDataSource()
          no-argument constructor (used mostly for archiving)
RMJDBCDataSource(RMJDBCDataSourceBasic other)
          Create a new JDBC datasource from a basic jdbc datasource.
 
Method Summary
 void close()
          Overridden to perform an explicit SHUTDOWN operation on the database.
 RMDatum createDatum(RMEntity anEntity)
          Creates and returns a new datum for a given entity.
 void dataAdd(RMDatum aData)
          Overrides RMDataSource version to record inserted data.
 void dataChange(RMDatum aData)
          Notifies datasource that a datum will change.
 void dataRemove(RMDatum aData)
          Notifies datasource that a datum will be removed.
 void deleteRows(java.util.List rows)
          Delete all the row data, which are assumed to be from the same entity.
 java.util.List fetchEntity(RMEntity e, java.lang.String whereClause)
          Pulls one or more entities out of a single table as a List of Maps
 RMDatum fetchJoin(RMJoin join, RMDatum parent, java.lang.String key)
          Runs a query to fetch data for the relationship.
 int generatePrimaryKey(RMEntity e)
          Autogenerate a primary key for a new datum.
 RMDatum getData()
          Returns the datasource default dataset as a datum.
 java.util.Map getDataset()
          Returns a sample dataset of objects associated with the datasource.
 RMDataSet getDataSet(RMFetch aFetch)
          Returns the dataset specified by the RMFetch.
 void getRelationships(RMSchema schema)
          Reads the RMINFO.RELATIONSHIPS table and adds joins to the RMSchema
 RMSchema getSchema()
          Overridden from RMJDBCDatasource.
 RMDatum getUniqueDatum(RMEntity entity, java.util.Map row, RMDatum parent, java.lang.String key)
          Returns the one datum for the given row & entity.
 boolean hasChanges()
          Returns whether or not there are any changes to be saved.
 boolean hasInfoSchema()
          Returns true if the RMINFO schema is present in the database.
 void insertRows(java.util.List rows)
          Insert all the row data, which are assumed to be from the same entity, into the table.
 void refresh()
          Invalidates any cached data.
 void releaseUniqueDatum(RMDatum d)
          Used when an object is deleted from the database to also remove it from the uniqueing map.
 void removeOwnedData(RMDatum aParent)
          Figure out which child objects are appropriate to delete when a parent object is deleted.
 void runErrorPanel()
          Runs an alert panel to display the current error.
 void runErrorPanel(java.sql.SQLException e)
          Runs the alert panel for exceptions that were caught externally.
 void saveChanges()
          Push all the dirty objects back to the database.
 void setFilterString(java.lang.String datasetName, java.lang.String filterString)
          Assign queries for the top-level entities.
 com.reportmill.archiver.RXElement toXML(com.reportmill.archiver.RXArchiver anArchiver)
          XML archival
 void updateRows(java.util.List rows)
          Update all the row data, which are assumed to be from the same entity.
 
Methods inherited from class com.reportmill.datasource.RMJDBCDataSourceBasic
cancelStatement, createResource, equals, executeQuery, fromXML, getConnection, getConnectionURL, getDatabaseSchema, getDatabaseSchema, getDefaultDatasetName, getDriverClassName, getError, getFetchLimit, getPassword, getQuery, getResource, getResourceNames, getTableSchema, getUserName, isConnected, isReadOnly, setConnectionURL, setDefaultDatasetName, setDriverClassName, setError, setFetchLimit, setLogging, setPassword, setQuery, setUserName
 
Methods inherited from class com.reportmill.datasource.RMDataSource
clone, getDataSet, getEntity, getName, getRelation, initFromDataSource, setName, setSchema, toString
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RMJDBCDataSource

public RMJDBCDataSource()
no-argument constructor (used mostly for archiving)


RMJDBCDataSource

public RMJDBCDataSource(RMJDBCDataSourceBasic other)
Create a new JDBC datasource from a basic jdbc datasource.

Method Detail

getSchema

public RMSchema getSchema()
Overridden from RMJDBCDatasource. The Entities of the ER diagram are taken from the database metadata. The Relationships are saved away in the special RMINFO.RELATIONSHIPS table.

Overrides:
getSchema in class RMJDBCDataSourceBasic

hasInfoSchema

public boolean hasInfoSchema()
Returns true if the RMINFO schema is present in the database. This schema, which is only visible to the system administrator, can hold any meta information that we don't get from the database. Currently used to store the relationships.


getRelationships

public void getRelationships(RMSchema schema)
                      throws java.sql.SQLException
Reads the RMINFO.RELATIONSHIPS table and adds joins to the RMSchema

Throws:
java.sql.SQLException

runErrorPanel

public void runErrorPanel()
Runs an alert panel to display the current error.


runErrorPanel

public void runErrorPanel(java.sql.SQLException e)
Runs the alert panel for exceptions that were caught externally.


fetchJoin

public RMDatum fetchJoin(RMJoin join,
                         RMDatum parent,
                         java.lang.String key)
Runs a query to fetch data for the relationship. This could be a single RMJDBCDatum for a to-one, or a RMJDBCDataset for a to-many.


fetchEntity

public java.util.List fetchEntity(RMEntity e,
                                  java.lang.String whereClause)
Pulls one or more entities out of a single table as a List of Maps


getUniqueDatum

public RMDatum getUniqueDatum(RMEntity entity,
                              java.util.Map row,
                              RMDatum parent,
                              java.lang.String key)
Returns the one datum for the given row & entity.


releaseUniqueDatum

public void releaseUniqueDatum(RMDatum d)
Used when an object is deleted from the database to also remove it from the uniqueing map.


dataAdd

public void dataAdd(RMDatum aData)
Overrides RMDataSource version to record inserted data.

Overrides:
dataAdd in class RMDataSource

dataChange

public void dataChange(RMDatum aData)
Description copied from class: RMDataSource
Notifies datasource that a datum will change.

Overrides:
dataChange in class RMDataSource

dataRemove

public void dataRemove(RMDatum aData)
Description copied from class: RMDataSource
Notifies datasource that a datum will be removed.

Overrides:
dataRemove in class RMDataSource

removeOwnedData

public void removeOwnedData(RMDatum aParent)
Figure out which child objects are appropriate to delete when a parent object is deleted. Currently, we declare any object that we have a to-many relationship to to be owned by us. We'll probably want a way to mark someone as an owner for certain to-one relationships as well, but that will probably have to be explicit.


saveChanges

public void saveChanges()
Push all the dirty objects back to the database. Due to the uniquing and the checks above, a datum is only ever in one of the dirty lists.

Overrides:
saveChanges in class RMDataSource

insertRows

public void insertRows(java.util.List rows)
                throws java.sql.SQLException
Insert all the row data, which are assumed to be from the same entity, into the table.

Throws:
java.sql.SQLException

updateRows

public void updateRows(java.util.List rows)
                throws java.sql.SQLException,
                       RMJDBCUpdateException
Update all the row data, which are assumed to be from the same entity. The update uses the data snapshot to ensure that the row we're changing hasn't been changed by someone else.

Throws:
java.sql.SQLException
RMJDBCUpdateException

deleteRows

public void deleteRows(java.util.List rows)
                throws java.sql.SQLException,
                       RMJDBCUpdateException
Delete all the row data, which are assumed to be from the same entity. The delete uses the data snapshot to ensure that the row we're deleteing hasn't been changed by someone else.

Throws:
java.sql.SQLException
RMJDBCUpdateException

createDatum

public RMDatum createDatum(RMEntity anEntity)
Creates and returns a new datum for a given entity.

Overrides:
createDatum in class RMDataSource

refresh

public void refresh()
Invalidates any cached data.

Overrides:
refresh in class RMJDBCDataSourceBasic

hasChanges

public boolean hasChanges()
Returns whether or not there are any changes to be saved.

Overrides:
hasChanges in class RMDataSource

getData

public RMDatum getData()
Returns the datasource default dataset as a datum.

Overrides:
getData in class RMDataSource

setFilterString

public void setFilterString(java.lang.String datasetName,
                            java.lang.String filterString)
Assign queries for the top-level entities.


getDataset

public java.util.Map getDataset()
Returns a sample dataset of objects associated with the datasource.

Overrides:
getDataset in class RMJDBCDataSourceBasic

getDataSet

public RMDataSet getDataSet(RMFetch aFetch)
Returns the dataset specified by the RMFetch.

Specified by:
getDataSet in interface RMBindSource
Overrides:
getDataSet in class RMDataSource

generatePrimaryKey

public int generatePrimaryKey(RMEntity e)
                       throws java.sql.SQLException
Autogenerate a primary key for a new datum.

Throws:
java.sql.SQLException

toXML

public com.reportmill.archiver.RXElement toXML(com.reportmill.archiver.RXArchiver anArchiver)
XML archival

Overrides:
toXML in class RMJDBCDataSourceBasic

close

public void close()
Overridden to perform an explicit SHUTDOWN operation on the database.

Overrides:
close in class RMJDBCDataSourceBasic

ReportMill 10 API