public class JDBCRC extends java.lang.Object implements ReplicaCatalog
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, site varchar(245), constraint pk_rc_lfn primary key(id), constraint sk_rc_lfn unique(lfn,pfn,site) ); 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, site varchar(245), constraint pk_rc_lfn primary key(id), constraint sk_rc_lfn unique(lfn,pfn,site) ); 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".
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
c_error
This message is sent whenever one of the member function is executed
which relies on an established database context.
|
private boolean |
m_autoinc
Remembers if obtaining generated keys will work or not.
|
protected java.sql.Connection |
mConnection
Maintains the connection to the database over the lifetime of
this instance.
|
private static java.lang.String[] |
mCStatements
The statement to prepare to slurp attributes.
|
protected LogManager |
mLogger
The handle to the logging object.
|
protected java.sql.PreparedStatement[] |
mStatements
Maintains an essential set of prepared statement, ready to use.
|
BATCH_KEY, c_prefix, DB_PREFIX, PROXY_KEY
DB_ALL_PREFIX
Constructor and Description |
---|
JDBCRC()
Default empty constructor creates an object that is not yet connected
to any database.
|
JDBCRC(java.lang.String jdbc,
java.lang.String url,
java.lang.String username,
java.lang.String password)
Convenience c'tor: Establishes the connection to the replica
catalog database.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
addItem(java.lang.Object value,
java.lang.String obj,
boolean where)
Helper function to assemble various pieces.
|
private java.util.Map |
attributes(java.lang.String id,
java.lang.String handle)
Slurps all attributes from related to a mapping into a map.
|
int |
clear()
Removes everything.
|
void |
close()
Explicitely free resources before the garbage collection hits.
|
boolean |
connect(java.util.Properties props)
Establishes a connection to the database from the properties.
|
void |
connect(java.lang.String url,
java.lang.String username,
java.lang.String password)
Connects to the database.
|
int |
delete(java.util.Map x,
boolean matchAttributes)
Deletes multiple mappings into the replica catalog.
|
int |
delete(java.lang.String lfn,
ReplicaCatalogEntry tuple)
Deletes a very specific mapping from the replica catalog.
|
int |
delete(java.lang.String lfn,
java.lang.String pfn)
Deletes a specific mapping from the replica catalog.
|
int |
delete(java.lang.String lfn,
java.lang.String name,
java.lang.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.
|
int |
deleteByResource(java.lang.String lfn,
java.lang.String handle)
Deletes all PFN entries for a given LFN from the replica catalog
where the resource handle is found.
|
protected java.sql.PreparedStatement |
getStatement(int i)
Singleton manager for prepared statements.
|
int |
insert(java.util.Map x)
Inserts multiple mappings into the replica catalog.
|
int |
insert(java.lang.String lfn,
ReplicaCatalogEntry tuple)
Inserts a new mapping into the replica catalog.
|
int |
insert(java.lang.String lfn,
java.lang.String pfn,
java.lang.String handle)
Inserts a new mapping into the replica catalog.
|
boolean |
isClosed()
Predicate to check, if the connection with the catalog's
implementation is still active.
|
java.util.Set |
list()
Lists all logical filenames in the catalog.
|
java.util.Set |
list(java.lang.String constraint)
Lists a subset of all logical filenames in the catalog.
|
java.util.Map |
lookup(java.util.Map constraints)
Retrieves multiple entries for a given logical filename, up to the
complete catalog.
|
java.util.Map |
lookup(java.util.Set lfns)
Retrieves multiple entries for a given logical filename, up to the
complete catalog.
|
java.util.Map |
lookup(java.util.Set lfns,
java.lang.String handle)
Retrieves multiple entries for a given logical filename, up to the
complete catalog.
|
java.util.Collection |
lookup(java.lang.String lfn)
Retrieves all entries for a given LFN from the replica catalog.
|
java.lang.String |
lookup(java.lang.String lfn,
java.lang.String handle)
Retrieves the entry for a given filename and site handle from the
replica catalog.
|
java.util.Map |
lookupNoAttributes(java.util.Set lfns)
Retrieves multiple entries for a given logical filename, up to the
complete catalog.
|
java.util.Map |
lookupNoAttributes(java.util.Set lfns,
java.lang.String handle)
Retrieves multiple entries for a given logical filename, up to the
complete catalog.
|
java.util.Set |
lookupNoAttributes(java.lang.String lfn)
Retrieves all entries for a given LFN from the replica catalog.
|
protected java.lang.String |
quote(java.lang.String s)
Quotes a string that may contain special SQL characters.
|
int |
remove(java.util.Set lfns)
Removes all mappings for a set of LFNs.
|
int |
remove(java.lang.String lfn)
Removes all mappings for an LFN from the replica catalog.
|
int |
removeByAttribute(java.lang.String handle)
Removes all entries associated with a particular resource handle.
|
int |
removeByAttribute(java.lang.String name,
java.lang.Object value)
Removes all entries from the replica catalog where the PFN attribute
is found, and matches exactly the object value.
|
private static final java.lang.String c_error
protected java.sql.Connection mConnection
protected java.sql.PreparedStatement[] mStatements
protected LogManager mLogger
private static final java.lang.String[] mCStatements
private boolean m_autoinc
public JDBCRC(java.lang.String jdbc, java.lang.String url, java.lang.String username, java.lang.String password) throws java.lang.LinkageError, java.lang.ExceptionInInitializerError, java.lang.ClassNotFoundException, java.sql.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.java.lang.LinkageError
- if linking the dynamically loaded driver fails.
This is a run-time error, and does not need to be caught.java.lang.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.java.lang.ClassNotFoundException
- if the class in your jdbc parameter
cannot be found in your given CLASSPATH environment. Callers must
catch this exception.java.sql.SQLException
- if something goes awry with the database.
Callers must catch this exception.public JDBCRC()
connect( String, String, String )
public void connect(java.lang.String url, java.lang.String username, java.lang.String password) throws java.sql.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.java.sql.SQLException
- if something goes awry with the database.
Callers must catch this exception.JDBCRC( String, String, String, String )
,
DriverManager.getConnection( String, String, String )
public boolean connect(java.util.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.java.lang.Error
- subclasses for runtime errors in the class loader.DriverManager.getConnection( String, Properties )
public void close()
public boolean isClosed()
close()
.protected java.lang.String quote(java.lang.String s)
s
- is the raw string.protected java.sql.PreparedStatement getStatement(int i) throws java.sql.SQLException
i
- is the index which prepared statement to check.java.sql.SQLException
public java.lang.String lookup(java.lang.String lfn, java.lang.String handle)
lookup
in interface ReplicaCatalog
lfn
- is the logical filename to obtain information for.handle
- is the resource handle to obtain entries for.null
if no match was found.private java.util.Map attributes(java.lang.String id, java.lang.String handle) throws java.sql.SQLException
id
- is the reference id to slurp from as string. Especially
Postgres's indexing mechanism goes from tables scans to btrees, if
the numeric key is represented as a string. Strings should be safe
for other databases, too.java.sql.SQLException
public java.util.Collection lookup(java.lang.String lfn)
lookup
in interface ReplicaCatalog
lfn
- is the logical filename to obtain information for.ReplicaCatalogEntry
public java.util.Set lookupNoAttributes(java.lang.String lfn)
lookupNoAttributes
in interface ReplicaCatalog
lfn
- is the logical filename to obtain information for.public java.util.Map lookup(java.util.Set lfns)
lookup
in interface ReplicaCatalog
lfns
- is a set of logical filename strings to look up.org.griphyn.common.catalog.ReplicaCatalogEntry
public java.util.Map lookupNoAttributes(java.util.Set lfns)
lookupNoAttributes
in interface ReplicaCatalog
lfns
- is a set of logical filename strings to look up.public java.util.Map lookup(java.util.Set lfns, java.lang.String handle)
lookup
in interface ReplicaCatalog
lfns
- is a set of logical filename strings to look up.handle
- is the resource handle, restricting the LFNs.ReplicaCatalogEntry
public java.util.Map lookupNoAttributes(java.util.Set lfns, java.lang.String handle)
lookupNoAttributes
in interface ReplicaCatalog
lfns
- is a set of logical filename strings to look up.handle
- is the resource handle, restricting the LFNs.private java.lang.String addItem(java.lang.Object value, java.lang.String obj, boolean where)
value
- is the value of the object from the map.obj
- is the name of the table columnwhere
- is the decision, if we had a previous WHERE clause or not.lookup( Map )
public java.util.Map lookup(java.util.Map constraints)
lookup
in interface ReplicaCatalog
constraints
- is mapping of keys 'lfn', 'pfn', or any
attribute name, e.g. the resource handle 'site', to a string that
has some meaning to the implementing system. This can be a SQL
wildcard for queries, or a regular expression for Java-based memory
collections. Unknown keys are ignored. Using an empty map requests
the complete catalog.ReplicaCatalogEntry
public java.util.Set list()
list
in interface ReplicaCatalog
public java.util.Set list(java.lang.String constraint)
list
in interface ReplicaCatalog
constraint
- is a constraint for the logical filename only. It
is a string that has some meaning to the implementing system. This
can be a SQL wildcard for queries, or a regular expression for
Java-based memory collections.public int insert(java.lang.String lfn, ReplicaCatalogEntry tuple)
insert
in interface ReplicaCatalog
lfn
- is the logical filename under which to book the entry.tuple
- is the physical filename and associated PFN attributes.public int insert(java.lang.String lfn, java.lang.String pfn, java.lang.String handle)
ReplicaCatalogEntry
element will be contructed, and
passed to the appropriate insert function.insert
in interface ReplicaCatalog
lfn
- is the logical filename under which to book the entry.pfn
- is the physical filename associated with it.handle
- is a resource handle where the PFN resides.insert( String, ReplicaCatalogEntry )
,
ReplicaCatalogEntry
public int insert(java.util.Map x)
insert
in interface ReplicaCatalog
x
- is a map from logical filename string to list of replica
catalog entries.org.griphyn.common.catalog.ReplicaCatalogEntry
public int delete(java.util.Map x, boolean matchAttributes)
delete
in interface ReplicaCatalog
x
- is a map from logical filename string to list of
replica catalog entries.matchAttributes
- whether mapping should be deleted only if all
attributes match.ReplicaCatalogEntry
public int delete(java.lang.String lfn, java.lang.String pfn)
delete
in interface ReplicaCatalog
lfn
- is the logical filename in the tuple.pfn
- is the physical filename in the tuple.public int delete(java.lang.String lfn, ReplicaCatalogEntry tuple)
delete
in interface ReplicaCatalog
lfn
- is the logical filename in the tuple.tuple
- is a description of the PFN and its attributes.public int delete(java.lang.String lfn, java.lang.String name, java.lang.Object value)
delete
in interface ReplicaCatalog
lfn
- is the logical filename to look for.name
- is the PFN attribute name to look for.value
- is an exact match of the attribute value to match.public int deleteByResource(java.lang.String lfn, java.lang.String handle)
delete( lfn, RESOURCE_HANDLE, handle )
deleteByResource
in interface ReplicaCatalog
lfn
- is the logical filename to look for.handle
- is the resource handlepublic int remove(java.lang.String lfn)
remove
in interface ReplicaCatalog
lfn
- is the logical filename to remove all mappings for.public int remove(java.util.Set lfns)
remove
in interface ReplicaCatalog
lfns
- is a set of logical filename to remove all mappings for.public int removeByAttribute(java.lang.String name, java.lang.Object value)
removeByAttribute
in interface ReplicaCatalog
name
- is the PFN attribute name to look for.value
- is an exact match of the attribute value to match.public int removeByAttribute(java.lang.String handle)
removeByAttribute
method.removeByAttribute
in interface ReplicaCatalog
handle
- is the site handle to remove all entries for.removeByAttribute( String, Object )
public int clear()
clear
in interface ReplicaCatalog