|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
com.apelon.modules.dts.editor.tql.TQL
public class TQL
The TQL
class provides API access to TQL parsing and execution functions.
Once the class has been instantiated, TQL queries can be executed from either
passed strings or files. TQL extends Thread
and implements the Runnable
interface, to simplify its use by background processes.
Access to the array of DTSConcepts satisfying a query's collection
set is also available.
Log messages are written to a log file, either the default TQL.log
or one specified in the constructor,
and fired to any attached ActionListeners
. The log file is cleared by the constructor, but
subsequent query processing messages are appended, potentially across multiple query executions.
TQL
uses the static DTSAppManager.DTSQuery
object for accessing the DTS
knowledgebase. This object should either be set up by the calling program or by passing the
server connection to the TQL
constructor.
Copyright (c) 2008 Apelon, Inc. All rights reserved.
Nested Class Summary | |
---|---|
static class |
TQL.StatementType
Enum for TQL statement types. |
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
static int |
COMPLETED
ActionEvent Id code for completed event |
static java.lang.String |
DEFAULT_DATE_FORMAT
Default date format string |
static java.lang.String |
DEFAULT_DELIMITER
Deprecated. |
static java.lang.String |
DEFAULT_FIELD_DELIMITER
Default field delimiter |
static java.lang.String |
DEFAULT_GROUP_DELIMITER
Default group delimiter |
static java.lang.String |
DEFAULT_LOGFILE
Name of default log file |
static java.lang.String |
DEFAULT_THESAURUS_AXIS
Name of default Thesaurus axis association |
static java.lang.String |
DEFAULT_TIME_FORMAT
Default time format string |
static int |
ERROR
ActionEvent Id code for error events |
static int |
INTERRUPTED
ActionEvent Id code for interrupted event |
static int |
PROGRESS
ActionEvent Id code for progress events |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
TQL()
Create a TQL instance that uses existing connection parameters
and the default log file. |
|
TQL(ServerConnection sc)
Deprecated. Use TQL(host, port, instance, user, psw) |
|
TQL(ServerConnection sc,
java.lang.String log)
Deprecated. Use TQL(host, port, instance, user, psw, log) |
|
TQL(java.lang.String log)
Create a TQL instance that uses existing connection parameters
and a specified log file. |
|
TQL(java.lang.String host,
int port,
java.lang.String instance,
java.lang.String user,
java.lang.String psw)
Create a TQL instance using connection parameters and the default log file. |
|
TQL(java.lang.String host,
int port,
java.lang.String instance,
java.lang.String user,
java.lang.String psw,
java.lang.String log)
Create a TQL instance using connection parameters and a specified log file. |
Method Summary | |
---|---|
void |
abort()
Abort the export process. |
void |
addActionListener(java.awt.event.ActionListener al)
Add an ActionListener for monitoring of log events. |
boolean |
getAppend()
Get the value of the TQL APPEND variable that determines whether exports are unconditionally appended to the export file. |
java.lang.String |
getAxisName()
Get the value of the TQL AXIS variable that names the AssociationType
used as the parent-to-child link for Namespaces. |
QualifiedObject |
getAxisObject(int nsid)
Get the qualified object representing the axis (hierarchy) relationship for a namespace The base direction is Parent to Child (parent_of). |
static QualifiedObject |
getAxisObject(java.lang.String name,
int nsid)
Static entry to get the qualified object representing the axis (hierarchy) relationship for a namespace The base direction is Parent to Child (parent_of). |
DTSConcept[] |
getCollection()
Deprecated. use getCollectionConcepts(); |
DTSConcept[] |
getCollection(ConceptAttributeSetDescriptor casd)
Deprecated. use getCollectionConcepts(casd) |
DTSConcept[] |
getCollectionConcepts()
Get the array of selected DTSConcept objects from the last executed collection query. |
DTSConcept[] |
getCollectionConcepts(ConceptAttributeSetDescriptor casd)
Get the array of selected concepts from the last executed collection query. |
DTSObject[] |
getCollectionObjects()
Get the array of selected DTSObject ojectsfrom the last executed collection query. |
Term[] |
getCollectionTerms()
Get the array of selected Term objects from the last executed collection query. |
Term[] |
getCollectionTerms(TermAttributeSetDescriptor tasd)
Get the array of selected terms from the last executed collection query. |
java.lang.String |
getDateFormat()
Get the value of the TQL DATE_FORMAT variable that specifies the format of exported dates (@D and version dates). |
java.lang.String |
getDefaultDelimiter()
Get the default delimiter(s). |
java.lang.String |
getDelimiter()
Get the value of the TQL DELIMITER variable used to separate fields in export lines. |
boolean |
getHeader()
Get the value of the TQL HEADER variable that determines whether a header line should be placed in the export file. |
int |
getLimit()
Get the value of the TQL LIMIT variable that limits the number of concept lines exported. |
boolean |
getPruneTerms()
Get the value of the TQL PRUNE_TERMS variable that determines whether orphaned Terms are deleted. |
boolean |
getRetainHead()
Get the value of the TQL RETAIN_HEAD variable that determines whether the DELETE_TREES command deletes its specified, head, Concepts. |
int |
getSize()
Get the value of the TQL SIZE variable that gives the size (number of Concepts or Terms) of the last Collection. |
TQL.StatementType[] |
getStatementTypes()
Get the query statement types. |
java.lang.String |
getTimeFormat()
Get the value of the TQL TIME_FORMAT variable that specifies the format of exported times (@T). |
boolean |
getTypeDefs()
Get the value of the TQL TYPEDEFS variable that determines whether Type definitions are included in EXPORT_CONCEPTS or EXPORT_SUBSET output. |
boolean |
getUnique()
Get the value of the TQL UNIQUE variable that determines whether only unique lines are exported. |
boolean |
hasParameters()
Test whether the query has parameters. |
boolean |
isAborted()
Check for abort request. |
boolean |
isReadonly()
Returns true if this query does not modify the DTS knowledgebase. |
void |
log(java.lang.String mess,
int code)
write log messages and fire associated events |
static void |
main(java.lang.String[] args)
Run TQL from the command line. |
boolean |
parse()
Parse the query. |
void |
removeActionListener(java.awt.event.ActionListener al)
Remove an ActionListener from the listener list. |
boolean |
replaceParametersAndParse(java.util.HashMap<java.lang.String,java.lang.String> parameterMap)
Replace query parameters with string values. |
void |
run()
Run (execute) the query. |
void |
setAppend(boolean b)
Set the value of the TQL APPEND variable. |
void |
setAxisName(java.lang.String axis)
Set the value of the TQL AXIS variable. |
void |
setDateFormat(java.lang.String str)
Set the value of the TQL DATE_FORMAT variable. |
void |
setDelimiter(java.lang.String delim)
Set the TQL export file delimiters. |
void |
setExportfile(java.lang.String name)
Set the TQL export file. |
void |
setExportwriter(java.io.PrintWriter writer)
Set the TQL export writer. |
void |
setHeader(boolean header)
Set the value of the TQL HEADER variable. |
void |
setLimit(int n)
Set the value of the TQL LIMIT variable. |
void |
setPruneTerms(boolean b)
Set the value of the TQL PRUNE_TERMS variable. |
void |
setQueryfile(java.lang.String name)
Set the TQL query file. |
void |
setQueryObject(java.util.List<StatementBean> array)
Set the TQL query object. |
void |
setQuerystring(java.lang.String query)
Set the TQL query string. |
void |
setRetainHead(boolean b)
Set the value of the TQL RETAIN_HEAD variable. |
void |
setTimeFormat(java.lang.String str)
Set the value of the TQL TIME_FORMAT variable. |
void |
setTypeDefs(boolean b)
Set the value of the TQL TYPEDEFS variable. |
void |
setUnique(boolean b)
Set the value of the TQL UNIQUE variable. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int PROGRESS
abort()
,
Constant Field Valuespublic static final int COMPLETED
abort()
,
Constant Field Valuespublic static final int INTERRUPTED
abort()
,
Constant Field Valuespublic static final int ERROR
abort()
,
Constant Field Valuespublic static final java.lang.String DEFAULT_FIELD_DELIMITER
public static final java.lang.String DEFAULT_DELIMITER
public static final java.lang.String DEFAULT_GROUP_DELIMITER
public static final java.lang.String DEFAULT_THESAURUS_AXIS
public static final java.lang.String DEFAULT_LOGFILE
public static final java.lang.String DEFAULT_DATE_FORMAT
public static final java.lang.String DEFAULT_TIME_FORMAT
Constructor Detail |
---|
public TQL()
TQL
instance that uses existing connection parameters
and the default log file. Connection parameters must have been set in DTSAppManager
for background thread to operate properly.
public TQL(java.lang.String log)
TQL
instance that uses existing connection parameters
and a specified log file. Connection parameters must have been set in DTSAppManager
for background thread to operate properly.
public TQL(ServerConnection sc)
TQL
instance and set up the DTSQuery object. Uses the default log file.
sc
- the ServerConnection
to be set uppublic TQL(ServerConnection sc, java.lang.String log)
TQL
instance. Initializes the DTSQuery object and log file.
sc
- the ServerConnection
to be set uplog
- the name of the log file to be used (can be null to prevent logging)public TQL(java.lang.String host, int port, java.lang.String instance, java.lang.String user, java.lang.String psw)
TQL
instance using connection parameters and the default log file.
Initializes the connection object.
host
- the connection host nameport
- the connection port numberinstance
- the connection instance nameuser
- the connection user namepsw
- the connection passwordhost
- the connection host namepublic TQL(java.lang.String host, int port, java.lang.String instance, java.lang.String user, java.lang.String psw, java.lang.String log)
TQL
instance using connection parameters and a specified log file.
Initializes the connection object.
host
- the connection host nameport
- the connection port numberinstance
- the connection instance nameuser
- the connection user namepsw
- the connection passwordhost
- the connection host namelog
- the name of the log file to be used (can be null to prevent logging)Method Detail |
---|
public java.lang.String getDefaultDelimiter()
public void setQuerystring(java.lang.String query)
query
- the string containing the querypublic void setQueryfile(java.lang.String name)
name
- the name of the query filepublic void setExportfile(java.lang.String name)
name
- the name of the export filepublic void setExportwriter(java.io.PrintWriter writer)
writer
- the PrintWriter
to be used for exported datapublic void setQueryObject(java.util.List<StatementBean> array)
array
- the TQL Query Object
public java.lang.String getDelimiter()
public void setDelimiter(java.lang.String delim)
delim
is null
or the empty string, the default delimiters are set. Otherwise,
the first character of the argument becomes the field delimiter
and the second character (if present) becomes the group delimiter.
delim
- the export file delimiterpublic boolean getHeader()
public void setHeader(boolean header)
header
- whether a header row should be writtenpublic java.lang.String getAxisName()
AssociationType
used as the parent-to-child link for Namespaces. An empty value defaults to Superconcept/Subconcept
for Ontylog Namespaces or "Parent Of" for Thesaurus Namespaces.
AssociationType
public void setAxisName(java.lang.String axis)
AssociationType
used as the parent-to-child link for Namespaces. An empty value defaults to Superconcept/Subconcept
for Ontylog Namespaces or "Parent Of" for Thesaurus Namespaces.
The value may begin with "INV" to denote that the link points from child-to-parent.
axis
- the name of the parent-to-child AssociationType
public QualifiedObject getAxisObject(int nsid) throws java.lang.Exception
nsid
- the id of the target namespace
java.lang.Exception
- on unknown association/role after logging errorpublic static QualifiedObject getAxisObject(java.lang.String name, int nsid) throws java.lang.Exception
the
- name to be used as the axis, may include "inv"nsid
- the id of the target namespace
java.lang.Exception
- on unknown association/role after logging errorpublic int getLimit()
public void setLimit(int n)
n
- the maximum number of concept lines to be exportedpublic boolean getAppend()
public void setAppend(boolean b)
b
- whether exports should be appendedpublic boolean getPruneTerms()
public void setPruneTerms(boolean b)
b
- whether orphaned Terms should be deletedpublic boolean getUnique()
public void setUnique(boolean b)
b
- whether only unique lines should be writtenpublic boolean getRetainHead()
public void setRetainHead(boolean b)
b
- whether head concepts should be retainedpublic boolean getTypeDefs()
public void setTypeDefs(boolean b)
b
- whether type definitions should be writtenpublic java.lang.String getDateFormat()
SimpleDateFormat
public void setDateFormat(java.lang.String str)
the
- Java SimpleDateFormat
format stringpublic java.lang.String getTimeFormat()
SimpleDateFormat
public void setTimeFormat(java.lang.String str)
the
- Java SimpleDateFormat
format stringpublic int getSize()
public boolean hasParameters()
TQL
Query object must have previous been set by
setQueryfile
or setQuerystring
and parsed by parse
.
If the query has parameters, they can be replaced by a call to replaceParameters
.
parse()
,
#replaceParameters
public boolean replaceParametersAndParse(java.util.HashMap<java.lang.String,java.lang.String> parameterMap)
TQL
query object must have previously been set by
setQueryfile
or setQuerystring
. Parameters in the TQL
query string
will be replaced by their values in the parameter map and query will be parsed. Note that TQL CONSTRAIN
statements are not processed by this method. Simple string replacement is performed. Any parse errors, including
unresolved parameter errors, are logged and may be captured via an ActionListener
.
parameterMap
- HashMap\
of parameter names (keys)and associated values
parse()
,
hasParameters()
public void abort()
run
thread.
Actual termination can be tracked through an ActionEvent.
public boolean isAborted()
public boolean parse()
setQueryfile
or setQuerystring
. A successful parse
sets the TQL
query object. This method may be used if determination
of a valid query is desired prior to running the query. Any parse errors are logged
and may be captured via an ActionListener
.
setQueryfile(String)
,
setQuerystring(String)
public TQL.StatementType[] getStatementTypes()
parse()
if query object has not been prepared.
public boolean isReadonly()
parse()
if query object has not been prepared.
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public DTSConcept[] getCollection()
public DTSObject[] getCollectionObjects()
DTSObject
ojectsfrom the last executed collection query.
DTSObjects
with no additional attributespublic DTSConcept[] getCollectionConcepts()
DTSConcept
objects from the last executed collection query.
Returns an empty array if query was not a basic collection query or if collection was Term-based.
DTSConcept
with no additional attributespublic Term[] getCollectionTerms()
Term
objects from the last executed collection query.
Returns an empty array if query was not a basic collection query or if collection was Concept-based.
Term
with no additional attributespublic DTSConcept[] getCollection(ConceptAttributeSetDescriptor casd) throws DTSException
ConceptAttributeSetDescritor
.
casd
- the ConceptAttributeSetDescriptor
that defines the attributes to be
returned on the concepts
DTSException
- if an error occurs in accessing the requested concept attributespublic DTSConcept[] getCollectionConcepts(ConceptAttributeSetDescriptor casd) throws DTSException
ConceptAttributeSetDescritor
.
Returns an empty array if query was not a basic collection query or if collection was Term-based.
casd
- the ConceptAttributeSetDescriptor
that defines the attributes to be
returned on the concepts
DTSException
- if an error occurs in accessing the requested concept attributespublic Term[] getCollectionTerms(TermAttributeSetDescriptor tasd) throws DTSException
TermAttributeSetDescritor
.
Returns an empty array if query was not a basic collection query or if collection was Concept-based.
tasd
- the TermAttributeSetDescriptor
that defines the attributes to be
returned on the terms
DTSException
- if an error occurs in accessing the requested term attributespublic void log(java.lang.String mess, int code)
public void addActionListener(java.awt.event.ActionListener al)
ActionListener
for monitoring of log events.
al
- ActionListener
to be addedpublic void removeActionListener(java.awt.event.ActionListener al)
ActionListener
from the listener list.
al
- ActionListener
to be removedpublic static void main(java.lang.String[] args)
TQL
from the command line. Usage is:
TQL -host:HOST -port:PORT -instance:INSTANCE -user:USER -psw:PASSWORD
-query:QUERYFILE -output:OUTFILE -delim:DELIMITER -header:HEADER -log:LOGFILE
If the argument list is empty, TQL
will prompt for the arguments.
args
- the argument array
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |