Package org.hibernate.engine

Examples of org.hibernate.engine.ResultSetMappingDefinition


  protected static ResultSetMappingDefinition buildResultSetMappingDefinition(Element resultSetElem, String path, Mappings mappings) {
    String resultSetName = resultSetElem.attribute( "name" ).getValue();
    if ( path != null ) {
      resultSetName = path + '.' + resultSetName;
    }
    ResultSetMappingDefinition definition = new ResultSetMappingDefinition( resultSetName );

    int cnt = 0;
    Iterator returns = resultSetElem.elementIterator();
    while ( returns.hasNext() ) {
      cnt++;
      Element returnElem = (Element) returns.next();
      String name = returnElem.getName();
      if ( "return-scalar".equals( name ) ) {
        String column = returnElem.attributeValue( "column" );
        String typeFromXML = HbmBinder.getTypeFromXML( returnElem );
        Type type = null;
        if(typeFromXML!=null) {
          type = mappings.getTypeResolver().heuristicType( typeFromXML );
          if ( type == null ) {
            throw new MappingException( "could not determine type " + type );
          }
        }
        definition.addQueryReturn( new NativeSQLQueryScalarReturn( column, type ) );
      }
      else if ( "return".equals( name ) ) {
        definition.addQueryReturn( bindReturn( returnElem, mappings, cnt ) );
      }
      else if ( "return-join".equals( name ) ) {
        definition.addQueryReturn( bindReturnJoin( returnElem, mappings ) );
      }
      else if ( "load-collection".equals( name ) ) {
        definition.addQueryReturn( bindLoadCollection( returnElem, mappings ) );
      }
    }
    return definition;
  }
