HHH-10664 - Prep 5.2 feature branch - Envers

This commit is contained in:
Chris Cranford 2016-05-06 14:37:00 -05:00
parent 89e63ebc4f
commit 58473c87dd
23 changed files with 143 additions and 155 deletions

View File

@ -14,7 +14,7 @@ dependencies {
provided( project( ':hibernate-jpamodelgen' ) )
testCompile( project( ':hibernate-testing' ) )
testCompile( project( path: ':hibernate-core', configuration: 'tests' ) )
testRuntime( libraries.javassist )
}

View File

@ -13,7 +13,7 @@ import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.envers.RevisionType;
import org.hibernate.internal.util.compare.EqualsHelper;
import org.hibernate.type.IntegerType;
@ -40,7 +40,7 @@ public class RevisionTypeType implements UserType, Serializable {
}
@Override
public RevisionType nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor session, Object owner)
public RevisionType nullSafeGet(ResultSet resultSet, String[] names, SharedSessionContractImplementor session, Object owner)
throws HibernateException, SQLException {
final Integer representationInt = IntegerType.INSTANCE.nullSafeGet( resultSet, names[0], session );
return representationInt == null ?
@ -49,7 +49,7 @@ public class RevisionTypeType implements UserType, Serializable {
}
@Override
public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index, SessionImplementor session)
public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException {
IntegerType.INSTANCE.nullSafeSet(
preparedStatement,

View File

@ -10,16 +10,15 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import javax.persistence.FlushModeType;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.envers.internal.revisioninfo.RevisionInfoGenerator;
import org.hibernate.envers.internal.synchronization.work.AuditWorkUnit;
import org.hibernate.envers.tools.Pair;
import org.jboss.logging.Logger;
/**
@ -134,7 +133,7 @@ public class AuditProcess implements BeforeTransactionCompletionProcess {
}
// see: http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4178431
if ( FlushMode.isManualFlushMode( session.getFlushMode() ) ) {
if ( FlushModeType.COMMIT.equals ( session.getFlushMode() ) ) {
Session temporarySession = null;
try {
temporarySession = ((Session) session).sessionWithOptions()

View File

@ -13,6 +13,7 @@ import org.hibernate.Transaction;
import org.hibernate.action.spi.AfterTransactionCompletionProcess;
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.envers.internal.revisioninfo.RevisionInfoGenerator;
import org.hibernate.event.spi.EventSource;
@ -30,7 +31,7 @@ public class AuditProcessManager {
}
public AuditProcess get(EventSource session) {
final Transaction transaction = session.getTransaction();
final Transaction transaction = session.accessTransaction();
AuditProcess auditProcess = auditProcesses.get( transaction );
if ( auditProcess == null ) {
@ -51,7 +52,7 @@ public class AuditProcessManager {
session.getActionQueue().registerProcess(
new AfterTransactionCompletionProcess() {
public void doAfterTransactionCompletion(boolean success, SessionImplementor session) {
public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session) {
auditProcesses.remove( transaction );
}
}

View File

@ -9,7 +9,7 @@ package org.hibernate.envers.internal.synchronization;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.action.spi.AfterTransactionCompletionProcess;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource;
/**
@ -29,7 +29,7 @@ public class SessionCacheCleaner {
public void scheduleAuditDataRemoval(final Session session, final Object data) {
((EventSource) session).getActionQueue().registerProcess(
new AfterTransactionCompletionProcess() {
public void doAfterTransactionCompletion(boolean success, SessionImplementor sessionImplementor) {
public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor sessionImplementor) {
if ( !sessionImplementor.isClosed() ) {
try {
( (Session) sessionImplementor ).evict( data );

View File

@ -7,10 +7,10 @@
package org.hibernate.envers.internal.tools;
import javassist.util.proxy.ProxyFactory;
import org.hibernate.Session;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy;
@ -43,7 +43,7 @@ public abstract class EntityTools {
return proxy.getHibernateLazyInitializer().getImplementation();
}
final SessionImplementor sessionImplementor = proxy.getHibernateLazyInitializer().getSession();
final SharedSessionContractImplementor sessionImplementor = proxy.getHibernateLazyInitializer().getSession();
final Session tempSession = sessionImplementor == null
? sessionFactoryImplementor.openTemporarySession()
: sessionImplementor.getFactory().openTemporarySession();

View File

@ -12,13 +12,14 @@ import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.transaction.SystemException;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory;
@ -26,19 +27,16 @@ import org.hibernate.envers.boot.internal.EnversIntegrator;
import org.hibernate.envers.configuration.EnversSettings;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.HibernateEntityManagerFactory;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter;
import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.BeforeClassOnce;
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
import org.hibernate.testing.junit4.Helper;
import org.junit.After;
import org.jboss.logging.Logger;
import org.junit.After;
/**
* @author Strong Liu (stliu@hibernate.org)
@ -50,7 +48,7 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest
private EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder;
private StandardServiceRegistryImpl serviceRegistry;
private HibernateEntityManagerFactory entityManagerFactory;
private SessionFactoryImplementor entityManagerFactory;
private EntityManager em;
private AuditReader auditReader;
@ -81,10 +79,9 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest
buildPersistenceUnitDescriptor(),
buildSettings()
);
entityManagerFactory = entityManagerFactoryBuilder.build().unwrap( HibernateEntityManagerFactory.class );
entityManagerFactory = entityManagerFactoryBuilder.build().unwrap( SessionFactoryImplementor.class );
serviceRegistry = (StandardServiceRegistryImpl) entityManagerFactory.getSessionFactory()
.getServiceRegistry()
serviceRegistry = (StandardServiceRegistryImpl) entityManagerFactory.getServiceRegistry()
.getParentServiceRegistry();
afterEntityManagerFactoryBuilt();
@ -265,9 +262,9 @@ public abstract class BaseEnversJPAFunctionalTestCase extends AbstractEnversTest
protected AuditReader getAuditReader() {
EntityManager entityManager = getOrCreateEntityManager();
PersistenceUnitTransactionType transactionType = ((EntityManagerImpl) entityManager).getTransactionType();
SessionImplementor sessionImplementor = entityManager.unwrap( SessionImplementor.class );
if ( transactionType == PersistenceUnitTransactionType.JTA ) {
if ( sessionImplementor.getTransactionCoordinator().getTransactionCoordinatorBuilder().isJta() ) {
if ( !JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) ) {
try {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();

View File

@ -12,7 +12,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.type.IntegerType;
import org.hibernate.type.StringType;
import org.hibernate.type.Type;
@ -75,7 +75,7 @@ public class CompositeTestUserType implements CompositeUserType {
public Object nullSafeGet(
final ResultSet rs, final String[] names,
final SessionImplementor session,
final SharedSessionContractImplementor session,
final Object owner) throws HibernateException, SQLException {
final String prop1 = rs.getString( names[0] );
if ( prop1 == null ) {
@ -88,7 +88,7 @@ public class CompositeTestUserType implements CompositeUserType {
public void nullSafeSet(
final PreparedStatement st, final Object value,
final int index, final SessionImplementor session)
final int index, final SharedSessionContractImplementor session)
throws HibernateException, SQLException {
if ( value == null ) {
st.setNull( index, StringType.INSTANCE.sqlType() );
@ -110,19 +110,20 @@ public class CompositeTestUserType implements CompositeUserType {
return true;
}
public Serializable disassemble(final Object value, final SessionImplementor session) throws HibernateException {
public Serializable disassemble(
final Object value, final SharedSessionContractImplementor session) throws HibernateException {
return (Serializable) value;
}
public Object assemble(
final Serializable cached, final SessionImplementor session,
final Serializable cached, final SharedSessionContractImplementor session,
final Object owner) throws HibernateException {
return cached;
}
public Object replace(
Object original, Object target,
SessionImplementor session, Object owner) throws HibernateException {
SharedSessionContractImplementor session, Object owner) throws HibernateException {
return original;
}
}

View File

@ -14,7 +14,7 @@ import java.sql.Types;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.type.StringType;
import org.hibernate.usertype.ParameterizedType;
import org.hibernate.usertype.UserType;
@ -37,12 +37,12 @@ public class ParametrizedTestUserType implements UserType, ParameterizedType {
return String.class;
}
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner)
throws HibernateException, SQLException {
return StringType.INSTANCE.nullSafeGet( rs, names[0], session );
}
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException {
if ( value != null ) {
String v = (String) value;

View File

@ -13,7 +13,7 @@ import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.usertype.UserType;
/**
@ -44,7 +44,7 @@ public class CustomEnumUserType implements UserType {
return (x == null) ? 0 : x.hashCode();
}
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner)
throws HibernateException, SQLException {
String name = rs.getString( names[0] );
if ( rs.wasNull() ) {
@ -53,7 +53,7 @@ public class CustomEnumUserType implements UserType {
return CustomEnum.fromYesNo( name );
}
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException {
CustomEnum val = (CustomEnum) value;
if ( val == null ) {

View File

@ -7,19 +7,17 @@
package org.hibernate.envers.test.integration.basic;
import java.util.Map;
import javax.persistence.TransactionRequiredException;
import org.hibernate.Session;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.envers.configuration.EnversSettings;
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.test.BaseEnversFunctionalTestCase;
import org.hibernate.envers.test.entities.StrTestEntity;
import org.hibernate.envers.test.integration.collection.norevision.Name;
import org.hibernate.envers.test.integration.collection.norevision.Person;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
/**
@ -41,7 +39,7 @@ public class OutsideTransactionTest extends BaseEnversFunctionalTestCase {
settings.put( EnversSettings.REVISION_ON_COLLECTION_CHANGE, "true" );
}
@Test(expected = AuditException.class)
@Test(expected = TransactionRequiredException.class)
public void testInsertOutsideActiveTransaction() {
Session session = openSession();
@ -53,7 +51,7 @@ public class OutsideTransactionTest extends BaseEnversFunctionalTestCase {
session.close();
}
@Test(expected = AuditException.class)
@Test(expected = TransactionRequiredException.class)
public void testUpdateOutsideActiveTransaction() {
Session session = openSession();
@ -71,7 +69,7 @@ public class OutsideTransactionTest extends BaseEnversFunctionalTestCase {
session.close();
}
@Test(expected = AuditException.class)
@Test(expected = TransactionRequiredException.class)
public void testDeleteOutsideActiveTransaction() {
Session session = openSession();
@ -88,7 +86,7 @@ public class OutsideTransactionTest extends BaseEnversFunctionalTestCase {
session.close();
}
@Test(expected = AuditException.class)
@Test(expected = TransactionRequiredException.class)
public void testCollectionUpdateOutsideActiveTransaction() {
Session session = openSession();
@ -109,7 +107,7 @@ public class OutsideTransactionTest extends BaseEnversFunctionalTestCase {
session.close();
}
@Test(expected = AuditException.class)
@Test(expected = TransactionRequiredException.class)
public void testCollectionRemovalOutsideActiveTransaction() {
Session session = openSession();

View File

@ -10,6 +10,7 @@ import org.hibernate.Session;
import org.hibernate.action.spi.AfterTransactionCompletionProcess;
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.envers.internal.tools.MutableInteger;
import org.hibernate.envers.test.BaseEnversFunctionalTestCase;
import org.hibernate.envers.test.entities.StrTestEntity;
@ -18,7 +19,6 @@ import org.hibernate.event.spi.EventType;
import org.hibernate.event.spi.PostInsertEvent;
import org.hibernate.event.spi.PostInsertEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.testing.TestForIssue;
import org.junit.Assert;
import org.junit.Test;
@ -71,7 +71,7 @@ public class RegisterUserEventListenersTest extends BaseEnversFunctionalTestCase
event.getSession().getActionQueue().registerProcess(
new AfterTransactionCompletionProcess() {
@Override
public void doAfterTransactionCompletion(boolean success, SessionImplementor session) {
public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session) {
afterCounter.increase();
}
}

View File

@ -11,84 +11,79 @@ import javax.persistence.EntityManager;
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
import org.hibernate.envers.test.entities.IntTestEntity;
import org.hibernate.internal.SessionImpl;
import org.hibernate.testing.TestForIssue;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author Tomasz Dziurko (tdziurko at gmail dot com)
*/
public class TransactionRollbackBehaviour extends BaseEnversJPAFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {IntTestEntity.class};
}
@Test
public void testAuditRecordsRollback() {
// Given
EntityManager em = getEntityManager();
em.getTransaction().begin();
IntTestEntity iteToRollback = new IntTestEntity( 30 );
em.persist( iteToRollback );
Integer rollbackedIteId = iteToRollback.getId();
em.getTransaction().rollback();
public void testAuditRecordsRollbackWithAutoClear() {
testAuditRecordsRollbackBehavior( false, true );
}
// When
em.getTransaction().begin();
IntTestEntity ite2 = new IntTestEntity( 50 );
em.persist( ite2 );
Integer ite2Id = ite2.getId();
em.getTransaction().commit();
// Then
List<Number> revisionsForSavedClass = getAuditReader().getRevisions( IntTestEntity.class, ite2Id );
Assert.assertEquals( "There should be one revision for inserted entity.", 1, revisionsForSavedClass.size() );
List<Number> revisionsForRolledbackClass = getAuditReader().getRevisions(
IntTestEntity.class,
rollbackedIteId
);
Assert.assertEquals(
"There should be no revision for rolled back transaction.",
0,
revisionsForRolledbackClass.size()
);
@Test
public void testAuditRecordsRollbackWithNoAutoClear() {
testAuditRecordsRollbackBehavior( false, false );
}
@Test
@TestForIssue(jiraKey = "HHH-8189")
public void testFlushedAuditRecordsRollback() {
// Given
EntityManager em = getEntityManager();
em.getTransaction().begin();
IntTestEntity iteToRollback = new IntTestEntity( 30 );
em.persist( iteToRollback );
em.flush();
Integer rollbackedIteId = iteToRollback.getId();
em.getTransaction().rollback();
// default auto-clear behavior
testAuditRecordsRollbackBehavior( true, null );
}
// When
em.getTransaction().begin();
IntTestEntity ite2 = new IntTestEntity( 50 );
em.persist( ite2 );
em.flush();
Integer ite2Id = ite2.getId();
em.getTransaction().commit();
private void testAuditRecordsRollbackBehavior(boolean flush, Boolean autoClear) {
EntityManager entityManager = getEntityManager();
try {
if ( autoClear != null ) {
entityManager.unwrap( SessionImpl.class ).setAutoClear( autoClear );
}
// Then
List<Number> revisionsForSavedClass = getAuditReader().getRevisions( IntTestEntity.class, ite2Id );
Assert.assertEquals( "There should be one revision for inserted entity.", 1, revisionsForSavedClass.size() );
// persist and rollback
entityManager.getTransaction().begin();
IntTestEntity rollbackEntity = new IntTestEntity( 30 );
entityManager.persist( rollbackEntity );
if ( flush ) {
entityManager.flush();
}
Integer rollbackId = rollbackEntity.getId();
entityManager.getTransaction().rollback();
// persist and commit
entityManager.getTransaction().begin();
IntTestEntity commitEntity = new IntTestEntity( 50 );
entityManager.persist( commitEntity );
if ( flush ) {
entityManager.flush();
}
Integer commitId = commitEntity.getId();
entityManager.getTransaction().commit();
List<Number> revisionsForSavedClass = getAuditReader().getRevisions(
IntTestEntity.class,
commitId
);
assertEquals( "There should be one revision for inserted entity.", 1, revisionsForSavedClass.size() );
List<Number> revisionsForRolledbackClass = getAuditReader().getRevisions(
IntTestEntity.class,
rollbackedIteId
);
Assert.assertEquals(
"There should be no revision for rolled back transaction.",
0,
revisionsForRolledbackClass.size()
rollbackId
);
assertEquals( "There should be no revision for rolled back entity.", 0, revisionsForRolledbackClass.size() );
}
finally {
entityManager.close();
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {IntTestEntity.class};
}
}

View File

@ -15,6 +15,7 @@ import javax.persistence.Query;
import javax.transaction.Status;
import javax.transaction.TransactionManager;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Oracle8iDialect;
import org.hibernate.envers.RevisionType;
import org.hibernate.envers.enhanced.SequenceIdRevisionEntity;
@ -66,6 +67,7 @@ public class DetachedMultipleCollectionChangeTest extends BaseEnversJPAFunctiona
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
TestingJtaBootstrap.prepare( options );
options.put( AvailableSettings.ALLOW_JTA_TRANSACTION_ACCESS, "true" );
tm = TestingJtaPlatformImpl.INSTANCE.getTransactionManager();
}

View File

@ -12,7 +12,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.type.IntegerType;
import org.hibernate.usertype.UserType;
@ -41,13 +41,13 @@ public class AgeType implements UserType {
}
@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner)
throws HibernateException, SQLException {
return new Age( rs.getInt( rs.findColumn( names[0] ) ) );
}
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException {
st.setInt( index, ( (Age) value ).getAgeInYears() );
}

