edu.ucsb.nceas.morpho.query
Class Query

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--edu.ucsb.nceas.morpho.query.Query
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class Query
extends org.xml.sax.helpers.DefaultHandler

A Class that represents a structured query, and can be constructed from an XML serialization conforming to @see pathquery.dtd. The printSQL() method can be used to print a SQL serialization of the query.


Constructor Summary
Query(ClientFramework framework)
          construct an instance of the Query class, manually setting the Query constraints rather that readin from an XML stream
Query(java.io.Reader queryspec, ClientFramework framework)
          construct an instance of the Query class from an XML Stream
Query(java.lang.String queryspec, ClientFramework framework)
          construct an instance of the Query class from an XML String
 
Method Summary
 void characters(char[] ch, int start, int length)
          callback method used by the SAX Parser when the text sequences of an xml stream are detected.
 boolean containsExtendedSQL()
          Returns true if the parsed query contains and extended xml query (i.e.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          callback method used by the SAX Parser when the end tag of an element is detected.
 ResultSet execute()
          Run the query against the local data store and metacat, depending on how the searchMetacat and searchLocal flags are set.
 java.util.Vector getFilterDocList()
          Accessor method to return a vector of the filter doc types as defined in the <filterdoctype> tag in the pathquery dtd.
 java.lang.String getIdentifier()
          Accessor method to return the identifier of this Query
 java.util.Vector getOwnerList()
          Accessor method to return a vector of the owner fields as defined in the <owner> tag in the pathquery dtd.
 QueryGroup getQueryGroup()
          get the QueryGroup used to express query constraints
 java.lang.String getQueryTitle()
          Accessor method to return the title of this Query
 java.util.Vector getReturnDocList()
          Accessor method to return a vector of the return document types as defined in the <returndoctype> tag in the pathquery dtd.
 java.util.Vector getReturnFieldList()
          Accessor method to return a vector of the extended return fields as defined in the <returnfield> tag in the pathquery dtd.
 boolean getSearchLocal()
          determine if we should search locally
 boolean getSearchMetacat()
          determine if we should search metacat
 java.util.Vector getSiteList()
          Accessor method to return a vector of the site fields as defined in the <site> tag in the pathquery dtd.
static void main(java.lang.String[] args)
          Main routine for testing
 java.lang.String printExtendedSQL(java.lang.String doclist)
          This method prints sql based upon the <returnfield> tag in the pathquery document.
static java.lang.String printGetDocByDoctypeSQL(java.lang.String docid)
           
static java.lang.String printPackageSQL()
          Prints sql that returns all relations in the database.
static java.lang.String printPackageSQL(java.lang.String docid)
          Prints sql that returns all relations in the database that were input under a specific docid
static java.lang.String printPackageSQL(java.lang.String subDocidURL, java.lang.String objDocidURL)
          Returns all of the relations that has a certain docid in the subject or the object.
static java.lang.String printRelationSQL(java.lang.String docid)
           
 java.lang.String printSQL(boolean useXMLIndex)
          create a SQL serialization of the query that this instance represents
 void save()
          Save an XML serialized version of the query in the profile directory
 void setFilterDocList(java.util.Vector filterDocList)
          method to set the list of filter docs of this query
 void setIdentifier(java.lang.String id)
          method to set the identifier of this query
 void setOwnerList(java.util.Vector ownerList)
          method to set the list of owners used to constrain this query
 void setQueryGroup(QueryGroup qg)
          set the QueryGroup used to express query constraints
 void setQueryTitle(java.lang.String title)
          method to set the title of this query
 void setReturnDocList(java.util.Vector returnDocList)
          method to set the list of return docs of this query
 void setReturnFieldList(java.util.Vector returnFieldList)
          method to set the list of fields to be returned by this query
 void setSearchLocal(boolean searchLocal)
          method to set searchLocal
 void setSearchMetacat(boolean searchMetacat)
          method to set searchMetacat
 void setSiteList(java.util.Vector siteList)
          method to set the list of sites used to constrain this query
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
          callback method used by the SAX Parser when the start tag of an element is detected.
 java.lang.String toString()
          create a String description of the query that this instance represents.
 java.lang.String toXml()
          create a XML serialization of the query that this instance represents
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Query

public Query(java.io.Reader queryspec,
             ClientFramework framework)
construct an instance of the Query class from an XML Stream
Parameters:
queryspec - the XML representation of the query (should conform to pathquery.dtd) as a Reader
framework - the client framework in which this Query is run

Query

public Query(java.lang.String queryspec,
             ClientFramework framework)
construct an instance of the Query class from an XML String
Parameters:
queryspec - the XML representation of the query (should conform to pathquery.dtd) as a String
framework - the client framework in which this Query is run

Query

public Query(ClientFramework framework)
construct an instance of the Query class, manually setting the Query constraints rather that readin from an XML stream
Parameters:
framework - the client framework in which this Query is run
Method Detail

containsExtendedSQL

public boolean containsExtendedSQL()
Returns true if the parsed query contains and extended xml query (i.e. there is at least one <returnfield> in the pathquery document)

getIdentifier

public java.lang.String getIdentifier()
Accessor method to return the identifier of this Query

setIdentifier

public void setIdentifier(java.lang.String id)
method to set the identifier of this query

getQueryTitle

public java.lang.String getQueryTitle()
Accessor method to return the title of this Query

setQueryTitle

public void setQueryTitle(java.lang.String title)
method to set the title of this query

getReturnDocList

public java.util.Vector getReturnDocList()
Accessor method to return a vector of the return document types as defined in the <returndoctype> tag in the pathquery dtd.

setReturnDocList

public void setReturnDocList(java.util.Vector returnDocList)
method to set the list of return docs of this query

getFilterDocList

public java.util.Vector getFilterDocList()
Accessor method to return a vector of the filter doc types as defined in the <filterdoctype> tag in the pathquery dtd.

setFilterDocList

public void setFilterDocList(java.util.Vector filterDocList)
method to set the list of filter docs of this query

getReturnFieldList

public java.util.Vector getReturnFieldList()
Accessor method to return a vector of the extended return fields as defined in the <returnfield> tag in the pathquery dtd.

setReturnFieldList

public void setReturnFieldList(java.util.Vector returnFieldList)
method to set the list of fields to be returned by this query

getOwnerList

public java.util.Vector getOwnerList()
Accessor method to return a vector of the owner fields as defined in the <owner> tag in the pathquery dtd.

setOwnerList

public void setOwnerList(java.util.Vector ownerList)
method to set the list of owners used to constrain this query

getSiteList

public java.util.Vector getSiteList()
Accessor method to return a vector of the site fields as defined in the <site> tag in the pathquery dtd.

setSiteList

public void setSiteList(java.util.Vector siteList)
method to set the list of sites used to constrain this query

getSearchMetacat

public boolean getSearchMetacat()
determine if we should search metacat

setSearchMetacat

public void setSearchMetacat(boolean searchMetacat)
method to set searchMetacat

getSearchLocal

public boolean getSearchLocal()
determine if we should search locally

setSearchLocal

public void setSearchLocal(boolean searchLocal)
method to set searchLocal

getQueryGroup

public QueryGroup getQueryGroup()
get the QueryGroup used to express query constraints

setQueryGroup

public void setQueryGroup(QueryGroup qg)
set the QueryGroup used to express query constraints

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
callback method used by the SAX Parser when the start tag of an element is detected. Used in this context to parse and store the query information in class variables.
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
callback method used by the SAX Parser when the end tag of an element is detected. Used in this context to parse and store the query information in class variables.
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler

characters

public void characters(char[] ch,
                       int start,
                       int length)
callback method used by the SAX Parser when the text sequences of an xml stream are detected. Used in this context to parse and store the query information in class variables.
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler

printSQL

public java.lang.String printSQL(boolean useXMLIndex)
create a SQL serialization of the query that this instance represents

toXml

public java.lang.String toXml()
create a XML serialization of the query that this instance represents

printExtendedSQL

public java.lang.String printExtendedSQL(java.lang.String doclist)
This method prints sql based upon the <returnfield> tag in the pathquery document. This allows for customization of the returned fields
Parameters:
doclist - the list of document ids to search by

printRelationSQL

public static java.lang.String printRelationSQL(java.lang.String docid)

printPackageSQL

public static java.lang.String printPackageSQL()
Prints sql that returns all relations in the database.

printPackageSQL

public static java.lang.String printPackageSQL(java.lang.String docid)
Prints sql that returns all relations in the database that were input under a specific docid
Parameters:
docid - the docid to search for.

printPackageSQL

public static java.lang.String printPackageSQL(java.lang.String subDocidURL,
                                               java.lang.String objDocidURL)
Returns all of the relations that has a certain docid in the subject or the object.
Parameters:
docid - the docid to search for

printGetDocByDoctypeSQL

public static java.lang.String printGetDocByDoctypeSQL(java.lang.String docid)

toString

public java.lang.String toString()
create a String description of the query that this instance represents. This should become a way to get the XML serialization of the query.
Overrides:
toString in class java.lang.Object

execute

public ResultSet execute()
Run the query against the local data store and metacat, depending on how the searchMetacat and searchLocal flags are set. If both local and metacat searches are run, merge the results into a single ResultSet and return it.

save

public void save()
          throws java.io.IOException
Save an XML serialized version of the query in the profile directory

main

public static void main(java.lang.String[] args)
Main routine for testing


Copyright © 2000 National Center for Ecological Analysis and Synthesis. All Rights Reserved.