| java.lang.Object org.griphyn.common.catalog.replica.JDBCRC
JDBCRC | public class JDBCRC implements ReplicaCatalog(Code) | | This class implements a replica catalog on top of a simple table in a
JDBC database. This enables a variety of replica catalog
implementations in a transactionally safe, concurrent environment.
The table must be defined using the statements appropriate for your
database - they are part of the setup in $PEGASUS_HOME/sql/.
If you chose to use an unsupported database, please check, if your
database either supports sequence number, or if it supports auto
increment columns. If your database supports sequences (e.g.
PostGreSQL), you can use a setup similar to the following (for
Oracle, the autoinc can be implemented via a trigger).
create sequence rc_lfn_id;
create table rc_lfn (
id bigint default nextval('rc_lfn_id'::text),
lfn varchar(255) not null,
pfn varchar(255) not null,
constraint pk_rc_lfn primary key(id),
constraint sk_rc_lfn unique(lfn,pfn)
);
create index idx_rc_lfn on rc_lfn(lfn);
create table rc_attr (
id bigint,
name varchar(64) not null,
value varchar(255) not null,
constraint pk_rc_attr primary key(id,name),
constraint fk_rc_attr foreign key(id) references rc_lfn(id) on delete cascade
);
create index idx_rc_attr on rc_attr(name);
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 rc_lfn (
id bigint default null auto_increment,
lfn varchar(255) not null,
pfn varchar(255) not null,
constraint pk_rc_lfn primary key(id),
constraint sk_rc_lfn unique(lfn,pfn)
);
create index idx_rc_lfn on rc_lfn(lfn);
create table rc_attr (
id bigint,
name varchar(64) not null,
value varchar(255) not null,
constraint pk_rc_attr primary key(id,name),
constraint fk_rc_attr foreign key id references rc_lfn(id) on delete cascade
);
create index idx_rc_attr on rc_attr(name);
The site attribute should be specified whenever possible. For the
shell planner, it will always be of value "local".
author: Jens-S. Vöckler author: Yong Zhao version: $Revision: 83 $ |
Constructor Summary | |
public | JDBCRC(String jdbc, String url, String username, String password) Convenience c'tor: Establishes the connection to the replica
catalog database. | public | JDBCRC() Default empty constructor creates an object that is not yet connected
to any database. |
Method Summary | |
public int | clear() Removes everything. | public void | close() Explicitely free resources before the garbage collection hits. | public void | connect(String url, String username, String password) Connects to the database. | public boolean | connect(Properties props) Establishes a connection to the database from the properties. | public int | delete(Map x, boolean matchAttributes) Deletes multiple mappings into the replica catalog. | public int | delete(String lfn, String pfn) Deletes a specific mapping from the replica catalog. | public int | delete(String lfn, ReplicaCatalogEntry tuple) Deletes a very specific mapping from the replica catalog. | public int | delete(String lfn, String name, Object value) Deletes all PFN entries for a given LFN from the replica catalog
where the PFN attribute is found, and matches exactly the object
value. | public int | deleteByResource(String lfn, String handle) Deletes all PFN entries for a given LFN from the replica catalog
where the resource handle is found. | protected PreparedStatement | getStatement(int i) Singleton manager for prepared statements. | public int | insert(String lfn, ReplicaCatalogEntry tuple) Inserts a new mapping into the replica catalog.
Parameters: lfn - is the logical filename under which to book the entry. Parameters: tuple - is the physical filename and associated PFN attributes. | public int | insert(String lfn, String pfn, String handle) Inserts a new mapping into the replica catalog. | public int | insert(Map x) Inserts multiple mappings into the replica catalog. | public boolean | isClosed() Predicate to check, if the connection with the catalog's
implementation is still active. | public Set | list() Lists all logical filenames in the catalog. | public Set | list(String constraint) Lists a subset of all logical filenames in the catalog.
Parameters: constraint - is a constraint for the logical filename only. | public String | lookup(String lfn, String handle) Retrieves the entry for a given filename and site handle from the
replica catalog.
Parameters: lfn - is the logical filename to obtain information for. Parameters: handle - is the resource handle to obtain entries for. | public Collection | lookup(String lfn) Retrieves all entries for a given LFN from the replica catalog.
Each entry in the result set is a tuple of a PFN and all its
attributes.
Parameters: lfn - is the logical filename to obtain information for. | public Map | lookup(Set lfns) Retrieves multiple entries for a given logical filename, up to the
complete catalog. | public Map | lookup(Set lfns, String handle) Retrieves multiple entries for a given logical filename, up to the
complete catalog. | public Map | lookup(Map constraints) Retrieves multiple entries for a given logical filename, up to the
complete catalog. | public Set | lookupNoAttributes(String lfn) Retrieves all entries for a given LFN from the replica catalog.
Each entry in the result set is just a PFN string. | public Map | lookupNoAttributes(Set lfns) Retrieves multiple entries for a given logical filename, up to the
complete catalog. | public Map | lookupNoAttributes(Set lfns, String handle) Retrieves multiple entries for a given logical filename, up to the
complete catalog. | protected String | quote(String s) Quotes a string that may contain special SQL characters.
Parameters: s - is the raw string. | public int | remove(String lfn) Removes all mappings for an LFN from the replica catalog.
Parameters: lfn - is the logical filename to remove all mappings for. | public int | remove(Set lfns) Removes all mappings for a set of LFNs.
Parameters: lfns - is a set of logical filename to remove all mappings for. | public int | removeByAttribute(String name, Object value) Removes all entries from the replica catalog where the PFN attribute
is found, and matches exactly the object value.
Parameters: name - is the PFN attribute name to look for. Parameters: value - is an exact match of the attribute value to match. | public int | removeByAttribute(String handle) Removes all entries associated with a particular resource handle.
This is useful, if a site goes offline. |
mConnection | protected Connection mConnection(Code) | | Maintains the connection to the database over the lifetime of
this instance.
|
mStatements | protected PreparedStatement mStatements(Code) | | Maintains an essential set of prepared statement, ready to use.
|
JDBCRC | public JDBCRC(String jdbc, String url, String username, String password) throws LinkageError, ExceptionInInitializerError, ClassNotFoundException, SQLException(Code) | | Convenience c'tor: Establishes the connection to the replica
catalog database. The usual suspects for the class name include:
org.postgresql.Driver
com.mysql.jdbc.Driver
com.microsoft.jdbc.sqlserver.SQLServerDriver
SQLite.JDBCDriver
sun.jdbc.odbc.JdbcOdbcDriver
Parameters: jdbc - is a string containing the full name of the java classthat must be dynamically loaded. This is usually an external jarfile which contains the Java database driver. Parameters: url - is the database driving URL. This string is databasespecific, and tell the JDBC driver, at which host and port thedatabase listens, permits additional arguments, and selects thedatabase inside the rDBMS to connect to. Please refer to yourJDBC driver documentation for the format and permitted values. Parameters: username - is the database user account name to connect with. Parameters: password - is the database account password to use. throws: LinkageError - if linking the dynamically loaded driver fails.This is a run-time error, and does not need to be caught. throws: ExceptionInInitializerError - if the initialization functionof the driver's instantiation threw an exception itself. This is arun-time error, and does not need to be caught. throws: ClassNotFoundException - if the class in your jdbc parametercannot be found in your given CLASSPATH environment. Callers mustcatch this exception. throws: SQLException - if something goes awry with the database.Callers must catch this exception. |
JDBCRC | public JDBCRC()(Code) | | Default empty constructor creates an object that is not yet connected
to any database. You must use support methods to connect before this
instance becomes usable.
See Also: JDBCRC.connect(String,String,String) |
clear | public int clear()(Code) | | Removes everything. Use with caution!
the number of removed entries. |
close | public void close()(Code) | | Explicitely free resources before the garbage collection hits.
|
connect | public void connect(String url, String username, String password) throws SQLException(Code) | | Connects to the database. This is effectively an accessor to
initialize the internal connection instance variable. Warning!
You must call
java.lang.Class.forName(String) yourself
to load the database JDBC driver jar!
Parameters: url - is the database driving URL. This string is databasespecific, and tell the JDBC driver, at which host and port thedatabase listens, permits additional arguments, and selects thedatabase inside the rDBMS to connect to. Please refer to yourJDBC driver documentation for the format and permitted values. Parameters: username - is the database user account name to connect with. Parameters: password - is the database account password to use. throws: SQLException - if something goes awry with the database.Callers must catch this exception. See Also: JDBCRC.JDBCRC(String,String,String,String) See Also: java.sql.DriverManager.getConnection(StringStringString) |
connect | public boolean connect(Properties props)(Code) | | Establishes a connection to the database from the properties. You
can specify a driver property to contain the class name of
the JDBC driver for your database. This property will be removed
before attempting to connect. You must speficy a url
property to describe the connection. It will be removed before
attempting to connect.
Parameters: props - is the property table with sufficient settings toestablish a link with the database. The minimum key required key is"url", and possibly "driver". Any other keys depend on the databasedriver. true if connected, false if failed to connect. See Also: java.sql.DriverManager.getConnection(StringProperties) throws: Error - subclasses for runtime errors in the class loader. |
delete | public int delete(Map x, boolean matchAttributes)(Code) | | Deletes multiple mappings into the replica catalog. The input is a
map indexed by the LFN. The value for each LFN key is a collection
of replica catalog entries. On setting matchAttributes to false, all entries
having matching lfn pfn mapping to an entry in the Map are deleted.
However, upon removal of an entry, all attributes associated with the pfn
also evaporate (cascaded deletion).
Parameters: x - is a map from logical filename string to list ofreplica catalog entries. Parameters: matchAttributes - whether mapping should be deleted only if allattributes match. the number of deletions. See Also: ReplicaCatalogEntry |
delete | public int delete(String lfn, String pfn)(Code) | | Deletes a specific mapping from the replica catalog. We don't care
about the resource handle. More than one entry could theoretically
be removed. Upon removal of an entry, all attributes associated
with the PFN also evaporate (cascading deletion).
Parameters: lfn - is the logical filename in the tuple. Parameters: pfn - is the physical filename in the tuple. the number of removed entries. |
delete | public int delete(String lfn, ReplicaCatalogEntry tuple)(Code) | | Deletes a very specific mapping from the replica catalog. The LFN
must be matches, the PFN, and all PFN attributes specified in the
replica catalog entry. More than one entry could theoretically be
removed. Upon removal of an entry, all attributes associated with
the PFN also evaporate (cascading deletion).
Parameters: lfn - is the logical filename in the tuple. Parameters: tuple - is a description of the PFN and its attributes. the number of removed entries, either 0 or 1. |
delete | public int delete(String lfn, String name, Object value)(Code) | | Deletes all PFN entries for a given LFN from the replica catalog
where the PFN attribute is found, and matches exactly the object
value. This method may be useful to remove all replica entries that
have a certain MD5 sum associated with them. It may also be harmful
overkill.
Parameters: lfn - is the logical filename to look for. Parameters: name - is the PFN attribute name to look for. Parameters: value - is an exact match of the attribute value to match. the number of removed entries. |
deleteByResource | public int deleteByResource(String lfn, String handle)(Code) | | Deletes all PFN entries for a given LFN from the replica catalog
where the resource handle is found. Karan requested this
convenience method, which can be coded like
delete( lfn, RESOURCE_HANDLE, handle )
Parameters: lfn - is the logical filename to look for. Parameters: handle - is the resource handle the number of entries removed. |
getStatement | protected PreparedStatement getStatement(int i) throws SQLException(Code) | | Singleton manager for prepared statements. This instruction
checks that a prepared statement is ready to use, and will
create an instance of the prepared statement, if it was unused
previously.
Parameters: i - is the index which prepared statement to check. a handle to the prepared statement. |
insert | public int insert(String lfn, ReplicaCatalogEntry tuple)(Code) | | Inserts a new mapping into the replica catalog.
Parameters: lfn - is the logical filename under which to book the entry. Parameters: tuple - is the physical filename and associated PFN attributes. number of insertions, should always be 1. On failure,throw an exception, don't use zero. |
insert | public int insert(String lfn, String pfn, String handle)(Code) | | Inserts a new mapping into the replica catalog. This is a
convenience function exposing the resource handle. Internally, the
ReplicaCatalogEntry element will be contructed, and
passed to the appropriate insert function.
Parameters: lfn - is the logical filename under which to book the entry. Parameters: pfn - is the physical filename associated with it. Parameters: handle - is a resource handle where the PFN resides. number of insertions, should always be 1. On failure,throw an exception, don't use zero. See Also: JDBCRC.insert(String,ReplicaCatalogEntry) See Also: ReplicaCatalogEntry |
insert | public int insert(Map x)(Code) | | Inserts multiple mappings into the replica catalog. The input is a
map indexed by the LFN. The value for each LFN key is a collection
of replica catalog entries.
Parameters: x - is a map from logical filename string to list of replicacatalog entries. the number of insertions. See Also: org.griphyn.common.catalog.ReplicaCatalogEntry |
isClosed | public boolean isClosed()(Code) | | Predicate to check, if the connection with the catalog's
implementation is still active. This helps determining, if it makes
sense to call close() .
true, if the implementation is disassociated, false otherwise. See Also: JDBCRC.close() |
list | public Set list()(Code) | | Lists all logical filenames in the catalog.
A set of all logical filenames known to the catalog. |
list | public Set list(String constraint)(Code) | | Lists a subset of all logical filenames in the catalog.
Parameters: constraint - is a constraint for the logical filename only. Itis a string that has some meaning to the implementing system. Thiscan be a SQL wildcard for queries, or a regular expression forJava-based memory collections. A set of logical filenames that match. The set may be empty |
lookup | public String lookup(String lfn, String handle)(Code) | | Retrieves the entry for a given filename and site handle from the
replica catalog.
Parameters: lfn - is the logical filename to obtain information for. Parameters: handle - is the resource handle to obtain entries for. the (first) matching physical filename, ornull if no match was found. |
lookup | public Collection lookup(String lfn)(Code) | | Retrieves all entries for a given LFN from the replica catalog.
Each entry in the result set is a tuple of a PFN and all its
attributes.
Parameters: lfn - is the logical filename to obtain information for. a collection of replica catalog entries See Also: ReplicaCatalogEntry |
lookup | public Map lookup(Set lfns)(Code) | | Retrieves multiple entries for a given logical filename, up to the
complete catalog. Retrieving full catalogs should be harmful, but
may be helpful in an online display or portal.
Parameters: lfns - is a set of logical filename strings to look up. a map indexed by the LFN. Each value is a collectionof replica catalog entries for the LFN. See Also: org.griphyn.common.catalog.ReplicaCatalogEntry |
lookup | public Map lookup(Set lfns, String handle)(Code) | | Retrieves multiple entries for a given logical filename, up to the
complete catalog. Retrieving full catalogs should be harmful, but
may be helpful in online display or portal.
Parameters: lfns - is a set of logical filename strings to look up. Parameters: handle - is the resource handle, restricting the LFNs. a map indexed by the LFN. Each value is a collectionof replica catalog entries (all attributes). See Also: ReplicaCatalogEntry |
lookup | public Map lookup(Map constraints)(Code) | | Retrieves multiple entries for a given logical filename, up to the
complete catalog. Retrieving full catalogs should be harmful, but
may be helpful in online display or portal.
Parameters: constraints - is mapping of keys 'lfn', 'pfn', or anyattribute name, e.g. the resource handle 'site', to a string thathas some meaning to the implementing system. This can be a SQLwildcard for queries, or a regular expression for Java-based memorycollections. Unknown keys are ignored. Using an empty map requeststhe complete catalog. a map indexed by the LFN. Each value is a collectionof replica catalog entries. See Also: ReplicaCatalogEntry |
lookupNoAttributes | public Set lookupNoAttributes(String lfn)(Code) | | Retrieves all entries for a given LFN from the replica catalog.
Each entry in the result set is just a PFN string. Duplicates
are reduced through the set paradigm.
Parameters: lfn - is the logical filename to obtain information for. a set of PFN strings |
lookupNoAttributes | public Map lookupNoAttributes(Set lfns)(Code) | | Retrieves multiple entries for a given logical filename, up to the
complete catalog. Retrieving full catalogs should be harmful, but
may be helpful in an online display or portal.
Parameters: lfns - is a set of logical filename strings to look up. a map indexed by the LFN. Each value is a setof PFN strings. |
lookupNoAttributes | public Map lookupNoAttributes(Set lfns, String handle)(Code) | | Retrieves multiple entries for a given logical filename, up to the
complete catalog. Retrieving full catalogs should be harmful, but
may be helpful in online display or portal.
Parameters: lfns - is a set of logical filename strings to look up. Parameters: handle - is the resource handle, restricting the LFNs. a map indexed by the LFN. Each value is a set ofphysical filenames. |
quote | protected String quote(String s)(Code) | | Quotes a string that may contain special SQL characters.
Parameters: s - is the raw string. the quoted string, which may be just the input string. |
remove | public int remove(String lfn)(Code) | | Removes all mappings for an LFN from the replica catalog.
Parameters: lfn - is the logical filename to remove all mappings for. the number of removed entries. |
remove | public int remove(Set lfns)(Code) | | Removes all mappings for a set of LFNs.
Parameters: lfns - is a set of logical filename to remove all mappings for. the number of removed entries. |
removeByAttribute | public int removeByAttribute(String name, Object value)(Code) | | Removes all entries from the replica catalog where the PFN attribute
is found, and matches exactly the object value.
Parameters: name - is the PFN attribute name to look for. Parameters: value - is an exact match of the attribute value to match. the number of removed entries. |
removeByAttribute | public int removeByAttribute(String handle)(Code) | | Removes all entries associated with a particular resource handle.
This is useful, if a site goes offline. It is a convenience method,
which calls the generic removeByAttribute method.
Parameters: handle - is the site handle to remove all entries for. the number of removed entries. See Also: JDBCRC.removeByAttribute(String,Object) |
|
|