public class Database extends Object implements WorkCatalog
CREATE TABLE wf_work ( id BIGSERIAL PRIMARY KEY, basedir TEXT, vogroup VARCHAR(255), workflow VARCHAR(255), run VARCHAR(255), creator VARCHAR(32), ctime TIMESTAMP WITH TIME ZONE NOT NULL, state INTEGER NOT NULL, mtime TIMESTAMP WITH TIME ZONE NOT NULL, CONSTRAINT sk_wf_work UNIQUE(basedir,vogroup,workflow,run) ); CREATE TABLE wf_jobstate ( wfid BIGINT REFERENCES wf_work(id) ON DELETE CASCADE, jobid VARCHAR(64), state VARCHAR(24) NOT NULL, mtime TIMESTAMP WITH TIME ZONE NOT NULL, site VARCHAR(64), CONSTRAINT pk_wf_jobstate PRIMARY KEY (wfid,jobid) ); CREATE INDEX ix_wf_jobstate ON wf_jobstate(jobid); CREATE TABLE wf_siteinfo ( id BIGSERIAL PRIMARY KEY, handle VARCHAR(48) NOT NULL, mtime TIMESTAMP WITH TIME ZONE, -- gauges other INTEGER DEFAULT 0, pending INTEGER DEFAULT 0, running INTEGER DEFAULT 0, -- counters success INTEGER DEFAULT 0, smtime TIMESTAMP WITH TIME ZONE, failure INTEGER DEFAULT 0, fmtime TIMESTAMP WITH TIME ZONE, CONSTRAINT sk_wf_siteinfo UNIQUE(handle) );In case of databases that do not support sequences (e.g. MySQL), do not specify the
create sequence
, and use an
auto-increment column for the primary key instead, e.g.:
CREATE TABLE wf_work ( id BIGINT AUTO_INCREMENT PRIMARY KEY, basedir TEXT, vogroup VARCHAR(255), workflow VARCHAR(255), run VARCHAR(255), creator VARCHAR(32), ctime DATETIME NOT NULL, state INTEGER NOT NULL, mtime DATETIME NOT NULL, CONSTRAINT sk_wf_work UNIQUE(basedir(255),vogroup,workflow,run) ) type=InnoDB; CREATE TABLE wf_jobstate ( wfid BIGINT REFERENCES wf_work(id) ON DELETE CASCADE, jobid VARCHAR(64), state VARCHAR(24) NOT NULL, mtime DATETIME NOT NULL, site VARCHAR(64), CONSTRAINT pk_wf_jobstate PRIMARY KEY (wfid,jobid) ) type=InnoDB; CREATE INDEX ix_wf_jobstate ON wf_jobstate(jobid); CREATE TABLE wf_siteinfo ( id BIGINT AUTO_INCREMENT PRIMARY KEY, handle VARCHAR(48) NOT NULL, mtime DATETIME, -- gauges other INTEGER DEFAULT 0, pending INTEGER DEFAULT 0, running INTEGER DEFAULT 0, -- counters success INTEGER DEFAULT 0, smtime DATETIME, failure INTEGER DEFAULT 0, fmtime DATETIME, CONSTRAINT sk_wf_siteinfo UNIQUE(handle) ) type=InnoDB;The site attribute should be specified whenever possible. For the shell planner, it will always be of value "local".
Modifier and Type | Field and Description |
---|---|
private boolean |
m_autoinc
Remembers if obtaining generated keys will work or not.
|
protected Connection |
mConnection
Maintains the connection to the database over the lifetime of
this instance.
|
private static String |
mConnectionError
This message is sent whenever one of the member function is executed
which relies on an established database context.
|
private static String[] |
mCStatements
The statement to prepare to slurp attributes.
|
protected LogManager |
mLogger
The handle to the logging object.
|
protected PreparedStatement[] |
mStatements
Maintains an essential set of prepared statement, ready to use.
|
c_prefix, DB_PREFIX, VERSION
DB_ALL_PREFIX
Constructor and Description |
---|
Database()
Default empty constructor creates an object that is not yet connected
to any database.
|
Database(String jdbc,
String url,
String username,
String password)
Convenience c'tor: Establishes the connection to the work
catalog database.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Explicitely free resources before the garbage collection hits.
|
boolean |
connect(Properties props)
Establishes a connection to the database from the properties.
|
void |
connect(String url,
String username,
String password)
Connects to the database.
|
int |
delete(String basedir,
String vogroup,
String label,
String run)
Deletes a mapping from the work catalog.
|
protected PreparedStatement |
getStatement(int i)
Singleton manager for prepared statements.
|
int |
insert(String basedir,
String vogroup,
String label,
String run,
String creator,
Date cTime,
Date mTime,
int state)
Inserts a new mapping into the work catalog.
|
boolean |
isClosed()
Predicate to check, if the connection with the catalog's
implementation is still active.
|
private static final String mConnectionError
protected Connection mConnection
protected PreparedStatement[] mStatements
protected LogManager mLogger
private static final String[] mCStatements
private boolean m_autoinc
public Database(String jdbc, String url, String username, String password) throws LinkageError, ExceptionInInitializerError, ClassNotFoundException, SQLException
org.postgresql.Driver com.mysql.jdbc.Driver com.microsoft.jdbc.sqlserver.SQLServerDriver SQLite.JDBCDriver sun.jdbc.odbc.JdbcOdbcDriver
jdbc
- is a string containing the full name of the java class
that must be dynamically loaded. This is usually an external jar
file which contains the Java database driver.url
- is the database driving URL. This string is database
specific, and tell the JDBC driver, at which host and port the
database listens, permits additional arguments, and selects the
database inside the rDBMS to connect to. Please refer to your
JDBC driver documentation for the format and permitted values.username
- is the database user account name to connect with.password
- is the database account password to use.LinkageError
- if linking the dynamically loaded driver fails.
This is a run-time error, and does not need to be caught.ExceptionInInitializerError
- if the initialization function
of the driver's instantiation threw an exception itself. This is a
run-time error, and does not need to be caught.ClassNotFoundException
- if the class in your jdbc parameter
cannot be found in your given CLASSPATH environment. Callers must
catch this exception.SQLException
- if something goes awry with the database.
Callers must catch this exception.public Database()
connect( String, String, String )
public void connect(String url, String username, String password) throws SQLException
Class.forName( String )
yourself
to load the database JDBC driver jar!url
- is the database driving URL. This string is database
specific, and tell the JDBC driver, at which host and port the
database listens, permits additional arguments, and selects the
database inside the rDBMS to connect to. Please refer to your
JDBC driver documentation for the format and permitted values.username
- is the database user account name to connect with.password
- is the database account password to use.SQLException
- if something goes awry with the database.
Callers must catch this exception.DriverManager.getConnection( String, String, String )
public boolean connect(Properties props)
connect
in interface Catalog
props
- is the property table with sufficient settings to
establish a link with the database. The minimum key required key is
"url", and possibly "driver". Any other keys depend on the database
driver.Error
- subclasses for runtime errors in the class loader.DriverManager.getConnection( String, Properties )
public void close()
public boolean isClosed()
close()
.protected PreparedStatement getStatement(int i) throws SQLException
i
- is the index which prepared statement to check.SQLException
- in case of unable to delete entry.public int insert(String basedir, String vogroup, String label, String run, String creator, Date cTime, Date mTime, int state) throws WorkCatalogException
insert
in interface WorkCatalog
basedir
- the base directoryvogroup
- the vo to which the user belongs to.label
- the label in the DAXrun
- the run number.creator
- the user who is running.cTime
- the creation time of the DAXmTime
- the modification time.state
- the state of the workflowWorkCatalogException
- in case of unable to delete entry.public int delete(String basedir, String vogroup, String label, String run) throws WorkCatalogException
delete
in interface WorkCatalog
basedir
- the base directoryvogroup
- the vo to which the user belongs to.label
- the label in the DAXrun
- the run number.WorkCatalogException
- in case of unable to delete entry.Copyright © 2011 The University of Southern California. All Rights Reserved.