re-enable tests

re-organize some tests
This commit is contained in:
Steve Ebersole 2021-03-22 17:28:28 -05:00
parent 1f028095cf
commit 1caebf7cc6
29 changed files with 360 additions and 161 deletions

View File

@ -6,6 +6,8 @@
*/
package org.hibernate.boot.model.process.internal;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import javax.persistence.AttributeConverter;
@ -15,9 +17,14 @@ import org.hibernate.boot.model.convert.spi.JpaAttributeConverterCreationContext
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.IndexedConsumer;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
import org.hibernate.metamodel.mapping.SqlExpressable;
import org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter;
import org.hibernate.sql.ast.Clause;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
@ -132,7 +139,8 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
relationalJtd,
relationalStd,
converter,
mutabilityPlan
mutabilityPlan,
context.getBootstrapContext().getTypeConfiguration()
);
}
@ -154,7 +162,8 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
JavaTypeDescriptor relationalJtd,
SqlTypeDescriptor relationalStd,
JpaAttributeConverter valueConverter,
MutabilityPlan mutabilityPlan) {
MutabilityPlan mutabilityPlan,
TypeConfiguration typeConfiguration) {
assert domainJtd != null;
this.domainJtd = domainJtd;
@ -194,7 +203,15 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
return binder;
}
};
// this.jdbcMapping = new StandardBasicTypeImpl( relationalJtd, relationalStd );
// this.jdbcMapping = new ConverterJdbcMappingImpl(
// domainJtd,
// relationalJtd,
// relationalStd,
// valueConverter,
// mutabilityPlan,
// typeConfiguration
// );
this.legacyResolvedType = new AttributeConverterTypeAdapter(
ConverterDescriptor.TYPE_NAME_PREFIX + valueConverter.getConverterJavaTypeDescriptor().getJavaType().getTypeName(),
@ -253,4 +270,141 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
public String toString() {
return "NamedConverterResolution(" + valueConverter.getConverterBean().getBeanClass().getName() + ')';
}
/**
* Allows treating the attribute conversion as a jdbc-level reference.
* This covers the conversion plus managing the JDBC-value
*/
private static class ConverterJdbcMappingImpl implements JdbcMapping, MappingModelExpressable<Object>, SqlExpressable {
private final JavaTypeDescriptor domainJtd;
private final JavaTypeDescriptor jdbcJtd;
private final SqlTypeDescriptor std;
private final JpaAttributeConverter valueConverter;
private final MutabilityPlan mutabilityPlan;
private final ValueExtractor extractor;
private final ValueBinder binder;
private final BasicType lowLevelJdbcMapping;
public ConverterJdbcMappingImpl(
JavaTypeDescriptor domainJtd,
JavaTypeDescriptor jdbcJtd,
SqlTypeDescriptor std,
JpaAttributeConverter valueConverter,
MutabilityPlan mutabilityPlan,
TypeConfiguration typeConfiguration) {
this.domainJtd = domainJtd;
this.jdbcJtd = jdbcJtd;
this.std = std;
this.valueConverter = valueConverter;
this.mutabilityPlan = mutabilityPlan;
this.extractor = std.getExtractor( jdbcJtd );
this.binder = std.getBinder( jdbcJtd );
this.lowLevelJdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve( jdbcJtd, std );
}
@Override
public JavaTypeDescriptor getJavaTypeDescriptor() {
return domainJtd;
}
@Override
public SqlTypeDescriptor getSqlTypeDescriptor() {
return std;
}
@Override
public ValueExtractor getJdbcValueExtractor() {
return extractor;
}
@Override
public ValueBinder getJdbcValueBinder() {
return binder;
}
@Override
public int getJdbcTypeCount() {
return 1;
}
@Override
public List<JdbcMapping> getJdbcMappings() {
return Collections.singletonList( this );
}
@Override
public int forEachJdbcType(IndexedConsumer<JdbcMapping> action) {
action.accept( 0, this );
return 1;
}
@Override
public int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> action) {
action.accept( offset, this );
return 1;
}
@Override
public Object disassemble(Object value, SharedSessionContractImplementor session) {
return mutabilityPlan.disassemble( value );
}
@Override
public int forEachJdbcValue(
Object value,
Clause clause,
int offset,
JdbcValuesConsumer valuesConsumer,
SharedSessionContractImplementor session) {
final AttributeConverter converter = (AttributeConverter) valueConverter.getConverterBean().getBeanInstance();
final Object converted = converter.convertToDatabaseColumn( value );
valuesConsumer.consume( offset, converted, this );
return 1;
}
@Override
public int forEachDisassembledJdbcValue(
Object value,
Clause clause,
JdbcValuesConsumer valuesConsumer,
SharedSessionContractImplementor session) {
final AttributeConverter converter = (AttributeConverter) valueConverter.getConverterBean().getBeanInstance();
final Object converted = converter.convertToDatabaseColumn( value );
valuesConsumer.consume( 0, converted, this );
return 1;
}
@Override
public int forEachDisassembledJdbcValue(
Object value,
Clause clause,
int offset,
JdbcValuesConsumer valuesConsumer,
SharedSessionContractImplementor session) {
final AttributeConverter converter = (AttributeConverter) valueConverter.getConverterBean().getBeanInstance();
final Object converted = converter.convertToDatabaseColumn( value );
valuesConsumer.consume( offset, converted, this );
return 1;
}
@Override
public int forEachJdbcValue(
Object value,
Clause clause,
JdbcValuesConsumer valuesConsumer,
SharedSessionContractImplementor session) {
final AttributeConverter converter = (AttributeConverter) valueConverter.getConverterBean().getBeanInstance();
final Object converted = converter.convertToDatabaseColumn( value );
valuesConsumer.consume( 0, converted, this );
return 1;
}
@Override
public JdbcMapping getJdbcMapping() {
return lowLevelJdbcMapping;
}
}
}

