|
| 1 | +/* |
| 2 | + * Hibernate, Relational Persistence for Idiomatic Java |
| 3 | + * |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
| 5 | + * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
| 6 | + */ |
| 7 | +package org.hibernate.jpa.test.persistenceunit; |
| 8 | + |
| 9 | +import java.util.Collections; |
| 10 | +import java.util.Map; |
| 11 | +import javax.persistence.Cacheable; |
| 12 | +import javax.persistence.Entity; |
| 13 | +import javax.persistence.Id; |
| 14 | +import javax.persistence.SharedCacheMode; |
| 15 | + |
| 16 | +import org.hibernate.cfg.AvailableSettings; |
| 17 | +import org.hibernate.cfg.Environment; |
| 18 | +import org.hibernate.engine.spi.SessionFactoryImplementor; |
| 19 | +import org.hibernate.jpa.boot.spi.Bootstrap; |
| 20 | +import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder; |
| 21 | +import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; |
| 22 | +import org.hibernate.persister.entity.EntityPersister; |
| 23 | + |
| 24 | +import org.hibernate.testing.TestForIssue; |
| 25 | +import org.junit.Test; |
| 26 | + |
| 27 | +import static org.junit.Assert.assertNotNull; |
| 28 | +import static org.junit.Assert.assertNull; |
| 29 | + |
| 30 | +/** |
| 31 | + * @author Gail Badner |
| 32 | + */ |
| 33 | +public class TwoPersistenceUnits2LCDisabledEnabled { |
| 34 | + |
| 35 | + @Test |
| 36 | + @TestForIssue( jiraKey = "HHH-11516" ) |
| 37 | + public void testDisabledEnabled() { |
| 38 | + final Map<Object, Object> config = Environment.getProperties(); |
| 39 | + config.put( org.hibernate.jpa.AvailableSettings.LOADED_CLASSES, Collections.singletonList( AnEntity.class ) ); |
| 40 | + config.put( "javax.persistence.sharedCache.mode", SharedCacheMode.ENABLE_SELECTIVE ); |
| 41 | + config.put( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); |
| 42 | + |
| 43 | + testIt( config ); |
| 44 | + |
| 45 | + config.put( AvailableSettings.USE_SECOND_LEVEL_CACHE, "true" ); |
| 46 | + |
| 47 | + testIt( config ); |
| 48 | + } |
| 49 | + |
| 50 | + private void testIt(Map config) { |
| 51 | + EntityManagerFactoryBuilder entityManagerFactoryBuilder = Bootstrap.getEntityManagerFactoryBuilder( |
| 52 | + new BaseEntityManagerFunctionalTestCase.TestingPersistenceUnitDescriptorImpl( getClass().getSimpleName() ), |
| 53 | + config |
| 54 | + ); |
| 55 | + SessionFactoryImplementor sf = entityManagerFactoryBuilder.build().unwrap( SessionFactoryImplementor.class ); |
| 56 | + final EntityPersister persister = sf.getMetamodel().entityPersister( AnEntity.class.getName() ); |
| 57 | + |
| 58 | + try { |
| 59 | + if ( config.get( AvailableSettings.USE_SECOND_LEVEL_CACHE ).equals( "true" ) ) { |
| 60 | + assertNotNull( persister.getCacheAccessStrategy() ); |
| 61 | + } |
| 62 | + else { |
| 63 | + assertNull( persister.getCacheAccessStrategy() ); |
| 64 | + } |
| 65 | + } |
| 66 | + finally { |
| 67 | + sf.close(); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + @Cacheable |
| 73 | + @Entity( name = "AnEntity" ) |
| 74 | + public static class AnEntity { |
| 75 | + @Id |
| 76 | + private Long id; |
| 77 | + } |
| 78 | +} |
0 commit comments