/** * Runs a query against the database. The query is expressed as a {@link TableCriteria} object plus a * query string to be merged with it (the typical case of a search in a crud defined by a query). * The query string is processed with an {@link OgnlSqlFormat}, so it can access values from the OGNL context, * as well as from an (optional) root object. * @param session the session * @param queryString the query * @param criteria the search criteria to merge with the query. * @param rootObject the root object passed to the ognl evaluator (can be null). * @param firstResult index of the first result to return * @param maxResults maximum number of results to return * @return at most <code>maxResults</code> results from the query */ public static List<Object> getObjects( Session session, String queryString, TableCriteria criteria, @Nullable Object rootObject, @Nullable Integer firstResult, @Nullable Integer maxResults) { QueryStringWithParameters result = mergeQuery(queryString, criteria, rootObject); return runHqlQuery(session, result.getQueryString(), result.getParameters(), firstResult, maxResults); }
getQueryStringWithParametersForCriteria( criteria, mainEntityAlias != null ? mainEntityAlias.getName() : null, parameters.length + 1); String criteriaQueryString = criteriaQuery.getQueryString(); Object[] criteriaParameters = criteriaQuery.getParameters(); mergedParametersList.toArray(mergedParameters); return new QueryStringWithParameters(fullQueryString, mergedParameters);
@Nullable TableCriteria criteria, @Nullable String alias, int initialParameterIndex) { if (criteria == null) { return new QueryStringWithParameters("", new Object[0]); parametersList.toArray(parameters); return new QueryStringWithParameters(queryString, parameters);
getQueryStringWithParametersForCriteria( criteria, mainEntityAlias != null ? mainEntityAlias.getName() : null, parameters.length + 1); String criteriaQueryString = criteriaQuery.getQueryString(); Object[] criteriaParameters = criteriaQuery.getParameters(); mergedParametersList.toArray(mergedParameters); return new QueryStringWithParameters(fullQueryString, mergedParameters);
@Nullable TableCriteria criteria, @Nullable String alias, int initialParameterIndex) { if (criteria == null) { return new QueryStringWithParameters("", new Object[0]); parametersList.toArray(parameters); return new QueryStringWithParameters(queryString, parameters);
String formatString = sqlFormat.getFormatString(); Object[] parameters = sqlFormat.evaluateOgnlExpressions(this); QueryStringWithParameters cacheKey = new QueryStringWithParameters(formatString, parameters); Collection<Object[]> objects = getFromQueryCache(current, cacheKey); if(objects == null) { String queryString = queryWithParameters.getQueryString(); Object[] parameters = queryWithParameters.getParameters(); logger.debug("Query not in cache: {}", queryString); try {
/** * Runs a query, expressed as {@link TableCriteria}, against the database. * @param session the session * @param criteria the search criteria * @param firstResult index of the first result to return * @param maxResults maximum number of results to return * @return at most <code>maxResults</code> results from the query */ public static List<Object> getObjects( Session session, TableCriteria criteria, @Nullable Integer firstResult, @Nullable Integer maxResults) { QueryStringWithParameters queryStringWithParameters = getQueryStringWithParametersForCriteria(criteria); return runHqlQuery( session, queryStringWithParameters.getQueryString(), queryStringWithParameters.getParameters(), firstResult, maxResults ); }
String formatString = sqlFormat.getFormatString(); Object[] parameters = sqlFormat.evaluateOgnlExpressions(this); QueryStringWithParameters cacheKey = new QueryStringWithParameters(formatString, parameters); Collection<Object[]> objects = getFromQueryCache(current, cacheKey); if(objects == null) { String queryString = queryWithParameters.getQueryString(); Object[] parameters = queryWithParameters.getParameters(); logger.debug("Query not in cache: {}", queryString); try {
/** * Runs a query, expressed as {@link TableCriteria}, against the database. * @param session the session * @param criteria the search criteria * @param firstResult index of the first result to return * @param maxResults maximum number of results to return * @return at most <code>maxResults</code> results from the query */ public static List<Object> getObjects( Session session, TableCriteria criteria, @Nullable Integer firstResult, @Nullable Integer maxResults) { QueryStringWithParameters queryStringWithParameters = getQueryStringWithParametersForCriteria(criteria); return runHqlQuery( session, queryStringWithParameters.getQueryString(), queryStringWithParameters.getParameters(), firstResult, maxResults ); }
/** * Runs a query against the database. The query is expressed as a {@link TableCriteria} object plus a * query string to be merged with it (the typical case of a search in a crud defined by a query). * The query string is processed with an {@link OgnlSqlFormat}, so it can access values from the OGNL context, * as well as from an (optional) rootFactory object. * @param session the session * @param queryString the query * @param criteria the search criteria to merge with the query. * @param rootObject the rootFactory object passed to the ognl evaluator (can be null). * @param firstResult index of the first result to return * @param maxResults maximum number of results to return * @return at most <code>maxResults</code> results from the query */ public static List<Object> getObjects( Session session, String queryString, TableCriteria criteria, @Nullable Object rootObject, @Nullable Integer firstResult, @Nullable Integer maxResults) { QueryStringWithParameters result = mergeQuery(queryString, criteria, rootObject); return runHqlQuery(session, result.getQueryString(), result.getParameters(), firstResult, maxResults); }
protected long calculateTotalSearchRecords() { // calculate totalRecords TableCriteria criteria = new TableCriteria(baseTable); if(searchForm != null) { searchForm.configureCriteria(criteria); } QueryStringWithParameters query = QueryUtils.mergeQuery(getBaseQuery(), criteria, this); String queryString = query.getQueryString(); String totalRecordsQueryString; try { totalRecordsQueryString = generateCountQuery(queryString); } catch (JSQLParserException e) { throw new Error(e); } //TODO gestire count non disponibile (totalRecordsQueryString == null) List<Object> result = QueryUtils.runHqlQuery (session, totalRecordsQueryString, query.getParameters()); return totalSearchRecords = ((Number) result.get(0)).longValue(); }
protected long calculateTotalSearchRecords() { // calculate totalRecords TableCriteria criteria = new TableCriteria(baseTable); if(searchForm != null) { searchForm.configureCriteria(criteria); } QueryStringWithParameters query = QueryUtils.mergeQuery(getBaseQuery(), criteria, this); String queryString = query.getQueryString(); String totalRecordsQueryString; try { totalRecordsQueryString = generateCountQuery(queryString); } catch (JSQLParserException e) { throw new Error(e); } //TODO gestire count non disponibile (totalRecordsQueryString == null) List<Object> result = QueryUtils.runHqlQuery (session, totalRecordsQueryString, query.getParameters()); return totalSearchRecords = ((Number) result.get(0)).longValue(); }
QueryUtils.runHqlQuery(session, queryString.getQueryString(), queryString.getParameters()); availableAssociations = new ArrayList<Object>(); String manyQueryString = ((DatabaseSelectionProvider) manySelectionProvider.getActualSelectionProvider()).getHql(); QueryUtils.mergeQuery(manyQueryString, null, this); potentiallyAvailableAssociations = QueryUtils.runHqlQuery(session, manyQuery.getQueryString(), manyQuery.getParameters()); PropertyAccessor[] manyKeyProperties = manyTableAccessor.getKeyProperties();
QueryUtils.runHqlQuery(session, queryString.getQueryString(), queryString.getParameters()); availableAssociations = new ArrayList<Object>(); String manyQueryString = ((DatabaseSelectionProvider) manySelectionProvider.getActualSelectionProvider()).getHql(); QueryUtils.mergeQuery(manyQueryString, null, this); potentiallyAvailableAssociations = QueryUtils.runHqlQuery(session, manyQuery.getQueryString(), manyQuery.getParameters()); PropertyAccessor[] manyKeyProperties = manyTableAccessor.getKeyProperties();