org.openptk.api
Class Query

java.lang.Object
  extended by org.openptk.api.Query

public final class Query
extends java.lang.Object

The Query class is used to define simple and complex queries. Simple queries are of type:

NOOPERATORNo Operator
EQEquals
NENot Equals
BEGINSBegins With
ENDSEnds With
CONTAINSContains
LTLess Than
LELess Than Or Equals To
GTGreater Than
GEGreater Than Or Equals To
LIKESounds Like

Examples:

 Query q1 = new Query(Query.TYPE_EQUALS,"lastname","Smith");
 Query q2 = new Query(Query.TYPE_CONTAINS,"firstname","Rob");
 

Complex queries are of type:

ANDAnd
OROr

Examples:

 Query qTop = new Query(Query.TYPE_OR);
 Query q1 = new Query(Query.TYPE_CONTAINS,"firstname","Scott");
 Query q2 = new Query(Query.TYPE_CONTAINS,"lastname","Scott");
 qTop.addQuery(q1);
 qTop.addQuery(q2);
 

A complex query has at least two sub-queries. Sub-queries can be either simple or complex

NOTICE: All getter methods return copies of the Query's data. If a any of the data from a Query is modified, after it has been "gotten", then it MUST be "put back".

Author:
Scott Fehrman, Sun Microsystems, Inc.

Nested Class Summary
static class Query.Type
           
 
Field Summary
 java.lang.String CLASS_NAME
           
static java.lang.String NAMESPACE
           
 
Constructor Summary
Query()
          Create a new complex Query with a default Type of "AND".
Query(Query.Type type)
          Create a new simple Query with the specified Type.
Query(Query.Type type, java.util.List<Query> qlist)
          Create a new complex Query using the List of Queries.
Query(Query.Type type, Query query)
          Create a new complex Query with the specified Type and adds the provided Query.
Query(Query.Type type, java.lang.String name, java.lang.String value)
          Create a new simple Query using the provided information.
Query(Query query)
          Create a new simple or complex Query from an existing Query The specified Query will be copied and it's data will be added to the new Query.
Query(java.lang.String type, java.lang.String name, java.lang.String value)
          Create a new simple Query using the provided information.
 
Method Summary
 void addQuery(Query query)
          Adds another Query (as a sub-query), making the Query complex.
 Query copy()
          Creates a copy of the Query.
 java.lang.String getName()
          Get the attribute name (Framework Name) from the Query.
 java.util.List<Query> getQueryList()
          Gets a List of the sub-Queries, if the Query is complex the List will contain two or more Queries.
 java.lang.String getServiceName()
          Get the Service attribute name, as known by the Service, from the Query This method is not to be used by OpenPTK applications.
 Query.Type getType()
          Get the Query Type.
 java.lang.String getTypeAsString()
          Get the String representation of the type.
 boolean getUseNamespace()
          Get the value [ true | false ] of the flag which determines if the "namespace" feature should be used with the toXML() method.
 java.lang.String getValue()
          Get the attribute value.
 boolean isInternal()
           
 void setInternal(boolean bool)
          Flag the Query as internal [ true | false ].
 void setName(java.lang.String name)
          Set the attribute name.
 void setQueryList(java.util.List<Query> qlist)
          Set / replace the List of sub-queries.
 void setServiceName(java.lang.String name)
          Set the Service attribute name, as known by the Service, in the Query This method is not to be used by OpenPTK applications.
 void setType(Query.Type type)
          Set the Query's Type.
 void setType(java.lang.String type)
          Set the Query Type, using the String representaion for the Type.
 void setUseNamespace(boolean bool)
          Set the value [ true | false ] for this flag.
 void setValue(java.lang.String value)
          Set the attribute value.
 java.lang.String toString()
          Returns a String that represents the Query Supports both simple and complex queries.
 java.lang.String toXML()
          Returns an XML structure that represents the Query Supports both simple and complex queries.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_NAME

public final java.lang.String CLASS_NAME

NAMESPACE

public static final java.lang.String NAMESPACE
See Also:
Constant Field Values
Constructor Detail

Query

public Query()
Create a new complex Query with a default Type of "AND". The "Attrbute" and "Value" must be set if this Query will be a simple Query (non-AND and non-OR type). If this will be a simple query, then the type must be changed.


Query

public Query(Query.Type type)
Create a new simple Query with the specified Type.

Parameters:
type - the Query Type [ AND | OR ]

Query

public Query(Query.Type type,
             java.util.List<Query> qlist)
