Examples of EntityManagerFactory


Examples of javax.persistence.EntityManagerFactory

  public EntityManagerFactory getEntityManagerFactory(String name)
  {
    if (_exception != null)
      throw new AmberRuntimeException(_exception);

    EntityManagerFactory factory = _factoryMap.get(name);
    if (factory != null)
      return factory;

    /*
    if (_pendingRootList.size() > 0)
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

    if (! _lifecycle.toDestroy())
      return;
   
    _entityManagerFactoryProxy.closeImpl();
   
    EntityManagerFactory emfDelegate = _emfDelegate;
    _emfDelegate = null;
   
    if (emfDelegate != null)
      emfDelegate.close();
  }
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

                    Reference reference = buildReferenceLocation(referenceInfo.location);
                    bindings.put(normalize(referenceInfo.referenceName), reference);
                    continue;
                }

                EntityManagerFactory factory = emfLinkResolver.resolveLink(referenceInfo.persistenceUnitName, moduleUri);
                if (factory == null) {
                    throw new IllegalArgumentException("Persistence unit " + referenceInfo.persistenceUnitName + " for persistence-unit-ref " +
                            referenceInfo.referenceName + " not found");
                }

                Reference reference = new PersistenceUnitReference(factory);
                bindings.put(normalize(referenceInfo.referenceName), reference);
            }

            for (PersistenceContextReferenceInfo contextInfo : jndiEnc.persistenceContextRefs) {
                if (contextInfo.location != null){
                    Reference reference = buildReferenceLocation(contextInfo.location);
                    bindings.put(normalize(contextInfo.referenceName), reference);
                    continue;
                }

                EntityManagerFactory factory = emfLinkResolver.resolveLink(contextInfo.persistenceUnitName, moduleUri);
                if (factory == null) {
                    throw new IllegalArgumentException("Persistence unit " + contextInfo.persistenceUnitName + " for persistence-context-ref " +
                            contextInfo.referenceName + " not found");
                }
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

        }
    }

    public boolean testEntityManagerFactory() {
        try {
            EntityManagerFactory entityManagerFactory = (EntityManagerFactory) new InitialContext().lookup("java:comp/env/jpa/testEMF");
            System.out.println("Accessed entity manager factory");
            EntityManager entityManager = entityManagerFactory.createEntityManager();
            AllFieldTypes allFieldTypes = new AllFieldTypes();
            entityManager.persist(allFieldTypes);
            System.out.println("saved object");
            entityManager.close();
            System.out.println("Closed entity manager");
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

  public PackagingRule ogmPackaging = new PackagingRule( "persistencexml/jpajtastandalone-ormogm.xml", Poem.class );

  @Test
  //Test for OGM-416 (avoid StackOverFlow when both an OGM and ORM PU are used
  public void testJTAStandaloneNoOgm() throws Exception {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory( "jpajtastandalone", TestHelper.getEnvironmentProperties() );
    emf.close();
    emf = Persistence.createEntityManagerFactory( "jpajtastandalone-noogm" );
    emf.close();
  }
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

        ) ) {
          //correct provider
          Map<Object,Object> protectiveCopy = new HashMap<Object,Object>(integration);
          enforceOgmConfig( protectiveCopy );
          protectiveCopy.put( AvailableSettings.PROVIDER, delegate.getClass().getName() );
          final EntityManagerFactory coreEMF = delegate.createEntityManagerFactory(
              emName, protectiveCopy
          );
          if ( coreEMF != null ) {
            //delegate might return null to refuse the configuration
            //(like when the configuration file is not defining the expected persistent unit)
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

      Map<Object,Object> protectiveCopy = map != null ? new HashMap<Object,Object>(map) : new HashMap<Object,Object>();
      enforceOgmConfig( protectiveCopy );
      //HEM only builds an EntityManagerFactory when HibernatePersistence.class.getName() is the PersistenceProvider
      //that's why we override it when
      //new DelegatorPersistenceUnitInfo(info)
      final EntityManagerFactory coreEMF = delegate.createContainerEntityManagerFactory(
          new DelegatorPersistenceUnitInfo(
              info
          ),
          protectiveCopy
      );
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

  public PackagingRule packaging = new PackagingRule( "persistencexml/jpajtastandalone.xml", Poem.class );

  @Test
  public void testJTAStandalone() throws Exception {

    final EntityManagerFactory emf = Persistence.createEntityManagerFactory( "jpajtastandalone", TestHelper.getEnvironmentProperties() );

    TransactionManager transactionManager = extractJBossTransactionManager( emf );

    transactionManager.begin();
    final EntityManager em = emf.createEntityManager();
    Poem poem = new Poem();
    poem.setName( "L'albatros" );
    em.persist( poem );
    transactionManager.commit();

    em.clear();

    transactionManager.begin();
    poem = em.find( Poem.class, poem.getId() );
    assertThat( poem ).isNotNull();
    assertThat( poem.getName() ).isEqualTo( "L'albatros" );
    em.remove( poem );
    transactionManager.commit();

    em.close();

    dropSchemaAndDatabase( emf );
    emf.close();
  }
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

  @Rule
  public RequiresTransactionalCapabilitiesRule transactions = new RequiresTransactionalCapabilitiesRule();

  @Test
  public void testJTAStandalone() throws Exception {
    final EntityManagerFactory emf = Persistence.createEntityManagerFactory( "jpajtastandalone", TestHelper.getEnvironmentProperties() );
    try {

      final EntityManager em = emf.createEntityManager();
      try {

        em.getTransaction().begin();
        Poem poem = new Poem();
        poem.setName( "L'albatros" );
        em.persist( poem );
        em.getTransaction().commit();

        em.clear();

        em.getTransaction().begin();
        Poem poem2 = new Poem();
        poem2.setName( "Wazaaaaa" );
        em.persist( poem2 );
        em.flush();
        assertThat( getNumberOfEntities( em ) ).isEqualTo( 2 );
        em.getTransaction().rollback();

        assertThat( getNumberOfEntities( em ) ).isEqualTo( 1 );

        em.getTransaction().begin();
        poem = em.find( Poem.class, poem.getId() );
        assertThat( poem ).isNotNull();
        assertThat( poem.getName() ).isEqualTo( "L'albatros" );
        em.remove( poem );
        poem2 = em.find( Poem.class, poem2.getId() );
        assertThat( poem2 ).isNull();
        em.getTransaction().commit();

      }
      finally {
        EntityTransaction transaction = em.getTransaction();
        if ( transaction != null && transaction.isActive() ) {
          transaction.rollback();
        }
        em.close();
      }
    }
    finally {
      dropSchemaAndDatabase( emf );
      emf.close();
    }
  }
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

  @Rule
  public ExpectedException thrown = ExpectedException.none();

  @Test
  public void testWrappedStandalone() throws Exception {
    final EntityManagerFactory emf = Persistence.createEntityManagerFactory( "jpajtastandalone", TestHelper.getEnvironmentProperties() );
    assertThat( emf.getClass() ).isEqualTo( OgmEntityManagerFactory.class );

    EntityManager em = emf.createEntityManager();
    assertThat( em.getClass() ).isEqualTo( OgmEntityManager.class );
    em.close();

    em = emf.createEntityManager( new HashMap() );
    assertThat( em.getClass() ).isEqualTo( OgmEntityManager.class );
    em.close();

    emf.close();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.