HHH-5025 - RevisionType serialization fix and test
This commit is contained in:
parent
94c1e9aba2
commit
3421a7c03d
|
@ -38,7 +38,9 @@ import org.hibernate.usertype.UserType;
|
||||||
* A hibernate type for the {@link RevisionType} enum.
|
* A hibernate type for the {@link RevisionType} enum.
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
*/
|
*/
|
||||||
public class RevisionTypeType implements UserType {
|
public class RevisionTypeType implements UserType, Serializable {
|
||||||
|
private static final long serialVersionUID = -1053201518229282688L;
|
||||||
|
|
||||||
private static final int[] SQL_TYPES = { Types.TINYINT };
|
private static final int[] SQL_TYPES = { Types.TINYINT };
|
||||||
|
|
||||||
public int[] sqlTypes() {
|
public int[] sqlTypes() {
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
package org.hibernate.envers.test.integration.cache;
|
||||||
|
|
||||||
|
import org.hibernate.MappingException;
|
||||||
|
import org.hibernate.cache.internal.EhCacheProvider;
|
||||||
|
import org.hibernate.cfg.Environment;
|
||||||
|
import org.hibernate.envers.RevisionType;
|
||||||
|
import org.hibernate.envers.query.criteria.RevisionTypeAuditExpression;
|
||||||
|
import org.hibernate.envers.test.AbstractSessionTest;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||||
|
import org.hibernate.stat.Statistics;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||||
|
*/
|
||||||
|
public class HibernateSecLvlQueryCache extends AbstractSessionTest {
|
||||||
|
@Override
|
||||||
|
protected void initMappings() throws MappingException, URISyntaxException {
|
||||||
|
config.addAnnotatedClass(StrTestEntity.class);
|
||||||
|
config.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true");
|
||||||
|
config.setProperty(Environment.USE_QUERY_CACHE, "true");
|
||||||
|
config.setProperty(Environment.CACHE_PROVIDER, EhCacheProvider.class.getName());
|
||||||
|
URL cacheURL = Thread.currentThread().getContextClassLoader().getResource("ehCache.xml");
|
||||||
|
config.setProperty(Environment.CACHE_PROVIDER_CONFIG, new File(cacheURL.toURI()).getAbsolutePath());
|
||||||
|
config.setProperty(Environment.GENERATE_STATISTICS, "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
// Revision 1
|
||||||
|
getSession().getTransaction().begin();
|
||||||
|
StrTestEntity ste = new StrTestEntity("data");
|
||||||
|
getSession().persist(ste);
|
||||||
|
getSession().getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSecLvlCacheWithRevisionTypeDiskPersistent() {
|
||||||
|
/* Invoking the same query twice for caching purpose. */
|
||||||
|
invokeSampleCacheableQuery();
|
||||||
|
invokeSampleCacheableQuery();
|
||||||
|
|
||||||
|
assert getQueryCacheStatistics() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void invokeSampleCacheableQuery() {
|
||||||
|
getAuditReader().createQuery().forEntitiesAtRevision(StrTestEntity.class, 1)
|
||||||
|
.add(new RevisionTypeAuditExpression(RevisionType.ADD, "="))
|
||||||
|
.setCacheable(true).getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getQueryCacheStatistics() {
|
||||||
|
Statistics stats = getSession().getSessionFactory().getStatistics();
|
||||||
|
|
||||||
|
double queryCacheHitCount = stats.getQueryCacheHitCount();
|
||||||
|
double queryCacheMissCount = stats.getQueryCacheMissCount();
|
||||||
|
double queryCacheHitRatio = queryCacheHitCount / (queryCacheHitCount + queryCacheMissCount);
|
||||||
|
|
||||||
|
return queryCacheHitRatio;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
<ehcache>
|
||||||
|
<diskStore path="java.io.tmpdir" />
|
||||||
|
<!-- Mandatory persist cached objects to disk (checks whether they are serializable). -->
|
||||||
|
<defaultCache eternal="false" diskPersistent="true"
|
||||||
|
maxElementsInMemory="1" maxElementsOnDisk="10000" overflowToDisk="true"
|
||||||
|
timeToIdleSeconds="3600" timeToLiveSeconds="3600" />
|
||||||
|
</ehcache>
|
Loading…
Reference in New Issue