Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.NamedQueryDefinition


      throw new AnnotationException( "A named query must have a name when used in class or package level" );
    }
    //EJBQL Query
    QueryHint[] hints = queryAnn.hints();
    String queryName = queryAnn.query();
    NamedQueryDefinition query = new NamedQueryDefinition(
        queryAnn.name(),
        queryName,
        getBoolean( queryName, "org.hibernate.cacheable", hints ),
        getString( queryName, "org.hibernate.cacheRegion", hints ),
        getTimeout( queryName, hints ),
        getInteger( queryName, "javax.persistence.lock.timeout", hints ),
        getInteger( queryName, "org.hibernate.fetchSize", hints ),
        getFlushMode( queryName, hints ),
        getCacheMode( queryName, hints ),
        getBoolean( queryName, "org.hibernate.readOnly", hints ),
        getString( queryName, "org.hibernate.comment", hints ),
        null
    );
    if ( isDefault ) {
      mappings.addDefaultQuery( query.getName(), query );
    }
    else {
      mappings.addQuery( query.getName(), query );
    }
    if ( LOG.isDebugEnabled() ) {
      LOG.debugf( "Binding named query: %s => %s", query.getName(), query.getQueryString() );
    }
  }
View Full Code Here


      throw new AnnotationException( "A named query must have a name when used in class or package level" );
    }
    FlushMode flushMode;
    flushMode = getFlushMode( queryAnn.flushMode() );

    NamedQueryDefinition query = new NamedQueryDefinition(
        queryAnn.name(),
        queryAnn.query(),
        queryAnn.cacheable(),
        BinderHelper.isEmptyAnnotationValue( queryAnn.cacheRegion() ) ? null : queryAnn.cacheRegion(),
        queryAnn.timeout() < 0 ? null : queryAnn.timeout(),
        queryAnn.fetchSize() < 0 ? null : queryAnn.fetchSize(),
        flushMode,
        getCacheMode( queryAnn.cacheMode() ),
        queryAnn.readOnly(),
        BinderHelper.isEmptyAnnotationValue( queryAnn.comment() ) ? null : queryAnn.comment(),
        null
    );

    mappings.addQuery( query.getName(), query );
    if ( LOG.isDebugEnabled() ) {
      LOG.debugf( "Binding named query: %s => %s", query.getName(), query.getQueryString() );
    }
  }
