Re-enabled additional tests
This commit is contained in:
parent
2622ce70d2
commit
3f87ed17ee
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.idgen.userdefined;
|
package org.hibernate.orm.test.idgen.userdefined;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
@ -40,15 +40,18 @@ import org.hibernate.resource.beans.container.spi.ContainedBean;
|
||||||
import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer;
|
import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.orm.junit.BaseUnitTest;
|
||||||
import org.junit.Test;
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yanming Zhou
|
* @author Yanming Zhou
|
||||||
*/
|
*/
|
||||||
@TestForIssue(jiraKey = "HHH-14688")
|
@TestForIssue(jiraKey = "HHH-14688")
|
||||||
public class UserDefinedGeneratorsTests extends BaseUnitTestCase {
|
@BaseUnitTest
|
||||||
|
public class UserDefinedGeneratorsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateGeneratorsByBeanContainer() {
|
public void testCreateGeneratorsByBeanContainer() {
|
||||||
|
@ -104,7 +107,7 @@ public class UserDefinedGeneratorsTests extends BaseUnitTestCase {
|
||||||
public static class Entity1 {
|
public static class Entity1 {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue( generator = "test" )
|
@GeneratedValue( generator = "test" )
|
||||||
@GenericGenerator( name = "test", strategy = "org.hibernate.test.idgen.userdefined.UserDefinedGeneratorsTests$TestIdentifierGenerator" )
|
@GenericGenerator( name = "test", strategy = "org.hibernate.orm.test.idgen.userdefined.UserDefinedGeneratorsTests$TestIdentifierGenerator" )
|
||||||
private Integer id;
|
private Integer id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +116,7 @@ public class UserDefinedGeneratorsTests extends BaseUnitTestCase {
|
||||||
public static class Entity2 {
|
public static class Entity2 {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue( generator = "test" )
|
@GeneratedValue( generator = "test" )
|
||||||
@GenericGenerator( name = "test", strategy = "org.hibernate.test.idgen.userdefined.UserDefinedGeneratorsTests$TestIdentifierGenerator" )
|
@GenericGenerator( name = "test", strategy = "org.hibernate.orm.test.idgen.userdefined.UserDefinedGeneratorsTests$TestIdentifierGenerator" )
|
||||||
private Integer id;
|
private Integer id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.quote;
|
package org.hibernate.orm.test.quote;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.quote;
|
package org.hibernate.orm.test.quote;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
|
@ -23,15 +23,17 @@ import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.orm.junit.BaseUnitTest;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class ColumnDefinitionQuotingTest extends BaseUnitTestCase {
|
@BaseUnitTest
|
||||||
|
public class ColumnDefinitionQuotingTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-9491" )
|
@TestForIssue( jiraKey = "HHH-9491" )
|
||||||
public void testExplicitQuoting() {
|
public void testExplicitQuoting() {
|
|
@ -10,9 +10,9 @@
|
||||||
SYSTEM
|
SYSTEM
|
||||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >
|
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >
|
||||||
|
|
||||||
<hibernate-mapping package="org.hibernate.test.quote">
|
<hibernate-mapping package="org.hibernate.orm.test.quote">
|
||||||
<typedef name="enumType" class="org.hibernate.type.EnumType">
|
<typedef name="enumType" class="org.hibernate.type.EnumType">
|
||||||
<param name="enumClass">org.hibernate.test.quote.DataPoint$DataPointEnum</param>
|
<param name="enumClass">org.hibernate.orm.test.quote.DataPoint$DataPointEnum</param>
|
||||||
</typedef>
|
</typedef>
|
||||||
|
|
||||||
<class name="DataPoint">
|
<class name="DataPoint">
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.quote;
|
package org.hibernate.orm.test.quote;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.quote;
|
package org.hibernate.orm.test.quote;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.quote;
|
package org.hibernate.orm.test.quote;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.quote;
|
package org.hibernate.orm.test.quote;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
|
@ -0,0 +1,115 @@
|
||||||
|
/*
|
||||||
|
* 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.orm.test.quote;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
import org.hibernate.mapping.Column;
|
||||||
|
import org.hibernate.mapping.Table;
|
||||||
|
import org.hibernate.mapping.UniqueKey;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
@DomainModel(
|
||||||
|
annotatedClasses = {
|
||||||
|
User.class,
|
||||||
|
Role.class,
|
||||||
|
Phone.class,
|
||||||
|
Person.class,
|
||||||
|
House.class
|
||||||
|
},
|
||||||
|
xmlMappings = "org/hibernate/orm/test/quote/DataPoint.hbm.xml"
|
||||||
|
)
|
||||||
|
@SessionFactory
|
||||||
|
@ServiceRegistry(
|
||||||
|
settings = @Setting(name = AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, value = "true")
|
||||||
|
)
|
||||||
|
public class QuoteGlobalTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-7890")
|
||||||
|
public void testQuotedUniqueConstraint(SessionFactoryScope scope) {
|
||||||
|
Iterator<UniqueKey> itr = scope.getMetadataImplementor().getEntityBinding( Person.class.getName() )
|
||||||
|
.getTable().getUniqueKeyIterator();
|
||||||
|
while ( itr.hasNext() ) {
|
||||||
|
UniqueKey uk = itr.next();
|
||||||
|
assertEquals( 1, uk.getColumns().size() );
|
||||||
|
assertEquals( "name", uk.getColumn( 0 ).getName() );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fail( "GLOBALLY_QUOTED_IDENTIFIERS caused the unique key creation to fail." );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testQuoteManytoMany(SessionFactoryScope scope) {
|
||||||
|
scope.inSession(
|
||||||
|
session -> {
|
||||||
|
try {
|
||||||
|
Transaction tx = session.beginTransaction();
|
||||||
|
User u = new User();
|
||||||
|
session.persist( u );
|
||||||
|
Role r = new Role();
|
||||||
|
session.persist( r );
|
||||||
|
u.getRoles().add( r );
|
||||||
|
session.flush();
|
||||||
|
session.clear();
|
||||||
|
u = session.get( User.class, u.getId() );
|
||||||
|
assertEquals( 1, u.getRoles().size() );
|
||||||
|
tx.rollback();
|
||||||
|
String role = User.class.getName() + ".roles";
|
||||||
|
assertEquals(
|
||||||
|
"User_Role",
|
||||||
|
scope.getMetadataImplementor()
|
||||||
|
.getCollectionBinding( role )
|
||||||
|
.getCollectionTable()
|
||||||
|
.getName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if ( session.getTransaction().isActive() ) {
|
||||||
|
session.getTransaction().rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-8520")
|
||||||
|
public void testHbmQuoting(SessionFactoryScope scope) {
|
||||||
|
final MetadataImplementor metadataImplementor = scope.getMetadataImplementor();
|
||||||
|
doTestHbmQuoting( DataPoint.class, metadataImplementor );
|
||||||
|
doTestHbmQuoting( AssociatedDataPoint.class, metadataImplementor );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doTestHbmQuoting(Class clazz, MetadataImplementor metadataImplementor) {
|
||||||
|
Table table = metadataImplementor.getEntityBinding( clazz.getName() ).getTable();
|
||||||
|
assertTrue( table.isQuoted() );
|
||||||
|
Iterator itr = table.getColumnIterator();
|
||||||
|
while ( itr.hasNext() ) {
|
||||||
|
Column column = (Column) itr.next();
|
||||||
|
assertTrue( column.isQuoted() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.quote;
|
package org.hibernate.orm.test.quote;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -21,7 +21,6 @@ import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//$Id$
|
//$Id$
|
||||||
package org.hibernate.test.quote;
|
package org.hibernate.orm.test.quote;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.quote;
|
package org.hibernate.orm.test.quote;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
|
@ -20,6 +20,7 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator;
|
import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator;
|
||||||
|
import org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl;
|
||||||
import org.hibernate.tool.hbm2ddl.SchemaValidator;
|
import org.hibernate.tool.hbm2ddl.SchemaValidator;
|
||||||
import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
|
import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
|
||||||
import org.hibernate.tool.schema.internal.SchemaDropperImpl;
|
import org.hibernate.tool.schema.internal.SchemaDropperImpl;
|
||||||
|
@ -27,28 +28,29 @@ import org.hibernate.tool.schema.internal.exec.GenerationTarget;
|
||||||
import org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase;
|
import org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.orm.junit.BaseUnitTest;
|
||||||
import org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class TableGeneratorQuotingTest extends BaseUnitTestCase {
|
@BaseUnitTest
|
||||||
|
public class TableGeneratorQuotingTest {
|
||||||
private StandardServiceRegistry serviceRegistry;
|
private StandardServiceRegistry serviceRegistry;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = new StandardServiceRegistryBuilder()
|
serviceRegistry = new StandardServiceRegistryBuilder()
|
||||||
.applySetting( AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, "true" )
|
.applySetting( AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, "true" )
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
if ( serviceRegistry != null ) {
|
if ( serviceRegistry != null ) {
|
||||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||||
|
@ -58,7 +60,8 @@ public class TableGeneratorQuotingTest extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-7927")
|
@TestForIssue(jiraKey = "HHH-7927")
|
||||||
public void testTableGeneratorQuoting() {
|
public void testTableGeneratorQuoting() {
|
||||||
final Metadata metadata = new MetadataSources( serviceRegistry ).addAnnotatedClass( TestEntity.class ).buildMetadata();
|
final Metadata metadata = new MetadataSources( serviceRegistry ).addAnnotatedClass( TestEntity.class )
|
||||||
|
.buildMetadata();
|
||||||
|
|
||||||
final ConnectionProvider connectionProvider = serviceRegistry.getService( ConnectionProvider.class );
|
final ConnectionProvider connectionProvider = serviceRegistry.getService( ConnectionProvider.class );
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//$Id$
|
//$Id$
|
||||||
package org.hibernate.test.quote;
|
package org.hibernate.orm.test.quote;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
|
@ -9,7 +9,7 @@
|
||||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||||
|
|
||||||
<hibernate-mapping package="org.hibernate.test.typeoverride">
|
<hibernate-mapping package="org.hibernate.orm.test.typeoverride">
|
||||||
|
|
||||||
<class name="Entity">
|
<class name="Entity">
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.typeoverride;
|
package org.hibernate.orm.test.typeoverride;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.typeoverride;
|
package org.hibernate.orm.test.typeoverride;
|
||||||
|
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.typeoverride;
|
package org.hibernate.orm.test.typeoverride;
|
||||||
|
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.typeoverride;
|
package org.hibernate.orm.test.typeoverride;
|
||||||
|
|
||||||
import java.sql.CallableStatement;
|
import java.sql.CallableStatement;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
|
@ -4,33 +4,44 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.typeoverride;
|
package org.hibernate.orm.test.typeoverride;
|
||||||
|
|
||||||
|
import org.hibernate.boot.MetadataBuilder;
|
||||||
|
import org.hibernate.dialect.AbstractHANADialect;
|
||||||
|
import org.hibernate.dialect.CockroachDialect;
|
||||||
|
import org.hibernate.dialect.Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
|
import org.hibernate.dialect.SybaseDialect;
|
||||||
|
import org.hibernate.type.descriptor.jdbc.BlobTypeDescriptor;
|
||||||
|
import org.hibernate.type.descriptor.jdbc.IntegerTypeDescriptor;
|
||||||
|
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||||
|
import org.hibernate.type.descriptor.jdbc.VarbinaryTypeDescriptor;
|
||||||
|
import org.hibernate.type.descriptor.jdbc.VarcharTypeDescriptor;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
|
||||||
|
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.Assert.assertNotSame;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.cfg.Configuration;
|
|
||||||
import org.hibernate.dialect.*;
|
|
||||||
import org.hibernate.testing.SkipForDialect;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|
||||||
import org.hibernate.type.descriptor.jdbc.*;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
*/
|
*/
|
||||||
public class TypeOverrideTest extends BaseCoreFunctionalTestCase {
|
public class TypeOverrideTest extends BaseSessionFactoryFunctionalTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getMappings() {
|
protected String[] getOrmXmlFiles() {
|
||||||
return new String[] { "typeoverride/Entity.hbm.xml" };
|
return new String[] { "org/hibernate/orm/test/typeoverride/Entity.hbm.xml" };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure(Configuration cfg) {
|
protected void applyMetadataBuilder(MetadataBuilder metadataBuilder) {
|
||||||
cfg.registerTypeOverride( StoredPrefixedStringType.INSTANCE );
|
metadataBuilder.applyBasicType( StoredPrefixedStringType.INSTANCE );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -39,19 +50,19 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase {
|
||||||
assertSame( IntegerTypeDescriptor.INSTANCE, remapSqlTypeDescriptor( IntegerTypeDescriptor.INSTANCE ) );
|
assertSame( IntegerTypeDescriptor.INSTANCE, remapSqlTypeDescriptor( IntegerTypeDescriptor.INSTANCE ) );
|
||||||
|
|
||||||
// A few dialects explicitly override BlobTypeDescriptor.DEFAULT
|
// A few dialects explicitly override BlobTypeDescriptor.DEFAULT
|
||||||
if ( CockroachDialect.class.isInstance( getDialect() )) {
|
if ( CockroachDialect.class.isInstance( getDialect() ) ) {
|
||||||
assertSame(
|
assertSame(
|
||||||
VarbinaryTypeDescriptor.INSTANCE,
|
VarbinaryTypeDescriptor.INSTANCE,
|
||||||
getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT )
|
getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if ( PostgreSQL81Dialect.class.isInstance( getDialect() ) || PostgreSQLDialect.class.isInstance( getDialect() ) ) {
|
else if ( PostgreSQL81Dialect.class.isInstance( getDialect() ) || PostgreSQLDialect.class.isInstance( getDialect() ) ) {
|
||||||
assertSame(
|
assertSame(
|
||||||
BlobTypeDescriptor.BLOB_BINDING,
|
BlobTypeDescriptor.BLOB_BINDING,
|
||||||
getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT )
|
getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (SybaseDialect.class.isInstance( getDialect() )) {
|
else if ( SybaseDialect.class.isInstance( getDialect() ) ) {
|
||||||
assertSame(
|
assertSame(
|
||||||
BlobTypeDescriptor.PRIMITIVE_ARRAY_BINDING,
|
BlobTypeDescriptor.PRIMITIVE_ARRAY_BINDING,
|
||||||
getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT )
|
getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT )
|
||||||
|
@ -60,7 +71,8 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase {
|
||||||
else if ( AbstractHANADialect.class.isInstance( getDialect() ) ) {
|
else if ( AbstractHANADialect.class.isInstance( getDialect() ) ) {
|
||||||
assertSame(
|
assertSame(
|
||||||
( (AbstractHANADialect) getDialect() ).getBlobTypeDescriptor(),
|
( (AbstractHANADialect) getDialect() ).getBlobTypeDescriptor(),
|
||||||
getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT ) );
|
getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assertSame(
|
assertSame(
|
||||||
|
@ -86,7 +98,10 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase {
|
||||||
public void testDialectWithNonStandardSqlTypeDescriptor() {
|
public void testDialectWithNonStandardSqlTypeDescriptor() {
|
||||||
assertNotSame( VarcharTypeDescriptor.INSTANCE, StoredPrefixedStringType.INSTANCE.getJdbcTypeDescriptor() );
|
assertNotSame( VarcharTypeDescriptor.INSTANCE, StoredPrefixedStringType.INSTANCE.getJdbcTypeDescriptor() );
|
||||||
final Dialect dialect = new H2DialectOverridePrefixedVarcharSqlTypeDesc();
|
final Dialect dialect = new H2DialectOverridePrefixedVarcharSqlTypeDesc();
|
||||||
final JdbcTypeDescriptor remapped = remapSqlTypeDescriptor( dialect, StoredPrefixedStringType.PREFIXED_VARCHAR_TYPE_DESCRIPTOR );
|
final JdbcTypeDescriptor remapped = remapSqlTypeDescriptor(
|
||||||
|
dialect,
|
||||||
|
StoredPrefixedStringType.PREFIXED_VARCHAR_TYPE_DESCRIPTOR
|
||||||
|
);
|
||||||
assertSame( VarcharTypeDescriptor.INSTANCE, remapped );
|
assertSame( VarcharTypeDescriptor.INSTANCE, remapped );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,48 +113,53 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase {
|
||||||
return dialect.remapSqlTypeDescriptor( jdbcTypeDescriptor );
|
return dialect.remapSqlTypeDescriptor( jdbcTypeDescriptor );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@AfterEach
|
||||||
public void testInsert() {
|
public void tearDown() {
|
||||||
Session s = openSession();
|
inTransaction(
|
||||||
s.getTransaction().begin();
|
session ->
|
||||||
Entity e = new Entity( "name" );
|
session.createQuery( "delete from Entity" ).executeUpdate()
|
||||||
s.save( e );
|
);
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
s = openSession();
|
|
||||||
s.getTransaction().begin();
|
|
||||||
e = ( Entity ) s.get( Entity.class, e.getId() );
|
|
||||||
assertFalse( e.getName().startsWith( StoredPrefixedStringType.PREFIX ) );
|
|
||||||
assertEquals( "name", e.getName() );
|
|
||||||
s.delete( e );
|
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SkipForDialect( value = SybaseASE15Dialect.class, jiraKey = "HHH-6426")
|
public void testInsert() {
|
||||||
|
Entity e = new Entity( "name" );
|
||||||
|
inTransaction(
|
||||||
|
session ->
|
||||||
|
session.save( e )
|
||||||
|
);
|
||||||
|
|
||||||
|
inTransaction(
|
||||||
|
session -> {
|
||||||
|
Entity entity = session.get( Entity.class, e.getId() );
|
||||||
|
assertFalse( entity.getName().startsWith( StoredPrefixedStringType.PREFIX ) );
|
||||||
|
assertEquals( "name", entity.getName() );
|
||||||
|
session.delete( entity );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "HHH-6426")
|
||||||
public void testRegisteredFunction() {
|
public void testRegisteredFunction() {
|
||||||
Session s = openSession();
|
|
||||||
s.getTransaction().begin();
|
|
||||||
Entity e = new Entity( "name " );
|
Entity e = new Entity( "name " );
|
||||||
s.save( e );
|
inTransaction(
|
||||||
s.getTransaction().commit();
|
session ->
|
||||||
s.close();
|
session.save( e )
|
||||||
|
);
|
||||||
|
|
||||||
s = openSession();
|
inTransaction(
|
||||||
s.getTransaction().begin();
|
session -> {
|
||||||
e = ( Entity ) s.get( Entity.class, e.getId() );
|
Entity entity = session.get( Entity.class, e.getId() );
|
||||||
assertFalse( e.getName().startsWith( StoredPrefixedStringType.PREFIX ) );
|
assertFalse( entity.getName().startsWith( StoredPrefixedStringType.PREFIX ) );
|
||||||
assertEquals( "name ", e.getName() );
|
assertEquals( "name ", entity.getName() );
|
||||||
s.getTransaction().commit();
|
}
|
||||||
s.close();
|
);
|
||||||
|
|
||||||
s = openSession();
|
inTransaction(
|
||||||
s.getTransaction().begin();
|
session ->
|
||||||
s.delete( e );
|
session.delete( e )
|
||||||
s.getTransaction().commit();
|
);
|
||||||
s.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,104 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.quote;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
|
||||||
import org.hibernate.mapping.Column;
|
|
||||||
import org.hibernate.mapping.Table;
|
|
||||||
import org.hibernate.mapping.UniqueKey;
|
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Emmanuel Bernard
|
|
||||||
* @author Brett Meyer
|
|
||||||
*/
|
|
||||||
public class QuoteGlobalTest extends BaseNonConfigCoreFunctionalTestCase {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestForIssue(jiraKey = "HHH-7890")
|
|
||||||
public void testQuotedUniqueConstraint() {
|
|
||||||
Iterator<UniqueKey> itr = metadata().getEntityBinding( Person.class.getName() )
|
|
||||||
.getTable().getUniqueKeyIterator();
|
|
||||||
while ( itr.hasNext() ) {
|
|
||||||
UniqueKey uk = itr.next();
|
|
||||||
assertEquals( uk.getColumns().size(), 1 );
|
|
||||||
assertEquals( uk.getColumn( 0 ).getName(), "name");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fail( "GLOBALLY_QUOTED_IDENTIFIERS caused the unique key creation to fail." );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testQuoteManytoMany() {
|
|
||||||
Session s = openSession();
|
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
User u = new User();
|
|
||||||
s.persist( u );
|
|
||||||
Role r = new Role();
|
|
||||||
s.persist( r );
|
|
||||||
u.getRoles().add( r );
|
|
||||||
s.flush();
|
|
||||||
s.clear();
|
|
||||||
u = (User) s.get( User.class, u.getId() );
|
|
||||||
assertEquals( 1, u.getRoles().size() );
|
|
||||||
tx.rollback();
|
|
||||||
String role = User.class.getName() + ".roles";
|
|
||||||
assertEquals( "User_Role", metadata().getCollectionBinding( role ).getCollectionTable().getName() );
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestForIssue(jiraKey = "HHH-8520")
|
|
||||||
public void testHbmQuoting() {
|
|
||||||
doTestHbmQuoting( DataPoint.class );
|
|
||||||
doTestHbmQuoting( AssociatedDataPoint.class );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doTestHbmQuoting(Class clazz) {
|
|
||||||
Table table = metadata().getEntityBinding( clazz.getName() ).getTable();
|
|
||||||
assertTrue( table.isQuoted() );
|
|
||||||
Iterator itr = table.getColumnIterator();
|
|
||||||
while(itr.hasNext()) {
|
|
||||||
Column column = (Column) itr.next();
|
|
||||||
assertTrue( column.isQuoted() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void addSettings(Map settings) {
|
|
||||||
settings.put( AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, "true" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class[] getAnnotatedClasses() {
|
|
||||||
return new Class[] {
|
|
||||||
User.class,
|
|
||||||
Role.class,
|
|
||||||
Phone.class,
|
|
||||||
Person.class,
|
|
||||||
House.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String[] getMappings() {
|
|
||||||
return new String[] { "quote/DataPoint.hbm.xml" };
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue