private Query createQuery(boolean forCount) {
        SQLSerializer serializer = new SQLSerializer(configuration);
        if (union != null) {
            serializer.serializeUnion(union, queryMixin.getMetadata(), unionAll);
        } else {
            serializer.serialize(queryMixin.getMetadata(), forCount);
        }


        // create Query
        if (logger.isLoggable(Level.FINE)) {
            logger.fine(serializer.toString());
        }
        Query query = persistenceManager.newQuery("javax.jdo.query.SQL", serializer.toString());
        orderedConstants = serializer.getConstants();
        queries.add(query);

        if (!forCount) {
            Expression<?> projection = queryMixin.getMetadata().getProjection();
            if (projection instanceof FactoryExpression) {
                this.projection = (FactoryExpression<?>) projection;
            }
        } else {
            query.setResultClass(Long.class);
        }

        return query;
    }
Close the query and related resources
querydsl-jdo/src/main/java/com/querydsl/jdo/sql/AbstractSQLQuery.java