EDU.utwente.CoCompose.util
Class Library

java.lang.Object
  extended byEDU.utwente.CoCompose.util.Library

public class Library
extends java.lang.Object

CoCompose component library based on a relational database.

Since:
0.1.22
Version:
0.1.22, 27-apr-2004
Author:
Willem Hajenius

Field Summary
static int ATLEAST
           
static int ATMOST
           
protected static java.sql.Connection conn
           
static java.lang.String databaseName
          Constants
static int INF_DEPTH
           
protected static java.io.PrintStream log
           
static java.lang.String tableLibraryFilename
           
static java.lang.String tablePropertiesFilename
           
static java.lang.String tableSavedQueriesFilename
           
static java.lang.String tableTaxonomyFilename
           
 
Constructor Summary
protected Library()
          Singleton constructor
 
Method Summary
protected  void addFacets(java.lang.String uri, java.util.Properties props)
          Subfunction to add the facets from the given Properties object to the database
 java.lang.Object[] CRQLtoSQL(java.lang.String query, java.util.AbstractMap propnames)
          Translate CRQL to ordinary SQL
 void deleteQuery(java.lang.String name)
          Delete a stored query (if found)
 void finalize()
           
 java.util.AbstractMap findAtleastValues(java.lang.String propname, java.lang.String propvalue, int limit)
          Find the legal values for an ATLEAST predicate
 java.util.AbstractMap findAtmostValues(java.lang.String propname, java.lang.String propvalue, int limit)
          Find the legal values for an ATMOST predicate
 java.util.AbstractMap findOtherAtleastValues(java.lang.String propname, java.lang.String propvalue, int limit, int depth)
          Recursive companion of findAtleastValues
 java.util.AbstractMap findOtherAtmostValues(java.lang.String propname, java.lang.String propvalue, int limit, int depth)
          Recursive companion of findAtmostValues
 java.util.AbstractMap findTableNames(java.lang.String query)
          Find the table names and the names of the properties they're used for
static void getFileTree(java.io.File dir, java.lang.String ext, java.util.List result)
          Get a file tree (files in given directory and all subdirs)
 void indexComponent(java.io.File file)
          Indexes a single component
 void indexComponents()
          (Re)Indexes all components
protected  void indexComposite(java.lang.String uri, Composite c)
          Subfunction to index the given Composite
protected  void indexConcept(java.lang.String uri, Concept c)
          Subfunction to index the given Concept
protected  void indexSolutionPattern(java.lang.String uri, Model m)
          Subfunction to index the given SolutionPattern (or plain vanilla Model)
static Library instance()
          Singleton accessor; initialises library when first accessed
 java.lang.String loadQuery(java.lang.String name)
          Retrieve a saved query with a given name.
static void main(java.lang.String[] args)
          Stand-alone debugging method
 java.util.Vector query(java.lang.String expression)
          Execute a CRQL query, returning the complete result table in the format of sqlQuery.
 double rank(java.lang.String id, java.util.List predicates)
          Rank a single result
 double rankOne(java.lang.String id, java.lang.String propname, java.util.AbstractMap values)
          Rank a single property of a single result
 void refreshComponents(boolean updateAll)
           
 void saveQuery(java.lang.String name, java.lang.String query)
          Save a given query in the database
 void setLog(java.io.PrintStream stream)
          Use a different log stream
protected  void setupTables()
          Create the DB tables (if necessary, for example when first used), and connect them to their physical (text) files.
 void shutdown()
          Closes database connection
 java.lang.String singleCRQLtoSQL(java.lang.String propname, int type, java.lang.String propvalue, int limit)
          Generate translated SQL for a single CRQL predicate
 java.util.Vector sqlQuery(java.lang.String expression)
          Execute a query in SQL and return the results as a Vector of rows A row is represented as a Vector of String The first entry contains the table names The rest of the rows contain the table's contents
 java.util.Vector sqlQuerySimple(java.lang.String expression, java.lang.String colname)
          Execute a SQL query, returning a single column
 void sqlUpdate(java.lang.String expression)
          Execute a SQL command that doesn't return any useful results, like INSERT or DELETE
 void sqlUpdateBlind(java.lang.String expression)
          Identical in behaviour to sqlUpdate, but ignores any exceptions.
 int tableSize(java.lang.String name)
          Check how many rows the given table contains, and if it exists
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

