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

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

本文整理了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

@Override
public PersistentEntity getEntity() {
  if (!entityStack.isEmpty()) {
    return entityStack.getLast();
  }
  return super.getEntity();
}

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

/**
 * Orders by the specified property name (defaults to ascending)
 *
 * @param o The order object
 * @return This criteria
 */
@Override
public Criteria order(Query.Order o) {
  if (paginationEnabledList) {
    orderEntries.add(o);
  }
  else {
    query.order(o);
  }
  return this;
}

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

/**
 * Adds the specified criterion instance to the query
 *
 * @param criterion The criterion instance
 */
public void add(Criterion criterion) {
  Junction currentJunction = criteria;
  add(currentJunction, criterion);
}

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

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

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

JoinType joinType = (JoinType) detachedCriteria.getJoinTypes().get(property);
    if(joinType != null) {
      query.join(property, joinType);
      query.join(property);
    query.select(property);
query.add(criterion);
query.projections().add(projection);
query.order(order);

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

final PropertyCriterion pc = (PropertyCriterion) criterion;
String property = pc.getProperty();
Object value = resolvePropertyValue(entity, property, pc.getValue());
pc.setValue(value);
AssociationQuery associationQuery = createQuery(ac.getAssociation().getName());
for (Criterion associationCriterion : ac.getCriteria()) {
  associationQuery.add(associationCriterion);
Junction newj;
if (j instanceof Disjunction) {
  newj= disjunction(currentJunction);
} else if (j instanceof Negation) {
  newj= negation(currentJunction);
  newj= conjunction(currentJunction);
  addToJunction(newj, c);

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

protected Query buildQuery(DynamicFinderInvocation invocation, Class<?> clazz, Query q) {
    applyAdditionalCriteria(q, invocation.getCriteria());
    configureQueryWithArguments(clazz, q, invocation.getArguments());

    String operatorInUse = invocation.getOperator();
    if (operatorInUse != null && operatorInUse.equals(OPERATOR_OR)) {
      Query.Junction disjunction = q.disjunction();

      for (MethodExpression expression : invocation.getExpressions()) {
        q.add(disjunction, expression.createCriterion());
      }
    }
    else {
      for (MethodExpression expression : invocation.getExpressions()) {
        q.add( expression.createCriterion() );
      }
    }

    q.projections().count();
    return q;
  }
}

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

@Override
public List query(Object primaryKey) {
  Association inverseSide = association.getInverseSide();
  Query query = session.createQuery(association.getAssociatedEntity().getJavaClass());
  query.eq(inverseSide.getName(), primaryKey);
  query.projections().id();
  return query.list();
}

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

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

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

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

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

protected void applyAdditionalCriteria(Query query, Closure additionalCriteria) {
    if (additionalCriteria == null) {
      return;
    }

    CriteriaBuilder builder = new CriteriaBuilder(query.getEntity().getJavaClass(), query.getSession(), query);
    builder.build(additionalCriteria);
  }
}

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

public Object doInSession(final Session session) {
    Query q = session.createQuery(clazz);
    applyAdditionalCriteria(q, additionalCriteria);
    boolean ascending = true;
    if (arguments.length > 0 && (arguments[0] instanceof Map)) {
      final Map args = new LinkedHashMap( (Map) arguments[0] );
      final Object order = args.remove(DynamicFinder.ARGUMENT_ORDER);
      if(order != null && "desc".equalsIgnoreCase(order.toString())) {
        ascending = false;
      }
      DynamicFinder.populateArgumentsForCriteria(clazz, q, args);
    }
    q.order( ascending ? Query.Order.asc(propertyName) : Query.Order.desc(propertyName));
    q.projections().distinct();
    return invokeQuery(q);
  }
});

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

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

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

@Override
public Object clone() {
  Session session = getSession();
  if(session == null) throw new IllegalStateException("Cannot clone a stateless query");
  Query newQuery = session.createQuery(entity.getJavaClass());
  for (Criterion criterion : criteria.getCriteria()) {
    newQuery.add(criterion);
  }
  return newQuery;
}

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

/**
 * Defines and executes a list distinct query in a single call. Example: Foo.createCriteria.listDistinct { }
 * @param callable The closure to execute
 *
 * @return The result list
 */
public List listDistinct(Closure callable) {
  ensureQueryIsInitialized();
  invokeClosureNode(callable);
  query.projections().distinct();
  return query.list();
}

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

protected Object invokeList() {
  Object result;
  result = query.list();
  return result;
}

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

protected Query buildQuery(DynamicFinderInvocation invocation, Class<?> clazz, Query query) {
  applyAdditionalCriteria(query, invocation.getCriteria());
  applyDetachedCriteria(query, invocation.getDetachedCriteria());
  configureQueryWithArguments(clazz, query, invocation.getArguments());
  final String operatorInUse = invocation.getOperator();
  if (operatorInUse != null && operatorInUse.equals(OPERATOR_OR)) {
    if (firstExpressionIsRequiredBoolean()) {
      MethodExpression expression = invocation.getExpressions().remove(0);
      query.add(expression.createCriterion());
    }
    Query.Junction disjunction = query.disjunction();
    for (MethodExpression expression : invocation.getExpressions()) {
      query.add(disjunction, expression.createCriterion());
    }
  }
  else {
    for (MethodExpression expression : invocation.getExpressions()) {
      query.add(expression.createCriterion());
    }
  }
  return query;
}

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

@Override
public BuildableCriteria cache(boolean cache) {
  query.cache(cache);
  return this;
}

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

/**
 * Creates a disjunction (OR) query
 * @return The Junction instance
 */
public Junction disjunction() {
  Junction currentJunction = criteria;
  return disjunction(currentJunction);
}

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

public AbstractQueryEvent(Query query) {
  super(query.getSession().getDatastore());
  this.query = query;
}

相关文章