|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.actor.AtomicActor
ptolemy.actor.TypedAtomicActor
ptolemy.actor.lib.database.DatabaseManager
public class DatabaseManager
A DatabaseManager. When preinitialized, this actor opens a connection to the specified database. When wrapup() is called, it closes the connection. A user of this class can also separately call getConnection() to open a connection, but then that user must also call closeConnection() when finished.
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://java.sun.com/j2se/1.5.0/docs/api/java/sql/DriverManager.html.
Red (cxh) |
Red (eal) |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class ptolemy.kernel.Entity |
---|
Entity.ContainedObjectsIterator |
Field Summary | |
---|---|
private java.sql.Connection |
_connection
The currently open connection. |
private char[] |
_password
The password last entered. |
StringParameter |
database
JDBC connection string to access the database. |
StringParameter |
userName
User name. |
Fields inherited from class ptolemy.actor.AtomicActor |
---|
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested |
Fields inherited from class ptolemy.kernel.util.NamedObj |
---|
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS |
Fields inherited from interface ptolemy.actor.Executable |
---|
COMPLETED, NOT_READY, STOP_ITERATING |
Constructor Summary | |
---|---|
DatabaseManager(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name. |
Method Summary | |
---|---|
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. |
Methods inherited from class ptolemy.actor.TypedAtomicActor |
---|
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints |
Methods inherited from class ptolemy.actor.AtomicActor |
---|
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, 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 |
Methods inherited from class ptolemy.kernel.ComponentEntity |
---|
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName |
Methods inherited from class ptolemy.kernel.Entity |
---|
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName |
Methods inherited from class ptolemy.kernel.InstantiableNamedObj |
---|
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface ptolemy.actor.Actor |
---|
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList |
Methods inherited from interface ptolemy.actor.Executable |
---|
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate |
Methods inherited from interface ptolemy.actor.Initializable |
---|
addInitializable, initialize, removeInitializable |
Methods inherited from interface ptolemy.kernel.util.Nameable |
---|
description, getContainer, getDisplayName, getFullName, getName, getName, setName |
Methods inherited from interface ptolemy.kernel.util.Derivable |
---|
getDerivedLevel, getDerivedList, propagateValue |
Field Detail |
---|
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 StringParameter userName
private java.sql.Connection _connection
private char[] _password
Constructor Detail |
---|
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.Method Detail |
---|
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
- Ifpublic void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class AtomicActor
IllegalActionException
- If opening the database fails.public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
wrapup
in class AtomicActor
IllegalActionException
- If the wrapup() method of
one of the associated actors throws it, or if we fail to
close the database connection.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |