Package org.hibernate

Examples of org.hibernate.NaturalIdLoadAccess


  @Override
  public List list(Criteria criteria) throws HibernateException {
    // TODO: Is this guaranteed to always be CriteriaImpl?
    CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
       
    final NaturalIdLoadAccess naturalIdLoadAccess = this.tryNaturalIdLoadAccess( criteriaImpl );
    if ( naturalIdLoadAccess != null ) {
      // EARLY EXIT!
      return Arrays.asList( naturalIdLoadAccess.load() );
    }

    errorIfClosed();
    checkTransactionSynchStatus();
    String[] implementors = factory.getImplementors( criteriaImpl.getEntityOrClassName() );
View Full Code Here


    if ( naturalIdentifierProperties.length != naturalIdValues.size() ) {
      return null;
    }

    final String[] propertyNames = entityPersister.getPropertyNames();
    final NaturalIdLoadAccess naturalIdLoader = this.byNaturalId( entityName );

    // Build NaturalIdLoadAccess and in the process verify all naturalId properties were specified
    for ( int i = 0; i < naturalIdentifierProperties.length; i++ ) {
      final String naturalIdProperty = propertyNames[naturalIdentifierProperties[i]];
      final Object naturalIdValue = naturalIdValues.get( naturalIdProperty );

      if ( naturalIdValue == null ) {
        // A NaturalId property is missing from the critera query, can't use NaturalIdLoadAccess
        return null;
      }

      naturalIdLoader.using( naturalIdProperty, naturalIdValue );
    }

    // Critera query contains a valid naturalId, use the new API
    LOG.warn( "Session.byNaturalId(" + entityName
        + ") should be used for naturalId queries instead of Restrictions.naturalId() from a Criteria" );
View Full Code Here

  public List list(Criteria criteria) throws HibernateException {
    // TODO: Is this guaranteed to always be CriteriaImpl?
    CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
       
    final NaturalIdLoadAccess naturalIdLoadAccess = this.tryNaturalIdLoadAccess( criteriaImpl );
    if ( naturalIdLoadAccess != null ) {
      // EARLY EXIT!
      return Arrays.asList( naturalIdLoadAccess.load() );
    }

    errorIfClosed();
    checkTransactionSynchStatus();
    String[] implementors = factory.getImplementors( criteriaImpl.getEntityOrClassName() );
View Full Code Here

    if ( naturalIdentifierProperties.length != naturalIdValues.size() ) {
      return null;
    }

    final String[] propertyNames = entityPersister.getPropertyNames();
    final NaturalIdLoadAccess naturalIdLoader = this.byNaturalId( entityName );

    // Build NaturalIdLoadAccess and in the process verify all naturalId properties were specified
    for ( int i = 0; i < naturalIdentifierProperties.length; i++ ) {
      final String naturalIdProperty = propertyNames[naturalIdentifierProperties[i]];
      final Object naturalIdValue = naturalIdValues.get( naturalIdProperty );

      if ( naturalIdValue == null ) {
        // A NaturalId property is missing from the critera query, can't use NaturalIdLoadAccess
        return null;
      }

      naturalIdLoader.using( naturalIdProperty, naturalIdValue );
    }

    // Critera query contains a valid naturalId, use the new API
    LOG.warn( "Session.byNaturalId(" + entityName
        + ") should be used for naturalId queries instead of Restrictions.naturalId() from a Criteria" );
View Full Code Here

         @Override
         public Citizen call() throws Exception {
            Session s = openSession();
            Transaction tx = s.beginTransaction();
            State france = BasicTransactionalTestCase.this.getState(s, "Ile de France");
            NaturalIdLoadAccess naturalIdLoader = s.byNaturalId(Citizen.class);
            naturalIdLoader.using("ssn", "1234").using("state", france);

            //Not clearing naturalId caches, should be warm from entity loading
            stats.clear();

            // first query
            Citizen citizen = (Citizen) naturalIdLoader.load();
            assertNotNull(citizen);
            assertEquals("NaturalId Cache Hits", 1, stats.getNaturalIdCacheHitCount());
            assertEquals("NaturalId Cache Misses", 0, stats.getNaturalIdCacheMissCount());
            assertEquals("NaturalId Cache Puts", 0, stats.getNaturalIdCachePutCount());
            assertEquals("NaturalId Cache Queries", 0, stats.getNaturalIdQueryExecutionCount());

            // cleanup
            tx.rollback();
            s.close();
            return citizen;
         }
      });

      // TODO: Clear caches manually via cache manager (it's faster!!)
      this.cleanupCache();
      Thread.sleep(PutFromLoadValidator.NAKED_PUT_INVALIDATION_PERIOD + TimeUnit.SECONDS.toMillis(1));
      stats.setStatisticsEnabled( true );
      stats.clear();

      //Try NaturalIdLoadAccess
      withTx(tm, new Callable<Void>() {
         @Override
         public Void call() throws Exception {
            Session s = openSession();
            Transaction tx = s.beginTransaction();

            // first query
            Citizen loadedCitizen = (Citizen) s.get( Citizen.class, citizen.getId() );
            assertNotNull( loadedCitizen );
            assertEquals( "NaturalId Cache Hits", 0, stats.getNaturalIdCacheHitCount() );
            assertEquals( "NaturalId Cache Misses", 0, stats.getNaturalIdCacheMissCount() );
            assertEquals( "NaturalId Cache Puts", 1, stats.getNaturalIdCachePutCount() );
            assertEquals( "NaturalId Cache Queries", 0, stats.getNaturalIdQueryExecutionCount() );

            // cleanup
            tx.rollback();
            s.close();
            return null;
         }
      });

      // Try NaturalIdLoadAccess after load
      withTx(tm, new Callable<Void>() {
         @Override
         public Void call() throws Exception {
            Session s = openSession();
            Transaction tx = s.beginTransaction();
            State france = BasicTransactionalTestCase.this.getState(s, "Ile de France");
            NaturalIdLoadAccess naturalIdLoader = s.byNaturalId(Citizen.class);
            naturalIdLoader.using( "ssn", "1234" ).using( "state", france );

            //Not clearing naturalId caches, should be warm from entity loading
            stats.setStatisticsEnabled( true );
            stats.clear();

            // first query
            Citizen loadedCitizen = (Citizen) naturalIdLoader.load();
            assertNotNull( loadedCitizen );
            assertEquals( "NaturalId Cache Hits", 1, stats.getNaturalIdCacheHitCount() );
            assertEquals( "NaturalId Cache Misses", 0, stats.getNaturalIdCacheMissCount() );
            assertEquals( "NaturalId Cache Puts", 0, stats.getNaturalIdCachePutCount() );
            assertEquals( "NaturalId Cache Queries", 0, stats.getNaturalIdQueryExecutionCount() );
View Full Code Here

      dontFlushFromFind--;
    }
  }

  public List list(CriteriaImpl criteria) throws HibernateException {
    final NaturalIdLoadAccess naturalIdLoadAccess = this.tryNaturalIdLoadAccess( criteria );
    if ( naturalIdLoadAccess != null ) {
      // EARLY EXIT!
      return Arrays.asList( naturalIdLoadAccess.load() );
    }

    errorIfClosed();
    checkTransactionSynchStatus();
    String[] implementors = factory.getImplementors( criteria.getEntityOrClassName() );
View Full Code Here

    if ( naturalIdentifierProperties.length != naturalIdValues.size() ) {
      return null;
    }

    final String[] propertyNames = entityPersister.getPropertyNames();
    final NaturalIdLoadAccess naturalIdLoader = this.byNaturalId( entityName );

    // Build NaturalIdLoadAccess and in the process verify all naturalId properties were specified
    for ( int i = 0; i < naturalIdentifierProperties.length; i++ ) {
      final String naturalIdProperty = propertyNames[naturalIdentifierProperties[i]];
      final Object naturalIdValue = naturalIdValues.get( naturalIdProperty );

      if ( naturalIdValue == null ) {
        // A NaturalId property is missing from the critera query, can't use NaturalIdLoadAccess
        return null;
      }

      naturalIdLoader.using( naturalIdProperty, naturalIdValue );
    }

    // Critera query contains a valid naturalId, use the new API
    LOG.warn( "Session.byNaturalId(" + entityName
        + ") should be used for naturalId queries instead of Restrictions.naturalId() from a Criteria" );
View Full Code Here

  public List list(Criteria criteria) throws HibernateException {
    // TODO: Is this guaranteed to always be CriteriaImpl?
    CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
       
    final NaturalIdLoadAccess naturalIdLoadAccess = this.tryNaturalIdLoadAccess( criteriaImpl );
    if ( naturalIdLoadAccess != null ) {
      // EARLY EXIT!
      return Arrays.asList( naturalIdLoadAccess.load() );
    }

    errorIfClosed();
    checkTransactionSynchStatus();
    String[] implementors = factory.getImplementors( criteriaImpl.getEntityOrClassName() );
View Full Code Here

    if ( naturalIdentifierProperties.length != naturalIdValues.size() ) {
      return null;
    }

    final String[] propertyNames = entityPersister.getPropertyNames();
    final NaturalIdLoadAccess naturalIdLoader = this.byNaturalId( entityName );

    // Build NaturalIdLoadAccess and in the process verify all naturalId properties were specified
    for ( int i = 0; i < naturalIdentifierProperties.length; i++ ) {
      final String naturalIdProperty = propertyNames[naturalIdentifierProperties[i]];
      final Object naturalIdValue = naturalIdValues.get( naturalIdProperty );

      if ( naturalIdValue == null ) {
        // A NaturalId property is missing from the critera query, can't use NaturalIdLoadAccess
        return null;
      }

      naturalIdLoader.using( naturalIdProperty, naturalIdValue );
    }

    // Critera query contains a valid naturalId, use the new API
    LOG.warn( "Session.byNaturalId(" + entityName
        + ") should be used for naturalId queries instead of Restrictions.naturalId() from a Criteria" );
View Full Code Here

      dontFlushFromFind--;
    }
  }

  public List list(CriteriaImpl criteria) throws HibernateException {
    final NaturalIdLoadAccess naturalIdLoadAccess = this.tryNaturalIdLoadAccess( criteria );
    if ( naturalIdLoadAccess != null ) {
      // EARLY EXIT!
      return Arrays.asList( naturalIdLoadAccess.load() );
    }

    errorIfClosed();
    checkTransactionSynchStatus();
    String[] implementors = factory.getImplementors( criteria.getEntityOrClassName() );
View Full Code Here

TOP

Related Classes of org.hibernate.NaturalIdLoadAccess

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.