org.edg.data.util.attribute
Class SQLHelpers

java.lang.Object
  |
  +--org.edg.data.util.attribute.SQLHelpers

public final class SQLHelpers
extends java.lang.Object

This abstracts out the concept of a 1-N guid -> entry mapping in a catalog. It is used in both the LRC and RMC with the entry being the pfn and alias respectively. It is configured by supplying different SQLCatalog instances, which contain the actual SQL that is relevant to the tables in the database.

Version:
$ Id:$
Author:
James Casey

Constructor Summary
SQLHelpers(java.lang.String catalog, java.lang.String vendor)
           
 
Method Summary
 boolean addEntry(java.sql.Connection conn, java.lang.String guid, java.lang.String entry)
          Add a entry for a guid.
 int countStarFromTable(java.sql.Connection conn, java.lang.String tableName)
           
 java.util.List entriesForGuid(java.sql.Connection conn, java.lang.String guid)
          get the list of entries for a guid.
 boolean entryExists(java.sql.Connection conn, java.lang.String entry)
          does a entry exist in the db ?
 java.lang.String getSchemaVersion(java.sql.Connection conn)
          Get the schema version from the catalog.
 boolean guidExists(java.sql.Connection conn, java.lang.String guid)
          does a guid exist in the db ?
 java.lang.String guidForEntry(java.sql.Connection conn, java.lang.String entry)
          Gets the guid that an entry is mapped to. returns null if the entry does not exist
 void removeEntryFromGuid(java.sql.Connection conn, java.lang.String guid, java.lang.String entry)
          remove an entry from the entry table in the rmc.
 void removeGuidIfEmpty(java.sql.Connection conn, java.lang.String guid)
          Remove a guid from the guid table if it has no entries mapped to it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLHelpers

public SQLHelpers(java.lang.String catalog,
                  java.lang.String vendor)
           throws InvalidCatalogException
Method Detail

guidExists

public boolean guidExists(java.sql.Connection conn,
                          java.lang.String guid)
                   throws java.sql.SQLException
does a guid exist in the db ?

java.sql.SQLException

entryExists

public boolean entryExists(java.sql.Connection conn,
                           java.lang.String entry)
                    throws java.sql.SQLException
does a entry exist in the db ?

java.sql.SQLException

addEntry

public boolean addEntry(java.sql.Connection conn,
                        java.lang.String guid,
                        java.lang.String entry)
                 throws java.sql.SQLException
Add a entry for a guid. If the guid not already in the database, it is added too.

Parameters:
conn - the connection
guid - the guid
entry - the entry
Returns:
true if the entry was not there already.
Throws:
java.sql.SQLException

removeEntryFromGuid

public void removeEntryFromGuid(java.sql.Connection conn,
                                java.lang.String guid,
                                java.lang.String entry)
                         throws java.sql.SQLException
remove an entry from the entry table in the rmc. Note this does not alter the guid table

Parameters:
conn - the catalog
entry - the entry to remove
java.sql.SQLException

removeGuidIfEmpty

public void removeGuidIfEmpty(java.sql.Connection conn,
                              java.lang.String guid)
                       throws java.sql.SQLException
Remove a guid from the guid table if it has no entries mapped to it.

Parameters:
conn - the catalog
guid - the guid to remove
java.sql.SQLException

entriesForGuid

public java.util.List entriesForGuid(java.sql.Connection conn,
                                     java.lang.String guid)
                              throws java.sql.SQLException
get the list of entries for a guid. This returns an empty list if there are no entries.

Parameters:
conn - the connection
guid - the guid
Returns:
the list of entries
Throws:
java.sql.SQLException

guidForEntry

public java.lang.String guidForEntry(java.sql.Connection conn,
                                     java.lang.String entry)
                              throws java.sql.SQLException
Gets the guid that an entry is mapped to. returns null if the entry does not exist

Parameters:
conn - the connection to the Catalog
entry - the entry to get the guid for
Returns:
the guid
Throws:
java.sql.SQLException

countStarFromTable

public int countStarFromTable(java.sql.Connection conn,
                              java.lang.String tableName)
                       throws java.sql.SQLException
java.sql.SQLException

getSchemaVersion

public java.lang.String getSchemaVersion(java.sql.Connection conn)
                                  throws java.sql.SQLException
Get the schema version from the catalog. Returns the string undefined if the appropriate table (schema_version) does not exist in the catalog, or if it contains no value.

Parameters:
conn - the database connection to use
java.sql.SQLException