View File

@ -25,6 +25,8 @@ import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import junit.framework.Assert;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
/**
* @author Lukasz Zuchowski (author at zuchos dot com)
* More advanced tests for dynamic component.
@ -349,12 +351,9 @@ public class AuditedDynamicComponentsAdvancedCasesTest extends BaseEnversFunctio
//then
Assert.fail();
}
catch ( QueryException e ) {
}
catch ( Exception e ) {
Assert.fail();
assertTyping( IllegalArgumentException.class, e );
}
try {
@ -367,16 +366,13 @@ public class AuditedDynamicComponentsAdvancedCasesTest extends BaseEnversFunctio
.getResultList();
Assert.fail();
}
catch ( AuditException e ) {
catch ( Exception e ) {
assertTyping( AuditException.class, e );
Assert.assertEquals(
"This type of relation (org.hibernate.envers.test.integration.components.dynamic.AdvancedEntity.dynamicConfiguration_internalMapWithEntities) isn't supported and can't be used in queries.",
e.getMessage()
);
}
catch ( Exception e ) {
Assert.fail();
}
}
@Test

View File

@ -9,15 +9,17 @@ package org.hibernate.envers.test.integration.components.dynamic;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.QueryException;
import junit.framework.Assert;
import org.hibernate.Session;
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.query.AuditEntity;
import org.hibernate.envers.test.BaseEnversFunctionalTestCase;
import org.hibernate.envers.test.Priority;
import org.junit.Test;
import junit.framework.Assert;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class SanityCheckTest extends BaseEnversFunctionalTestCase {
@ -141,17 +143,15 @@ public class SanityCheckTest extends BaseEnversFunctionalTestCase {
.add( AuditEntity.property( "component_manyToManyList" ).eq( manyToManyEntities ) )
.getResultList();
//then
Assert.fail();
fail( "This should have generated an AuditException" );
}
catch ( AuditException e ) {
Assert.assertEquals(
catch ( Exception e ) {
assertTyping( AuditException.class, e );
assertEquals(
"This type of relation (org.hibernate.envers.test.integration.components.dynamic.PlainEntity.component_manyToManyList) isn't supported and can't be used in queries.",
e.getMessage()
);
}
catch ( Exception e ) {
Assert.fail();
}
}
@Test
@ -176,12 +176,10 @@ public class SanityCheckTest extends BaseEnversFunctionalTestCase {
.getResultList();
//then
Assert.fail();
}
catch ( QueryException e ) {
fail( "This should have generated an IllegalArgumentException" );
}
catch ( Exception e ) {
Assert.fail();
assertTyping( IllegalArgumentException.class, e );
}
}
}

View File

@ -20,7 +20,7 @@ import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.usertype.UserType;
/**
@ -60,14 +60,14 @@ public class ObjectUserType implements UserType {
}
@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner)
throws HibernateException, SQLException {
final String type = rs.getString( names[0] ); // For debug purpose.
return convertInputStreamToObject( rs.getBinaryStream( names[1] ) );
}
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException {
if ( value == null ) {
st.setNull( index, TYPES[0] );

View File

@ -6,6 +6,8 @@
*/
package org.hibernate.envers.test.integration.customtype;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -17,6 +19,7 @@ import org.hibernate.envers.test.BaseEnversFunctionalTestCase;
import org.hibernate.envers.test.Priority;
import org.hibernate.envers.test.entities.customtype.UnspecifiedEnumTypeEntity;
import org.hibernate.jdbc.Work;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.junit.Assert;
@ -58,11 +61,10 @@ public class UnspecifiedEnumTypeTest extends BaseEnversFunctionalTestCase {
}
public void dropSchema(Session session) {
executeUpdateSafety( session, "alter table ENUM_ENTITY_AUD drop constraint FK_AUD_REV" );
executeUpdateSafety( session, "drop table ENUM_ENTITY if exists" );
executeUpdateSafety( session, "drop table ENUM_ENTITY_AUD if exists" );
executeUpdateSafety( session, "drop table REVINFO if exists" );
executeUpdateSafety( session, "drop sequence REVISION_GENERATOR" );
executeUpdateSafety( session, "drop sequence REVISION_GENERATOR if exists" );
}
private void createSchema(Session session) {
@ -86,11 +88,14 @@ public class UnspecifiedEnumTypeTest extends BaseEnversFunctionalTestCase {
}
private void executeUpdateSafety(Session session, String query) {
try {
session.createSQLQuery( query ).executeUpdate();
session.doWork(
new Work() {
@Override
public void execute(Connection connection) throws SQLException {
connection.createStatement().execute( query );
}
catch (Exception e) {
}
);
}
@Test

View File

@ -10,6 +10,7 @@ import java.util.List;
import java.util.Map;
import javax.persistence.EntityManager;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
import org.hibernate.envers.test.Priority;
import org.hibernate.envers.test.entities.IntTestEntity;
@ -35,6 +36,7 @@ public class JtaTransaction extends BaseEnversJPAFunctionalTestCase {
@Override
protected void addConfigOptions(Map options) {
TestingJtaBootstrap.prepare( options );
options.put( AvailableSettings.ALLOW_JTA_TRANSACTION_ACCESS, "true" );
}
@Test

View File

@ -9,13 +9,11 @@ package org.hibernate.envers.test.integration.modifiedflags;
import java.util.List;
import javax.persistence.EntityManager;
import org.hibernate.QueryException;
import org.hibernate.envers.test.Priority;
import org.hibernate.envers.test.entities.components.Component1;
import org.hibernate.envers.test.entities.components.Component2;
import org.hibernate.envers.test.entities.components.ComponentTestEntity;
import org.hibernate.envers.test.tools.TestTools;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
@ -129,7 +127,7 @@ public class HasChangedComponents extends AbstractModifiedFlagsEntityTest {
);
}
@Test(expected = QueryException.class)
@Test(expected = IllegalArgumentException.class)
public void testHasChangedNotAudited() throws Exception {
queryForPropertyHasChanged( ComponentTestEntity.class, id1, "comp2" );
}

View File

@ -10,14 +10,12 @@ import java.util.Arrays;
import java.util.List;
import javax.persistence.EntityManager;
import org.hibernate.QueryException;
import org.hibernate.envers.test.Priority;
import org.hibernate.envers.test.entities.StrTestEntity;
import org.hibernate.envers.test.entities.components.Component1;
import org.hibernate.envers.test.entities.components.Component2;
import org.hibernate.envers.test.integration.modifiedflags.entities.PartialModifiedFlagsEntity;
import org.hibernate.envers.test.integration.modifiedflags.entities.WithModifiedFlagReferencingEntity;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
@ -191,7 +189,7 @@ public class HasChangedForDefaultNotUsing extends AbstractModifiedFlagsEntityTes
assertEquals( makeList( 3 ), extractRevisionNumbers( list ) );
}
@Test(expected = QueryException.class)
@Test(expected = IllegalArgumentException.class)
public void testHasChangedComp2() throws Exception {
queryForPropertyHasChanged(
PartialModifiedFlagsEntity.class,
@ -209,7 +207,7 @@ public class HasChangedForDefaultNotUsing extends AbstractModifiedFlagsEntityTes
assertEquals( makeList( 5, 6 ), extractRevisionNumbers( list ) );
}
@Test(expected = QueryException.class)
@Test(expected = IllegalArgumentException.class)
public void testHasChangedReferencing2() throws Exception {
queryForPropertyHasChanged(
PartialModifiedFlagsEntity.class,

View File

@ -9,10 +9,8 @@ package org.hibernate.envers.test.integration.modifiedflags;
import java.util.List;
import javax.persistence.EntityManager;
import org.hibernate.QueryException;
import org.hibernate.envers.test.Priority;
import org.hibernate.envers.test.integration.basic.BasicTestEntity2;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
@ -69,7 +67,7 @@ public class HasChangedUnversionedProperties extends AbstractModifiedFlagsEntity
assertEquals( makeList( 1, 2 ), extractRevisionNumbers( list ) );
}
@Test(expected = QueryException.class)
@Test(expected = IllegalArgumentException.class)
public void testExceptionOnHasChangedQuery() throws Exception {
queryForPropertyHasChangedWithDeleted(
BasicTestEntity2.class,