예제 #1
0
  private Query createQuery(boolean forCount) {
    Expression<?> source = getSource();

    // serialize
    JDOQLSerializer serializer = new JDOQLSerializer(getTemplates(), source);
    serializer.serialize(queryMixin.getMetadata(), forCount, false);

    logQuery(serializer.toString());

    // create Query
    Query query = persistenceManager.newQuery(serializer.toString());
    orderedConstants = serializer.getConstants();
    queries.add(query);

    if (!forCount) {
      List<? extends Expression<?>> projection = queryMixin.getMetadata().getProjection();
      Class<?> exprType = projection.get(0).getClass();
      if (exprType.equals(QTuple.class)) {
        query.setResultClass(JDOTuple.class);
      } else if (FactoryExpression.class.isAssignableFrom(exprType)) {
        query.setResultClass(projection.get(0).getType());
      }

      if (!fetchGroups.isEmpty()) {
        query.getFetchPlan().setGroups(fetchGroups);
      }
      if (maxFetchDepth != null) {
        query.getFetchPlan().setMaxFetchDepth(maxFetchDepth);
      }
    }

    return query;
  }
예제 #2
0
 @Override
 public String toString() {
   if (!queryMixin.getMetadata().getJoins().isEmpty()) {
     Expression<?> source = getSource();
     JDOQLSerializer serializer = new JDOQLSerializer(getTemplates(), source);
     serializer.serialize(queryMixin.getMetadata(), false, false);
     return serializer.toString().trim();
   } else {
     return super.toString();
   }
 }