/*
(non-Javadoc)

@see
javax.persistence.criteria.CriteriaBuilder#createQuery(java.lang.Class)
964110
@Override
    public <T> CriteriaQuery<T> createQuery(Class<T> returnClazz)
    {
        return new KunderaCritieriaQuery<T>(this, returnClazz);
    }
1042003
@Override
    public QueryResult execute( String query,
                                String language ) throws RepositoryException {
        logger.trace("Executing query: {0}", query);

        // Create the query ...

        final Query jcrQuery = getLocalSession().getSession().getWorkspace().getQueryManager().createQuery(query, language);
        return jcrQuery.execute();
    }
121498
protected final <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery) {
        return this.getEntityManager().createQuery(criteriaQuery);
    }
1126680
@Override
    public List executeQuery(Class clazz, List<String> relationalField, boolean isNative, String cqlQuery)
    {
        if (clazz == null)
        {
            return super.executeScalarQuery(cqlQuery);
        }
        return super.executeSelectQuery(clazz, relationalField, dataHandler, isNative, cqlQuery);
    }
43743
@Override
	public <T> QueryRequest<List<T>> query(String fql, Class<T> type) {
		return this.query(fql, mapper.getTypeFactory().constructCollectionType(ArrayList.class, type));
	}
874960
@Override
    public SqlQuery createSqlQuery(String sql) {
        Assert.hasText(sql, "sql must has text");
        return ebeanServer.createSqlQuery(sql);
    }
1026886
@Override
    @SuppressWarnings("rawtypes")
    public Query createNativeQuery(String sqlString, Class resultClass)
    {
        return ivEm.createNativeQuery(sqlString, resultClass);
    }
212659
public ResultSetAndStatement executeQuery(Query query, ClassDescriptor cld) throws PersistenceBrokerException
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("executeQuery: " + query);
        }
        /*
		 * MBAIRD: we should create a scrollable resultset if the start at
		 * index or end at index is set
		 */
        boolean scrollable = ((query.getStartAtIndex() > Query.NO_START_AT_INDEX) || (query.getEndAtIndex() > Query.NO_END_AT_INDEX));
        /*
		 * OR if the prefetching of relationships is being used.
		 */
        if (query != null && query.getPrefetchedRelationships() != null && !query.getPrefetchedRelationships().isEmpty())
        {
            scrollable = true;
        }
        final StatementManagerIF sm = broker.serviceStatementManager();
        final SelectStatement sql = broker.serviceSqlGenerator().getPreparedSelectStatement(query, cld);
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try
        {
            final int queryFetchSize = query.getFetchSize();
            final boolean isStoredProcedure = isStoredProcedure(sql.getStatement());
            stmt = sm.getPreparedStatement(cld, sql.getStatement() ,
                    scrollable, queryFetchSize, isStoredProcedure);
            if (isStoredProcedure)
            {
                // Query implemented as a stored procedure, which must return a result set.
                // Query sytax is: { ?= call PROCEDURE_NAME(?,...,?)}
                getPlatform().registerOutResultSet((CallableStatement) stmt, 1);
                sm.bindStatement(stmt, query, cld, 2);

                if (logger.isDebugEnabled())
                    logger.debug("executeQuery: " + stmt);

                stmt.execute();
                rs = (ResultSet) ((CallableStatement) stmt).getObject(1);
            }
            else
            {
                sm.bindStatement(stmt, query, cld, 1);

                if (logger.isDebugEnabled())
                    logger.debug("executeQuery: " + stmt);

                rs = stmt.executeQuery();
            }

            return new ResultSetAndStatement(sm, stmt, rs, sql);
        }
        catch (PersistenceBrokerException e)
        {
            // release resources on exception
            sm.closeResources(stmt, rs);
            logger.error("PersistenceBrokerException during the execution of the query: " + e.getMessage(), e);
            throw e;
        }
        catch (SQLException e)
        {
            // release resources on exception
            sm.closeResources(stmt, rs);
            throw ExceptionHelper.generateException(e, sql.getStatement(), null, logger, null);
        }
    }
296347
public static <T> Query<T> query(Class<T> entityType, Object queryObject) {
        return query(db(), entityType, null, queryObject, null);
    }
646750
protected <T, K extends Serializable>
    Query<T> _buildQuery(
                    final DAO<T, K>  dao,
                    final Class<T> type,
                    final QueryParams params
                    )
    {
        Query<T>  query = null;
        try {
            query = dao.createQuery();
            QueryBuilder  builder = _getQueryBuilderFactory().newBuilder( type );
            query = builder.build( query, params );
        } catch (RepositoryConfigurationException ex) {
            throw ex;
        } catch (QueryException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new QueryException( ex );
        }

        return query;
    }
259952
public void addQueryCriterion(QueryCriterion criterion){
        if( criteria == null){
            criteria = new ArrayList<QueryCriterion>();
        }
        criteria.add(criterion);
    }
934515
public static QueryBuilder byInstance(Object instance){
        Validate.argumentsAreNotNull(instance);
        return new QueryBuilder(new InstanceFilterDefinition(instance));
    }
1191206
public static DependencyQueryBuilder create(DependencyQuery query)
   {
      DependencyQueryBuilder builder = new DependencyQueryBuilder();
      builder.setCoordinate(query.getCoordinate());
      builder.setFilter(query.getDependencyFilter());
      builder.setRepositories(query.getDependencyRepositories());
      builder.setScopeType(query.getScopeType());
      return builder;
   }
413075
public QueryType<EntityBeanType<T>> getOrCreateQuery()
   {
      List<Node> nodeList = childNode.get("query");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new QueryTypeImpl<EntityBeanType<T>>(this, "query", childNode, nodeList.get(0));
      }
      return createQuery();
   }
296977
public static function createQuery() {
		if(self::$entity_manager == null)
			self::initialize();

		return call_user_func_array(array(self::$entity_manager, "createQuery"), func_get_args());
	}
436554
public static @NotNull SqlQuery query(@NotNull @SQL String sql, Object... args) {
        return new SqlQuery(sql, asList(args));
    }
997630
public static <E> OqlBuilder<E> hql(final String hql) {
    OqlBuilder<E> query = new OqlBuilder<E>();
    query.statement = hql;
    return query;
  }