Class Query
in package de.infoasset.platform.store
- Declaration
- public abstract class Query
- extends Object
- Hierarchy
java.lang.Object
de.infoasset.platform.store.Query- Known Direct Subclasses
How to Query Entitys from the Database?
Tricia uses a query API for defining filter criteria on entities. Queries are defines as objects of type Query. A query object then can be used to retrieve all matching entities from an PersistentSchema:
A simple example of a query that matches all documents with the title Thesis is defined like this:
Query q = new QueryEquals(Document.SCHEMA.prototype().title, "Thesis");The model elements which are part of the query are referenced using the prototype entity of the associated PersistentSchema (see Schema.prototype()).
Now all results can be iterated:
for (Document d : Document.SCHEMA.queryEntities(q)) {
System.out.println("match: " + d);
}
If you want to retrieve the results ordered by attribute value, you can use a
SortingCriterion:
Query q = new QueryAll(); q.addSortingCriterion(new Ascending(Document.SCHEMA.prototype().title));The complete class hierarchy of Query is given here:
How to Formulate Joins
Often it is necessary to formulate filter criteria, that span relationships to other entity types.As shown in the picture, a QueryCondition referes to instances of the interface Attribute. Since the superclass Property implements this interface, all properties can be used to formulate a query condition.
Relationships are defined using Roles, so it is necessary to get an instance of Attribute from a role in order to define a join query.
This is done by the method Role.getAttributeSignature(). This method returns the foreign key column which realizes the role in the relational database as an instance of Attribute, and can then be used to build complex join queries.
Doing so requires some knowledge about the relational mapping of the data model (see ObjectRelationalMappingDoc).

Constructor Summary
|
Constructor Detail
Query
public Query()
Method Detail
visit
public abstract Object visit(QueryVisitor v)
addJoin
public void addJoin(Join q2)
getJoins
public List getJoins()
addSortingCriterion
public void addSortingCriterion(SortingCriterion c)
getAllSortingCriterions
public List getAllSortingCriterions()
toString
public String toString()
|
Referenced by
(41)
|
0 Comments