HHH-11593 - Fix test issues in SQL Server
This commit is contained in:
parent
e6d2ff4ac4
commit
ae23ecd937
|
@ -64,7 +64,6 @@ public class SecondLevelCacheTest extends BaseEntityManagerFunctionalTestCase {
|
|||
@Test
|
||||
public void testCache() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
entityManager.persist( new Person() );
|
||||
entityManager.persist( new Person() );
|
||||
Person aPerson= new Person();
|
||||
aPerson.setName( "John Doe" );
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.hibernate.dialect.H2Dialect;
|
|||
import org.hibernate.dialect.MySQL5Dialect;
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.type.StringType;
|
||||
import org.hibernate.userguide.model.AddressType;
|
||||
|
@ -41,7 +42,10 @@ import org.hibernate.userguide.model.Phone;
|
|||
import org.hibernate.userguide.model.PhoneType;
|
||||
import org.hibernate.userguide.model.WireTransferPayment;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -1131,7 +1135,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase {
|
|||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
//tag::hql-concat-function-example[]
|
||||
List<String> callHistory = entityManager.createQuery(
|
||||
"select concat( p.number, ' : ' ,c.duration ) " +
|
||||
"select concat( p.number, ' : ' , cast(c.duration as string) ) " +
|
||||
"from Call c " +
|
||||
"join c.phone p", String.class )
|
||||
.getResultList();
|
||||
|
@ -1259,6 +1263,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialect(SQLServerDialect.class)
|
||||
public void test_hql_current_date_function_example() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
//tag::hql-current-date-function-example[]
|
||||
|
@ -1272,6 +1277,19 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresDialect(SQLServerDialect.class)
|
||||
public void test_hql_current_date_function_example_sql_server() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
List<Call> calls = entityManager.createQuery(
|
||||
"select c " +
|
||||
"from Call c " +
|
||||
"where c.timestamp = current_date()", Call.class )
|
||||
.getResultList();
|
||||
assertEquals(0, calls.size());
|
||||
});
|
||||
}
|
||||
|
||||
@Test @RequiresDialect(H2Dialect.class)
|
||||
public void test_hql_current_time_function_example() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
|
@ -1356,6 +1374,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialect(SQLServerDialect.class)
|
||||
public void test_hql_str_function_example() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
//tag::hql-str-function-example[]
|
||||
|
@ -1368,6 +1387,20 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresDialect(SQLServerDialect.class)
|
||||
public void test_hql_str_function_example_sql_server() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
//tag::hql-str-function-example[]
|
||||
List<String> timestamps = entityManager.createQuery(
|
||||
"select str( cast(duration as float) / 60, 4, 2 ) " +
|
||||
"from Call c ", String.class )
|
||||
.getResultList();
|
||||
//end::hql-str-function-example[]
|
||||
assertEquals(2, timestamps.size());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_hql_collection_expressions_example_1() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
|
@ -2159,6 +2192,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase {
|
|||
|
||||
|
||||
@Test
|
||||
@RequiresDialectFeature(DialectChecks.SupportRowValueConstructorSyntaxInInList.class)
|
||||
public void test_hql_in_predicate_example_6() {
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.hibernate.hql.internal.ast.QuerySyntaxException;
|
|||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import org.hibernate.jpa.AvailableSettings;
|
|||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.jpa.test.Wallet;
|
||||
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.hibernate.jpa.AvailableSettings;
|
|||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.jpa.test.Wallet;
|
||||
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.hibernate.cfg.AvailableSettings;
|
|||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -23,6 +23,8 @@ import org.hibernate.Transaction;
|
|||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.dialect.PostgreSQL9Dialect;
|
||||
import org.hibernate.dialect.PostgresPlusDialect;
|
||||
import org.hibernate.dialect.SQLServer2005Dialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.engine.query.spi.HQLQueryPlan;
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.hibernate.hql.spi.QueryTranslator;
|
||||
|
@ -66,6 +68,7 @@ public class CompositeIdTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
@SkipForDialect(value = Oracle8iDialect.class, comment = "Cannot count distinct over multiple columns in Oracle")
|
||||
@SkipForDialect(value = SQLServerDialect.class, comment = "Cannot count distinct over multiple columns in SQL Server")
|
||||
public void testDistinctCountOfEntityWithCompositeId() {
|
||||
// today we do not account for Dialects supportsTupleDistinctCounts() is false. though really the only
|
||||
// "option" there is to throw an error.
|
||||
|
|
|
@ -26,8 +26,6 @@ import org.hibernate.ScrollableResults;
|
|||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.criterion.DetachedCriteria;
|
||||
import org.hibernate.criterion.Example;
|
||||
import org.hibernate.criterion.MatchMode;
|
||||
|
@ -50,11 +48,10 @@ import org.hibernate.testing.DialectChecks;
|
|||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.hql.Animal;
|
||||
import org.hibernate.test.hql.Reptile;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.hibernate.exception.SQLGrammarException;
|
|||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.SQLStatementInterceptor;
|
||||
import org.hibernate.testing.jdbc.SQLStatementInterceptor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.dialect.functional;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.dialect.SQLServer2005Dialect;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* used driver hibernate.connection.driver_class com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
*
|
||||
* @author Guenther Demetz
|
||||
*/
|
||||
@RequiresDialect(value = { SQLServer2005Dialect.class })
|
||||
public class SQLServerDialectCollationTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
private static final Logger log = Logger.getLogger( SQLServerDialectCollationTest.class );
|
||||
|
||||
@Override
|
||||
protected Configuration constructConfiguration() {
|
||||
Configuration configuration = super.constructConfiguration();
|
||||
configuration.setProperty( AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, Boolean.TRUE.toString() );
|
||||
return configuration;
|
||||
}
|
||||
|
||||
protected void buildSessionFactory() {
|
||||
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
|
||||
StandardServiceRegistryImpl _serviceRegistry = buildServiceRegistry( bootRegistry, constructConfiguration() );
|
||||
|
||||
try {
|
||||
try (Connection connection = _serviceRegistry.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess().obtainConnection();
|
||||
Statement statement = connection.createStatement()) {
|
||||
connection.setAutoCommit( true );
|
||||
statement.executeUpdate( "DROP DATABASE hibernate_orm_test_collation" );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
log.debug( e.getMessage() );
|
||||
}
|
||||
try (Connection connection = _serviceRegistry.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess().obtainConnection();
|
||||
Statement statement = connection.createStatement()) {
|
||||
connection.setAutoCommit( true );
|
||||
statement.executeUpdate( "CREATE DATABASE hibernate_orm_test_collation COLLATE Latin1_General_CS_AS" );
|
||||
statement.executeUpdate( "ALTER DATABASE [hibernate_orm_test_collation] SET AUTO_CLOSE OFF " );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
log.debug( e.getMessage() );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
_serviceRegistry.destroy();
|
||||
}
|
||||
super.buildSessionFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7198")
|
||||
public void testMaxResultsSqlServerWithCaseSensitiveCollation() throws Exception {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
for ( int i = 1; i <= 20; i++ ) {
|
||||
session.persist( new CustomProduct( i, "Kit" + i ) );
|
||||
}
|
||||
session.flush();
|
||||
session.clear();
|
||||
|
||||
List list = session.createQuery( "from CustomProduct where description like 'Kit%'" )
|
||||
.setFirstResult( 2 )
|
||||
.setMaxResults( 2 )
|
||||
.list();
|
||||
assertEquals( 2, list.size() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
CustomProduct.class
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Entity(name = "CustomProduct")
|
||||
@Table(catalog = "hibernate_orm_test_collation", schema = "dbo")
|
||||
public static class CustomProduct implements Serializable {
|
||||
@Id
|
||||
public Integer id;
|
||||
|
||||
@Column(name = "description", nullable = false)
|
||||
public String description;
|
||||
|
||||
public CustomProduct() {
|
||||
}
|
||||
|
||||
public CustomProduct(Integer id, String description) {
|
||||
this.id = id;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
CustomProduct that = (CustomProduct) o;
|
||||
return Objects.equals( description, that.description );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash( description );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CustomProduct{" +
|
||||
"id=" + id +
|
||||
", description='" + description + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean rebuildSessionFactoryOnError() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -51,8 +51,6 @@ import static org.junit.Assert.assertTrue;
|
|||
@RequiresDialect(value = { SQLServer2005Dialect.class })
|
||||
public class SQLServerDialectTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
|
||||
@Override
|
||||
protected Configuration constructConfiguration() {
|
||||
Configuration configuration = super.constructConfiguration();
|
||||
|
@ -60,63 +58,6 @@ public class SQLServerDialectTest extends BaseCoreFunctionalTestCase {
|
|||
return configuration;
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7198")
|
||||
public void testMaxResultsSqlServerWithCaseSensitiveCollation() throws Exception {
|
||||
|
||||
final Session s1 = openSession();
|
||||
s1.beginTransaction();
|
||||
String defaultCollationName = s1.doReturningWork( connection -> {
|
||||
String databaseName = connection.getCatalog();
|
||||
Statement st = ((SessionImplementor)s1).getJdbcCoordinator().getStatementPreparer().createStatement();
|
||||
ResultSet rs = ((SessionImplementor)s1).getJdbcCoordinator().getResultSetReturn().extract( st, "SELECT collation_name FROM sys.databases WHERE name = '"+databaseName+ "';" );
|
||||
while(rs.next()){
|
||||
return rs.getString( "collation_name" );
|
||||
}
|
||||
throw new AssertionError( "can't get collation name of database "+databaseName );
|
||||
|
||||
} );
|
||||
s1.getTransaction().commit();
|
||||
s1.close();
|
||||
|
||||
Session s2 = openSession();
|
||||
Transaction tx = s2.beginTransaction();
|
||||
|
||||
String databaseName = s2.doReturningWork( new ReturningWork<String>() {
|
||||
@Override
|
||||
public String execute(Connection connection) throws SQLException {
|
||||
return connection.getCatalog();
|
||||
}
|
||||
} );
|
||||
s2.createNativeQuery( "ALTER DATABASE " + databaseName + " set single_user with rollback immediate" )
|
||||
.executeUpdate();
|
||||
s2.createNativeQuery( "ALTER DATABASE " + databaseName + " COLLATE Latin1_General_CS_AS" ).executeUpdate();
|
||||
s2.createNativeQuery( "ALTER DATABASE " + databaseName + " set multi_user" ).executeUpdate();
|
||||
|
||||
for ( int i = 1; i <= 20; i++ ) {
|
||||
s2.persist( new Product2( i, "Kit" + i ) );
|
||||
}
|
||||
s2.flush();
|
||||
s2.clear();
|
||||
|
||||
List list = s2.createQuery( "from Product2 where description like 'Kit%'" )
|
||||
.setFirstResult( 2 )
|
||||
.setMaxResults( 2 )
|
||||
.list();
|
||||
assertEquals( 2, list.size() );
|
||||
tx.rollback();
|
||||
s2.close();
|
||||
|
||||
executorService.execute( () -> {
|
||||
doInHibernate( this::sessionFactory, s3 -> {
|
||||
s3.createNativeQuery( "ALTER DATABASE " + databaseName + " set single_user with rollback immediate" )
|
||||
.executeUpdate();
|
||||
s3.createNativeQuery( "ALTER DATABASE " + databaseName + " COLLATE " + defaultCollationName ).executeUpdate();
|
||||
s3.createNativeQuery( "ALTER DATABASE " + databaseName + " set multi_user" ).executeUpdate();
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7369")
|
||||
public void testPaginationWithScalarQuery() throws Exception {
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.hibernate.jpa.QueryHints;
|
|||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.SQLStatementInterceptor;
|
||||
import org.hibernate.testing.jdbc.SQLStatementInterceptor;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
<filter name="effectiveDate" condition=":asOfDate BETWEEN eff_start_dt and eff_end_dt"/>
|
||||
<filter name="unioned">
|
||||
'abc' in ( select d.reg from DEPARTMENT d where (d.dept_id=123) union select p.name from SALES_PERSON p )
|
||||
'abc' in ( select d.REG from DEPARTMENT d where (d.DEPT_ID=123) union select p.NAME from SALES_PERSON p )
|
||||
</filter>
|
||||
|
||||
</class>
|
||||
|
|
|
@ -1433,25 +1433,25 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
.setParameterList( "1", params )
|
||||
.list();
|
||||
|
||||
s.createQuery( "from Human where nickname = ?1 and ( name.first = ?2 or name.last in (?3) )" )
|
||||
s.createQuery( "from Human where nickName = ?1 and ( name.first = ?2 or name.last in (?3) )" )
|
||||
.setParameter( "1", "Yogster" )
|
||||
.setParameter( "2", "Yogi" )
|
||||
.setParameterList( "3", params )
|
||||
.list();
|
||||
|
||||
s.createQuery( "from Human where nickname = ?1 and ( name.first = ?2 or name.last in ?3 )" )
|
||||
s.createQuery( "from Human where nickName = ?1 and ( name.first = ?2 or name.last in ?3 )" )
|
||||
.setParameter( "1", "Yogster" )
|
||||
.setParameter( "2", "Yogi" )
|
||||
.setParameterList( "3", params )
|
||||
.list();
|
||||
|
||||
s.createQuery( "from Human where nickname = ?1 or ( name.first = ?2 and name.last in (?3) )" )
|
||||
s.createQuery( "from Human where nickName = ?1 or ( name.first = ?2 and name.last in (?3) )" )
|
||||
.setParameter( "1", "Yogster" )
|
||||
.setParameter( "2", "Yogi" )
|
||||
.setParameterList( "3", params )
|
||||
.list();
|
||||
|
||||
s.createQuery( "from Human where nickname = ?1 or ( name.first = ?2 and name.last in ?3 )" )
|
||||
s.createQuery( "from Human where nickName = ?1 or ( name.first = ?2 and name.last in ?3 )" )
|
||||
.setParameter( "1", "Yogster" )
|
||||
.setParameter( "2", "Yogi" )
|
||||
.setParameterList( "3", params )
|
||||
|
@ -2234,7 +2234,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
s.flush();
|
||||
|
||||
// Check order via SQL. Numbers are negated in the DB, so second comes first.
|
||||
List listViaSql = s.createSQLQuery("select id from SIMPLE_1 order by negated_num").list();
|
||||
List listViaSql = s.createSQLQuery("select ID from SIMPLE_1 order by negated_num").list();
|
||||
assertEquals( 2, listViaSql.size() );
|
||||
assertEquals( second.getId().longValue(), ((Number) listViaSql.get( 0 )).longValue() );
|
||||
assertEquals( first.getId().longValue(), ((Number) listViaSql.get( 1 )).longValue() );
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Projections;
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.hibernate.hql.internal.ast.QueryTranslatorImpl;
|
||||
import org.hibernate.hql.internal.ast.tree.SelectClause;
|
||||
|
@ -209,6 +210,7 @@ public class CriteriaHQLAlignmentTest extends QueryTranslatorTestCase {
|
|||
|
||||
@Test
|
||||
@SkipForDialect(value = Oracle8iDialect.class, comment = "Cannot count distinct over multiple columns in Oracle")
|
||||
@SkipForDialect(value = SQLServerDialect.class, comment = "Cannot count distinct over multiple columns in SQL Server")
|
||||
public void testCountReturnValues() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
|
|
|
@ -251,7 +251,7 @@ public class WithClauseTest extends BaseCoreFunctionalTestCase {
|
|||
Transaction txn = s.beginTransaction();
|
||||
|
||||
// Just a stupid example that makes use of a column that isn't from the collection table or the target entity table
|
||||
List list = s.createQuery( "from Human h join h.friends as friend left join h.family as f with key(f) = concat('son', friend.intValue) where h.description = 'father'" )
|
||||
List list = s.createQuery( "from Human h join h.friends as friend left join h.family as f with key(f) = concat('son', cast(friend.intValue as string)) where h.description = 'father'" )
|
||||
.list();
|
||||
assertEquals( "subquery rewriting of join table did not take effect", 2, list.size() );
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
|
||||
<class name="Person">
|
||||
<id name="id" column="id">
|
||||
<generator class="sequence">
|
||||
<param name="parameters">start with 10</param>
|
||||
<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
|
||||
<param name="initial_value">10</param>
|
||||
</generator>
|
||||
</id>
|
||||
</class>
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.id;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.SQLServer2012Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SQLServer2012SequenceGeneratorAnnotationTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Person.class };
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL server requires that sequence be initialized to something other than the minimum value for the type
|
||||
* (e.g., Long.MIN_VALUE). For generator = "sequence", the initial value must be provided as a parameter.
|
||||
* For this test, the sequence is initialized to 10.
|
||||
*/
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-8814")
|
||||
@RequiresDialect(value=SQLServer2012Dialect.class)
|
||||
public void testStartOfSequence() {
|
||||
final Person person = doInHibernate( this::sessionFactory, session -> {
|
||||
final Person _person = new Person();
|
||||
session.persist(_person);
|
||||
return _person;
|
||||
} );
|
||||
|
||||
assertTrue(person.getId() == 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCleanupTestDataRequired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Entity(name = "Person")
|
||||
public static class Person {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
|
||||
@SequenceGenerator(initialValue = 10, name = "seq")
|
||||
private long id;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,10 @@
|
|||
*/
|
||||
package org.hibernate.test.id;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
@ -34,22 +38,18 @@ public class SQLServer2012SequenceGeneratorTest extends BaseCoreFunctionalTestCa
|
|||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-8814")
|
||||
@RequiresDialect(value=SQLServer2012Dialect.class)
|
||||
public void testStartOfSequence() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
final Person person = new Person();
|
||||
s.persist(person);
|
||||
tx.commit();
|
||||
s.close();
|
||||
public void testStartOfSequence() {
|
||||
final Person person = doInHibernate( this::sessionFactory, session -> {
|
||||
final Person _person = new Person();
|
||||
session.persist(_person);
|
||||
return _person;
|
||||
} );
|
||||
|
||||
assertTrue(person.getId() == 10);
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
s.createQuery( "delete from Person" ).executeUpdate();
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCleanupTestDataRequired() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import org.hibernate.testing.RequiresDialectFeature;
|
|||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.SQLStatementInterceptor;
|
||||
import org.hibernate.testing.jdbc.SQLStatementInterceptor;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.hibernate.cfg.Environment;
|
|||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.hibernate.cfg.Environment;
|
|||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.hibernate.cfg.Environment;
|
|||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.hibernate.cfg.Environment;
|
|||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
package org.hibernate.test.insertordering;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
@ -15,8 +15,6 @@ import org.junit.Test;
|
|||
import javax.persistence.*;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.hibernate.cfg.Environment;
|
|||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.hibernate.cfg.Environment;
|
|||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.hibernate.cfg.Environment;
|
|||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.hibernate.cfg.Environment;
|
|||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.hibernate.cfg.Environment;
|
|||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -17,7 +17,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
|
|
@ -9,12 +9,16 @@ package org.hibernate.test.jpa.lock;
|
|||
import org.hibernate.LockMode;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.test.jpa.AbstractJPATest;
|
||||
import org.hibernate.test.jpa.Item;
|
||||
import org.hibernate.test.jpa.MyEntity;
|
||||
import org.hibernate.testing.jdbc.SQLServerSnapshotIsolationConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -29,6 +33,23 @@ import static org.junit.Assert.fail;
|
|||
*/
|
||||
@RequiresDialectFeature( DialectChecks.DoesReadCommittedNotCauseWritersToBlockReadersCheck.class )
|
||||
public class JPALockTest extends AbstractJPATest {
|
||||
|
||||
private SQLServerSnapshotIsolationConnectionProvider connectionProvider = new SQLServerSnapshotIsolationConnectionProvider();
|
||||
|
||||
@Override
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
if( SQLServerDialect.class.isAssignableFrom( DIALECT.getClass() )) {
|
||||
cfg.getProperties().put( AvailableSettings.CONNECTION_PROVIDER, connectionProvider );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void releaseSessionFactory() {
|
||||
super.releaseSessionFactory();
|
||||
connectionProvider.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the equivalent of EJB3 LockModeType.READ
|
||||
* <p/>
|
||||
|
@ -122,7 +143,7 @@ public class JPALockTest extends AbstractJPATest {
|
|||
* lock(entity, LockModeType.WRITE) on non-versioned objects will not be portable.
|
||||
* <p/>
|
||||
* Due to the requirement that LockModeType.WRITE needs to force a version increment,
|
||||
* a new Hibernate LockMode was added to support this behavior: {@link org.hibernate.LockMode#FORCE}.
|
||||
* a new Hibernate LockMode was added to support this behavior: {@link LockMode#FORCE}.
|
||||
*/
|
||||
@Test
|
||||
public void testLockModeTypeWrite() {
|
||||
|
|
|
@ -14,11 +14,14 @@ import org.hibernate.LockMode;
|
|||
import org.hibernate.Session;
|
||||
import org.hibernate.StaleObjectStateException;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.hibernate.test.jpa.AbstractJPATest;
|
||||
import org.hibernate.test.jpa.Item;
|
||||
import org.hibernate.test.jpa.Part;
|
||||
import org.hibernate.testing.jdbc.SQLServerSnapshotIsolationConnectionProvider;
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
|
||||
|
@ -34,6 +37,23 @@ import static org.junit.Assert.fail;
|
|||
*/
|
||||
@RequiresDialectFeature( DialectChecks.DoesReadCommittedNotCauseWritersToBlockReadersCheck.class )
|
||||
public class RepeatableReadTest extends AbstractJPATest {
|
||||
|
||||
private SQLServerSnapshotIsolationConnectionProvider connectionProvider = new SQLServerSnapshotIsolationConnectionProvider();
|
||||
|
||||
@Override
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
if( SQLServerDialect.class.isAssignableFrom( DIALECT.getClass() )) {
|
||||
cfg.getProperties().put( AvailableSettings.CONNECTION_PROVIDER, connectionProvider );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void releaseSessionFactory() {
|
||||
super.releaseSessionFactory();
|
||||
connectionProvider.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaleVersionedInstanceFoundInQueryResult() {
|
||||
String check = "EJB3 Specification";
|
||||
|
|
|
@ -58,8 +58,7 @@ import org.hibernate.dialect.PointbaseDialect;
|
|||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.dialect.SAPDBDialect;
|
||||
import org.hibernate.dialect.Sybase11Dialect;
|
||||
import org.hibernate.dialect.SybaseASE15Dialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.dialect.SybaseDialect;
|
||||
import org.hibernate.dialect.TeradataDialect;
|
||||
import org.hibernate.dialect.TimesTenDialect;
|
||||
|
@ -2287,7 +2286,12 @@ public class FooBarTest extends LegacyTestCase {
|
|||
s.createQuery( "select count(*) from Baz as baz where 1 in indices(baz.fooArray)" ).list();
|
||||
s.createQuery( "select count(*) from Bar as bar where 'abc' in elements(bar.baz.fooArray)" ).list();
|
||||
s.createQuery( "select count(*) from Bar as bar where 1 in indices(bar.baz.fooArray)" ).list();
|
||||
if ( !(getDialect() instanceof DB2Dialect) && !(getDialect() instanceof Oracle8iDialect ) && !( getDialect() instanceof SybaseDialect ) && !( getDialect() instanceof Sybase11Dialect ) && !( getDialect() instanceof SybaseASE15Dialect ) && !( getDialect() instanceof PostgreSQLDialect ) && !(getDialect() instanceof PostgreSQL81Dialect) && !(getDialect() instanceof AbstractHANADialect)) {
|
||||
if ( !(getDialect() instanceof DB2Dialect) &&
|
||||
!( getDialect() instanceof Oracle8iDialect ) &&
|
||||
!( SybaseDialect.class.isAssignableFrom( getDialect().getClass() ) ) &&
|
||||
!( SQLServerDialect.class.isAssignableFrom( getDialect().getClass() ) ) &&
|
||||
!( getDialect() instanceof PostgreSQLDialect ) && !(getDialect() instanceof PostgreSQL81Dialect ) &&
|
||||
!( getDialect() instanceof AbstractHANADialect) ) {
|
||||
// SybaseAnywhereDialect supports implicit conversions from strings to ints
|
||||
s.createQuery(
|
||||
"select count(*) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)"
|
||||
|
|
|
@ -17,6 +17,7 @@ import javax.persistence.Lob;
|
|||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.engine.jdbc.ClobProxy;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
|
@ -36,7 +37,8 @@ import static org.junit.Assert.fail;
|
|||
@TestForIssue(jiraKey = "HHH-11477")
|
||||
@SkipForDialect(Oracle8iDialect.class)
|
||||
public class LobStringTest extends BaseCoreFunctionalTestCase {
|
||||
private static final int LONG_STRING_SIZE = 10000;
|
||||
//SQL Server - VARCHAR(MAX) is limited to 8000 bytes only
|
||||
private static final int LONG_STRING_SIZE = 3999;
|
||||
|
||||
private final String value1 = buildRecursively( LONG_STRING_SIZE, 'x' );
|
||||
private final String value2 = buildRecursively( LONG_STRING_SIZE, 'y' );
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.hibernate.dialect.SQLServer2005Dialect;
|
|||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.SQLStatementInterceptor;
|
||||
import org.hibernate.testing.jdbc.SQLStatementInterceptor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
|
@ -0,0 +1,266 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.schemaupdate;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Index;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaValidator;
|
||||
import org.hibernate.tool.schema.JdbcMetadaAccessStrategy;
|
||||
import org.hibernate.tool.schema.TargetType;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
@RequiresDialect(SQLServerDialect.class)
|
||||
public class SchemaUpdateSQLServerTest extends BaseUnitTestCase {
|
||||
|
||||
private static final Logger log = Logger.getLogger( SchemaUpdateSQLServerTest.class );
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<String> parameters() {
|
||||
return Arrays.asList(
|
||||
new String[] {JdbcMetadaAccessStrategy.GROUPED.toString(), JdbcMetadaAccessStrategy.INDIVIDUALLY.toString()}
|
||||
);
|
||||
}
|
||||
|
||||
@Parameterized.Parameter
|
||||
public String jdbcMetadataExtractorStrategy;
|
||||
|
||||
private File output;
|
||||
private StandardServiceRegistry ssr;
|
||||
private MetadataImplementor metadata;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
if(!SQLServerDialect.class.isAssignableFrom( Dialect.getDialect().getClass() )) {
|
||||
return;
|
||||
}
|
||||
|
||||
output = File.createTempFile( "update_script", ".sql" );
|
||||
output.deleteOnExit();
|
||||
ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, "true" )
|
||||
.applySetting( AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY, jdbcMetadataExtractorStrategy )
|
||||
.build();
|
||||
|
||||
try (Connection connection = ssr.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess().obtainConnection();
|
||||
Statement statement = connection.createStatement()) {
|
||||
connection.setAutoCommit( true );
|
||||
statement.executeUpdate( "DROP DATABASE hibernate_orm_test_collation" );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
log.debug( e.getMessage() );
|
||||
}
|
||||
try (Connection connection = ssr.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess().obtainConnection();
|
||||
Statement statement = connection.createStatement()) {
|
||||
connection.setAutoCommit( true );
|
||||
statement.executeUpdate( "CREATE DATABASE hibernate_orm_test_collation COLLATE Latin1_General_CS_AS" );
|
||||
statement.executeUpdate( "ALTER DATABASE [hibernate_orm_test_collation] SET AUTO_CLOSE OFF " );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
log.debug( e.getMessage() );
|
||||
}
|
||||
|
||||
final MetadataSources metadataSources = new MetadataSources( ssr );
|
||||
metadataSources.addAnnotatedClass( LowercaseTableNameEntity.class );
|
||||
metadataSources.addAnnotatedClass( TestEntity.class );
|
||||
metadataSources.addAnnotatedClass( UppercaseTableNameEntity.class );
|
||||
metadataSources.addAnnotatedClass( MixedCaseTableNameEntity.class );
|
||||
metadataSources.addAnnotatedClass( Match.class );
|
||||
metadataSources.addAnnotatedClass( InheritanceRootEntity.class );
|
||||
metadataSources.addAnnotatedClass( InheritanceChildEntity.class );
|
||||
metadataSources.addAnnotatedClass( InheritanceSecondChildEntity.class );
|
||||
|
||||
metadata = (MetadataImplementor) metadataSources.buildMetadata();
|
||||
metadata.validate();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearsDown() {
|
||||
if(!SQLServerDialect.class.isAssignableFrom( Dialect.getDialect().getClass() )) {
|
||||
return;
|
||||
}
|
||||
|
||||
new SchemaExport().setHaltOnError( true )
|
||||
.setOutputFile( output.getAbsolutePath() )
|
||||
.setFormat( false )
|
||||
.drop( EnumSet.of( TargetType.DATABASE ), metadata );
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchemaUpdateAndValidation() throws Exception {
|
||||
if(!SQLServerDialect.class.isAssignableFrom( Dialect.getDialect().getClass() )) {
|
||||
return;
|
||||
}
|
||||
|
||||
new SchemaUpdate().setHaltOnError( true )
|
||||
.execute( EnumSet.of( TargetType.DATABASE ), metadata );
|
||||
|
||||
new SchemaValidator().validate( metadata );
|
||||
|
||||
new SchemaUpdate().setHaltOnError( true )
|
||||
.setOutputFile( output.getAbsolutePath() )
|
||||
.setFormat( false )
|
||||
.execute( EnumSet.of( TargetType.DATABASE, TargetType.SCRIPT ), metadata );
|
||||
|
||||
final String fileContent = new String( Files.readAllBytes( output.toPath() ) );
|
||||
assertThat( "The update output file should be empty", fileContent, is( "" ) );
|
||||
}
|
||||
|
||||
@Entity(name = "TestEntity")
|
||||
@Table(name = "`testentity`", catalog = "hibernate_orm_test_collation", schema = "dbo")
|
||||
public static class LowercaseTableNameEntity {
|
||||
@Id
|
||||
long id;
|
||||
String field1;
|
||||
|
||||
@ManyToMany(mappedBy = "entities")
|
||||
Set<TestEntity> entity1s;
|
||||
}
|
||||
|
||||
@Entity(name = "TestEntity1")
|
||||
@Table(name = "TestEntity1", catalog = "hibernate_orm_test_collation", schema = "dbo")
|
||||
public static class TestEntity {
|
||||
@Id
|
||||
@Column(name = "`Id`")
|
||||
long id;
|
||||
String field1;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(catalog = "hibernate_orm_test_collation", schema = "dbo")
|
||||
Set<LowercaseTableNameEntity> entities;
|
||||
|
||||
@OneToMany
|
||||
@JoinColumn
|
||||
private Set<UppercaseTableNameEntity> entitie2s;
|
||||
|
||||
@ManyToOne
|
||||
private LowercaseTableNameEntity entity;
|
||||
}
|
||||
|
||||
@Entity(name = "TestEntity2")
|
||||
@Table(name = "`TESTENTITY`", catalog = "hibernate_orm_test_collation", schema = "dbo")
|
||||
public static class UppercaseTableNameEntity {
|
||||
@Id
|
||||
long id;
|
||||
String field1;
|
||||
|
||||
@ManyToOne
|
||||
TestEntity testEntity;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(foreignKey = @ForeignKey(name = "FK_mixedCase"))
|
||||
MixedCaseTableNameEntity mixedCaseTableNameEntity;
|
||||
}
|
||||
|
||||
@Entity(name = "TestEntity3")
|
||||
@Table(name = "`TESTentity`", catalog = "hibernate_orm_test_collation", schema = "dbo",
|
||||
indexes = {@Index(name = "index1", columnList = "`FieLd1`"), @Index(name = "Index2", columnList = "`FIELD_2`")})
|
||||
public static class MixedCaseTableNameEntity {
|
||||
@Id
|
||||
long id;
|
||||
@Column(name = "`FieLd1`")
|
||||
String field1;
|
||||
@Column(name = "`FIELD_2`")
|
||||
String field2;
|
||||
@Column(name = "`field_3`")
|
||||
String field3;
|
||||
String field4;
|
||||
|
||||
@OneToMany
|
||||
@JoinColumn
|
||||
private Set<Match> matches = new HashSet<>();
|
||||
}
|
||||
|
||||
@Entity(name = "Match")
|
||||
@Table(name = "Match", catalog = "hibernate_orm_test_collation", schema = "dbo")
|
||||
public static class Match {
|
||||
@Id
|
||||
long id;
|
||||
String match;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(catalog = "hibernate_orm_test_collation", schema = "dbo")
|
||||
private Map<Integer, Integer> timeline = new TreeMap<>();
|
||||
}
|
||||
|
||||
@Entity(name = "InheritanceRootEntity")
|
||||
@Table(name = "InheritanceRootEntity", catalog = "hibernate_orm_test_collation", schema = "dbo")
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
public static class InheritanceRootEntity {
|
||||
@Id
|
||||
protected Long id;
|
||||
}
|
||||
|
||||
@Entity(name = "InheritanceChildEntity")
|
||||
@Table(name = "InheritanceChildEntity", catalog = "hibernate_orm_test_collation", schema = "dbo")
|
||||
@PrimaryKeyJoinColumn(name = "ID", foreignKey = @ForeignKey(name = "FK_ROOT"))
|
||||
public static class InheritanceChildEntity extends InheritanceRootEntity {
|
||||
}
|
||||
|
||||
@Entity(name = "InheritanceSecondChildEntity")
|
||||
@Table(name = "InheritanceSecondChildEntity", catalog = "hibernate_orm_test_collation", schema = "dbo")
|
||||
@PrimaryKeyJoinColumn(name = "ID")
|
||||
public static class InheritanceSecondChildEntity extends InheritanceRootEntity {
|
||||
@ManyToOne
|
||||
@JoinColumn
|
||||
public Match match;
|
||||
}
|
||||
}
|
|
@ -37,12 +37,16 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
|
|||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaValidator;
|
||||
import org.hibernate.tool.schema.JdbcMetadaAccessStrategy;
|
||||
import org.hibernate.tool.schema.TargetType;
|
||||
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -57,6 +61,7 @@ import static org.junit.Assert.assertThat;
|
|||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class SchemaUpdateTest {
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<String> parameters() {
|
||||
return Arrays.asList(
|
||||
|
@ -73,6 +78,9 @@ public class SchemaUpdateTest {
|
|||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
if(SQLServerDialect.class.isAssignableFrom( Dialect.getDialect().getClass() )) {
|
||||
return;
|
||||
}
|
||||
output = File.createTempFile( "update_script", ".sql" );
|
||||
output.deleteOnExit();
|
||||
ssr = new StandardServiceRegistryBuilder()
|
||||
|
@ -95,6 +103,9 @@ public class SchemaUpdateTest {
|
|||
|
||||
@After
|
||||
public void tearsDown() {
|
||||
if(SQLServerDialect.class.isAssignableFrom( Dialect.getDialect().getClass() )) {
|
||||
return;
|
||||
}
|
||||
new SchemaExport().setHaltOnError( true )
|
||||
.setOutputFile( output.getAbsolutePath() )
|
||||
.setFormat( false )
|
||||
|
@ -104,7 +115,9 @@ public class SchemaUpdateTest {
|
|||
|
||||
@Test
|
||||
public void testSchemaUpdateAndValidation() throws Exception {
|
||||
|
||||
if(SQLServerDialect.class.isAssignableFrom( Dialect.getDialect().getClass() )) {
|
||||
return;
|
||||
}
|
||||
new SchemaUpdate().setHaltOnError( true )
|
||||
.execute( EnumSet.of( TargetType.DATABASE ), metadata );
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ import org.junit.Test;
|
|||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
@ -55,7 +57,14 @@ public class TimePropertyTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
s = openSession();
|
||||
s.getTransaction().begin();
|
||||
final Query queryWithParameter = s.createQuery( "from TimePropertyTest$Entity where tAsDate=?" ).setParameter( 0, eGotten.tAsDate );
|
||||
|
||||
String queryString = "from TimePropertyTest$Entity where tAsDate = ?";
|
||||
|
||||
if( SQLServerDialect.class.isAssignableFrom( getDialect().getClass() )) {
|
||||
queryString = "from TimePropertyTest$Entity where tAsDate = cast ( ? as time )";
|
||||
}
|
||||
|
||||
final Query queryWithParameter = s.createQuery( queryString ).setParameter( 0, eGotten.tAsDate );
|
||||
final Entity eQueriedWithParameter = (Entity) queryWithParameter.uniqueResult();
|
||||
assertNotNull( eQueriedWithParameter );
|
||||
s.getTransaction().commit();
|
||||
|
@ -63,7 +72,8 @@ public class TimePropertyTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
s = openSession();
|
||||
s.getTransaction().begin();
|
||||
final Query query = s.createQuery( "from TimePropertyTest$Entity where tAsDate=?" ).setTime( 0, eGotten.tAsDate );
|
||||
|
||||
final Query query = s.createQuery( queryString ).setTime( 0, eGotten.tAsDate );
|
||||
final Entity eQueried = (Entity) query.uniqueResult();
|
||||
assertNotNull( eQueried );
|
||||
s.getTransaction().commit();
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.hibernate.dialect.MariaDBDialect;
|
|||
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
|
|
@ -17,7 +17,7 @@ import javax.persistence.Id;
|
|||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.hibernate.dialect.MariaDBDialect;
|
|||
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.hibernate.dialect.MariaDBDialect;
|
|||
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
|
|
@ -16,7 +16,7 @@ import javax.persistence.Id;
|
|||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.PreparedStatementSpyConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.hibernate.cfg.AvailableSettings;
|
|||
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.test.util.jdbc.TimeZoneConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.TimeZoneConnectionProvider;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.hibernate.cfg.AvailableSettings;
|
|||
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.test.util.jdbc.TimeZoneConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.TimeZoneConnectionProvider;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.hibernate.dialect.PostgreSQL82Dialect;
|
|||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.TimeZoneConnectionProvider;
|
||||
import org.hibernate.testing.jdbc.TimeZoneConnectionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.hibernate.dialect.MySQLDialect;
|
|||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.util.jdbc.ConnectionProviderDelegate;
|
||||
import org.hibernate.testing.jdbc.ConnectionProviderDelegate;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernateSessionBuilder;
|
||||
|
|
|
@ -18,10 +18,12 @@ import org.hibernate.ScrollableResults;
|
|||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
|
@ -36,6 +38,7 @@ import static org.junit.Assert.fail;
|
|||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
@SkipForDialect(SQLServerDialect.class)
|
||||
public class CMTTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
|
|
|
@ -21,11 +21,14 @@ import org.hibernate.annotations.Cache;
|
|||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.jdbc.SQLServerSnapshotIsolationConnectionProvider;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -37,6 +40,8 @@ import static org.junit.Assert.assertEquals;
|
|||
@TestForIssue(jiraKey = "HHH-10649")
|
||||
public class RefreshUpdatedDataTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
private SQLServerSnapshotIsolationConnectionProvider connectionProvider;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
|
@ -54,9 +59,21 @@ public class RefreshUpdatedDataTest extends BaseNonConfigCoreFunctionalTestCase
|
|||
if ( H2Dialect.class.equals( Dialect.getDialect().getClass() ) ) {
|
||||
settings.put( Environment.URL, "jdbc:h2:mem:db-mvcc;MVCC=true" );
|
||||
}
|
||||
else if( SQLServerDialect.class.isAssignableFrom( Dialect.getDialect().getClass() )) {
|
||||
connectionProvider = new SQLServerSnapshotIsolationConnectionProvider();
|
||||
settings.put( AvailableSettings.CONNECTION_PROVIDER, connectionProvider );
|
||||
}
|
||||
settings.put( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void releaseResources() {
|
||||
super.releaseResources();
|
||||
if( SQLServerDialect.class.isAssignableFrom( Dialect.getDialect().getClass() )) {
|
||||
connectionProvider.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureStandardServiceRegistryBuilder(StandardServiceRegistryBuilder ssrb) {
|
||||
super.configureStandardServiceRegistryBuilder( ssrb );
|
||||
|
|
|
@ -16,6 +16,8 @@ dependencies {
|
|||
compile ( libraries.jboss_jta ) {
|
||||
transitive=false;
|
||||
}
|
||||
compile( libraries.mockito )
|
||||
compile( libraries.mockito_inline )
|
||||
}
|
||||
|
||||
// resources inherently exclude sources
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.util.jdbc;
|
||||
package org.hibernate.testing.jdbc;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.util.jdbc;
|
||||
package org.hibernate.testing.jdbc;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
@ -18,6 +18,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.internal.util.MockUtil;
|
||||
|
||||
|
@ -59,27 +60,27 @@ public class PreparedStatementSpyConnectionProvider
|
|||
}
|
||||
Connection connectionSpy = Mockito.spy( connection );
|
||||
try {
|
||||
doAnswer( invocation -> {
|
||||
Mockito.doAnswer( invocation -> {
|
||||
PreparedStatement statement = (PreparedStatement) invocation.callRealMethod();
|
||||
PreparedStatement statementSpy = Mockito.spy( statement );
|
||||
String sql = (String) invocation.getArguments()[0];
|
||||
preparedStatementMap.put( statementSpy, sql );
|
||||
return statementSpy;
|
||||
} ).when( connectionSpy ).prepareStatement( anyString() );
|
||||
} ).when( connectionSpy ).prepareStatement( ArgumentMatchers.anyString() );
|
||||
|
||||
doAnswer( invocation -> {
|
||||
Mockito.doAnswer( invocation -> {
|
||||
Statement statement = (Statement) invocation.callRealMethod();
|
||||
Statement statementSpy = Mockito.spy( statement );
|
||||
doAnswer( statementInvocation -> {
|
||||
Mockito.doAnswer( statementInvocation -> {
|
||||
String sql = (String) statementInvocation.getArguments()[0];
|
||||
executeStatements.add( sql );
|
||||
return statementInvocation.callRealMethod();
|
||||
}).when( statementSpy ).execute( anyString() );
|
||||
doAnswer( statementInvocation -> {
|
||||
}).when( statementSpy ).execute( ArgumentMatchers.anyString() );
|
||||
Mockito.doAnswer( statementInvocation -> {
|
||||
String sql = (String) statementInvocation.getArguments()[0];
|
||||
executeUpdateStatements.add( sql );
|
||||
return statementInvocation.callRealMethod();
|
||||
}).when( statementSpy ).executeUpdate( anyString() );
|
||||
}).when( statementSpy ).executeUpdate( ArgumentMatchers.anyString() );
|
||||
return statementSpy;
|
||||
} ).when( connectionSpy ).createStatement();
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.testing.jdbc;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* This {@link ConnectionProvider} extends any other ConnectionProvider that would be used by default taken the current configuration properties, and it
|
||||
* just sets the READ_COMMITTED_SNAPSHOT isolation level for SQL Server.
|
||||
*
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
public class SQLServerSnapshotIsolationConnectionProvider
|
||||
extends ConnectionProviderDelegate {
|
||||
|
||||
private static final String RCS = "ALTER DATABASE %s SET READ_COMMITTED_SNAPSHOT %s";
|
||||
private static final String SI = "ALTER DATABASE %s SET ALLOW_SNAPSHOT_ISOLATION %s";
|
||||
|
||||
private String dbName = null;
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
Connection connection = super.getConnection();
|
||||
try(Statement statement = connection.createStatement()) {
|
||||
if ( dbName == null ) {
|
||||
try(ResultSet rs = statement.executeQuery( "SELECT DB_NAME()" )) {
|
||||
rs.next();
|
||||
dbName = rs.getString( 1 );
|
||||
}
|
||||
}
|
||||
statement.executeUpdate(String.format( RCS, dbName, "ON" ));
|
||||
statement.executeUpdate(String.format( SI, dbName, "ON" ));
|
||||
}
|
||||
catch (SQLException se) {
|
||||
fail( se.getMessage());
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.util.jdbc;
|
||||
package org.hibernate.testing.jdbc;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.util.jdbc;
|
||||
package org.hibernate.testing.jdbc;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
Loading…
Reference in New Issue