org.griphyn.vdl.dbschema
Class ChunkSchema

java.lang.Object
  extended by org.griphyn.vdl.dbschema.DatabaseSchema
      extended by org.griphyn.vdl.dbschema.ChunkSchema
All Implemented Interfaces:
Catalog, VDC

public class ChunkSchema
extends DatabaseSchema
implements VDC

This class provides basic functionalities to interact with the backend database, such as insertion, deletion, and search of entities in the VDC.

Version:
$Revision: 50 $
Author:
Jens-S. V??ckler, Yong Zhao

Field Summary
protected static String[] c_lfn_names
          Name of the four parameter tables in human readable format.
protected  Cache m_cache
          A cache for definitions to avoid reloading from the database.
protected  boolean m_deferDeleteCommit
          Communication between saveDefinition and deleteDefinition in update mode.
private  VDLxParser m_parser
          An instance of the VDLx XML parser.
 
Fields inherited from class org.griphyn.vdl.dbschema.DatabaseSchema
m_dbdriver, m_dbschemaprops
 
Fields inherited from interface org.griphyn.vdl.dbschema.VDC
PROPERTY_PREFIX
 
Constructor Summary
ChunkSchema(String dbDriverName)
          Default constructor for the "chunk" schema.
 
Method Summary
 boolean containsDefinition(Definition definition)
          Search the database for the existence of a definition.
 boolean deleteDefinition(Definition definition)
          Delete a specific Definition objects from the database.
 List deleteDefinition(String namespace, String name, String version, int type)
          Delete Definition objects from the database.
protected  Long getDefinitionId(Definition d)
          Obtains the primary key id for a given definition.
protected  List getDefinitionId(String namespace, String name, String version, int type)
          Obtains the list of primary key ids for a matching definitions.
private  Definition loadDefinition(long id)
          Load a single Definition from the backend database into a Java object by its primary key id.
 Definition loadDefinition(String namespace, String name, String version, int type)
          Loads a single Definition from the backend database into an Java object.
private  VDLxParser parserInstance()
          Instantiates an XML parser for VDLx on demand.
 boolean saveDefinition(Definition definition, boolean overwrite)
          Saves a Definition, that is either a Transformation or Derivation, into the backend database.
private  void saveScalar(long id, Scalar scalar, Set already, PreparedStatement[] stmt, int[] count)
          Saves all logical filenames from a Scalar object.
 List searchDefinition(String namespace, String name, String version, int type)
          Search the database for definitions by ns::name:version triple and by type (either Transformation or Derivation).
 List searchFilename(String lfn, int link)
          Searches the database for all derivations that contain a certain LFN.
private  String what(Definition d)
          Compiles the name of a DV/TR for log messages.
 
Methods inherited from class org.griphyn.vdl.dbschema.DatabaseSchema
cachingMakesSense, close, finalize, loadSchema, loadSchema, longOrNull, makeNotNull, stringOrNull
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

c_lfn_names

protected static final String[] c_lfn_names
Name of the four parameter tables in human readable format.


m_deferDeleteCommit

protected boolean m_deferDeleteCommit
Communication between saveDefinition and deleteDefinition in update mode.


m_parser

private VDLxParser m_parser
An instance of the VDLx XML parser.


m_cache

protected Cache m_cache
A cache for definitions to avoid reloading from the database.

Constructor Detail

ChunkSchema

public ChunkSchema(String dbDriverName)
            throws ClassNotFoundException,
                   NoSuchMethodException,
                   InstantiationException,
                   IllegalAccessException,
                   InvocationTargetException,
                   SQLException,
                   IOException
Default constructor for the "chunk" schema.

Parameters:
dbDriverName - is the database driver name
Throws:
ClassNotFoundException
NoSuchMethodException
InstantiationException
IllegalAccessException
InvocationTargetException
SQLException
IOException
Method Detail

parserInstance

private VDLxParser parserInstance()
Instantiates an XML parser for VDLx on demand. Since XML parsing XML parsing and parser instantiation is an expensive business, the reader will only be generated on demand.

Returns:
a valid VDLx parser instance.

loadDefinition

public Definition loadDefinition(String namespace,
                                 String name,
                                 String version,
                                 int type)
                          throws SQLException
Loads a single Definition from the backend database into an Java object. This method does not allow wildcarding!

Specified by:
loadDefinition in interface VDC
Parameters:
namespace - namespace, null will be converted into empty string
name - name, null will be converted into empty string
version - version, null will be converted into empty string
type - type of the definition (TR or DV), must not be -1.
Returns:
the Definition as specified, or null if not found.
Throws:
SQLException
See Also:
Definition.TRANSFORMATION, Definition.DERIVATION, saveDefinition( Definition, boolean )

loadDefinition

private Definition loadDefinition(long id)
                           throws SQLException
Load a single Definition from the backend database into a Java object by its primary key id. This is an internal helper function.

Parameters:
id - is a long which represent the primary id.
Returns:
the Definitions that was matched by the id.
Throws:
SQLException
See Also:
loadDefinition( String, String, String, int ), saveDefinition( Definition, boolean )