databaseName

public static final java.lang.String databaseName
Constants

See Also:
Constant Field Values

tableLibraryFilename

public static final java.lang.String tableLibraryFilename
See Also:
Constant Field Values

tablePropertiesFilename

public static final java.lang.String tablePropertiesFilename
See Also:
Constant Field Values

tableTaxonomyFilename

public static final java.lang.String tableTaxonomyFilename
See Also:
Constant Field Values

tableSavedQueriesFilename

public static final java.lang.String tableSavedQueriesFilename
See Also:
Constant Field Values

INF_DEPTH

public static final int INF_DEPTH
See Also:
Constant Field Values

ATLEAST

public static final int ATLEAST
See Also:
Constant Field Values

ATMOST

public static final int ATMOST
See Also:
Constant Field Values

conn

protected static java.sql.Connection conn

log

protected static java.io.PrintStream log
Constructor Detail

Library

protected Library()
Singleton constructor

Method Detail

main

public static void main(java.lang.String[] args)
Stand-alone debugging method

Parameters:
args - Command-line arguments

findAtleastValues

public java.util.AbstractMap findAtleastValues(java.lang.String propname,
                                               java.lang.String propvalue,
                                               int limit)
Find the legal values for an ATLEAST predicate

Parameters:
propname - The property's name
propvalue - The property's ideal value
limit - Maximal search depth (may be INF_DEPTH)
Returns:
A map (value --> depth)

findOtherAtleastValues

public java.util.AbstractMap findOtherAtleastValues(java.lang.String propname,
                                                    java.lang.String propvalue,
                                                    int limit,
                                                    int depth)
Recursive companion of findAtleastValues


findAtmostValues

public java.util.AbstractMap findAtmostValues(java.lang.String propname,
                                              java.lang.String propvalue,
                                              int limit)
Find the legal values for an ATMOST predicate

Parameters:
propname - The property's name
propvalue - The property's ideal value
limit - Maximal search depth (may be INF_DEPTH)
Returns:
A map (value --> depth)

findOtherAtmostValues

public java.util.AbstractMap findOtherAtmostValues(java.lang.String propname,
                                                   java.lang.String propvalue,
                                                   int limit,
                                                   int depth)
Recursive companion of findAtmostValues


singleCRQLtoSQL

public java.lang.String singleCRQLtoSQL(java.lang.String propname,
                                        int type,
                                        java.lang.String propvalue,
                                        int limit)
Generate translated SQL for a single CRQL predicate

Parameters:
propname - The property's name
type - The kind of predicate (ATLEAST or ATMOST)
propvalue - The property's ideal value
limit - The maximal search depth (may be INF_DEPTH)
Returns:
The generated SQL code

findTableNames

public java.util.AbstractMap findTableNames(java.lang.String query)
Find the table names and the names of the properties they're used for

Parameters:
query - A query in CRQL
Returns:
A map (table name --> property name)

CRQLtoSQL

public java.lang.Object[] CRQLtoSQL(java.lang.String query,
                                    java.util.AbstractMap propnames)
Translate CRQL to ordinary SQL

Parameters:
query - The input query
propnames - A map (table name --> property name), as given by findTableNames
Returns:
an array of two elements: first location holds the reritten query, second location holds the list of CRQL predicates in the query (for use by other methods)

rank

public double rank(java.lang.String id,
                   java.util.List predicates)
Rank a single result

Parameters:
id - The URI of the result
predicates - A list of predicates (as returned by CRQLtoSQL)
Returns:
A normalized rank in the range [0..1]

rankOne

public double rankOne(java.lang.String id,
                      java.lang.String propname,
                      java.util.AbstractMap values)
Rank a single property of a single result