View Full Code Here


   */
  public NoSQLQueryImpl(NamedSQLQueryDefinition queryDef, SessionImplementor session, ParameterMetadata parameterMetadata) {
    super( queryDef.getQueryString(), queryDef.getFlushMode(), session, parameterMetadata );
    this.session = session;
    if ( queryDef.getResultSetRef() != null ) {
      ResultSetMappingDefinition definition = session.getFactory().getResultSetMapping( queryDef.getResultSetRef() );
      if ( definition == null ) {
        throw new MappingException( "Unable to find resultset-ref definition: " + queryDef.getResultSetRef() );
      }
      this.queryReturns = new ArrayList<NativeSQLQueryReturn>( Arrays.asList( definition.getQueryReturns() ) );
    }
    else if ( queryDef.getQueryReturns() != null && queryDef.getQueryReturns().length > 0 ) {
      this.queryReturns = new ArrayList<NativeSQLQueryReturn>( Arrays.asList( queryDef.getQueryReturns() ) );
    }
    else {
View Full Code Here

    return this;
  }

  @Override
  public SQLQuery setResultSetMapping(String name) {
    ResultSetMappingDefinition mapping = session.getFactory().getResultSetMapping( name );
    if ( mapping == null ) {
      throw new MappingException( "Unknown SqlResultSetMapping [" + name + "]" );
    }
    NativeSQLQueryReturn[] returns = mapping.getQueryReturns();
    queryReturns.addAll( Arrays.asList( returns ) );
    return this;
  }
View Full Code Here

   */
  public NoSQLQueryImpl(NamedSQLQueryDefinition queryDef, SessionImplementor session, ParameterMetadata parameterMetadata) {
    super( queryDef.getQueryString(), queryDef.getFlushMode(), session, parameterMetadata );
    this.session = session;
    if ( queryDef.getResultSetRef() != null ) {
      ResultSetMappingDefinition definition = session.getFactory().getResultSetMapping( queryDef.getResultSetRef() );
      if ( definition == null ) {
        throw new MappingException( "Unable to find resultset-ref definition: " + queryDef.getResultSetRef() );
      }
      this.queryReturns = new ArrayList<NativeSQLQueryReturn>( Arrays.asList( definition.getQueryReturns() ) );
    }
    else if ( queryDef.getQueryReturns() != null && queryDef.getQueryReturns().length > 0 ) {
      this.queryReturns = new ArrayList<NativeSQLQueryReturn>( Arrays.asList( queryDef.getQueryReturns() ) );
    }
    else {
View Full Code Here

    return this;
  }

  @Override
  public SQLQuery setResultSetMapping(String name) {
    ResultSetMappingDefinition mapping = session.getFactory().getResultSetMapping( name );
    if ( mapping == null ) {
      throw new MappingException( "Unknown SqlResultSetMapping [" + name + "]" );
    }
    NativeSQLQueryReturn[] returns = mapping.getQueryReturns();
    queryReturns.addAll( Arrays.asList( returns ) );
    return this;
  }
View Full Code Here

        noSqlQuery.addEntity( "alias1", rootReturn.getReturnEntityName(), LockMode.READ );
      }
    }
    else if ( sqlDefinition.getResultSetRef() != null ) {
      SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) factory.getSessionFactory();
      ResultSetMappingDefinition resultSetMapping = sessionFactory.getResultSetMapping( sqlDefinition.getResultSetRef() );

      if ( resultSetMapping == null ) {
        throw new HibernateException( "Result set mapping '" + sqlDefinition.getResultSetRef() + "' referenced by query '" + sqlDefinition.getName() + "' does not exist." );
      }

      for (NativeSQLQueryReturn queryReturn : resultSetMapping.getQueryReturns() ) {
        if ( queryReturn instanceof NativeSQLQueryScalarReturn ) {
          noSqlQuery.addScalar( ( (NativeSQLQueryScalarReturn) queryReturn ).getColumnAlias() );
        }
        else if ( queryReturn instanceof NativeSQLQueryRootReturn ) {
          noSqlQuery.addEntity( ( (NativeSQLQueryRootReturn) queryReturn ).getReturnEntityName() );
View Full Code Here

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

  protected static ResultSetMappingDefinition buildResultSetMappingDefinition(Element resultSetElem, String path, Mappings mappings) {
    String resultSetName = resultSetElem.attribute( "name" ).getValue();
    if ( path != null ) {
      resultSetName = path + '.' + resultSetName;
    }
    ResultSetMappingDefinition definition = new ResultSetMappingDefinition( resultSetName );

    int cnt = 0;
    Iterator returns = resultSetElem.elementIterator();
    while ( returns.hasNext() ) {
      cnt++;
      Element returnElem = (Element) returns.next();
      String name = returnElem.getName();
      if ( "return-scalar".equals( name ) ) {
        String column = returnElem.attributeValue( "column" );
        String typeFromXML = HbmBinder.getTypeFromXML( returnElem );
        Type type = null;
        if(typeFromXML!=null) {
          type = TypeFactory.heuristicType( typeFromXML );
          if ( type == null ) {
            throw new MappingException( "could not determine type " + type );
          }
        }
        definition.addQueryReturn( new NativeSQLQueryScalarReturn( column, type ) );
      }
      else if ( "return".equals( name ) ) {
        definition.addQueryReturn( bindReturn( returnElem, mappings, cnt ) );
      }
      else if ( "return-join".equals( name ) ) {
        definition.addQueryReturn( bindReturnJoin( returnElem, mappings ) );
      }
      else if ( "load-collection".equals( name ) ) {
        definition.addQueryReturn( bindLoadCollection( returnElem, mappings ) );
      }
    }
    return definition;
  }
View Full Code Here

          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,
View Full Code Here

    this.path = path;
    this.mappings = mappings;
  }

  public void doSecondPass(Map persistentClasses) throws MappingException {
    ResultSetMappingDefinition definition = buildResultSetMappingDefinition( element, path, mappings);
    mappings.addResultSetMapping( definition );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.engine.ResultSetMappingDefinition

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.