Create a new complex Query using the List of Queries.

Parameters:
type - the Type of complex Query
qlist - a List of Query objects

Query

public Query(Query.Type type,
             Query query)
      throws QueryException
Create a new complex Query with the specified Type and adds the provided Query. This is only valid for Queries that are of type "AND" or "OR" where they require two or more sub-queries.

Parameters:
type - the Query Type [ AND | OR ]
query - the sub-query used for the "AND" or "OR" logic
Throws:
QueryException

Query

public Query(Query.Type type,
             java.lang.String name,
             java.lang.String value)
Create a new simple Query using the provided information.

Parameters:
type - the Query Type
name - the attributes name
value - the attributes value

Example:

Query q = new Query(Query.TYPE_EQUALS,"lastname","Smith");

Query

public Query(Query query)
Create a new simple or complex Query from an existing Query The specified Query will be copied and it's data will be added to the new Query.

Parameters:
query - an existing Query

Query

public Query(java.lang.String type,
             java.lang.String name,
             java.lang.String value)
      throws QueryException
Create a new simple Query using the provided information.

Parameters:
type - the Query TYPE (String name)
name - the attributes name
value - the attributes value
Throws:
QueryException -

Example:

Query q = new Query("equals","lastname","Smith");
Method Detail

addQuery

public final void addQuery(Query query)
Adds another Query (as a sub-query), making the Query complex.

Parameters:
query - an existing Query

copy

public Query copy()
Creates a copy of the Query.

Returns:
Query a new Query that is a copy of this one

getName

public final java.lang.String getName()
Get the attribute name (Framework Name) from the Query.

Returns:
String the attribute name

getQueryList

public final java.util.List<Query> getQueryList()
Gets a List of the sub-Queries, if the Query is complex the List will contain two or more Queries.

Returns:
List a List of sub-queries

getServiceName

public final java.lang.String getServiceName()
Get the Service attribute name, as known by the Service, from the Query This method is not to be used by OpenPTK applications. It's only used by OpenPTK Framework operations. It's interface and operation may NOT be consistent

Returns:
String the service attribute name

getType

public final Query.Type getType()
Get the Query Type.

Returns:
Query.Type the Query Type

getTypeAsString

public final java.lang.String getTypeAsString()
Get the String representation of the type.

Returns:
String the type

getUseNamespace

public final boolean getUseNamespace()
Get the value [ true | false ] of the flag which determines if the "namespace" feature should be used with the toXML() method.

Returns:
boolean the value of this flag

getValue

public final java.lang.String getValue()
Get the attribute value.

Returns:
String the attributes value

isInternal

public final boolean isInternal()
Returns:
boolean is this Internal

setInternal

public final void setInternal(boolean bool)
Flag the Query as internal [ true | false ].

Parameters:
bool -

setName

public final void setName(java.lang.String name)
Set the attribute name.

Parameters:
name - the attributes name

setQueryList

public final void setQueryList(java.util.List<Query> qlist)
Set / replace the List of sub-queries.

Parameters:
qlist -

setServiceName

public final void setServiceName(java.lang.String name)
Set the Service attribute name, as known by the Service, in the Query This method is not to be used by OpenPTK applications. It's only used by OpenPTK Framework operations. It's interface and operation may NOT be consistent

Parameters:
name - the Service attribute name

setType

public final void setType(Query.Type type)
Set the Query's Type.

Parameters:
type - the Query Type

setType

public final void setType(java.lang.String type)
                   throws QueryException
Set the Query Type, using the String representaion for the Type. The type must be a valid Query type.

Parameters:
type - the String representation of Query Type
Throws:
QueryException

setUseNamespace

public final void setUseNamespace(boolean bool)
Set the value [ true | false ] for this flag. If true, the toXML() method will use a "namespace" feature.

Parameters:
bool - true or false

setValue

public final void setValue(java.lang.String value)
Set the attribute value.

Parameters:
value - the attributes value

toString

public java.lang.String toString()
Returns a String that represents the Query Supports both simple and complex queries.

Overrides:
toString in class java.lang.Object
Returns:
String the Query as a String

toXML

public final java.lang.String toXML()
Returns an XML structure that represents the Query Supports both simple and complex queries.

Returns:
String the XML data


View/submit a bug or feature

For further API reference and developer documentation, see www.openptk.org. That documentation contains more detailed, developer-targeted descriptions, definitions of terms, workarounds, and working code examples.

Copyright (C) 2008-2012, Project OpenPTK. All Rights Reserved