Parameters:
id - The URI of the result
propname - The property's name
values - A map (property value --> depth)
Returns:
A normalized rank in the range [0..1]

query

public java.util.Vector query(java.lang.String expression)
Execute a CRQL query, returning the complete result table in the format of sqlQuery.


sqlQuery

public java.util.Vector sqlQuery(java.lang.String expression)
Execute a query in SQL and return the results as a Vector of rows


instance

public static Library instance()
Singleton accessor; initialises library when first accessed

Returns:
A reference to the library

shutdown

public void shutdown()
Closes database connection


finalize

public void finalize()
              throws java.lang.Throwable
Throws:
java.lang.Throwable

setLog

public void setLog(java.io.PrintStream stream)
Use a different log stream

Parameters:
stream - The stream receiving the logging information, eg. System.out

deleteQuery

public void deleteQuery(java.lang.String name)
Delete a stored query (if found)

Parameters:
name - The query's name

saveQuery

public void saveQuery(java.lang.String name,
                      java.lang.String query)
Save a given query in the database

Parameters:
name - The name you want to give to the query (avoid spaces and the like!)
query - The query itself

loadQuery

public java.lang.String loadQuery(java.lang.String name)
Retrieve a saved query with a given name. Returns an empty string if the query is not found.

Parameters:
name - The query's name
Returns:
The stored query if it's found, the empty string otherwise

sqlUpdate

public void sqlUpdate(java.lang.String expression)
               throws java.sql.SQLException
Execute a SQL command that doesn't return any useful results, like INSERT or DELETE

Parameters:
expression - A SQL expression
Throws:
java.sql.SQLException - if an error occurs while updating

sqlUpdateBlind

public void sqlUpdateBlind(java.lang.String expression)
Identical in behaviour to sqlUpdate, but ignores any exceptions. Especially useful when lots of updates have to happen, and you don't want an error in one of them to hamper the control flow.

Parameters:
expression - A SQL expression
See Also:
sqlUpdate(String)

sqlQuerySimple

public java.util.Vector sqlQuerySimple(java.lang.String expression,
                                       java.lang.String colname)
Execute a SQL query, returning a single column

Parameters:
expression - The query
Returns:
A Vector of String, containing the values of the given column

indexComponents

public void indexComponents()
(Re)Indexes all components


refreshComponents

public void refreshComponents(boolean updateAll)
Parameters:
updateAll - If true, all components are indexed, otherwise only the modified components are updated

getFileTree

public static void getFileTree(java.io.File dir,
                               java.lang.String ext,
                               java.util.List result)
Get a file tree (files in given directory and all subdirs)

Parameters:
dir - The topmost directory
ext - The suffix of the valid files (e.g. ".xml")
result - The resulting list of filenames

indexComponent

public void indexComponent(java.io.File file)
Indexes a single component

Parameters:
file - The XML file containing the component
Returns:
true if the operation completes successfully, false otherwise

indexComposite

protected void indexComposite(java.lang.String uri,
                              Composite c)
Subfunction to index the given Composite

Parameters:
uri - The Composite's filename
c - The Composite to index

indexConcept

protected void indexConcept(java.lang.String uri,
                            Concept c)
Subfunction to index the given Concept

Parameters:
uri - The concept's filename
c - The concept to index

indexSolutionPattern

protected void indexSolutionPattern(java.lang.String uri,
                                    Model m)
Subfunction to index the given SolutionPattern (or plain vanilla Model)

Parameters:
uri - The solution's filename
m - The solution to index

addFacets

protected void addFacets(java.lang.String uri,
                         java.util.Properties props)
Subfunction to add the facets from the given Properties object to the database

Parameters:
uri - The filename
props - The Properties object containing the facets

setupTables

protected void setupTables()
Create the DB tables (if necessary, for example when first used), and connect them to their physical (text) files.


tableSize

public int tableSize(java.lang.String name)
Check how many rows the given table contains, and if it exists

Parameters:
name - The table name to check
Returns:
If the table with the given name exists return its number of rows, else return -1