Package org.hibernate

Examples of org.hibernate.SessionBuilder


  public SessionFactoryImplementor factory() {
    return factory;
  }

  protected SessionBuilder baseSessionBuilder() {
    final SessionBuilder builder = factory.withOptions();
    final CurrentTenantIdentifierResolver resolver = factory.getCurrentTenantIdentifierResolver();
    if ( resolver != null ) {
      builder.tenantIdentifier( resolver.resolveCurrentTenantIdentifier() );
    }
    return builder;
  }
View Full Code Here


  }

  @Override
    protected Session getRawSession() {
    if ( session == null ) {
      SessionBuilder sessionBuilder = getEntityManagerFactory().getSessionFactory().withOptions();
      if (sessionInterceptorClass != null) {
        try {
          Interceptor interceptor = (Interceptor) sessionInterceptorClass.newInstance();
          sessionBuilder.interceptor( interceptor );
        }
        catch (InstantiationException e) {
          throw new PersistenceException("Unable to instanciate session interceptor: " + sessionInterceptorClass, e);
        }
        catch (IllegalAccessException e) {
          throw new PersistenceException("Unable to instanciate session interceptor: " + sessionInterceptorClass, e);
        }
        catch (ClassCastException e) {
          throw new PersistenceException("Session interceptor does not implement Interceptor: " + sessionInterceptorClass, e);
        }
      }
      sessionBuilder.autoJoinTransactions( getTransactionType() != PersistenceUnitTransactionType.JTA );
      session = sessionBuilder.openSession();
      if ( persistenceContextType == PersistenceContextType.TRANSACTION ) {
        ( (SessionImplementor) session ).setAutoClear( true );
      }
    }
    return session;
View Full Code Here

  }

  @Override
    protected Session getRawSession() {
    if ( session == null ) {
      SessionBuilder sessionBuilder = getEntityManagerFactory().getSessionFactory().withOptions();
      if (sessionInterceptorClass != null) {
        try {
          Interceptor interceptor = (Interceptor) sessionInterceptorClass.newInstance();
          sessionBuilder.interceptor( interceptor );
        }
        catch (InstantiationException e) {
          throw new PersistenceException("Unable to instanciate session interceptor: " + sessionInterceptorClass, e);
        }
        catch (IllegalAccessException e) {
          throw new PersistenceException("Unable to instanciate session interceptor: " + sessionInterceptorClass, e);
        }
        catch (ClassCastException e) {
          throw new PersistenceException("Session interceptor does not implement Interceptor: " + sessionInterceptorClass, e);
        }
      }
      sessionBuilder.autoJoinTransactions( getTransactionType() != PersistenceUnitTransactionType.JTA );
      session = sessionBuilder.openSession();
      if ( persistenceContextType == PersistenceContextType.TRANSACTION ) {
        ( (SessionImplementor) session ).setAutoClear( true );
      }
    }
    return session;
View Full Code Here

  public SessionFactoryImplementor factory() {
    return factory;
  }

  protected SessionBuilder baseSessionBuilder() {
    final SessionBuilder builder = factory.withOptions();
    final CurrentTenantIdentifierResolver resolver = factory.getCurrentTenantIdentifierResolver();
    if ( resolver != null ) {
      builder.tenantIdentifier( resolver.resolveCurrentTenantIdentifier() );
    }
    return builder;
  }
View Full Code Here

  }

  @Override
    protected Session getRawSession() {
    if ( session == null ) {
      SessionBuilder sessionBuilder = getEntityManagerFactory().getSessionFactory().withOptions();
      if (sessionInterceptorClass != null) {
        try {
          Interceptor interceptor = (Interceptor) sessionInterceptorClass.newInstance();
          sessionBuilder.interceptor( interceptor );
        }
        catch (InstantiationException e) {
          throw new PersistenceException("Unable to instanciate session interceptor: " + sessionInterceptorClass, e);
        }
        catch (IllegalAccessException e) {
          throw new PersistenceException("Unable to instanciate session interceptor: " + sessionInterceptorClass, e);
        }
        catch (ClassCastException e) {
          throw new PersistenceException("Session interceptor does not implement Interceptor: " + sessionInterceptorClass, e);
        }
      }
      sessionBuilder.autoJoinTransactions( getTransactionType() != PersistenceUnitTransactionType.JTA );
      session = sessionBuilder.openSession();
      if ( persistenceContextType == PersistenceContextType.TRANSACTION ) {
        ( (SessionImplementor) session ).setAutoClear( true );
      }
    }
    return session;
View Full Code Here

  public void testTransactionCommitWithEntityInterceptor() throws Exception {
    Interceptor entityInterceptor = mock(Interceptor.class);
    Connection con = mock(Connection.class);
    final SessionFactory sf = mock(SessionFactory.class);
    ImplementingSession session = mock(ImplementingSession.class);
    SessionBuilder options = mock(SessionBuilder.class);
    Transaction tx = mock(Transaction.class);

    given(sf.withOptions()).willReturn(options);
    given(options.interceptor(entityInterceptor)).willReturn(options);
    given(options.openSession()).willReturn(session);
    given(session.beginTransaction()).willReturn(tx);
    given(session.isOpen()).willReturn(true);
    given(session.isConnected()).willReturn(true);
    given(session.connection()).willReturn(con);
View Full Code Here

    Interceptor entityInterceptor = mock(Interceptor.class);
    Interceptor entityInterceptor2 = mock(Interceptor.class);
    Connection con = mock(Connection.class);
    final SessionFactory sf = mock(SessionFactory.class);
    ImplementingSession session = mock(ImplementingSession.class);
    SessionBuilder options = mock(SessionBuilder.class);
    Transaction tx = mock(Transaction.class);

    given(sf.withOptions()).willReturn(options);
    given(options.interceptor(entityInterceptor)).willReturn(options);
    given(options.interceptor(entityInterceptor2)).willReturn(options);
    given(options.openSession()).willReturn(session);
    given(session.beginTransaction()).willReturn(tx);
    given(session.isOpen()).willReturn(true);
    given(session.isConnected()).willReturn(true);
    given(session.connection()).willReturn(con);
View Full Code Here

  }

  @Override
    protected Session getRawSession() {
    if ( session == null ) {
      SessionBuilder sessionBuilder = getEntityManagerFactory().getSessionFactory().withOptions();
      if (sessionInterceptorClass != null) {
        try {
          Interceptor interceptor = (Interceptor) sessionInterceptorClass.newInstance();
          sessionBuilder.interceptor( interceptor );
        }
        catch (InstantiationException e) {
          throw new PersistenceException("Unable to instanciate session interceptor: " + sessionInterceptorClass, e);
        }
        catch (IllegalAccessException e) {
          throw new PersistenceException("Unable to instanciate session interceptor: " + sessionInterceptorClass, e);
        }
        catch (ClassCastException e) {
          throw new PersistenceException("Session interceptor does not implement Interceptor: " + sessionInterceptorClass, e);
        }
      }
      sessionBuilder.autoJoinTransactions( getTransactionType() != PersistenceUnitTransactionType.JTA );
      session = sessionBuilder.openSession();
      if ( persistenceContextType == PersistenceContextType.TRANSACTION ) {
        ( (SessionImplementor) session ).setAutoClear( true );
      }
    }
    return session;
View Full Code Here

TOP

Related Classes of org.hibernate.SessionBuilder

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.