org.grails.datastore.mapping.query.Query类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(279)

本文整理了Java中org.grails.datastore.mapping.query.Query类的一些代码示例,展示了Query类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query类的具体详情如下:
包路径:org.grails.datastore.mapping.query.Query
类名称:Query

Query介绍

[英]Models a query that can be executed against a data store.
[中]为可以针对数据存储执行的查询建模。

代码示例

代码示例来源:origin: org.grails/grails-datastore-gorm-hibernate-core

  1. @Override
  2. public PersistentEntity getEntity() {
  3. if (!entityStack.isEmpty()) {
  4. return entityStack.getLast();
  5. }
  6. return super.getEntity();
  7. }

代码示例来源:origin: org.grails/grails-datastore-gorm

  1. /**
  2. * Orders by the specified property name (defaults to ascending)
  3. *
  4. * @param o The order object
  5. * @return This criteria
  6. */
  7. @Override
  8. public Criteria order(Query.Order o) {
  9. if (paginationEnabledList) {
  10. orderEntries.add(o);
  11. }
  12. else {
  13. query.order(o);
  14. }
  15. return this;
  16. }

代码示例来源:origin: org.grails/grails-datastore-core

  1. /**
  2. * Adds the specified criterion instance to the query
  3. *
  4. * @param criterion The criterion instance
  5. */
  6. public void add(Criterion criterion) {
  7. Junction currentJunction = criteria;
  8. add(currentJunction, criterion);
  9. }

