Package org.springframework.orm.jpa

Examples of org.springframework.orm.jpa.EntityManagerHolder


    assertNotNull(transactionalField.em);
    // the EM w/o properties will be created
    assertNotNull(transactionalField.em.getDelegate());
    // bind em to the thread now since it's created
    try {
      TransactionSynchronizationManager.bindResource(mockEmf, new EntityManagerHolder(em));
      assertNotNull(transactionalFieldWithProperties.em.getDelegate());
      emfMc.verify();
      emC.verify();
    }
    finally {
View Full Code Here


    }

    public void beginCommandScopedEntityManager() {
        EntityManager cmdScopedEntityManager = (EntityManager) env.get( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER );
        if ( cmdScopedEntityManager == null || !cmdScopedEntityManager.isOpen() ) {
            EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource( "cmdEM" );
            EntityManager em = null;
            if ( emHolder == null ) {
                em = this.emf.createEntityManager();
                emHolder = new EntityManagerHolder( em );
                TransactionSynchronizationManager.bindResource( "cmdEM",
                                                                emHolder );
            } else {
                em = emHolder.getEntityManager();
            }
            this.env.set( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER,
                          em );
        }
View Full Code Here

    EntityManager em = mock(EntityManager.class,"em");
    em.contains("foo");
    em.contains("bar");
    em.merge("bar");
    em.flush();
    TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em));

    List<String> items = Arrays.asList(new String[] { "foo", "bar" });

    writer.write(items);
View Full Code Here

    EntityManager em = mock(EntityManager.class,"em");
    em.contains("foo");
    em.contains("bar");
    em.merge("bar");
    when(em).thenThrow(ex);
    TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em));
    List<String> items = Arrays.asList(new String[] { "foo", "bar" });

    try {
      writer.write(items);
      fail("Expected RuntimeException");
View Full Code Here

            if ( this.appScopedEntityManager != null && !this.appScopedEntityManager.isOpen() ) {
                throw new RuntimeException( "Provided APP_SCOPED_ENTITY_MANAGER is not open" );
            }

            if ( this.appScopedEntityManager == null ) {
                EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource( this.emf );
                if ( emHolder == null ) {
                    this.appScopedEntityManager = this.emf.createEntityManager();
                    emHolder = new EntityManagerHolder( this.appScopedEntityManager );
                    TransactionSynchronizationManager.bindResource( this.emf,
                                                                    emHolder );
                    internalAppScopedEntityManager = true;
                } else {
                    this.appScopedEntityManager = emHolder.getEntityManager();
                }

                this.env.set( EnvironmentName.APP_SCOPED_ENTITY_MANAGER,
                              emHolder.getEntityManager() );
            }
        }
        if ( TransactionSynchronizationManager.isActualTransactionActive() ) {
            this.appScopedEntityManager.joinTransaction();
        }
View Full Code Here

  @Override
  protected void setUp() throws Exception {
    EntityManagerFactory factory = this.getEntityManagerFactory();
    this.entityManager = factory.createEntityManager();
    this.bind(factory, new EntityManagerHolder(this.entityManager));
  }
View Full Code Here

  }

  @Override
  protected void tearDown() throws Exception {
    EntityManagerFactory factory = this.getEntityManagerFactory();
    EntityManagerHolder holder = (EntityManagerHolder) this.unbind(factory);
    EntityManager manager = holder.getEntityManager();
    manager.close();
  }
View Full Code Here

            if ( this.appScopedEntityManager != null && !this.appScopedEntityManager.isOpen() ) {
                throw new RuntimeException("Provided APP_SCOPED_ENTITY_MANAGER is not open");
            }

            if ( this.appScopedEntityManager == null ) {
                EntityManagerHolder emHolder = ( EntityManagerHolder ) TransactionSynchronizationManager.getResource( this.emf );
                if ( emHolder == null ) {
                    this.appScopedEntityManager = this.emf.createEntityManager();
                    emHolder =  new EntityManagerHolder( this.appScopedEntityManager );
                    TransactionSynchronizationManager.bindResource( this.emf,
                                                                    emHolder );
                    internalAppScopedEntityManager = true;
                } else {
                    this.appScopedEntityManager = emHolder.getEntityManager();
                }


                this.env.set( EnvironmentName.APP_SCOPED_ENTITY_MANAGER,
                              emHolder.getEntityManager() );
            }
        }
        if (TransactionSynchronizationManager.isActualTransactionActive()){
            this.appScopedEntityManager.joinTransaction();
        }
View Full Code Here

        return (EntityManager) this.env.get( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER);
    }

    public void beginCommandScopedEntityManager() {
        if ( this.getCommandScopedEntityManager() == null || !this.getCommandScopedEntityManager().isOpen() ) {
            EntityManagerHolder emHolder = ( EntityManagerHolder ) TransactionSynchronizationManager.getResource( "cmdEM" );
            EntityManager em = null;
            if ( emHolder == null ) {
                em = this.emf.createEntityManager();
                emHolder =  new EntityManagerHolder( em );
                TransactionSynchronizationManager.bindResource( "cmdEM",
                                                                emHolder );
            } else {
                em = emHolder.getEntityManager();
            }
            this.env.set( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER,
                          em );
        }
View Full Code Here

  @Override
  protected void setUp() throws Exception {
    EntityManagerFactory factory = this.getEntityManagerFactory();
    this.entityManager = factory.createEntityManager();
    this.bind(factory, new EntityManagerHolder(this.entityManager));
  }
View Full Code Here

TOP

Related Classes of org.springframework.orm.jpa.EntityManagerHolder

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.