Package org.hibernate.impl

Examples of org.hibernate.impl.AbstractQueryImpl


    if ( ! AbstractQueryImpl.class.isInstance( query ) ) {
      throw new IllegalStateException( "Unknown query type for parameter extraction" );
    }

    HashSet<Parameter<?>> parameters = new HashSet<Parameter<?>>();
    AbstractQueryImpl queryImpl = AbstractQueryImpl.class.cast( query );

    // extract named params
    for ( String name : (Set<String>) queryImpl.getParameterMetadata().getNamedParameterNames() ) {
      final NamedParameterDescriptor descriptor =
          queryImpl.getParameterMetadata().getNamedParameterDescriptor( name );
      Class javaType = namedParameterTypeRedefinition.get( name );
      if ( javaType != null ) {
        descriptor.resetExpectedType(
            TypeFactory.heuristicType( javaType.getName() )
        );
      }
      else if ( descriptor.getExpectedType() != null ) {
        javaType = descriptor.getExpectedType().getReturnedClass();
      }
      final ParameterImpl parameter = new ParameterImpl( name, javaType );
      parameters.add( parameter );
      if ( descriptor.isJpaStyle() ) {
        if ( jpaPositionalIndices == null ) {
          jpaPositionalIndices = new HashSet<Integer>();
        }
        jpaPositionalIndices.add( Integer.valueOf( name ) );
      }
    }

    // extract positional parameters
    for ( int i = 0, max = queryImpl.getParameterMetadata().getOrdinalParameterCount(); i < max; i++ ) {
      final OrdinalParameterDescriptor descriptor =
          queryImpl.getParameterMetadata().getOrdinalParameterDescriptor( i+1 );
      ParameterImpl parameter = new ParameterImpl(
          i + 1,
          descriptor.getExpectedType() == null
              ? null
              : descriptor.getExpectedType().getReturnedClass()
View Full Code Here


    if ( ! AbstractQueryImpl.class.isInstance( query ) ) {
      throw new IllegalStateException( "Unknown query type for parameter extraction" );
    }

    HashSet<Parameter<?>> parameters = new HashSet<Parameter<?>>();
    AbstractQueryImpl queryImpl = AbstractQueryImpl.class.cast( query );

    // extract named params
    for ( String name : (Set<String>) queryImpl.getParameterMetadata().getNamedParameterNames() ) {
      final NamedParameterDescriptor descriptor =
          queryImpl.getParameterMetadata().getNamedParameterDescriptor( name );
      Class javaType = namedParameterTypeRedefinition.get( name );
      if ( javaType != null ) {
        descriptor.resetExpectedType(
            TypeFactory.heuristicType( javaType.getName() )
        );
      }
      else if ( descriptor.getExpectedType() != null ) {
        javaType = descriptor.getExpectedType().getReturnedClass();
      }
      final ParameterImpl parameter = new ParameterImpl( name, javaType );
      parameters.add( parameter );
      if ( descriptor.isJpaStyle() ) {
        if ( jpaPositionalIndices == null ) {
          jpaPositionalIndices = new HashSet<Integer>();
        }
        jpaPositionalIndices.add( Integer.valueOf( name ) );
      }
    }

    // extract positional parameters
    for ( int i = 0, max = queryImpl.getParameterMetadata().getOrdinalParameterCount(); i < max; i++ ) {
      final OrdinalParameterDescriptor descriptor =
          queryImpl.getParameterMetadata().getOrdinalParameterDescriptor( i+1 );
      ParameterImpl parameter = new ParameterImpl(
          i + 1,
          descriptor.getExpectedType() == null
              ? null
              : descriptor.getExpectedType().getReturnedClass()
View Full Code Here

          "loading entity: " + persister.getEntityName() +
          " using named query: " + queryName
        );
    }
   
    AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedQuery(queryName);
    if ( query.hasNamedParameters() ) {
      query.setParameter(
          query.getNamedParameters()[0],
          id,
          persister.getIdentifierType()
        );
    }
    else {
      query.setParameter( 0, id, persister.getIdentifierType() );
    }
    query.setOptionalId(id);
    query.setOptionalEntityName( persister.getEntityName() );
    query.setOptionalObject(optionalObject);
    query.setFlushMode( FlushMode.MANUAL );
    query.list();
   
    // now look up the object we are really interested in!
    // (this lets us correctly handle proxies and multi-row
    // or multi-column queries)
    return session.getPersistenceContext()
View Full Code Here

  }

  public void testQueryCacheModes() {
    EntityManager em = getOrCreateEntityManager();
    Query jpaQuery = em.createQuery( "from SimpleEntity" );
    AbstractQueryImpl hibQuery = (AbstractQueryImpl) ( (HibernateQuery) jpaQuery ).getHibernateQuery();

    jpaQuery.setHint( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.USE );
    assertEquals( CacheStoreMode.USE, jpaQuery.getHints().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
    assertEquals( CacheMode.NORMAL, hibQuery.getCacheMode() );

    jpaQuery.setHint( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.BYPASS );
    assertEquals( CacheStoreMode.BYPASS, jpaQuery.getHints().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
    assertEquals( CacheMode.GET, hibQuery.getCacheMode() );

    jpaQuery.setHint( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.REFRESH );
    assertEquals( CacheStoreMode.REFRESH, jpaQuery.getHints().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
    assertEquals( CacheMode.REFRESH, hibQuery.getCacheMode() );

    jpaQuery.setHint( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE, CacheRetrieveMode.BYPASS );
    assertEquals( CacheRetrieveMode.BYPASS, jpaQuery.getHints().get( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE ) );
    assertEquals( CacheStoreMode.REFRESH, jpaQuery.getHints().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
    assertEquals( CacheMode.REFRESH, hibQuery.getCacheMode() );

    jpaQuery.setHint( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.BYPASS );
    assertEquals( CacheRetrieveMode.BYPASS, jpaQuery.getHints().get( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE ) );
    assertEquals( CacheStoreMode.BYPASS, jpaQuery.getHints().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
    assertEquals( CacheMode.IGNORE, hibQuery.getCacheMode() );

    jpaQuery.setHint( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.USE );
    assertEquals( CacheRetrieveMode.BYPASS, jpaQuery.getHints().get( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE ) );
    assertEquals( CacheStoreMode.USE, jpaQuery.getHints().get( AvailableSettings.SHARED_CACHE_STORE_MODE ) );
    assertEquals( CacheMode.PUT, hibQuery.getCacheMode() );
  }
View Full Code Here

    em.getTransaction().commit();
    em.close();
  }

  private int countGeneratedParameters(Query query) {
    AbstractQueryImpl hqlQueryImpl = (AbstractQueryImpl) query;
    return hqlQueryImpl.getParameterMetadata().getNamedParameterNames().size();
  }
View Full Code Here

  }

  public Object load(Serializable id, Object optionalObject, SessionImplementor session) {
        LOG.debugf("Loading entity: %s using named query: %s", persister.getEntityName(), queryName);

    AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedQuery(queryName);
    if ( query.hasNamedParameters() ) {
      query.setParameter(
          query.getNamedParameters()[0],
          id,
          persister.getIdentifierType()
        );
    }
    else {
      query.setParameter( 0, id, persister.getIdentifierType() );
    }
    query.setOptionalId(id);
    query.setOptionalEntityName( persister.getEntityName() );
    query.setOptionalObject(optionalObject);
    query.setFlushMode( FlushMode.MANUAL );
    query.list();

    // now look up the object we are really interested in!
    // (this lets us correctly handle proxies and multi-row or multi-column queries)
    return session.getPersistenceContext().getEntity( session.generateEntityKey( id, persister ) );
View Full Code Here

    if ( ! AbstractQueryImpl.class.isInstance( query ) ) {
      throw new IllegalStateException( "Unknown query type for parameter extraction" );
    }

    HashSet<Parameter<?>> parameters = new HashSet<Parameter<?>>();
    AbstractQueryImpl queryImpl = AbstractQueryImpl.class.cast( query );

    // extract named params
    for ( String name : (Set<String>) queryImpl.getParameterMetadata().getNamedParameterNames() ) {
      final NamedParameterDescriptor descriptor =
          queryImpl.getParameterMetadata().getNamedParameterDescriptor( name );
      Class javaType = namedParameterTypeRedefinition.get( name );
      if ( javaType != null && mightNeedRedefinition( javaType ) ) {
        descriptor.resetExpectedType(
            TypeFactory.heuristicType( javaType.getName() )
        );
      }
      else if ( descriptor.getExpectedType() != null ) {
        javaType = descriptor.getExpectedType().getReturnedClass();
      }
      final ParameterImpl parameter = new ParameterImpl( name, javaType );
      parameters.add( parameter );
      if ( descriptor.isJpaStyle() ) {
        if ( jpaPositionalIndices == null ) {
          jpaPositionalIndices = new HashSet<Integer>();
        }
        jpaPositionalIndices.add( Integer.valueOf( name ) );
      }
    }

    // extract positional parameters
    for ( int i = 0, max = queryImpl.getParameterMetadata().getOrdinalParameterCount(); i < max; i++ ) {
      final OrdinalParameterDescriptor descriptor =
          queryImpl.getParameterMetadata().getOrdinalParameterDescriptor( i+1 );
      ParameterImpl parameter = new ParameterImpl(
          i + 1,
          descriptor.getExpectedType() == null
              ? null
              : descriptor.getExpectedType().getReturnedClass()
View Full Code Here

  }

  public Object load(Serializable id, Object optionalObject, SessionImplementor session) {
        LOG.debugf("Loading entity: %s using named query: %s", persister.getEntityName(), queryName);

    AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedQuery(queryName);
    if ( query.hasNamedParameters() ) {
      query.setParameter(
          query.getNamedParameters()[0],
          id,
          persister.getIdentifierType()
        );
    }
    else {
      query.setParameter( 0, id, persister.getIdentifierType() );
    }
    query.setOptionalId(id);
    query.setOptionalEntityName( persister.getEntityName() );
    query.setOptionalObject(optionalObject);
    query.setFlushMode( FlushMode.MANUAL );
    query.list();

    // now look up the object we are really interested in!
    // (this lets us correctly handle proxies and multi-row
    // or multi-column queries)
    return session.getPersistenceContext()
View Full Code Here

  throws HibernateException {

        LOG.debugf("Initializing collection: %s using named query: %s", persister.getRole(), queryName);

    //TODO: is there a more elegant way than downcasting?
    AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedSQLQuery(queryName);
    if ( query.getNamedParameters().length>0 ) {
      query.setParameter(
          query.getNamedParameters()[0],
          key,
          persister.getKeyType()
        );
    }
    else {
      query.setParameter( 0, key, persister.getKeyType() );
    }
    query.setCollectionKey( key )
        .setFlushMode( FlushMode.MANUAL )
        .list();

  }
View Full Code Here

    if ( ! AbstractQueryImpl.class.isInstance( query ) ) {
      throw new IllegalStateException( "Unknown query type for parameter extraction" );
    }

    HashSet<Parameter<?>> parameters = new HashSet<Parameter<?>>();
    AbstractQueryImpl queryImpl = AbstractQueryImpl.class.cast( query );

    // extract named params
    for ( String name : (Set<String>) queryImpl.getParameterMetadata().getNamedParameterNames() ) {
      final NamedParameterDescriptor descriptor =
          queryImpl.getParameterMetadata().getNamedParameterDescriptor( name );
      Class javaType = namedParameterTypeRedefinition.get( name );
      if ( javaType != null && mightNeedRedefinition( javaType ) ) {
        descriptor.resetExpectedType(
            sfi().getTypeResolver().heuristicType( javaType.getName() )
        );
      }
      else if ( descriptor.getExpectedType() != null ) {
        javaType = descriptor.getExpectedType().getReturnedClass();
      }
      final ParameterImpl parameter = new ParameterImpl( name, javaType );
      parameters.add( parameter );
      if ( descriptor.isJpaStyle() ) {
        if ( jpaPositionalIndices == null ) {
          jpaPositionalIndices = new HashSet<Integer>();
        }
        jpaPositionalIndices.add( Integer.valueOf( name ) );
      }
    }

    // extract positional parameters
    for ( int i = 0, max = queryImpl.getParameterMetadata().getOrdinalParameterCount(); i < max; i++ ) {
      final OrdinalParameterDescriptor descriptor =
          queryImpl.getParameterMetadata().getOrdinalParameterDescriptor( i+1 );
      ParameterImpl parameter = new ParameterImpl(
          i + 1,
          descriptor.getExpectedType() == null
              ? null
              : descriptor.getExpectedType().getReturnedClass()
View Full Code Here

TOP

Related Classes of org.hibernate.impl.AbstractQueryImpl

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.