代码示例来源:origin: org.grails/grails-datastore-gorm

  1. final ConversionService conversionService = query.getEntity().getMappingContext().getConversionService();
  2. if (argMap.containsKey(ARGUMENT_MAX)) {
  3. maxParam = conversionService.convert(argMap.get(ARGUMENT_MAX), Integer.class);
  4. query.join(associationName, joinType);
  5. } else {
  6. FetchType fetchType = getFetchMode(fetchValue);
  7. query.cache(ClassUtils.getBooleanFromMap(ARGUMENT_CACHE, argMap));
  8. query.lock(ClassUtils.getBooleanFromMap(ARGUMENT_LOCK, argMap));
  9. final int offset = offsetParam == null ? -1 : offsetParam;
  10. if (max > -1) {
  11. query.max(max);
  12. query.offset(offset);

代码示例来源:origin: org.grails/grails-datastore-gorm

  1. JoinType joinType = (JoinType) detachedCriteria.getJoinTypes().get(property);
  2. if(joinType != null) {
  3. query.join(property, joinType);
  4. query.join(property);
  5. query.select(property);
  6. query.add(criterion);
  7. query.projections().add(projection);
  8. query.order(order);

代码示例来源:origin: org.grails/grails-datastore-core

  1. final PropertyCriterion pc = (PropertyCriterion) criterion;
  2. String property = pc.getProperty();
  3. Object value = resolvePropertyValue(entity, property, pc.getValue());
  4. pc.setValue(value);
  5. AssociationQuery associationQuery = createQuery(ac.getAssociation().getName());
  6. for (Criterion associationCriterion : ac.getCriteria()) {
  7. associationQuery.add(associationCriterion);
  8. Junction newj;
  9. if (j instanceof Disjunction) {
  10. newj= disjunction(currentJunction);
  11. } else if (j instanceof Negation) {
  12. newj= negation(currentJunction);
  13. newj= conjunction(currentJunction);
  14. addToJunction(newj, c);

代码示例来源:origin: org.grails/grails-datastore-gorm

  1. protected Query buildQuery(DynamicFinderInvocation invocation, Class<?> clazz, Query q) {
  2. applyAdditionalCriteria(q, invocation.getCriteria());
  3. configureQueryWithArguments(clazz, q, invocation.getArguments());
  4. String operatorInUse = invocation.getOperator();
  5. if (operatorInUse != null && operatorInUse.equals(OPERATOR_OR)) {
  6. Query.Junction disjunction = q.disjunction();
  7. for (MethodExpression expression : invocation.getExpressions()) {
  8. q.add(disjunction, expression.createCriterion());
  9. }
  10. }
  11. else {
  12. for (MethodExpression expression : invocation.getExpressions()) {
  13. q.add( expression.createCriterion() );
  14. }
  15. }
  16. q.projections().count();
  17. return q;
  18. }
  19. }

代码示例来源:origin: org.grails/grails-datastore-core

  1. @Override
  2. public List query(Object primaryKey) {
  3. Association inverseSide = association.getInverseSide();
  4. Query query = session.createQuery(association.getAssociatedEntity().getJavaClass());
  5. query.eq(inverseSide.getName(), primaryKey);
  6. query.projections().id();
  7. return query.list();
  8. }

代码示例来源:origin: org.grails/grails-datastore-gorm

  1. result = query.singleResult();
  2. associationQuery = query.createQuery(property.getName());
  3. if (associationQuery instanceof AssociationQuery) {
  4. previousQuery.add((Query.Criterion) associationQuery);

代码示例来源:origin: org.grails/grails-datastore-core

  1. query.eq(association.getInverseSide().getName(), obj)
  2. .projections().id();
  3. tmp = (Serializable) query.singleResult();

代码示例来源:origin: org.grails/grails-datastore-gorm

  1. protected void applyAdditionalCriteria(Query query, Closure additionalCriteria) {
  2. if (additionalCriteria == null) {
  3. return;
  4. }
  5. CriteriaBuilder builder = new CriteriaBuilder(query.getEntity().getJavaClass(), query.getSession(), query);
  6. builder.build(additionalCriteria);
  7. }
  8. }

代码示例来源:origin: org.grails/grails-datastore-gorm

  1. public Object doInSession(final Session session) {
  2. Query q = session.createQuery(clazz);
  3. applyAdditionalCriteria(q, additionalCriteria);
  4. boolean ascending = true;
  5. if (arguments.length > 0 && (arguments[0] instanceof Map)) {
  6. final Map args = new LinkedHashMap( (Map) arguments[0] );
  7. final Object order = args.remove(DynamicFinder.ARGUMENT_ORDER);
  8. if(order != null && "desc".equalsIgnoreCase(order.toString())) {
  9. ascending = false;
  10. }
  11. DynamicFinder.populateArgumentsForCriteria(clazz, q, args);
  12. }
  13. q.order( ascending ? Query.Order.asc(propertyName) : Query.Order.desc(propertyName));
  14. q.projections().distinct();
  15. return invokeQuery(q);
  16. }
  17. });

代码示例来源:origin: org.grails/grails-datastore-gorm

  1. Query query = preQueryEvent.getQuery();
  2. PersistentEntity entity = query.getEntity();
  3. if(entity.isMultiTenant()) {
  4. if(datastore == null) {
  5. currentId = Tenants.currentId(datastore.getClass());
  6. query.eq(tenantId.getName(), currentId );

代码示例来源:origin: org.grails/grails-datastore-core

  1. @Override
  2. public Object clone() {
  3. Session session = getSession();
  4. if(session == null) throw new IllegalStateException("Cannot clone a stateless query");
  5. Query newQuery = session.createQuery(entity.getJavaClass());
  6. for (Criterion criterion : criteria.getCriteria()) {
  7. newQuery.add(criterion);
  8. }
  9. return newQuery;
  10. }

代码示例来源:origin: org.grails/grails-datastore-gorm

  1. /**
  2. * Defines and executes a list distinct query in a single call. Example: Foo.createCriteria.listDistinct { }
  3. * @param callable The closure to execute
  4. *
  5. * @return The result list
  6. */
  7. public List listDistinct(Closure callable) {
  8. ensureQueryIsInitialized();
  9. invokeClosureNode(callable);
  10. query.projections().distinct();
  11. return query.list();
  12. }

代码示例来源:origin: org.grails/grails-datastore-gorm

  1. protected Object invokeList() {
  2. Object result;
  3. result = query.list();
  4. return result;
  5. }

代码示例来源:origin: org.grails/grails-datastore-gorm

  1. protected Query buildQuery(DynamicFinderInvocation invocation, Class<?> clazz, Query query) {
  2. applyAdditionalCriteria(query, invocation.getCriteria());
  3. applyDetachedCriteria(query, invocation.getDetachedCriteria());
  4. configureQueryWithArguments(clazz, query, invocation.getArguments());
  5. final String operatorInUse = invocation.getOperator();
  6. if (operatorInUse != null && operatorInUse.equals(OPERATOR_OR)) {
  7. if (firstExpressionIsRequiredBoolean()) {
  8. MethodExpression expression = invocation.getExpressions().remove(0);
  9. query.add(expression.createCriterion());
  10. }
  11. Query.Junction disjunction = query.disjunction();
  12. for (MethodExpression expression : invocation.getExpressions()) {
  13. query.add(disjunction, expression.createCriterion());
  14. }
  15. }
  16. else {
  17. for (MethodExpression expression : invocation.getExpressions()) {
  18. query.add(expression.createCriterion());
  19. }
  20. }
  21. return query;
  22. }

代码示例来源:origin: org.grails/grails-datastore-gorm

  1. @Override
  2. public BuildableCriteria cache(boolean cache) {
  3. query.cache(cache);
  4. return this;
  5. }

代码示例来源:origin: org.grails/grails-datastore-core

  1. /**
  2. * Creates a disjunction (OR) query
  3. * @return The Junction instance
  4. */
  5. public Junction disjunction() {
  6. Junction currentJunction = criteria;
  7. return disjunction(currentJunction);
  8. }

代码示例来源:origin: org.grails/grails-datastore-core

  1. public AbstractQueryEvent(Query query) {
  2. super(query.getSession().getDatastore());
  3. this.query = query;
  4. }

相关文章