Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.NamedSQLQueryDefinition


    }
    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 ( nqd.getLockOptions() != null ) {
        query.setLockOptions( nqd.getLockOptions() );
      }
    }
    else {
      NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
      if ( nsqlqd==null ) {
        throw new MappingException( "Named query not known: " + queryName );
      }
      ParameterMetadata parameterMetadata = factory.getQueryPlanCache().getSQLParameterMetadata( nsqlqd.getQueryString() );
      query = new SQLQueryImpl(
          nsqlqd,
              this,
          parameterMetadata
      );
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

    while ( tables.hasNext() ) {
      synchronizedTables.add( ( (Element) tables.next() ).attributeValue( "table" ) );
    }
    boolean callable = "true".equals( queryElem.attributeValue( "callable" ) );

    NamedSQLQueryDefinition namedQuery;
    Attribute ref = queryElem.attribute( "resultset-ref" );
    String resultSetRef = ref == null ? null : ref.getValue();
    if ( StringHelper.isNotEmpty( resultSetRef ) ) {
      namedQuery = new NamedSQLQueryDefinitionBuilder().setName( queryName )
          .setQuery( queryElem.getText() )
          .setResultSetRef( resultSetRef )
          .setQuerySpaces( synchronizedTables )
          .setCacheable( cacheable )
          .setCacheRegion( region )
          .setTimeout( timeout )
          .setFetchSize( fetchSize )
          .setFlushMode( FlushMode.interpretExternalSetting( queryElem.attributeValue( "flush-mode" ) ) )
          .setCacheMode( CacheMode.interpretExternalSetting( cacheMode ) )
          .setReadOnly( readOnly )
          .setComment( comment )
          .setParameterTypes( HbmBinder.getParameterTypes( queryElem ) )
          .setCallable( callable )
          .createNamedQueryDefinition();
      //TODO check there is no actual definition elemnents when a ref is defined
    }
    else {
      ResultSetMappingDefinition definition = buildResultSetMappingDefinition( queryElem, path, mappings );
      namedQuery = new NamedSQLQueryDefinitionBuilder().setName( queryName )
          .setQuery( queryElem.getText() )
          .setQueryReturns( definition.getQueryReturns() )
          .setQuerySpaces( synchronizedTables )
          .setCacheable( cacheable )
          .setCacheRegion( region )
          .setTimeout( timeout )
          .setFetchSize( fetchSize )
          .setFlushMode( FlushMode.interpretExternalSetting( queryElem.attributeValue( "flush-mode" ) ) )
          .setCacheMode( CacheMode.interpretExternalSetting( cacheMode ) )
          .setReadOnly( readOnly )
          .setComment( comment )
          .setParameterTypes( HbmBinder.getParameterTypes( queryElem ) )
          .setCallable( callable )
          .createNamedQueryDefinition();
    }

    if ( LOG.isDebugEnabled() ) {
      LOG.debugf( "Named SQL query: %s -> %s", namedQuery.getName(), namedQuery.getQueryString() );
    }
    mappings.addSQLQuery( queryName, namedQuery );
  }
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

    }
    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

  public static void bindNativeQuery(NamedNativeQuery queryAnn, Mappings mappings, boolean isDefault) {
    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();
    QueryHint[] hints = queryAnn.hints();
    String queryName = queryAnn.query();
    if ( !BinderHelper.isEmptyAnnotationValue( resultSetMapping ) ) {
      //sql result set usage
      query = new NamedSQLQueryDefinition(
          queryAnn.name(),
          queryName,
          resultSetMapping,
          null,
          getBoolean( queryName, "org.hibernate.cacheable", hints ),
          getString( queryName, "org.hibernate.cacheRegion", hints ),
          getTimeout( queryName, 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,
          getBoolean( queryName, "org.hibernate.callable", hints )
      );
    }
    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 NamedSQLQueryDefinition(
          queryAnn.name(),
          queryName,
          new NativeSQLQueryReturn[] { entityQueryReturn },
          null,
          getBoolean( queryName, "org.hibernate.cacheable", hints ),
          getString( queryName, "org.hibernate.cacheRegion", hints ),
          getTimeout( queryName, 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,
          getBoolean( queryName, "org.hibernate.callable", hints )
      );
    }
    else {
      throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" );
    }
    if ( isDefault ) {
      mappings.addDefaultSQLQuery( query.getName(), query );
    }
    else {
      mappings.addSQLQuery( query.getName(), query );
    }
        LOG.debugf( "Binding named native query: %s => %s", queryAnn.name(), queryAnn.query() );
  }
View Full Code Here

  public static void bindNativeQuery(org.hibernate.annotations.NamedNativeQuery queryAnn, Mappings mappings) {
    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 NamedSQLQueryDefinition(
          queryAnn.name(),
          queryAnn.query(),
          resultSetMapping,
          null,
          queryAnn.cacheable(),
          BinderHelper.isEmptyAnnotationValue( queryAnn.cacheRegion() ) ? null : queryAnn.cacheRegion(),
          queryAnn.timeout() < 0 ? null : queryAnn.timeout(),
          queryAnn.fetchSize() < 0 ? null : queryAnn.fetchSize(),
          getFlushMode( queryAnn.flushMode() ),
          getCacheMode( queryAnn.cacheMode() ),
          queryAnn.readOnly(),
          BinderHelper.isEmptyAnnotationValue( queryAnn.comment() ) ? null : queryAnn.comment(),
          null,
          queryAnn.callable()
      );
    }
    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 NamedSQLQueryDefinition(
          queryAnn.name(),
          queryAnn.query(),
          new NativeSQLQueryReturn[] { entityQueryReturn },
          null,
          queryAnn.cacheable(),
          BinderHelper.isEmptyAnnotationValue( queryAnn.cacheRegion() ) ? null : queryAnn.cacheRegion(),
          queryAnn.timeout() < 0 ? null : queryAnn.timeout(),
          queryAnn.fetchSize() < 0 ? null : queryAnn.fetchSize(),
          getFlushMode( queryAnn.flushMode() ),
          getCacheMode( queryAnn.cacheMode() ),
          queryAnn.readOnly(),
          BinderHelper.isEmptyAnnotationValue( queryAnn.comment() ) ? null : queryAnn.comment(),
          null,
          queryAnn.callable()
      );
    }
    else {
      throw new NotYetImplementedException( "Pure native scalar queries are not yet supported" );
    }
    mappings.addSQLQuery( query.getName(), query );
        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.