public class DatabaseManager extends TypedAtomicActor
This class polls all available JDBC database drivers until one is willing to open the string given by the database parameter. Depending on the driver, this string may be a URL. Some database drivers are packaged with Ptolemy II and available from a vergil process. You can make others available by setting the jdbc.drivers property. For example, when invoking vergil, do something like this:
export JAVAFLAGS=-Djdbc.drivers=com.mysql.jdbc.Driver:bad.tast.ourDriver $PTII/bin/vergil -verboseThe above lists two drivers, in order of preference, separated by a ":". More information can be found at http://download.oracle.com/javase/6/docs/api/java/sql/DriverManager.html
Red (cxh) |
Red (eal) |
Entity.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
StringParameter |
database
JDBC connection string to access the database.
|
FileParameter |
passwordFile
The file that contains the password.
|
StringParameter |
userName
User name.
|
_typesValid
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
COMPLETED, NOT_READY, STOP_ITERATING
Constructor and Description |
---|
DatabaseManager(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name.
|
Modifier and Type | Method and Description |
---|---|
void |
attributeChanged(Attribute attribute)
React to a change in an attribute.
|
void |
closeConnection()
Close the connection to the database, if one is open.
|
java.lang.String |
execute(java.lang.String sql)
Execute the specified SQL statement and return the result as
a string.
|
ArrayToken |
executeQuery(java.lang.String sql)
Execute the SQL query given in the specified string
and return an array of record tokens containing the results.
|
int |
executeUpdate(java.lang.String sql,
int expectedResult)
Execute the SQL update given in the specified string
and return the number of affected rows or zero if the update
does not return anything.
|
static DatabaseManager |
findDatabaseManager(java.lang.String name,
NamedObj actor)
Find a database manager with the specified name for the specified
actor.
|
java.sql.Connection |
getConnection()
Get a connection to the database.
|
void |
preinitialize()
Open a connection to the database, if one is not already open,
prompting the user for a password.
|
void |
wrapup()
Close the connection to the database, if it is open.
|
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, fire, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
addInitializable, initialize, removeInitializable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
getDerivedLevel, getDerivedList, propagateValue
public StringParameter database
jdbc:oracle:thin:@buffy.eecs.berkeley.edu:1521:acgeecsspecifies a thin client for an Oracle database located at host buffy.eecs.berkeley.edu, which listens on port 1521. The "acgeecs" is the database name. Another example is
jdbc:mysql://localhost:3306/spacewhich specifies a MySQL database on the local host, where "space" is the name of the database.
public FileParameter passwordFile
public StringParameter userName
public DatabaseManager(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
container
- The container.name
- The name of this actor.IllegalActionException
- If the entity cannot be contained
by the proposed container.NameDuplicationException
- If the container already has an
actor with this name.public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class NamedObj
attribute
- The attribute that changed.IllegalActionException
- If the change is not acceptable
to this container (not thrown in this base class).public void closeConnection() throws IllegalActionException
IllegalActionException
- If closing the connection fails.public java.lang.String execute(java.lang.String sql) throws IllegalActionException
sql
- The query.IllegalActionException
- If the statement fails.public ArrayToken executeQuery(java.lang.String sql) throws IllegalActionException
sql
- The query.IllegalActionException
- If the query fails.public int executeUpdate(java.lang.String sql, int expectedResult) throws IllegalActionException
sql
- The query.expectedResult
- If a non-negative number is given here, then
the update is not committed unless the result matches.IllegalActionException
- If the query fails or if the
result does not match the value of expectedResult.public static DatabaseManager findDatabaseManager(java.lang.String name, NamedObj actor) throws IllegalActionException
name
- Database manager name.actor
- The actor.IllegalActionException
- If no database manager is found.public java.sql.Connection getConnection() throws IllegalActionException
IllegalActionException
- If the password file cannot
be read and "ptolemy.ptII.isRunningNightlyBuild" property
exists and is not empty or if the "ptolemy.ptII.batchMode"
property exists and is not empty and the property
"ptolemyII.ptII.testingMessageHandler" is not set.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class AtomicActor<TypedIOPort>
IllegalActionException
- If opening the database fails.public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
wrapup
in class AtomicActor<TypedIOPort>
IllegalActionException
- If the wrapup() method of
one of the associated actors throws it, or if we fail to
close the database connection.