|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.objectwave.transactionalSupport.ObjectEditor | +--com.objectwave.persist.SQLQuery
Used to define dynamic queries at an object level. This is intended to allow a developer to never include SQL code in their development efforts. For example:
SQLQuery query = new SQLQuery(somePersistentObject);
somePersistentObject.setAttributeValue("one");
query.find();
This should return a vector containing instances of SomePersistentObject.
The query would be constrained by those cases that AttributeValue = "one";
Persistence
,
Broker
,
Serialized FormNested Class Summary | |
static class |
SQLQuery.Test
Unit test |
Nested classes inherited from class com.objectwave.transactionalSupport.ObjectEditor |
ObjectEditor.Test |
Field Summary | |
protected boolean |
attributeSearch
|
protected Broker |
brok
|
protected CollectionAdapter |
collectionAdapter
|
protected Persistence |
constraint
|
protected java.util.HashMap |
constraints
|
protected static Broker |
defaultBroker
|
protected boolean |
distinct
|
protected int |
objectLimit
|
protected java.util.Vector |
orderByList
|
protected boolean |
queryLike
|
protected Persistence |
subject
|
protected java.util.Vector |
subQuery
|
Fields inherited from class com.objectwave.transactionalSupport.ObjectEditor |
dataExchange, fds, security |
Constructor Summary | |
SQLQuery()
When using this constructor, before this query would be valid you MUST call the setSubject method. |
|
SQLQuery(Persistence obj)
Create a query object that will be used to locate persistent objects. |
Method Summary | |
void |
addConstraint(Constraint constraint)
Add a constraint to the query. |
void |
addOrderByField(java.lang.String pathToField)
Add a new element to our list of order by clauses. |
void |
addOrderByField(java.lang.String pathToField,
boolean descend)
Add a new element to our list of order by clauses. |
int |
count()
Return a collection of persistent objects of the type of this current query's subject. |
void |
deleteAll()
Delete all records that match the search criteria. |
boolean |
fieldIsConstrained(java.lang.String field)
Determine if there is a constraint assigned for the provided field name. |
java.util.Vector |
find()
Return a collection of persistent objects of the type of this current query's subject. |
java.util.Vector |
findAttributes(java.lang.String[] attributes)
Return a vector of Object []. |
java.lang.Object |
findCollection()
Return a collection of persistent objects of the type of this current query's subject. |
java.lang.Object |
findCollection(java.lang.Class clazz)
Return a collection of persistent objects of the type of this current query's subject. |
java.util.Vector |
findIn(Persistence obj)
|
Persistence |
findUnique()
Find the one and only one persistent object that matches our Query conditions. |
Broker |
getBroker()
If the broker is explicitly set, use that broker. |
java.util.List |
getChildConstraintFor(java.lang.String field)
How do we deal with multiple constraints on a given field? Answer: we don't. |
CollectionAdapter |
getCollectionAdapter()
Used when building result sets. |
Constraint |
getConstraintFor(java.lang.String field)
How do we deal with multiple constraints on a given field? Answer: we don't. |
static Broker |
getDefaultBroker()
A SQLQuery object can be pegged to a specific broker. |
Persistence |
getJoinConstraint()
Gets the JoinConstraint attribute of the SQLQuery object |
int |
getObjectLimit()
|
java.util.Vector |
getOrderByList()
Each string in the vector is a path to the field we wish to use. |
Persistence |
getSubject()
The main subject of this query. |
boolean |
isAttributeSearch()
Gets the AttributeSearch attribute of the SQLQuery object |
boolean |
isDistinct()
Gets the Distinct attribute of the SQLQuery object |
boolean |
isLike()
Should we default the comparison of values (when using query by example) to be a 'LIKE' comparison. |
protected int |
populateStack(java.util.Vector symbols,
int idx,
java.util.Stack currentStack)
Examine the symbols and build constraints from the information. |
protected int |
processBracket(StringCalculator.CalcItem calcItem,
java.util.Vector symbols,
int idx,
java.util.Stack currentStack)
The setConstraintString has detected and opening '('. |
protected void |
processOperator(StringCalculator.CalcItem calcItem,
java.util.Vector symbols,
int idx,
java.util.Stack currentStack)
The constraint string has found an operation (like '=' or '&&') and it needs to build the appropriate Constraint object. |
static void |
registerCollectionAdapter(java.lang.Class collectionClass,
java.lang.Class adapter)
To support different collection types, multiple collection adapters must be registered. |
void |
set(java.lang.reflect.Field adapt,
java.lang.Object val,
java.lang.Object originalVal)
If we set any field on this object that also happens to be a persistent object, wrap it with a SQLQuery. |
void |
setAsLike(boolean value)
Should we default the comparison of values (when using query by example) to be a 'LIKE' comparison. |
void |
setBroker(Broker b)
Set broker for which this query is to use. |
void |
setCollectionAdapter(CollectionAdapter adapter)
This method may be to powerfull for its own good. |
void |
setConstraint(Persistence p)
|
void |
setConstraintString(java.lang.String constraints)
Attempt to simplify the creation of constraints. |
static void |
setDefaultBroker(Broker b)
When a query is executed, it needs to be executed against a specific broker. |
void |
setDistinct(boolean b)
Should only distinct rows be found. |
void |
setFieldConstraint(Persistence search,
java.lang.String fieldPath,
java.lang.String value,
java.lang.String compareConstraintType)
Convenience method for setting field constraints. |
void |
setIsanyOf(Persistence p,
java.lang.String fieldName,
java.util.Vector anyOf)
Determine that all elements of the result set must have a value in the given field (indicated by fieldName) which occurs as an element "anyOf". |
void |
setIsNotNull(Persistence p,
java.lang.String fieldName)
We can provide our own objects for the comparison. |
void |
setIsNull(Persistence p,
java.lang.String fieldName)
We can provide our own objects for the comparison. |
void |
setNotAnyOf(Persistence p,
java.lang.String fieldName,
java.util.Vector anyOf)
Similar to setIsAnyOf, but the "inverse" of the results |
void |
setObjectLimit(int num)
Limit the number of objects that can be created through this query. |
void |
setOrderByList(java.util.Vector v)
Field paths that are used to order the result set. |
void |
setSubject(Persistence obj)
The basis of a JGringer query is the concept of Query by Example. |
void |
setSubSelect(Persistence p,
java.lang.String fieldPath,
java.lang.String subSelectFieldPath,
SQLQuery subSelectQuery,
boolean isNot)
|
protected java.lang.String |
stripTicks(java.lang.String aValue)
The constraint string uses \' (ticks) to denote string boundaries. |
java.lang.String |
toString()
Try to provide some useful debugging information. |
Methods inherited from class com.objectwave.transactionalSupport.ObjectEditor |
changes, clearChanges, clearChanges, commit, containsAnyChanges, containsAttributeChanges, get, get, get, get, get, get, get, get, get, get, getCollectionChanges, getDomainField, getDomainObject, getFieldMap, getMods, getSecurity, getValue, isDirty, isTransient, lock, lockedBy, markChange, migrateChanges, noKnownLogs, putFieldMap, putMod, quickChanges, rollback, set, set, set, set, set, set, set, set, set, set, setAsTransient, setDomainField, setSecurity, setValue, unlock |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected static Broker defaultBroker
protected java.util.HashMap constraints
protected transient Broker brok
protected Persistence subject
protected boolean queryLike
protected boolean distinct
protected boolean attributeSearch
protected java.util.Vector subQuery
protected CollectionAdapter collectionAdapter
protected java.util.Vector orderByList
protected Persistence constraint
protected int objectLimit
Constructor Detail |
public SQLQuery()
setSubject(com.objectwave.persist.Persistence)
public SQLQuery(Persistence obj)
obj
- An object implmenting Persistence interface.Method Detail |
public static void setDefaultBroker(Broker b)
b
- The new DefaultBroker valuepublic static Broker getDefaultBroker()
public static void registerCollectionAdapter(java.lang.Class collectionClass, java.lang.Class adapter) throws java.lang.IllegalArgumentException
adapter
- It is assumed that this class implements the
CollectionAdapter interface.collectionClass
- The 'type' that is built by this collection adapter.
java.lang.IllegalArgumentException
- If the adapter parameter does not
implement the CollectionAdapter interface.public void setSubject(Persistence obj)
obj
- The example object we are using as the basis of the querypublic void setObjectLimit(int num)
num
- The limit on the number of objects to create.public void set(java.lang.reflect.Field adapt, java.lang.Object val, java.lang.Object originalVal)
set
in interface SetAndGetDelegateIF
set
in class ObjectEditor
adapt
- val
- originalVal
- #setValue(java.lang.Field, java.lang.Object, java.lang.Object)
public void setAsLike(boolean value)
value
- boolean indicating if this should be a "like" querypublic void setBroker(Broker b)
b
- The new Broker valuepublic void setCollectionAdapter(CollectionAdapter adapter)
adapter
- The new CollectionAdapter valuepublic void setConstraint(Persistence p)
p
- The new Constraint valuepublic void setConstraintString(java.lang.String constraints) throws java.text.ParseException
constraints
- A simple string like "name = 'Dave' && orderSize < 10"
java.text.ParseException
- The provided string is not validpublic void setDistinct(boolean b)
b
- The new Distinct valuepublic void setFieldConstraint(Persistence search, java.lang.String fieldPath, java.lang.String value, java.lang.String compareConstraintType)
search
- The persistent object that has the field?fieldPath
- Field of the 'search' param?value
- The value to use in the comparison.compareConstraintType
- A simple comparison type '=', ' <=', etc....public void setSubSelect(Persistence p, java.lang.String fieldPath, java.lang.String subSelectFieldPath, SQLQuery subSelectQuery, boolean isNot)
p
- The new SubSelect valuefieldPath
- The new SubSelect valuesubSelectFieldPath
- The new SubSelect valuesubSelectQuery
- The new SubSelect valueisNot
- The new SubSelect valuepublic void setIsanyOf(Persistence p, java.lang.String fieldName, java.util.Vector anyOf)
p
- The new IsanyOf valuefieldName
- The new IsanyOf valueanyOf
- The new IsanyOf valuepublic void setIsNotNull(Persistence p, java.lang.String fieldName)
p
- The new IsNotNull valuefieldName
- The new IsNotNull valuepublic void setIsNull(Persistence p, java.lang.String fieldName)
p
- The new IsNull valuefieldName
- The new IsNull valuepublic void setNotAnyOf(Persistence p, java.lang.String fieldName, java.util.Vector anyOf)
p
- The new NotAnyOf valuefieldName
- The new NotAnyOf valueanyOf
- The new NotAnyOf valuepublic void setOrderByList(java.util.Vector v)
v
- Vector of Strings.getOrderByList()
public Persistence getJoinConstraint()
public boolean isAttributeSearch()
public boolean isDistinct()
public int getObjectLimit()
public Broker getBroker()
public CollectionAdapter getCollectionAdapter()
public Constraint getConstraintFor(java.lang.String field)
field
- The name of a constrained field.
public java.util.List getChildConstraintFor(java.lang.String field)
field
- The name of a constrained field.
public Persistence getSubject()
public boolean isLike()
public java.util.Vector getOrderByList()
public void addConstraint(Constraint constraint)
constraint
- The constraint object representing the restricted values.public int count() throws QueryException
QueryException
public boolean fieldIsConstrained(java.lang.String field)
field
-
addConstraint(Constraint)
public java.util.Vector find() throws QueryException
QueryException
public java.lang.Object findCollection() throws QueryException
QueryException
public java.util.Vector findAttributes(java.lang.String[] attributes) throws QueryException
attributes
- A list of the attributes that are to be retrieved.
QueryException
public java.lang.Object findCollection(java.lang.Class clazz) throws QueryException
clazz
- The class of object we want as the result set value
QueryException
public java.util.Vector findIn(Persistence obj) throws QueryException
obj
- is an object that can join with the subject of this query.
QueryException
public Persistence findUnique() throws QueryException
QueryException
- One of the following occured:
public void addOrderByField(java.lang.String pathToField)
pathToField
- The feature to be added to the OrderByField attributegetOrderByList()
public void addOrderByField(java.lang.String pathToField, boolean descend)
descend
- If true, sort the results in descending order.pathToField
- The feature to be added to the OrderByField attributegetOrderByList()
public void deleteAll() throws QueryException
QueryException
protected int populateStack(java.util.Vector symbols, int idx, java.util.Stack currentStack) throws java.text.ParseException
symbols
- The reverse polish notation of all the symbols in the
constraint string.idx
- The current index of the element to process within the symbols
vectorcurrentStack
- The holder of the created Constraint objects.
java.text.ParseException
- Something wasn't right about the constraint
stringprotected void processOperator(StringCalculator.CalcItem calcItem, java.util.Vector symbols, int idx, java.util.Stack currentStack) throws java.text.ParseException
calcItem
- An item found within the constratint stringsymbols
- The reverse polish notation of all the symbols in the
constraint string.idx
- The current index of the current operation within the symbolscurrentStack
- The holder of the created Constraint objects.
java.text.ParseException
- The boolean expression did not use the correct
symbolsprotected java.lang.String stripTicks(java.lang.String aValue)
aValue
- Like "'aValue'"
protected int processBracket(StringCalculator.CalcItem calcItem, java.util.Vector symbols, int idx, java.util.Stack currentStack) throws java.text.ParseException
calcItem
- An item found within the constratint stringsymbols
- The reverse polish notation of all the symbols in the
constraint string.idx
- The current index of the "(" within the symbols vectorcurrentStack
- The holder of the created Constraint objects.
java.text.ParseException
- Something wasn't right within the brackets.public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |