Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.NamedSQLQueryDefinition


  }

  @Override
  public Query getNamedSQLQuery(String queryName) {
    errorIfClosed();
    NamedSQLQueryDefinition nsqlqd = findNamedNativeQuery( queryName );
    Query query = new NoSQLQueryImpl(
        nsqlqd,
        this,
        factory.getQueryPlanCache().getSQLParameterMetadata( nsqlqd.getQuery() )
    );
    query.setComment( "named native query " + queryName );
    return query;
  }
View Full Code Here


    query.setComment( "named native query " + queryName );
    return query;
  }

  private NamedSQLQueryDefinition findNamedNativeQuery(String queryName) {
    NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
    if ( nsqlqd == null ) {
      throw new MappingException( "Named native query not found: " + queryName );
    }
    return nsqlqd;
  }
View Full Code Here

  }

  @Override
  public Query getNamedSQLQuery(String queryName) {
    errorIfClosed();
    NamedSQLQueryDefinition nsqlqd = findNamedNativeQuery( queryName );
    Query query = new NoSQLQueryImpl(
        nsqlqd,
        this,
        factory.getQueryPlanCache().getSQLParameterMetadata( nsqlqd.getQuery() )
    );
    query.setComment( "named native query " + queryName );
    return query;
  }
View Full Code Here

    query.setComment( "named native query " + queryName );
    return query;
  }

  private NamedSQLQueryDefinition findNamedNativeQuery(String queryName) {
    NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
    if ( nsqlqd == null ) {
      throw new MappingException( "Named native query not found: " + queryName );
    }
    return nsqlqd;
  }
View Full Code Here

    }

    // create and register the proper NamedQueryDefinition...
    final org.hibernate.Query hibernateQuery = ( (HibernateQuery) query ).getHibernateQuery();
    if ( org.hibernate.SQLQuery.class.isInstance( hibernateQuery ) ) {
      final NamedSQLQueryDefinition namedQueryDefinition = extractSqlQueryDefinition( ( org.hibernate.SQLQuery ) hibernateQuery, name );
      sessionFactory.registerNamedSQLQueryDefinition( name, namedQueryDefinition );
    }
    else {
      final NamedQueryDefinition namedQueryDefinition = extractHqlQueryDefinition( hibernateQuery, name );
      sessionFactory.registerNamedQueryDefinition( name, namedQueryDefinition );
View Full Code Here

       * If the named query is a HQL query, use getReturnType()
       */
      org.hibernate.Query namedQuery = internalGetSession().getNamedQuery( name );
      //TODO clean this up to avoid downcasting
      final SessionFactoryImplementor factoryImplementor = 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

    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

    }
    else {
      builder.setQueryReturns( new NativeSQLQueryReturn[0] );
    }
   
    NamedSQLQueryDefinition query = builder.createNamedQueryDefinition();
   
    if ( isDefault ) {
      mappings.addDefaultSQLQuery( query.getName(), query );
    }
    else {
      mappings.addSQLQuery( query.getName(), query );
    }
    if ( LOG.isDebugEnabled() ) {
      LOG.debugf( "Binding named native query: %s => %s", queryAnn.name(), queryAnn.query() );
    }
  }
View Full Code Here

    if ( queryAnn == null ) return;
    //ResultSetMappingDefinition mappingDefinition = mappings.getResultSetMapping( queryAnn.resultSetMapping() );
    if ( BinderHelper.isEmptyAnnotationValue( queryAnn.name() ) ) {
      throw new AnnotationException( "A named query must have a name when used in class or package level" );
    }
    NamedSQLQueryDefinition query;
    String resultSetMapping = queryAnn.resultSetMapping();
    if ( !BinderHelper.isEmptyAnnotationValue( resultSetMapping ) ) {
      //sql result set usage
      query = new NamedSQLQueryDefinitionBuilder().setName( queryAnn.name() )
          .setQuery( queryAnn.query() )
          .setResultSetRef( resultSetMapping )
          .setQuerySpaces( null )
          .setCacheable( queryAnn.cacheable() )
          .setCacheRegion(
              BinderHelper.isEmptyAnnotationValue( queryAnn.cacheRegion() ) ?
                  null :
                  queryAnn.cacheRegion()
          )
          .setTimeout( queryAnn.timeout() < 0 ? null : queryAnn.timeout() )
          .setFetchSize( queryAnn.fetchSize() < 0 ? null : queryAnn.fetchSize() )
          .setFlushMode( getFlushMode( queryAnn.flushMode() ) )
          .setCacheMode( getCacheMode( queryAnn.cacheMode() ) )
          .setReadOnly( queryAnn.readOnly() )
          .setComment( BinderHelper.isEmptyAnnotationValue( queryAnn.comment() ) ? null : queryAnn.comment() )
          .setParameterTypes( null )
          .setCallable( queryAnn.callable() )
          .createNamedQueryDefinition();
    }
    else if ( !void.class.equals( queryAnn.resultClass() ) ) {
      //class mapping usage
      //FIXME should be done in a second pass due to entity name?
      final NativeSQLQueryRootReturn entityQueryReturn =
          new NativeSQLQueryRootReturn( "alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ );
      query = new NamedSQLQueryDefinitionBuilder().setName( queryAnn.name() )
          .setQuery( queryAnn.query() )
          .setQueryReturns( new NativeSQLQueryReturn[] {entityQueryReturn} )
          .setQuerySpaces( null )
          .setCacheable( queryAnn.cacheable() )
          .setCacheRegion(
              BinderHelper.isEmptyAnnotationValue( queryAnn.cacheRegion() ) ?
                  null :
                  queryAnn.cacheRegion()
          )
          .setTimeout( queryAnn.timeout() < 0 ? null : queryAnn.timeout() )
          .setFetchSize( queryAnn.fetchSize() < 0 ? null : queryAnn.fetchSize() )
          .setFlushMode( getFlushMode( queryAnn.flushMode() ) )
          .setCacheMode( getCacheMode( queryAnn.cacheMode() ) )
          .setReadOnly( queryAnn.readOnly() )
          .setComment( BinderHelper.isEmptyAnnotationValue( queryAnn.comment() ) ? null : queryAnn.comment() )
          .setParameterTypes( null )
          .setCallable( queryAnn.callable() )
          .createNamedQueryDefinition();
    }
    else {
      throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" );
    }
    mappings.addSQLQuery( query.getName(), query );
    if ( LOG.isDebugEnabled() ) {
      LOG.debugf( "Binding named native query: %s => %s", query.getName(), queryAnn.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.