what

private String what(Definition d)
Compiles the name of a DV/TR for log messages.

Parameters:
d - is a definition
Returns:
the type plus FQDN of the definition

saveDefinition

public boolean saveDefinition(Definition definition,
                              boolean overwrite)
                       throws SQLException
Saves a Definition, that is either a Transformation or Derivation, into the backend database. This method, of course, does not allow wildcarding. The definition has to be completely specified and valid.

Specified by:
saveDefinition in interface VDC
Parameters:
definition - is the new Definition to store.
overwrite - true, if existing defitions will be overwritten by new ones with the same primary (or secondary) key (-set), or false, if a new definition will be rejected on key matches.
Returns:
true, if the backend database was changed, or false, if the definition was not accepted into the backend.
Throws:
SQLException
See Also:
Definition, Transformation, Derivation, loadDefinition( String, String, String, int )

saveScalar

private void saveScalar(long id,
                        Scalar scalar,
                        Set already,
                        PreparedStatement[] stmt,
                        int[] count)
                 throws SQLException
Saves all logical filenames from a Scalar object. This is a helper function to save a single definition.

Parameters:
id - is the definition id in the DEFINITION table
scalar - is a Scalar instance of which the LFNs are to be saved.
already - is a set of filenames that were already added during this session
stmt - is an array of the ids of the prepared statements for the different tables.
count - count the number of entries in a prepared statement.
Throws:
SQLException
See Also:
saveDefinition( Definition, boolean )

getDefinitionId

protected Long getDefinitionId(Definition d)
                        throws SQLException
Obtains the primary key id for a given definition. "Fake" definitions are permissable. This is an internal helper function.

Parameters:
d - is a definition specification.
Returns:
the id of the definition, or null if not found.
Throws:
SQLException
See Also:
getDefinitionId( String, String, String, int )

getDefinitionId

protected List getDefinitionId(String namespace,
                               String name,
                               String version,
                               int type)
                        throws SQLException
Obtains the list of primary key ids for a matching definitions. This method allows for wildcards in the usual fashion. Use null for strings as wildcards, and -1 for the type wildcard. This method may return an empty list, but it will not return null. This is an internal helper function.

Parameters:
namespace - namespace, null to match any namespace
name - name, null to match any name
version - version, null to match any version
type - definition type (TR or DV)
Returns:
a possibly empty list containing all matching definition ids as Longs.
Throws:
SQLException
See Also:
Definition.TRANSFORMATION, Definition.DERIVATION, getDefinitionId( Definition )

containsDefinition

public boolean containsDefinition(Definition definition)
                           throws SQLException
Search the database for the existence of a definition.

Specified by:
containsDefinition in interface VDC
Parameters:
definition - the definition object to search for
Returns:
true, if the definition exists, false if not found
Throws:
SQLException

deleteDefinition

public boolean deleteDefinition(Definition definition)
                         throws SQLException
Delete a specific Definition objects from the database. No wildcard matching will be done. "Fake" definitions are permissable, meaning it just has the secondary key triple.

Specified by:
deleteDefinition in interface VDC
Parameters:
definition - is the definition specification to delete
Returns:
true is something was deleted, false if non existent.
Throws:
SQLException
See Also:
Definition.TRANSFORMATION, Definition.DERIVATION

deleteDefinition

public List deleteDefinition(String namespace,
                             String name,
                             String version,
                             int type)
                      throws SQLException
Delete Definition objects from the database. This method allows for wildcards in the usual fashion. Use null for strings as wildcards, and -1 for the type wildcard. For efficiency reasons, this method will return an empty list.

Specified by:
deleteDefinition in interface VDC
Parameters:
namespace - namespace, null to match any namespace
name - name, null to match any name
version - version, null to match any version
type - definition type (TR or DV)
Returns:
a list containing all Definitions that were deleted
Throws:
SQLException
See Also:
Definition.TRANSFORMATION, Definition.DERIVATION

searchDefinition

public List searchDefinition(String namespace,
                             String name,
                             String version,
                             int type)
                      throws SQLException
Search the database for definitions by ns::name:version triple and by type (either Transformation or Derivation). This version of the search allows for jokers expressed as null value

Specified by:
searchDefinition in interface VDC
Parameters:
namespace - namespace, null to match any namespace
name - name, null to match any name
version - version, null to match any version
type - type of definition (TR/DV, or both)
Returns:
a list of definitions
Throws:
SQLException
See Also:
Definition.TRANSFORMATION, Definition.DERIVATION

searchFilename

public List searchFilename(String lfn,
                           int link)
                    throws SQLException
Searches the database for all derivations that contain a certain LFN. The linkage is an additional constraint. This method does not allow jokers.

Specified by:
searchFilename in interface VDC
Parameters:
lfn - the LFN name
link - the linkage type of the LFN
Returns:
a list of Definition items that match the criterion.
Throws:
SQLException
See Also:
LFN.NONE, LFN.INPUT, LFN.OUTPUT, LFN.INOUT


Copyright © 2007 The University of Southern California. All Rights Reserved.