Package javax.persistence

Examples of javax.persistence.EntityManager.unwrap()


  public <T> T unwrap(Class<T> cls)
  {
    EntityManager em = getCurrent();
   
    if (em != null) {
      return em.unwrap(cls);
    }
   
    em = createEntityManager();
   
    try {
View Full Code Here


    }
   
    em = createEntityManager();
   
    try {
      return em.unwrap(cls);
    } finally {
      freeEntityManager(em);
    }
  }
View Full Code Here

  @Test
  public void testHibernateSearchNativeAPIUsage() throws Exception {
    getTransactionManager().begin();
    final EntityManager entityManager = getFactory().createEntityManager();
    final FullTextSession ftSession = org.hibernate.search.Search.getFullTextSession( entityManager.unwrap( Session.class ) );
    final Insurance insurance = new Insurance();
    insurance.setName( "Macif" );
    ftSession.persist( insurance );
    getTransactionManager().commit();
View Full Code Here

    assertThat( s.getClass() ).isEqualTo( OgmSessionImpl.class );
    assertThat( s.getSessionFactory().getClass() ).isEqualTo( OgmSessionFactoryImpl.class );
    s.close();

    EntityManager em = emf.createEntityManager();
    assertThat( em.unwrap( Session.class ) instanceof OgmSession );
    assertThat( em.getDelegate().getClass() ).isEqualTo( OgmSessionImpl.class );

    em.close();

    emf.close();
View Full Code Here

  public <T> T unwrap(Class<T> arg0)
  {
    EntityManager em = getPersistenceContext(false);
    try {
      return em.unwrap(arg0);
    } finally {
      if(em == detachedManager)
        em.clear();
    }
  }
View Full Code Here

   * Check if disabling 2LC works as expected
   */
  public String disabled2LCCheck() {
   
    EntityManager em = emfNo2LC.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
   
    try {
      // check if entities are NOT cached in 2LC
      String names[] = stats.getSecondLevelCacheRegionNames();
View Full Code Here

   *  Checking entity 2LC in one EntityManager session
   */
  public String sameSessionCheck(String CACHE_REGION_NAME) {
   
    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
     
    try{
      // add new entities and check if they are put in 2LC
View Full Code Here

   *  Checking entity 2LC in a different EntityManager session
   */
  public String secondSessionCheck(String CACHE_REGION_NAME) {
   
    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
     
    try{
      // add new entity
View Full Code Here

   * Insert 2 entities and put them into the 2LC and then evicts entity cache.
   */
  public String addEntitiesAndEvictAll(String CACHE_REGION_NAME){

    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
   
    try{
      createEmployee(em, "Jan", "Ostrava", 20);
View Full Code Here

   * Checks if entity 2LC is empty.
   */
  public String evictedEntityCacheCheck(String CACHE_REGION_NAME){

    EntityManager em = emf.createEntityManager();
    Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics emp2LCStats = stats.getSecondLevelCacheStatistics(CACHE_REGION_NAME+"Employee");
     
    try
      assertEquals("Expected no entities stored in the cache"+emp2LCStats, 0, emp2LCStats.getElementCountInMemory());
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.