Examples of JPAEntityManager


Examples of de.mhus.lib.jpa.JpaEntityManager

    BookStoreSchema schema = new BookStoreSchema();
    prop.setSchema(schema);
   
    JpaManager manager = new JpaManager(prop);
   
    JpaEntityManager em = manager.createEntityManager();
   
    em.begin();
   
    Book book1 = new Book();
    book1.setName("Oh wie schoen ist Panama");
    em.persist(book1);
   
    Book book2 = new Book();
    book2.setName("Sofies Welt");
    em.persist(book2);
   
    em.commit();
   
    System.out.println("ID: " + book1.getId() );
    System.out.println("ID: " + book2.getId() );
   
    assertNotSame(book1.getId(), book2.getId());

    Book foundBook = em.find(Book.class, book1.getId());
   
    assertSame(book1.getName(), foundBook.getName());
   
    assertSame(book1, foundBook);
   
    Book copyBook1 = em.copy(book1);
   
    assertSame(book1.getName(), copyBook1.getName());
   
    assertTrue(book1 != copyBook1);
   
    // assertTrue(foundBook.is)
   
    {
      JpaQuery<Book> query = em.createQuery("select b from Book b", Book.class);
     
 
      List<Book> list = query.getResultList();
     
      assertTrue(list.size() == 2);
     
      for ( Book res : list) {
        System.out.println("RES: " + res.getId() + " " + res.getName());
      }
    } 
   
    em.begin();
   
    Person p1 = em.injectObject(new Person());
    p1.setName("Kurt Cobain");
    p1.save();
   
   
    Person p2 = em.injectObject(new Person());
    p2.setName("Lola Langohr");
    p2.save();
   
    em.commit();
   
    {
      JpaQuery<Person> query = em.createQuery("select p from Person p", Person.class);
      List<Person> list = query.getResultList();
      assertTrue(list.size() == 2);
     
      for ( Person res : list) {
        System.out.println("RES: " + res.getId() + " " + res.getName());
      }
    }
   
    em.begin();
    p2.remove();
    em.commit();
   
    {
      JpaQuery<Person> query = em.createQuery("select p from Person p", Person.class);
      List<Person> list = query.getResultList();
      assertTrue(list.size() == 1);
     
      for ( Person res : list) {
        System.out.println("RES: " + res.getId() + " " + res.getName());
View Full Code Here

Examples of org.datanucleus.api.jpa.JPAEntityManager

public class JPADataSourceConfigTest extends TestCase {

  public void testTransactionalEMF() {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory(
            JPATestCase.EntityManagerFactoryName.transactional_ds_non_transactional_ops_not_allowed.name());
    JPAEntityManager em = (JPAEntityManager) emf.createEntityManager();
    DatastoreManager storeMgr = (DatastoreManager) em.getExecutionContext().getStoreManager();
    assertTrue(storeMgr.connectionFactoryIsAutoCreateTransaction());
    em.close();
    emf.close();
  }
View Full Code Here

Examples of org.datanucleus.api.jpa.JPAEntityManager

  }

  public void testNonTransactionalEMF() {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory(
            JPATestCase.EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_not_allowed.name());
    JPAEntityManager em = (JPAEntityManager) emf.createEntityManager();
    DatastoreManager storeMgr = (DatastoreManager) em.getExecutionContext().getStoreManager();
    assertFalse(storeMgr.connectionFactoryIsAutoCreateTransaction());
    em.close();
    emf.close();
  }
View Full Code Here

Examples of org.eclipse.persistence.jpa.JpaEntityManager

    assertTrue(emfi.getNativeEntityManagerFactory().getClass().getName().endsWith("EntityManagerFactoryImpl"));
  }

  public void testCanCastSharedEntityManagerProxyToTopLinkEntityManager() {
    assertTrue(sharedEntityManager instanceof JpaEntityManager);
    JpaEntityManager eclipselinkEntityManager = (JpaEntityManager) sharedEntityManager;
    assertNotNull(eclipselinkEntityManager.getActiveSession());
  }
View Full Code Here

Examples of org.eclipse.persistence.jpa.JpaEntityManager

  /**
   * Get a traditional EclipseLink Session from the given EntityManager.
   */
  protected Session getSession(EntityManager em) {
    JpaEntityManager emi = (JpaEntityManager) em;
    return emi.getActiveSession();
  }
View Full Code Here

Examples of org.eclipse.persistence.jpa.JpaEntityManager

  /**
   * Get a traditional EclipseLink Session from the given EntityManager.
   */
  protected Session getSession(EntityManager em) {
    JpaEntityManager emi = (JpaEntityManager) em;
    return emi.getActiveSession();
  }
View Full Code Here

Examples of org.eclipse.persistence.jpa.JpaEntityManager

     * This method will return null for non-EclipseLink EntityManagers.
     *
     * @see JpaEntityManagerFactory
     */
    public static JpaEntityManagerFactory getEntityManagerFactory(javax.persistence.EntityManager em) {
        JpaEntityManager entityManager = getEntityManager(em);
        if (entityManager != null){
            if (entityManager.getEntityManagerFactory() != null){
                return ((EntityManagerFactoryDelegate)entityManager.getEntityManagerFactory()).getOwner();
            }
        }
        return null;
    }
View Full Code Here

Examples of org.eclipse.persistence.jpa.JpaEntityManager

    assertTrue(emfi.getNativeEntityManagerFactory().getClass().getName().endsWith("EntityManagerFactoryImpl"));
  }

  public void testCanCastSharedEntityManagerProxyToEclipseLinkEntityManager() {
    assertTrue(sharedEntityManager instanceof JpaEntityManager);
    JpaEntityManager eclipselinkEntityManager = (JpaEntityManager) sharedEntityManager;
    assertNotNull(eclipselinkEntityManager.getActiveSession());
  }
View Full Code Here

Examples of org.eclipse.persistence.jpa.JpaEntityManager

        super(entityManagerProvider);
    }
   
    @Override
    public String getQueryStringOfNamedQuery(String queryName) {
        JpaEntityManager jpaEntityManager = (JpaEntityManager) getEntityManager().getDelegate();
        return jpaEntityManager.getActiveSession().getQuery(queryName).getJPQLString();
    }
View Full Code Here

Examples of org.eclipse.persistence.jpa.JpaEntityManager

     * This method will return null for non-EclipseLink EntityManagers.
     *
     * @see JpaEntityManagerFactory
     */
    public static JpaEntityManagerFactory getEntityManagerFactory(javax.persistence.EntityManager em) {
        JpaEntityManager entityManager = getEntityManager(em);
        if (entityManager != null){
            if (entityManager.getEntityManagerFactory() != null){
                return ((EntityManagerFactoryDelegate)entityManager.getEntityManagerFactory()).getOwner();
            }
        }
        return null;
    }
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.