View File

@ -701,7 +701,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
try {
NativeQueryImplementor query = createNativeQuery( sqlString );
query.addEntity( "alias1", resultClass.getName(), LockMode.READ );
// query.addEntity( "alias1", resultClass.getName(), LockMode.READ );
return query;
}
catch (RuntimeException he) {

View File

@ -12,6 +12,7 @@ import java.sql.SQLException;
import org.hibernate.metamodel.mapping.BasicValuedMapping;
import org.hibernate.metamodel.mapping.ConvertibleModelPart;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.model.convert.spi.BasicValueConverter;
import org.hibernate.query.sqm.sql.internal.DomainResultProducer;
import org.hibernate.sql.ast.SqlAstWalker;
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
@ -34,8 +35,16 @@ public class QueryLiteral<T> implements Literal, DomainResultProducer<T> {
private final BasicValuedMapping type;
public QueryLiteral(T value, BasicValuedMapping type) {
this.value = value;
this.type = type;
if ( type instanceof ConvertibleModelPart ) {
final ConvertibleModelPart convertible = (ConvertibleModelPart) type;
final BasicValueConverter valueConverter = convertible.getValueConverter();
this.value = (T) valueConverter.toRelationalValue( value );
}
else {
this.value = value;
}
}
@Override

View File

@ -15,9 +15,6 @@ import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
@ -32,8 +29,9 @@ import org.hibernate.type.EnumType;
import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter;
import org.hibernate.usertype.UserType;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.ServiceRegistryScope;
import org.junit.jupiter.api.Test;
import static javax.persistence.EnumType.ORDINAL;
@ -48,14 +46,14 @@ import static org.hamcrest.MatcherAssert.assertThat;
* @author Steve Ebersole
*/
@ServiceRegistry
@DomainModel( annotatedClasses = EnumResolutionTests.EntityWithEnums.class )
public class EnumResolutionTests {
@Test
public void testVariousEnumResolutions(ServiceRegistryScope serviceRegistryScope) {
final StandardServiceRegistry registry = serviceRegistryScope.getRegistry();
final Metadata metadata = new MetadataSources( registry ).addAnnotatedClass( EntityWithEnums.class ).buildMetadata();
final PersistentClass entityBinding = metadata.getEntityBinding( EntityWithEnums.class.getName() );
public void testRawEnumResolution(DomainModelScope scope) {
final PersistentClass entityBinding = scope
.getDomainModel()
.getEntityBinding( EntityWithEnums.class.getName() );
verifyEnumResolution(
entityBinding.getProperty( "rawEnum" ),
@ -64,6 +62,13 @@ public class EnumResolutionTests {
OrdinalEnumValueConverter.class,
true
);
}
@Test
public void testUnspecifiedMappingEnumResolution(DomainModelScope scope) {
final PersistentClass entityBinding = scope
.getDomainModel()
.getEntityBinding( EntityWithEnums.class.getName() );
verifyEnumResolution(
entityBinding.getProperty( "unspecifiedMappingEnum" ),
@ -72,6 +77,13 @@ public class EnumResolutionTests {
OrdinalEnumValueConverter.class,
true
);
}
@Test
public void testOrdinalEnumResolution(DomainModelScope scope) {
final PersistentClass entityBinding = scope
.getDomainModel()
.getEntityBinding( EntityWithEnums.class.getName() );
verifyEnumResolution(
entityBinding.getProperty( "ordinalEnum" ),
@ -80,6 +92,13 @@ public class EnumResolutionTests {
OrdinalEnumValueConverter.class,
true
);
}
@Test
public void testNamedEnumResolution(DomainModelScope scope) {
final PersistentClass entityBinding = scope
.getDomainModel()
.getEntityBinding( EntityWithEnums.class.getName() );
verifyEnumResolution(
entityBinding.getProperty( "namedEnum" ),
@ -88,6 +107,13 @@ public class EnumResolutionTests {
NamedEnumValueConverter.class,
false
);
}
@Test
public void testConvertedEnumResolution(DomainModelScope scope) {
final PersistentClass entityBinding = scope
.getDomainModel()
.getEntityBinding( EntityWithEnums.class.getName() );
verifyEnumResolution(
entityBinding.getProperty( "convertedEnum" ),

View File

@ -17,7 +17,6 @@ import org.hibernate.query.Query;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
@ -52,7 +51,6 @@ public class FormulaNativeQueryTest {
}
@Test
@FailureExpected( jiraKey = "HHH-7525", reason = "native query not implemented yet")
void testNativeQuery(SessionFactoryScope scope) {
scope.inTransaction( session -> {
final Query<Foo> query = session.createNativeQuery( "SELECT ft.* FROM foo_table ft", Foo.class );

View File

@ -16,7 +16,6 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.Session;
import org.hibernate.annotations.Immutable;
import org.hibernate.boot.MetadataBuilder;
import org.hibernate.boot.MetadataSources;
@ -30,11 +29,13 @@ import org.hibernate.type.descriptor.java.MutabilityPlan;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptorIndicators;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@ -55,6 +56,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT
@Test
@TestForIssue( jiraKey = "HHH-11098" )
@FailureExpected( jiraKey = "n/a", message = "Arg!!!" )
public void testIt() {
// create data and check assertions
inTransaction(
@ -72,7 +74,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT
assertThat( pseudoMutableToDatabaseCallCount, is(1 ) ); // was 2 (like mutable) before the JavaTypeDescriptor registration
}
@BeforeEach
@Before
public void clearCounts() {
// in case we add additional tests
sessionFactory().getStatistics().clear();
@ -87,7 +89,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT
pseudoMutableToDomainCallCount = 0;
}
@AfterEach
@After
public void dropTestData() {
inTransaction(
(session) -> session.createQuery( "delete TheEntity" ).executeUpdate()

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.Clob;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.math.BigDecimal;
import org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.math.BigInteger;
import org.hibernate.type.descriptor.java.BigIntegerTypeDescriptor;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;

View File

@ -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.orm.test.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.time.Duration;
import org.hibernate.type.descriptor.java.DurationJavaDescriptor;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.time.Instant;
import org.hibernate.type.descriptor.java.InstantJavaDescriptor;

View File

@ -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.orm.test.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.util.Comparator;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.util.Date;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.util.Date;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.time.LocalDate;
import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.time.LocalDateTime;
import org.hibernate.type.descriptor.java.LocalDateTimeJavaDescriptor;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.time.LocalDate;
import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import static org.junit.Assert.assertEquals;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.time.LocalTime;
import java.time.OffsetTime;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import org.hibernate.type.descriptor.java.StringTypeDescriptor;

View File

@ -1,10 +1,10 @@
/*
* 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>.
* 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.type.descriptor.java;
package org.hibernate.orm.test.mapping.type.java;
import java.time.LocalDateTime;
import java.time.ZoneId;

View File

@ -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.orm.test.type.descriptor.jdbc;
package org.hibernate.orm.test.mapping.type.jdbc;
import java.sql.Types;

View File

@ -7,6 +7,7 @@
package org.hibernate.test.converter;
import java.io.Serializable;
import java.sql.Clob;
import java.sql.Timestamp;
import java.sql.Types;
import javax.persistence.AttributeConverter;
@ -30,14 +31,13 @@ import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.HANACloudColumnStoreDialect;
import org.hibernate.dialect.HANAColumnStoreDialect;
import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.type.AbstractStandardBasicType;
import org.hibernate.type.BasicType;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter;
import org.hibernate.type.descriptor.java.EnumJavaTypeDescriptor;
@ -53,6 +53,12 @@ import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.util.ExceptionUtil;
import org.junit.Test;
import org.hamcrest.Matchers;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -98,25 +104,25 @@ public class AttributeConverterTest extends BaseUnitTestCase {
@Test
public void testBasicOperation() {
SimpleValue simpleValue = new BasicValue( new MetadataBuildingContextTestingImpl() );
simpleValue.setJpaAttributeConverterDescriptor(
final BasicValue basicValue = new BasicValue( new MetadataBuildingContextTestingImpl() );
basicValue.setJpaAttributeConverterDescriptor(
new InstanceBasedConverterDescriptor(
new StringClobConverter(),
new ClassmateContext()
)
);
simpleValue.setTypeUsingReflection( IrrelevantEntity.class.getName(), "name" );
basicValue.setTypeUsingReflection( IrrelevantEntity.class.getName(), "name" );
Type type = simpleValue.getType();
final Type type = basicValue.getType();
assertNotNull( type );
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
fail( "AttributeConverter not applied" );
}
AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor( ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) );
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo( String.class ) );
final SqlTypeDescriptor sqlTypeDescriptor = typeAdapter.getSqlTypeDescriptor();
assertThat( sqlTypeDescriptor.getJdbcTypeCode(), is( Types.CLOB ) );
}
@Test
@ -150,25 +156,24 @@ public class AttributeConverterTest extends BaseUnitTestCase {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
.addAnnotatedClass( Tester.class )
.getMetadataBuilder()
.applyAttributeConverter( StringClobConverter.class, true )
.build();
PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
Property nameProp = tester.getProperty( "name" );
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
final PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
final Property nameProp = tester.getProperty( "name" );
final BasicValue nameValue = (BasicValue) nameProp.getValue();
final Type type = nameValue.getType();
assertNotNull( type );
assertTyping( BasicType.class, type );
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
fail( "AttributeConverter not applied" );
}
AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) );
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), Matchers.equalTo( String.class ) );
final SqlTypeDescriptor sqlTypeDescriptor = typeAdapter.getSqlTypeDescriptor();
assertThat( sqlTypeDescriptor.getJdbcTypeCode(), is( Types.CLOB ) );
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );
@ -189,16 +194,18 @@ public class AttributeConverterTest extends BaseUnitTestCase {
PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
Property nameProp = tester.getProperty( "name" );
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
BasicValue nameValue = (BasicValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull( type );
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
fail( "AttributeConverter not applied" );
}
AttributeConverterTypeAdapter basicType = assertTyping( AttributeConverterTypeAdapter.class, type );
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) );
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo( String.class ) );
assertThat( typeAdapter.getRelationalJtd().getJavaTypeClass(), equalTo( Clob.class ) );
final SqlTypeDescriptor sqlTypeDescriptor = typeAdapter.getSqlTypeDescriptor();
assertThat( sqlTypeDescriptor.getJdbcTypeCode(), is( Types.CLOB ) );
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );
@ -405,23 +412,25 @@ public class AttributeConverterTest extends BaseUnitTestCase {
.build();
// first lets validate that the converter was applied...
PersistentClass tester = metadata.getEntityBinding( EntityWithConvertibleField.class.getName() );
Property nameProp = tester.getProperty( "convertibleEnum" );
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
final PersistentClass tester = metadata.getEntityBinding( EntityWithConvertibleField.class.getName() );
final Property nameProp = tester.getProperty( "convertibleEnum" );
final BasicValue nameValue = (BasicValue) nameProp.getValue();
final Type type = nameValue.getType();
assertNotNull( type );
assertTyping( BasicType.class, type );
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
fail( "AttributeConverter not applied" );
}
AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
assertTyping( EnumJavaTypeDescriptor.class, basicType.getJavaTypeDescriptor() );
if (metadata.getDatabase().getDialect() instanceof HANACloudColumnStoreDialect) {
assertEquals( Types.NVARCHAR, basicType.getSqlTypeDescriptor().getSqlType() );
assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) );
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
assertThat( typeAdapter.getDomainJtd(), instanceOf( EnumJavaTypeDescriptor.class ) );
final int expectedJdbcTypeCode;
if ( metadata.getDatabase().getDialect() instanceof HANAColumnStoreDialect ) {
expectedJdbcTypeCode = Types.NVARCHAR;
}
else {
assertEquals( Types.VARCHAR, basicType.getSqlTypeDescriptor().getSqlType() );
expectedJdbcTypeCode = Types.VARCHAR;
}
assertThat( typeAdapter.getSqlTypeDescriptor().getJdbcTypeCode(), is( expectedJdbcTypeCode ) );
// then lets build the SF and verify its use...
final SessionFactory sf = metadata.buildSessionFactory();

View File

@ -6,8 +6,6 @@
*/
package org.hibernate.test.converter;
import java.util.Arrays;
import java.util.List;
import javax.persistence.AttributeConverter;
import javax.persistence.Convert;
import javax.persistence.Converter;
@ -15,52 +13,55 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Tuple;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
/**
* @author Vlad Mihalcea
*/
@TestForIssue( jiraKey = "HHH-10778" )
public class PackagePrivateAttributeConverterEntityManagerFactoryTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] { Tester.class };
}
@DomainModel( annotatedClasses = PackagePrivateAttributeConverterEntityManagerFactoryTest.Tester.class )
@SessionFactory
public class PackagePrivateAttributeConverterEntityManagerFactoryTest {
public final String sql = "select code from Tester where id = :id";
@Test
public void test() {
doInJPA( this::entityManagerFactory, entityManager -> {
Tester tester = new Tester();
@NotImplementedYet( strict = false, reason = "Support for passing `resultType` to `#createNativeQuery` not yet implemented" )
public void test(SessionFactoryScope scope) {
scope.inTransaction(
(session) -> {
final Tester tester = new Tester();
tester.setId( 1L );
tester.setCode( 123 );
entityManager.persist( tester );
} );
session.persist( tester );
}
);
doInJPA( this::entityManagerFactory, entityManager -> {
Tuple tuple = (Tuple) entityManager.createNativeQuery(
"select code " +
"from Tester " +
"where id = :id", Tuple.class )
scope.inTransaction(
(session) -> {
final Tuple tuple = (Tuple) session.createNativeQuery( sql, Tuple.class )
.setParameter( "id", 1L )
.getSingleResult();
assertEquals( "123", tuple.get( "code" ) );
Tester tester = entityManager.find( Tester.class, 1L );
final Tester tester = session.find( Tester.class, 1L );
assertEquals( 123, (int) tester.getCode() );
} );
}
);
}
@AfterEach
public void dropTestData(SessionFactoryScope scope) {
scope.inTransaction( (session) -> session.createQuery( "delete Tester" ).executeUpdate() );
}
// Entity declarations used in the test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~