Package org.nuiton.topia.framework
Class TopiaQuery
java.lang.Object
org.nuiton.topia.framework.TopiaQuery
@Deprecated
public class TopiaQuery
extends java.lang.Object
Deprecated.
since 2.6.12,
TopiaQuery will be removed in version 3.0Query HQL managment to simplify usage of
TopiaContext.findAll(String,
Object...).
TODO-FD20091224 JUnit Tests
This class is used to construct a HQL query and then execute it from a
TopiaContext. The TopiaQuery is linked to a TopiaEntity which
is the main element manipulated in the query. There is two parts in using
this class :
- construction of the query, using add, addFrom, addOrder, addSelect,
addGroup, ...
- execution of the query, using executeToEntityList, executeToEntity,
executeToInteger, ...
Construction
============
This class make easier the way to construct a HQL query.
Example 1 :
-----------
SQL :
"SELECT * FROM PersonImpl WHERE firstName LIKE 'M%' AND year > 1980"
HQL using TopiaContext.findAll(String, Object...) :
TopiaContext context = rootContext.beginTransaction();
context.find("FROM " + Person.class.getName() + " WHERE firstName LIKE
:firstName AND year > :year",
"firstName", "M%", year, 1980);
TopiaQuery :
TopiaQuery query = TopiaQuery.createQuery(Person.class).add(
Person.FIRST_NAME, Op.LIKE, "M%").add(Person.YEAR, Op.GT, 1980);
But the real advantage is when you have some parameters to test before
adding
them to the query. With the older method, it was tidious to construct
and add parameters to finally use the find method from TopiaContext.
Example 2 :
-----------
HQL using TopiaContext.findAll(String, Object...) :
TopiaContext context = rootContext.beginTransaction();
String query = "FROM " + Person.class.getName();
List<Object> params = new ArrayList<>();
String separator = " WHERE ";
// company parameter can be null
if (company != null) {
query += separator + "company = :company";
params.add("company");
params.add(company);
separator = " AND ";
}
// contact paramater can be null
if (contact != null) {
query += separator + "contact = :contact";
params.add("contact");
params.add(contact);
separator = " AND ";
}
context.findAll(query, params.toArray());
Here we have only two non obligatory params, but imagine if we must have
almost 6 or 7 parameters like this !
TopiaQuery :
TopiaQuery query = TopiaQuery.createQuery(Person.class);
if (company != null) {
query.add(Person.COMPANY, company);
}
if (contact != null) {
query.add(Person.CONTACT, contact);
}
Many ways to create the same query :
------------------------------------
You can use multiple different manners to create a query, it depends on the
complexicity. More complex is the query, more easier is to construct it.
HQL : "FROM PersonImpl AS P WHERE (P.company IS NULL OR P.company =
:company)
AND P.firstName LIKE :firstName"
Using TopiaQuery and an Alias (these different queries are equivalent) :
query = TopiaQuery.createQuery(Person.class, "P");
1- query.add("(P.company IS NULL OR P.company = :company") AND P.firstName
LIKE :firstName")
.addParam("company", company).addParam("firstName",firstName + "%");
2- query.add("P.company IS NULL OR P.company = :company")
.add("P.firstName LIKE :firstName").addParam("company", company)
.addParam("firstName",firstName + "%");
3- query.add("P.company IS NULL OR P.company = :company")
.add("P.firstName", Op.LIKE, firstName + "%")
.addParam("company", company);
4- query.addNullOr("P.company", Op.EQ, company).
add("P.firstName", Op.LIKE, firstName + "%");
You can use TopiaQuery to create a subquery in an other TopiaQuery, you have
to use the method fullQuery() to get the full query in HQL and
give
it as a string in the other TopiaQuery.
Execution
=========
After construction, you can execute the query in different ways.
Default method :
----------------
- execute : as the same result as
TopiaContext.findAll(String, Object...)
Depends on entity type ;
------------------------
- executeToEntity : only one result, the first one
- executeToEntityList : all results returned in a List
- executeToEntityMap : all results returned in a Map with key defined by
user
or topiaId by default
For aggregate :
---------------
These methods have in argument the SELECT to execute the query. The previous
SELECT (if defined) will not be deleted, but temporarly not used.
- executeToInteger : for example for "SUM", "COUNT"
- executeToString : for example for "MAX"
- executeCount : directly a "count(*)"
- executeToObject : for other type of possible result (Long, Boolean,
Double,
...)
Property loading
================
When using Hibernate, some times, Entities linked to the main one will be
lazy initialized, but you want them directly when the query will be executed
to avoid problems when closing context. You can use the method
addLoad(String...) to tell the TopiaQuery to load some
properties when executing the query. After that, you don't need to call them
for loading them in Hibernate.
The syntax is the same as a property in HQL query using delegation :
"person.company" where person and company are entities.
Note : loading only available on collection or entities but not property
on a collection of entities which must be made manually.
For a Contact which is linked to a person (entity) and the person linked to
company (entity) you can add to a TopiaQuery<Contact> :
query.addLoad("person.company")
For a list of addresses (entity) in the contact you can do :
query.addLoad("addresses")
But it's not possible to do for example with meeting (entity) linked to the
contact and responsible (entity) linked to a meeting :
query.addLoad("meetings.responsible")
Created: 21 déc. 2009- Since:
- 2.3.0
- Version:
- $Revision$
- Author:
- fdesbois
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTopiaQuery.OpDeprecated.Enum to simmplify using operation in query. -
Field Summary
Fields Modifier and Type Field Description protected booleandistinctDeprecated.protected java.lang.IntegerendIndexDeprecated.protected java.lang.StringBuilderfromDeprecated.From part of the query.static java.lang.StringFROM_SEPARATOR_DEFAULTDeprecated.static java.lang.StringFROM_SEPARATOR_JOINDeprecated.static java.lang.StringFROM_SEPARATOR_LEFT_JOINDeprecated.protected java.util.List<java.lang.String>groupBysDeprecated.To keep GROUP BY part of the query filled by user.protected java.lang.StringmainAliasDeprecated.protected java.util.List<java.lang.String>orderBysDeprecated.To keep ORDER BY part of the query filled by user.protected java.util.List<java.lang.Object>paramsDeprecated.Params for HQL query.protected java.util.List<java.lang.String>propertiesToLoadDeprecated.protected java.lang.IntegerstartIndexDeprecated.protected java.util.List<java.lang.String>userSelectsDeprecated.To keep SELECT part of the query filled by user.protected java.util.List<java.lang.String>wheresDeprecated.To keep WHERE part of the query filled by user. -
Constructor Summary
Constructors Constructor Description TopiaQuery()Deprecated.TopiaQuery(java.lang.Class<? extends TopiaEntity> mainEntityClass)Deprecated.Create a TopiaQuery based on theentityClass.TopiaQuery(java.lang.Class<? extends TopiaEntity> mainEntityClass, java.lang.String alias)Deprecated.Create a TopiaQuery based on theentityClass. -
Method Summary
Modifier and Type Method Description TopiaQueryadd(java.lang.String where)Deprecated.since 2.3.4, useaddWhere(String)insteadTopiaQueryadd(java.lang.String paramName, java.lang.Object... paramValue)Deprecated.since 2.3.4, useaddEquals(String, Object...)insteadTopiaQueryadd(java.lang.String paramName, TopiaQuery.Op constraint, java.lang.Object paramValue)Deprecated.since 2.3.4, useaddWhere(String, Op, Object)insteadTopiaQueryadd(java.util.Map<java.lang.String,java.lang.Object> properties)Deprecated.since 2.3.4 useaddEquals(Map)TopiaQueryaddBetween(java.lang.String paramName, java.lang.Object value1, java.lang.Object value2)Deprecated.Add an element with BETWEEN operation.TopiaQueryaddDistinct()Deprecated.Add the distinct key word in the query.TopiaQueryaddEquals(java.lang.String paramName, java.lang.Object... paramValue)Deprecated.Add an element to the query.TopiaQueryaddEquals(java.util.Map<java.lang.String,java.lang.Object> properties)Deprecated.Add a map of properties to the where clause of the query.TopiaQueryaddFetch(java.lang.String... properties)Deprecated.Used to load properties during query execution using FETCH keyword.TopiaQueryaddFilter(EntityFilter filter)Deprecated.Add afilterto the query that contains limit indexes, orderBy condition and referenceId if needed.TopiaQueryaddFilter(EntityFilter filter, java.lang.String propertyToFilter)Deprecated.Add afilterto the query that contains limit indexes, orderBy condition and referenceId if needed.TopiaQueryaddFrom(java.lang.Class<? extends TopiaEntity> entityClass)Deprecated.Add an other entity type to the from in the query.TopiaQueryaddFrom(java.lang.Class<? extends TopiaEntity> entityClass, java.lang.String alias)Deprecated.Add an other entity type to the from in the query with an alias.TopiaQueryaddFrom(java.lang.String str)Deprecated.since 2.3.4 use correct addFrom or addJoin or addLeftJoinprotected TopiaQueryaddFrom(java.lang.String separator, java.lang.String property, java.lang.String alias)Deprecated.Add an element to the from in the query.protected TopiaQueryaddFromJoin(java.lang.String separator, java.lang.String property, java.lang.String alias, boolean fetch)Deprecated.TopiaQueryaddGroup(java.lang.String... group)Deprecated.Add an element to the group of the query.TopiaQueryaddInElements(java.lang.String elementProperty, java.lang.String containerProperty)Deprecated.Add link constraint between two properties.TopiaQueryaddJoin(java.lang.String property, java.lang.String alias, boolean fetch)Deprecated.Add a inner joinpropertyto the query withalias.TopiaQueryaddLeftJoin(java.lang.String property, java.lang.String alias, boolean fetch)Deprecated.Add a left joinpropertyto the query withalias.TopiaQueryaddLoad(java.lang.String... properties)Deprecated.Add a property to load when query is executed.TopiaQueryaddNotNull(java.lang.String paramName)Deprecated.Add an element to the query with the constraint Not null.TopiaQueryaddNull(java.lang.String paramName)Deprecated.Add an element to the query with the constraint null.TopiaQueryaddNullOr(java.lang.String paramName, TopiaQuery.Op constraint, java.lang.Object paramValue)Deprecated.Add an element to the query.TopiaQueryaddOrder(java.lang.String... order)Deprecated.Add an element to the order in the query.TopiaQueryaddOrderDesc(java.lang.String order)Deprecated.TopiaQueryaddParam(java.lang.String id, java.lang.Object paramValue)Deprecated.Add a HQL parameter to the Query.TopiaQueryaddParams(java.util.List<java.lang.Object> params)Deprecated.Add muliple paramaters to the Query.TopiaQueryaddSelect(java.lang.String... select)Deprecated.Add an element to the select in the query.TopiaQueryaddSubQuery(java.lang.String queryPart, TopiaQuery subquery)Deprecated.Method used to add a subquery in an existing query.TopiaQueryaddWhere(java.lang.String where)Deprecated.Add a where element to the Query.TopiaQueryaddWhere(java.lang.String paramName, TopiaQuery.Op operator, java.lang.Object paramValue)Deprecated.Add an element to the query.java.util.Listexecute(TopiaContext transaction)Deprecated.Simple execution of the query.intexecuteCount(TopiaContext transaction)Deprecated.Execute a simple count on the query, i.e. the number of results get from the query.<E extends TopiaEntity>
EexecuteToEntity(TopiaContext transaction, java.lang.Class<E> entityClass)Deprecated.Execute the query and get the first result entity.<E extends TopiaEntity>
java.util.List<E>executeToEntityList(TopiaContext transaction, java.lang.Class<E> entityClass)Deprecated.Execute the query and get a List of entity.<E extends TopiaEntity>
java.util.Map<java.lang.String,E>executeToEntityMap(TopiaContext transaction, java.lang.Class<E> entityClass)Deprecated.Execute the query and get a Map of entity with topiaId in key.<E extends TopiaEntity, K>
java.util.Map<K,E>executeToEntityMap(TopiaContext transaction, java.lang.Class<E> entityClass, java.lang.String keyName, java.lang.Class<K> keyClass)Deprecated.Execute the query and get a Map of entity with key type in argument.intexecuteToInteger(TopiaContext transaction, java.lang.String select)Deprecated.Execute the query and get an Integer for result.java.lang.ObjectexecuteToObject(TopiaContext transaction, java.lang.String select)Deprecated.Execute the query and get an Object for result.java.lang.StringexecuteToString(TopiaContext transaction, java.lang.String select)Deprecated.Execute the query and get a String for result.protected voidfinalize()Deprecated.java.lang.StringfullQuery()Deprecated.Get the full query.java.lang.StringgetMainAlias()Deprecated.Return the mainAlias set from constructor.java.util.List<java.lang.Object>getParams()Deprecated.protected java.util.List<java.lang.String>getPropertiesToLoad()Deprecated.static java.lang.StringgetProperty(java.lang.String... entityProperty)Deprecated.This method is used to concat properties from entities.java.lang.StringgetPropertyCreateDate(java.lang.String alias)Deprecated.java.lang.StringgetPropertyId(java.lang.String alias)Deprecated.java.lang.StringgetPropertyVersion(java.lang.String alias)Deprecated.protected java.lang.StringgetValueName(java.lang.String paramName)Deprecated.protected booleanisUserSelectEqualsMainAlias()Deprecated.protected <T extends TopiaEntity>
TopiaEntityloadEntityProperty(T entity, java.lang.String property)Deprecated.Load a property of type TopiaEntity from an other entity.protected voidloadProperties(TopiaEntity entity)Deprecated.Load all properties for the entity.protected <T extends TopiaEntity>
java.lang.ObjectloadProperty(T entity, java.lang.String property)Deprecated.Load a property from an entity.TopiaQueryresetLimit()Deprecated.Remove limits previously setTopiaQuerysetFrom(java.lang.Class<? extends TopiaEntity> mainEntityClass)Deprecated.Set the mainEntity in the from part of the query.TopiaQuerysetFrom(java.lang.Class<? extends TopiaEntity> mainEntityClass, java.lang.String alias)Deprecated.Set the mainEntity in the from part of the query and use an alias for this mainEntity.TopiaQuerysetLimit(int start, int end)Deprecated.Limit the result of the query with startIndex and endIndex.TopiaQuerysetMaxResults(int max)Deprecated.Set the max results wanted for the query.TopiaQuerysetSelect(java.lang.String... select)Deprecated.Set the select in the query.java.lang.StringtoString()Deprecated.
-
Field Details
-
FROM_SEPARATOR_DEFAULT
public static final java.lang.String FROM_SEPARATOR_DEFAULTDeprecated.- See Also:
- Constant Field Values
-
FROM_SEPARATOR_JOIN
public static final java.lang.String FROM_SEPARATOR_JOINDeprecated.- See Also:
- Constant Field Values
-
FROM_SEPARATOR_LEFT_JOIN
public static final java.lang.String FROM_SEPARATOR_LEFT_JOINDeprecated.- See Also:
- Constant Field Values
-
params
protected java.util.List<java.lang.Object> paramsDeprecated.Params for HQL query. -
userSelects
protected java.util.List<java.lang.String> userSelectsDeprecated.To keep SELECT part of the query filled by user.- Since:
- 2.6.7
-
groupBys
protected java.util.List<java.lang.String> groupBysDeprecated.To keep GROUP BY part of the query filled by user.- Since:
- 2.6.7
-
orderBys
protected java.util.List<java.lang.String> orderBysDeprecated.To keep ORDER BY part of the query filled by user.- Since:
- 2.6.7
-
wheres
protected java.util.List<java.lang.String> wheresDeprecated.To keep WHERE part of the query filled by user.- Since:
- 2.6.7
-
distinct
protected boolean distinctDeprecated. -
from
protected java.lang.StringBuilder fromDeprecated.From part of the query. -
startIndex
protected java.lang.Integer startIndexDeprecated. -
endIndex
protected java.lang.Integer endIndexDeprecated. -
propertiesToLoad
protected java.util.List<java.lang.String> propertiesToLoadDeprecated. -
mainAlias
protected java.lang.String mainAliasDeprecated.
-
-
Constructor Details
-
TopiaQuery
public TopiaQuery()Deprecated. -
TopiaQuery
Deprecated.Create a TopiaQuery based on theentityClass. The from statement is automatically set.- Parameters:
mainEntityClass- used as from part of the query
-
TopiaQuery
Deprecated.Create a TopiaQuery based on theentityClass. The from statement is automatically set, the select statement must be necessary in some case, the query will manage this case using the mainAlias by default.- Parameters:
mainEntityClass- used as from part of the queryalias- for the mainEntityClass
-
-
Method Details
-
setFrom
Deprecated.Set the mainEntity in the from part of the query.- Parameters:
mainEntityClass- type of the mainEntity- Returns:
- the TopiaQuery
-
setFrom
public TopiaQuery setFrom(java.lang.Class<? extends TopiaEntity> mainEntityClass, java.lang.String alias)Deprecated.Set the mainEntity in the from part of the query and use an alias for this mainEntity.- Parameters:
mainEntityClass- type of the mainEntityalias- for the entity in the query- Returns:
- the TopiaQuery
-
addFrom
Deprecated.since 2.3.4 use correct addFrom or addJoin or addLeftJoinAdd an element to the from in the query. Used to add some other data in the query. The default separator used is the ", ".- Parameters:
str- the element to add- Returns:
- the TopiaQuery
- See Also:
addFrom(Class, String),addJoin(String, String, boolean),addLeftJoin(String, String, boolean)
-
addFrom
protected TopiaQuery addFrom(java.lang.String separator, java.lang.String property, java.lang.String alias)Deprecated.Add an element to the from in the query. Used to add some other data in the query or for join as specificseparator.- Parameters:
property- the property to addalias- alias of the property to add in form part of the queryseparator- The separator to use before adding the element (if null theFROM_SEPARATOR_DEFAULTwill be used).- Returns:
- the TopiaQuery
- Since:
- 2.3.4
-
addJoin
Deprecated.Add a inner joinpropertyto the query withalias. The join is done in From statement as : FROM Contact C JOIN C.boat B. The added part is 'JOIN C.boat B' using addJoin("C.boat", "B", false). The order of callingaddFrom(Class, String)or this method is very important. The first element in the FROM is always the main entity of the query.- Parameters:
property- Property name to use as a Joinalias- Alias of the property in the queryfetch- Add FETCH keyword to load the property in result (avoid lazy initialization)- Returns:
- the TopiaQuery
- Since:
- 2.3.4
-
addLeftJoin
Deprecated.Add a left joinpropertyto the query withalias. The join is done in From statement as : FROM Contact C LEFT JOIN C.boat B. The added part is 'LEFT JOIN C.boat B' using addJoin("C.boat", "B", false). The order of callingaddFrom(Class, String)or this method is very important. The first element in the FROM is always the main entity of the query.- Parameters:
property- Property name to use as a Joinalias- Alias of the property in the queryfetch- Add FETCH keyword to load the property in result (avoid lazy initialization)- Returns:
- the TopiaQuery
- Since:
- 2.3.4
-
addFromJoin
protected TopiaQuery addFromJoin(java.lang.String separator, java.lang.String property, java.lang.String alias, boolean fetch)Deprecated. -
addFrom
Deprecated.Add an other entity type to the from in the query.- Parameters:
entityClass- different from the mainEntity- Returns:
- the TopiaQuery
-
addFrom
public TopiaQuery addFrom(java.lang.Class<? extends TopiaEntity> entityClass, java.lang.String alias)Deprecated.Add an other entity type to the from in the query with an alias.- Parameters:
entityClass- different from the mainEntityalias- of the entity in the query- Returns:
- the TopiaQuery
-
fullQuery
public java.lang.String fullQuery()Deprecated.Get the full query.- Returns:
- a String corresponding to the full query.
-
addParam
Deprecated.Add a HQL parameter to the Query.- Parameters:
id- identification of the param in the queryparamValue- value of the param- Returns:
- the TopiaQuery
-
addParams
Deprecated.Add muliple paramaters to the Query. The key of each param will be tested if not already exist in the existing params list and will be renamed in this case.- Parameters:
params- a list of HQL params with key and value in order.- Returns:
- the TopiaQuery
- See Also:
getValueName(String)
-
getParams
public java.util.List<java.lang.Object> getParams()Deprecated. -
getMainAlias
public java.lang.String getMainAlias()Deprecated.Return the mainAlias set from constructor.- Returns:
- a String or null if no alias is set
-
addLoad
Deprecated.Add a property to load when query is executed. Used to avoid LazyInitializationException for property needed after closing context. The property is a string like those in HQL query.Exemples : - "person.company" (Property TopiaEntity person linked to the result entity in query and company linked to person) --> calling myEntity.getPerson().getCompany(); - "partyRoles" (Property Collection partyRoles linked to the result entity in query) --> calling myEntity.getPartyRoles().size();
- Parameters:
properties- List of properties to load- Returns:
- the TopiaQuery
-
addFetch
Deprecated.Used to load properties during query execution using FETCH keyword. This keyword is used in a JOIN, so the alias is needed to identify properties to load. Also an empty SELECT statement will be defined to retrieve the correct entity depends on the mainEntity type in the query. Carefull using addFetch, hibernate doesn't support more than 3 or 4 join. In this case, you can useaddLoad(String...)or load manually the entities wanted.- Parameters:
properties- Properties to load during query execution- Returns:
- the TopiaQuery
-
getPropertiesToLoad
protected java.util.List<java.lang.String> getPropertiesToLoad()Deprecated. -
add
Deprecated.since 2.3.4, useaddWhere(String)instead- Parameters:
where- Where statement to add- Returns:
- TopiaQuery
-
addWhere
Deprecated.Add a where element to the Query. Could be anything. Parentheses are added automatically (even if there are not needed).- Parameters:
where- element to add- Returns:
- the TopiaQuery
- Since:
- 2.3.4
-
add
@Deprecated public TopiaQuery add(java.lang.String paramName, TopiaQuery.Op constraint, java.lang.Object paramValue)Deprecated.since 2.3.4, useaddWhere(String, Op, Object)instead- Parameters:
paramName- name of the parameter to addconstraint- constraint to useparamValue- value of this parameter- Returns:
- TopiaQuery
-
addWhere
public TopiaQuery addWhere(java.lang.String paramName, TopiaQuery.Op operator, java.lang.Object paramValue)Deprecated.Add an element to the query. The parameter will be automatically added. Theoperatoris needed to determine what type of operation it is. Ex : add("boat", Op.EQ, boat) means -> boat = :boat. Also if the paramValue is Null, the paramName will be added to the query with the constraint null (IS NULL). TODO-fdesbois-2010-05-26 : maybe manage more than one paramValue with Object... Depends on operator- Parameters:
paramName- the name of the parameter in the query (attribute of the entity)operator- the operation concernedparamValue- the value of the parameter (an other entity, a String, ...)- Returns:
- the TopiaQuery
- Since:
- 2.3.4
-
getValueName
protected java.lang.String getValueName(java.lang.String paramName)Deprecated. -
add
Deprecated.since 2.3.4, useaddEquals(String, Object...)instead- Parameters:
paramName- name of the parameter to addparamValue- value of this parameter- Returns:
- TopiaQuery
- Since:
- 2.3.1
-
addEquals
Deprecated.Add an element to the query. The parameter will be automatically added. The default constrainst operation is Op.EQ for EQUALS. Ex : add("boat", boat) means -> boat = :boat. If you add more than one values, the statement IN will be used. You can also have a null value in theparamValuelist (except if it's the only one value, it's ambiguous). Note : this method do nothing if theparamValueis not defined. You can also setparamValueto null if you want theparamNameto be null in the query.- Parameters:
paramName- name of the parameter in the queryparamValue- values of the parameter- Returns:
- the TopiaQuery
- Since:
- 2.3.4
- See Also:
addWhere(String, Op, Object)
-
add
Deprecated.since 2.3.4 useaddEquals(Map)- Parameters:
properties- map of the properties to add- Returns:
- TopiaQuery
-
addEquals
Deprecated.Add a map of properties to the where clause of the query. Each property will be added to the query with Op.EQ operation, the key in the map is the property name, and the value is the value of the parameter in the query.- Parameters:
properties- to add to the query- Returns:
- the TopiaQuery
- Since:
- 2.3.4
-
addNotNull
Deprecated.Add an element to the query with the constraint Not null.- Parameters:
paramName- name of the parameter in the query- Returns:
- the TopiaQuery
-
addNullOr
public TopiaQuery addNullOr(java.lang.String paramName, TopiaQuery.Op constraint, java.lang.Object paramValue)Deprecated.Add an element to the query. The nullity is tested or a constraint is added for that element. Ex : addNullOr("begin", Op.GT, new Date()) means begin IS NULL OR begin > :begin (where :begin = new Date()).- Parameters:
paramName- the name of the parameter in the query (attribute of the entity)constraint- the operation concerned by the orparamValue- the value of the parameter (an other entity, a String, ...)- Returns:
- the TopiaQuery
-
addNull
Deprecated.Add an element to the query with the constraint null.- Parameters:
paramName- name of the parameter in the query- Returns:
- the TopiaQuery
-
addBetween
public TopiaQuery addBetween(java.lang.String paramName, java.lang.Object value1, java.lang.Object value2)Deprecated.Add an element with BETWEEN operation. TheparamNamewill be found betweenvalue1andvalue2. Useful for date manipulations.- Parameters:
paramName- The name of the parameter in the query (entity property)value1- First valuevalue2- Second value- Returns:
- the TopiaQuery
-
addInElements
public TopiaQuery addInElements(java.lang.String elementProperty, java.lang.String containerProperty)Deprecated.Add link constraint between two properties.elementPropertyis in elements ofcontainerPropertywhich is a collection with same type thanelementProperty. (HQL : elementProperty IN elements (containerProperty))- Parameters:
elementProperty- contains in containerProperty collectioncontainerProperty- collection which contains elementProperty- Returns:
- the TopiaQuery
- Since:
- 2.3.4
-
addSubQuery
Deprecated.Method used to add a subquery in an existing query. The params will be automatically checked and copied from the subquery to the current one. This method is used to injectsubqueryin WHERE part of the query. ThequeryPartis the element in the query to bind with thesubquery. The ? character is used to inject the subquery into thequeryPart. Ex :// Add a SUB_ELMT = (subquery) into the query query.addSubQuery("SUB_ELMT = (?)", subquery, false);- Parameters:
queryPart- part of the query where subquery need to be injectedsubquery- existing topiaQuery as subquery- Returns:
- the TopiaQuery
- Since:
- 2.3.4
- See Also:
getValueName(String)
-
addSelect
Deprecated.Add an element to the select in the query. Depends on the result wanted in execute methods. The main entity will be automatically added only if an alias is initialize from constructor. If you want only this select element, usesetSelect(String...)method instead.- Parameters:
select- element to add- Returns:
- the TopiaQuery
-
setSelect
Deprecated.Set the select in the query. Depends on the result wanted in execute methods.- Parameters:
select- element to set- Returns:
- the TopiaQuery
-
addDistinct
Deprecated.Add the distinct key word in the query. The result will not have multiple same values.- Returns:
- the TopiaQuery
-
addOrder
Deprecated.Add an element to the order in the query. Used to add some parameters to order by.- Parameters:
order- element to add- Returns:
- the TopiaQuery
-
addOrderDesc
Deprecated. -
addGroup
Deprecated.Add an element to the group of the query. Used to add some paramters to group by.- Parameters:
group- element to add- Returns:
- the TopiaQuery
-
setLimit
Deprecated.Limit the result of the query with startIndex and endIndex.- Parameters:
start- first index to get from the resultsend- last index to get from the results- Returns:
- the TopiaQuery
-
resetLimit
Deprecated.Remove limits previously set- Returns:
- the TopiaQuery
-
setMaxResults
Deprecated.Set the max results wanted for the query.- Parameters:
max- the number of elements wanted- Returns:
- the TopiaQuery
-
addFilter
Deprecated.Add afilterto the query that contains limit indexes, orderBy condition and referenceId if needed. The referenceProperty is necessary to use the referenceId of thefilter. The filter will be applied on the main entity in the query (using the mainAlias if necessary). Note : the default orderBy is the topiaCreateDate ordered desc (the most recent in first)- Parameters:
filter- Filter to apply on the query- Returns:
- the TopiaQuery
- Throws:
java.lang.IllegalArgumentException- if referenceId is defined but no referenceProperty was set- See Also:
addFilter(EntityFilter, String)
-
addFilter
public TopiaQuery addFilter(EntityFilter filter, java.lang.String propertyToFilter) throws java.lang.IllegalArgumentExceptionDeprecated.Add afilterto the query that contains limit indexes, orderBy condition and referenceId if needed. In some case it's necessary to specify explicitely thepropertyToFilterin complex queries. The referenceProperty need to be specifie infilterto have a correspondance between the referenceId and it's property in the query. By default, thepropertyToFilteris the mainAlias of the query. Note : the default orderBy is the topiaCreateDate ordered desc (the most recent in first)- Parameters:
filter- Filter to apply on the querypropertyToFilter- Explicit property to filter- Returns:
- the TopiaQuery
- Throws:
java.lang.IllegalArgumentException- if referenceId is defined but no referenceProperty was set
-
execute
Deprecated.Simple execution of the query. This method use directly the find method in TopiaContext interface.- Parameters:
transaction- the TopiaContext to use for execution- Returns:
- a List of results
- Throws:
TopiaException- for error on query execution- See Also:
TopiaContext.findAll(String, Object...)
-
executeToEntityList
public <E extends TopiaEntity> java.util.List<E> executeToEntityList(TopiaContext transaction, java.lang.Class<E> entityClass) throws TopiaException, java.lang.ClassCastExceptionDeprecated.Execute the query and get a List of entity. Some properties will be loaded if they are prealably set using $addLoad(String...).- Type Parameters:
E- entity type- Parameters:
transaction- the TopiaContext to use for executionentityClass- used to check return type of execution results- Returns:
- a List of TopiaEntity corresponding to the entityClass in argument
- Throws:
TopiaException- for error on query executionjava.lang.ClassCastException- if entityClass doesn't match to results
-
executeToEntityMap
public <E extends TopiaEntity, K> java.util.Map<K,E> executeToEntityMap(TopiaContext transaction, java.lang.Class<E> entityClass, java.lang.String keyName, java.lang.Class<K> keyClass) throws TopiaException, java.lang.ClassCastExceptionDeprecated.Execute the query and get a Map of entity with key type in argument. Some properties will be loaded if they are prealably set using $addLoad(String...).- Type Parameters:
E- entity typeK- the type of the map key- Parameters:
transaction- the TopiaContext to use for executionentityClass- needed to execute the querykeyName- the property name of the key in the entitykeyClass- the key class for the result map- Returns:
- a Map with the key type defined and the entity in value
- Throws:
TopiaException- for error on query executionjava.lang.ClassCastException- if entityClass doesn't match to results
-
executeToEntityMap
public <E extends TopiaEntity> java.util.Map<java.lang.String,E> executeToEntityMap(TopiaContext transaction, java.lang.Class<E> entityClass) throws TopiaException, java.lang.ClassCastExceptionDeprecated.Execute the query and get a Map of entity with topiaId in key. Some properties will be loaded if they are prealably set using $addLoad(String...).- Type Parameters:
E- entity type- Parameters:
transaction- the TopiaContext to use for executionentityClass- used to check return type of execution results- Returns:
- a Map with the key type defined and the entity in value
- Throws:
TopiaException- for error on query executionjava.lang.ClassCastException- if entityClass doesn't match to results
-
executeToEntity
public <E extends TopiaEntity> E executeToEntity(TopiaContext transaction, java.lang.Class<E> entityClass) throws TopiaException, java.lang.ClassCastExceptionDeprecated.Execute the query and get the first result entity. Some properties will be loaded if they are prealably set using $addLoad(String...).- Type Parameters:
E- entity type- Parameters:
transaction- the TopiaContext to use for executionentityClass- used to check return type of execution results- Returns:
- a TopiaEntity corresponding to the entityClass in argument
- Throws:
TopiaException- for error on query executionjava.lang.ClassCastException- if entityClass doesn't match to results
-
executeToObject
public java.lang.Object executeToObject(TopiaContext transaction, java.lang.String select) throws TopiaExceptionDeprecated.Execute the query and get an Object for result. The select is overriden to get only the right value for return.- Parameters:
transaction- the TopiaContext to use for executionselect- the Select overriden- Returns:
- an Object
- Throws:
TopiaException- for error on query execution
-
executeToInteger
public int executeToInteger(TopiaContext transaction, java.lang.String select) throws TopiaExceptionDeprecated.Execute the query and get an Integer for result. Used only for query with aggration select which return a Long : COUNT, SUM ... The select is overriden to get only the right value for return.- Parameters:
transaction- the TopiaContext to use for executionselect- the Select overriden (ex : SUM(myParam))- Returns:
- an Integer
- Throws:
TopiaException- for error on query execution
-
executeToString
public java.lang.String executeToString(TopiaContext transaction, java.lang.String select) throws TopiaExceptionDeprecated.Execute the query and get a String for result. Used for query with MAX, ... The select is overriden to get only the right value for return.- Parameters:
transaction- the TopiaContext to use for executionselect- the Select overriden (ex : MAX(myParam))- Returns:
- a String
- Throws:
TopiaException- for error on query execution
-
executeCount
Deprecated.Execute a simple count on the query, i.e. the number of results get from the query. The order is not considered to count the elements and will be temporarly disabled. The distinct constraint will be manage if necessary :COUNT(DISTINCT mainAlias)
- Parameters:
transaction- the TopiaContext to use for execution- Returns:
- an int corresponding to the number of result in the query
- Throws:
TopiaException- for error on query execution
-
isUserSelectEqualsMainAlias
protected boolean isUserSelectEqualsMainAlias()Deprecated. -
loadProperties
Deprecated.Load all properties for the entity.- Parameters:
entity- used to load properties- Throws:
TopiaException- for error on query execution
-
loadEntityProperty
protected <T extends TopiaEntity> TopiaEntity loadEntityProperty(T entity, java.lang.String property) throws TopiaExceptionDeprecated.Load a property of type TopiaEntity from an other entity.- Type Parameters:
T- type of the entity extends TopiaEntity- Parameters:
entity- used to load the propertyproperty- name of the property in the entity- Returns:
- a TopiaEntity corresponding to the property loaded
- Throws:
TopiaException- for error on query execution
-
loadProperty
protected <T extends TopiaEntity> java.lang.Object loadProperty(T entity, java.lang.String property) throws TopiaExceptionDeprecated.Load a property from an entity.- Type Parameters:
T- type of the entity extends TopiaEntity- Parameters:
entity- used to load the propertyproperty- name of the property in the entity- Returns:
- an Object corresponding to the property loaded
- Throws:
TopiaException- for error loading property (encapsulate IllegalACessException, InvocationTargetException, NoSuchMethodException)
-
getProperty
public static java.lang.String getProperty(java.lang.String... entityProperty)Deprecated.This method is used to concat properties from entities. Ex in HQL you can have boat.shipOwner.name, these properties are defined as constants in each entity associated (SHIP_OWNER in Boat entity, NAME in ShipOwner entity) so you just have to call this method as :getProperty("boat", Boat.SHIP_OWNER, ShipOwner.NAME); // will return boat.shipOwner.nameIt's better to use constants instead of directly the string chain to avoid problems on changing property name in model. Furthermore it's better to use this method instead of doing :"boat." + Boat.SHIP_OWNER + "." + ShipOwner.NAME
- Parameters:
entityProperty- to concat- Returns:
- the string chain with properties separated with a dot
-
getPropertyId
public java.lang.String getPropertyId(java.lang.String alias)Deprecated. -
getPropertyCreateDate
public java.lang.String getPropertyCreateDate(java.lang.String alias)Deprecated. -
getPropertyVersion
public java.lang.String getPropertyVersion(java.lang.String alias)Deprecated. -
finalize
protected void finalize() throws java.lang.ThrowableDeprecated.- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
toString
public java.lang.String toString()Deprecated.- Overrides:
toStringin classjava.lang.Object
-