Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.NamedSQLQueryDefinition


  }

  @Override
  public Query getNamedSQLQuery(String queryName) throws MappingException {
    errorIfClosed();
    NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
    if ( nsqlqd==null ) {
      throw new MappingException( "Named SQL query not known: " + queryName );
    }
    Query query = new SQLQueryImpl(
        nsqlqd,
            this,
            factory.getQueryPlanCache().getSQLParameterMetadata( nsqlqd.getQueryString() )
    );
    query.setComment( "named native SQL query " + queryName );
    initQuery( query, nsqlqd );
    return query;
  }
View Full Code Here


    }
    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 {
        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

       * If the named query is a HQL query, use getReturnType()
       */
      org.hibernate.Query namedQuery = getSession().getNamedQuery( name );
      //TODO clean this up to avoid downcasting
      final SessionFactoryImplementor factoryImplementor = ( SessionFactoryImplementor ) entityManagerFactory.getSessionFactory();
      final NamedSQLQueryDefinition queryDefinition = factoryImplementor.getNamedSQLQuery( name );
      try {
        if ( queryDefinition != null ) {
          Class<?> actualReturnedClass;

          final NativeSQLQueryReturn[] queryReturns;
          if ( queryDefinition.getQueryReturns() != null ) {
            queryReturns = queryDefinition.getQueryReturns();
          }
          else if ( queryDefinition.getResultSetRef() != null ) {
            final ResultSetMappingDefinition rsMapping = factoryImplementor.getResultSetMapping(
                queryDefinition.getResultSetRef()
            );
            queryReturns = rsMapping.getQueryReturns();
          }
          else {
            throw new AssertionFailure( "Unsupported named query model. Please report the bug in Hibernate EntityManager");
View Full Code Here

      }
    }

    // then as a native (SQL) query
    {
      final NamedSQLQueryDefinition namedQueryDefinition = sfi.getNamedQueryRepository().getNamedSQLQueryDefinition( name );
      if ( namedQueryDefinition != null ) {
        return createNamedSqlQuery( namedQueryDefinition, resultType );
      }
    }
View Full Code Here

    if ( StringHelper.isEmpty( comment ) ) {
      comment = null;
    }

    boolean callable = getBoolean( hints, QueryHints.CALLABLE, name );
    NamedSQLQueryDefinition def;
    if ( StringHelper.isNotEmpty( resultSetMapping ) ) {
      def = new NamedSQLQueryDefinition(
          name,
          query, resultSetMapping, null, cacheable,
          cacheRegion, timeout, fetchSize,
          flushMode, cacheMode, readOnly, comment,
          null, callable
      );
    }
    else {
      AnnotationValue annotationValue = annotation.value( "resultClass" );
      if ( annotationValue == null ) {
        throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" );
      }
      NativeSQLQueryRootReturn queryRoots[] = new NativeSQLQueryRootReturn[] {
          new NativeSQLQueryRootReturn(
              "alias1",
              annotationValue.asString(),
              new HashMap<String, String[]>(),
              LockMode.READ
          )
      };
      def = new NamedSQLQueryDefinition(
          name,
          query,
          queryRoots,
          null,
          cacheable,
View Full Code Here

       * If the named query is a HQL query, use getReturnType()
       */
      org.hibernate.Query namedQuery = getSession().getNamedQuery( name );
      //TODO clean this up to avoid downcasting
      final SessionFactoryImplementor factoryImplementor = ( SessionFactoryImplementor ) entityManagerFactory.getSessionFactory();
      final NamedSQLQueryDefinition queryDefinition = factoryImplementor.getNamedSQLQuery( name );
      try {
        if ( queryDefinition != null ) {
          Class<?> actualReturnedClass;

          final NativeSQLQueryReturn[] queryReturns;
          if ( queryDefinition.getQueryReturns() != null ) {
            queryReturns = queryDefinition.getQueryReturns();
          }
          else if ( queryDefinition.getResultSetRef() != null ) {
            final ResultSetMappingDefinition rsMapping = factoryImplementor.getResultSetMapping(
                queryDefinition.getResultSetRef()
            );
            queryReturns = rsMapping.getQueryReturns();
          }
          else {
            throw new AssertionFailure( "Unsupported named query model. Please report the bug in Hibernate EntityManager");
View Full Code Here

        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 {
                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 = ( ResultSetMappingDefinition ) 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

        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 {
                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

    final Query query;
    if ( nqd != null ) {
      query = createQuery( nqd );
    }
    else {
      NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
      if ( nsqlqd==null ) {
        throw new MappingException( "Named query not known: " + queryName );
      }

      query = createSQLQuery( nsqlqd );
View Full Code Here

  }

  @Override
  public Query getNamedSQLQuery(String queryName) throws MappingException {
    errorIfClosed();
    NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
    if ( nsqlqd==null ) {
      throw new MappingException( "Named SQL query not known: " + queryName );
    }
    Query query = new SQLQueryImpl(
        nsqlqd,
            this,
            factory.getQueryPlanCache().getSQLParameterMetadata( nsqlqd.getQueryString() )
    );
    query.setComment( "named native SQL query " + queryName );
    initQuery( query, nsqlqd );
    return query;
  }
View Full Code Here

TOP

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

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.