Package org.hibernate.engine

Examples of org.hibernate.engine.NamedSQLQueryDefinition


    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 NamedSQLQueryDefinition(
          queryElem.getText(),
          resultSetRef,
          synchronizedTables,
          cacheable,
          region,
          timeout,
          fetchSize,
          HbmBinder.getFlushMode( queryElem.attributeValue( "flush-mode" ) ),
          HbmBinder.getCacheMode( cacheMode ),
          readOnly,
          comment,
          HbmBinder.getParameterTypes( queryElem ),
          callable
      );
      //TODO check there is no actual definition elemnents when a ref is defined
    }
    else {
      ResultSetMappingDefinition definition = buildResultSetMappingDefinition( queryElem, path, mappings );
      namedQuery = new NamedSQLQueryDefinition(
          queryElem.getText(),
          definition.getQueryReturns(),
          synchronizedTables,
          cacheable,
          region,
          timeout,
          fetchSize,
          HbmBinder.getFlushMode( queryElem.attributeValue( "flush-mode" ) ),
          HbmBinder.getCacheMode( cacheMode ),
          readOnly,
          comment,
          HbmBinder.getParameterTypes( queryElem ),
          callable
      );
    }

    log.debug( "Named SQL query: " + queryName + " -> " + namedQuery.getQueryString() );
    mappings.addSQLQuery( queryName, namedQuery );
  }
View Full Code Here


    log.debug("Checking " + namedSqlQueries.size() + " named SQL queries");
    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.debug("Checking named SQL query: " + 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

    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 NamedSQLQueryDefinition(
          queryElem.getText(),
          resultSetRef,
          synchronizedTables,
          cacheable,
          region,
          timeout,
          fetchSize,
          HbmBinder.getFlushMode( queryElem.attributeValue( "flush-mode" ) ),
          HbmBinder.getCacheMode( cacheMode ),
          readOnly,
          comment,
          HbmBinder.getParameterTypes( queryElem ),
          callable
      );
      //TODO check there is no actual definition elemnents when a ref is defined
    }
    else {
      ResultSetMappingDefinition definition = buildResultSetMappingDefinition( queryElem, path, mappings );
      namedQuery = new NamedSQLQueryDefinition(
          queryElem.getText(),
          definition.getQueryReturns(),
          synchronizedTables,
          cacheable,
          region,
          timeout,
          fetchSize,
          HbmBinder.getFlushMode( queryElem.attributeValue( "flush-mode" ) ),
          HbmBinder.getCacheMode( cacheMode ),
          readOnly,
          comment,
          HbmBinder.getParameterTypes( queryElem ),
          callable
      );
    }

    log.debug( "Named SQL query: " + queryName + " -> " + namedQuery.getQueryString() );
    mappings.addSQLQuery( queryName, namedQuery );
  }
View Full Code Here

    log.debug("Checking " + namedSqlQueries.size() + " named SQL queries");
    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.debug("Checking named SQL query: " + 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

              getHQLQueryPlan( queryString, false ).getParameterMetadata()
      );
      query.setComment( "named HQL query " + queryName );
    }
    else {
      NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
      if ( nsqlqd==null ) {
        throw new MappingException( "Named query not known: " + queryName );
      }
      query = new SQLQueryImpl(
          nsqlqd,
              this,
              factory.getQueryPlanCache().getSQLParameterMetadata( nsqlqd.getQueryString() )
      );
      query.setComment( "named native SQL query " + queryName );
      nqd = nsqlqd;
    }
    initQuery( query, nqd );
View Full Code Here

    return query;
  }

  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 NamedSQLQueryDefinition(
          queryElem.getText(),
          resultSetRef,
          synchronizedTables,
          cacheable,
          region,
          timeout,
          fetchSize,
          HbmBinder.getFlushMode( queryElem.attributeValue( "flush-mode" ) ),
          HbmBinder.getCacheMode( cacheMode ),
          readOnly,
          comment,
          HbmBinder.getParameterTypes( queryElem ),
          callable
      );
      //TODO check there is no actual definition elemnents when a ref is defined
    }
    else {
      ResultSetMappingDefinition definition = buildResultSetMappingDefinition( queryElem, path, mappings );
      namedQuery = new NamedSQLQueryDefinition(
          queryElem.getText(),
          definition.getQueryReturns(),
          synchronizedTables,
          cacheable,
          region,
          timeout,
          fetchSize,
          HbmBinder.getFlushMode( queryElem.attributeValue( "flush-mode" ) ),
          HbmBinder.getCacheMode( cacheMode ),
          readOnly,
          comment,
          HbmBinder.getParameterTypes( queryElem ),
          callable
      );
    }

    log.debug( "Named SQL query: " + queryName + " -> " + namedQuery.getQueryString() );
    mappings.addSQLQuery( queryName, namedQuery );
  }
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

              getHQLQueryPlan( queryString, false ).getParameterMetadata()
      );
      query.setComment( "named HQL query " + queryName );
    }
    else {
      NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
      if ( nsqlqd==null ) {
        throw new MappingException( "Named query not known: " + queryName );
      }
      query = new SQLQueryImpl(
          nsqlqd,
              this,
              factory.getQueryPlanCache().getSQLParameterMetadata( nsqlqd.getQueryString() )
      );
      query.setComment( "named native SQL query " + queryName );
      nqd = nsqlqd;
    }
    initQuery( query, nqd );
View Full Code Here

    return query;
  }

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