View Full Code Here

    }
    Iterator itr = namedQueries.entrySet().iterator();
    while ( itr.hasNext() ) {
      final Map.Entry entry = ( Map.Entry ) itr.next();
      final String queryName = ( String ) entry.getKey();
      final NamedQueryDefinition qd = ( NamedQueryDefinition ) entry.getValue();
      // this will throw an error if there's something wrong.
      try {
        if ( debugEnabled ) {
          LOG.debugf( "Checking named query: %s", queryName );
        }
        //TODO: BUG! this currently fails for named queries for non-POJO entities
        queryPlanCache.getHQLQueryPlan( qd.getQueryString(), false, Collections.EMPTY_MAP );
      }
      catch ( QueryException e ) {
        errors.put( queryName, e );
      }
      catch ( MappingException e ) {
        errors.put( queryName, e );
      }
    }
    if ( debugEnabled ) {
      LOG.debugf( "Checking %s named SQL queries", namedSqlQueries.size() );
    }
    itr = namedSqlQueries.entrySet().iterator();
    while ( itr.hasNext() ) {
      final Map.Entry entry = ( Map.Entry ) itr.next();
      final String queryName = ( String ) entry.getKey();
      final NamedSQLQueryDefinition qd = ( NamedSQLQueryDefinition ) entry.getValue();
      // this will throw an error if there's something wrong.
      try {
        if ( debugEnabled ) {
          LOG.debugf( "Checking named SQL query: %s", queryName );
        }
        // TODO : would be really nice to cache the spec on the query-def so as to not have to re-calc the hash;
        // currently not doable though because of the resultset-ref stuff...
        NativeSQLQuerySpecification spec;
        if ( qd.getResultSetRef() != null ) {
          ResultSetMappingDefinition definition = sqlResultSetMappings.get( qd.getResultSetRef() );
          if ( definition == null ) {
            throw new MappingException( "Unable to find resultset-ref definition: " + qd.getResultSetRef() );
          }
          spec = new NativeSQLQuerySpecification(
              qd.getQueryString(),
                  definition.getQueryReturns(),
                  qd.getQuerySpaces()
          );
        }
        else {
          spec =  new NativeSQLQuerySpecification(
              qd.getQueryString(),
                  qd.getQueryReturns(),
                  qd.getQuerySpaces()
          );
        }
        queryPlanCache.getNativeSQLQueryPlan( spec );
      }
      catch ( QueryException e ) {
View Full Code Here

    }
    Iterator itr = namedQueries.entrySet().iterator();
    while ( itr.hasNext() ) {
      final Map.Entry entry = ( Map.Entry ) itr.next();
      final String queryName = ( String ) entry.getKey();
      final NamedQueryDefinition qd = ( NamedQueryDefinition ) entry.getValue();
      // this will throw an error if there's something wrong.
      try {
        if ( debugEnabled ) {
          LOG.debugf( "Checking named query: %s", queryName );
        }
        //TODO: BUG! this currently fails for named queries for non-POJO entities
        queryPlanCache.getHQLQueryPlan( qd.getQueryString(), false, Collections.EMPTY_MAP );
      }
      catch ( QueryException e ) {
        errors.put( queryName, e );
      }
      catch ( MappingException e ) {
        errors.put( queryName, e );
      }
    }
    if ( debugEnabled ) {
      LOG.debugf( "Checking %s named SQL queries", namedSqlQueries.size() );
    }
    itr = namedSqlQueries.entrySet().iterator();
    while ( itr.hasNext() ) {
      final Map.Entry entry = ( Map.Entry ) itr.next();
      final String queryName = ( String ) entry.getKey();
      final NamedSQLQueryDefinition qd = ( NamedSQLQueryDefinition ) entry.getValue();
      // this will throw an error if there's something wrong.
      try {
        if ( debugEnabled ) {
          LOG.debugf( "Checking named SQL query: %s", queryName );
        }
        // TODO : would be really nice to cache the spec on the query-def so as to not have to re-calc the hash;
        // currently not doable though because of the resultset-ref stuff...
        NativeSQLQuerySpecification spec;
        if ( qd.getResultSetRef() != null ) {
          ResultSetMappingDefinition definition = sqlResultSetMappings.get( qd.getResultSetRef() );
          if ( definition == null ) {
            throw new MappingException( "Unable to find resultset-ref definition: " + qd.getResultSetRef() );
          }
          spec = new NativeSQLQuerySpecification(
              qd.getQueryString(),
                  definition.getQueryReturns(),
                  qd.getQuerySpaces()
          );
        }
        else {
          spec =  new NativeSQLQuerySpecification(
              qd.getQueryString(),
                  qd.getQueryReturns(),
                  qd.getQuerySpaces()
          );
        }
        queryPlanCache.getNativeSQLQueryPlan( spec );
      }
      catch ( QueryException e ) {
View Full Code Here

     *
     * @return the transformed query
     */
    public static Query createQueryWithOrderBy(EntityManager entityManager, String queryName,
        OrderingField... orderByFields) {
        NamedQueryDefinition ndc = getNamedQueryDefinition(entityManager, queryName);
        StringBuilder query = new StringBuilder(ndc.getQueryString());
        buildOrderBy(query, orderByFields);
        return entityManager.createQuery(query.toString());
    }
View Full Code Here

     * @param  countItem     the object or attribute that needs to be counted, when it's ambiguous
     *
     * @return a query that can be bound and executed to get the total count of results
     */
    public static Query createCountQuery(EntityManager entityManager, String queryName, String countItem) {
        NamedQueryDefinition namedQueryDefinition = getNamedQueryDefinition(entityManager, queryName);
        String query = namedQueryDefinition.getQueryString();

        Matcher matcher = COUNT_QUERY_PATTERN.matcher(query);
        if (!matcher.find()) {
            throw new RuntimeException("Unable to transform query into count query [" + queryName + " - " + query + "]");
        }
View Full Code Here

        return hibernateStatistics;
    }

    private static NamedQueryDefinition getNamedQueryDefinition(EntityManager entityManager, String queryName) {
        SessionFactoryImplementor sessionFactory = getHibernateSessionFactoryImplementor(entityManager);
        NamedQueryDefinition namedQueryDefinition = sessionFactory.getNamedQuery(queryName);
        if (namedQueryDefinition == null) {
            throw new RuntimeException("EJB3 query not found [" + queryName + "]");
        }

        return namedQueryDefinition;
View Full Code Here

  }

  @Override
  public Query getNamedQuery(String queryName) throws MappingException {
    errorIfClosed();
    NamedQueryDefinition nqd = factory.getNamedQuery( queryName );
    final Query query;
    if ( nqd != null ) {
      String queryString = nqd.getQueryString();
      query = new QueryImpl(
          queryString,
              nqd.getFlushMode(),
              this,
              getHQLQueryPlan( queryString, false ).getParameterMetadata()
      );
      query.setComment( "named HQL query " + queryName );
      if ( nqd.getLockTimeout() != null ) {
        ( (QueryImpl) query ).getLockOptions().setTimeOut( nqd.getLockTimeout() );
      }
    }
    else {
      NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
      if ( nsqlqd==null ) {
View Full Code Here

  //SessionImplementor methods
  @Override
  public Query getNamedQuery(String name) {
    errorIfClosed();
    NamedQueryDefinition namedQuery = factory.getNamedQuery( name );
    //ORM looks for native queries when no HQL definition is found, we do the same here.
    if (namedQuery == null) {
      return getNamedSQLQuery( name );
    }
View Full Code Here

  }

  @Override
  public Query getNamedQuery(String queryName) throws MappingException {
    errorIfClosed();
    NamedQueryDefinition nqd = factory.getNamedQuery( queryName );
    final Query query;
    if ( nqd != null ) {
      String queryString = nqd.getQueryString();
      query = new QueryImpl(
          queryString,
              nqd.getFlushMode(),
              this,
              getHQLQueryPlan( queryString, false ).getParameterMetadata()
      );
      query.setComment( "named HQL query " + queryName );
      if ( nqd.getLockTimeout() != null ) {
        ( (QueryImpl) query ).getLockOptions().setTimeOut( nqd.getLockTimeout() );
      }
    }
    else {
      NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
      if ( nsqlqd==null ) {
View Full Code Here

TOP

Related Classes of org.hibernate.engine.spi.NamedQueryDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.