use of org.hibernate.metamodel.spi.MappingMetamodelImplementor in project hibernate-orm by hibernate.
the class ByteMappingTests method testMappings.
@Test
public void testMappings(SessionFactoryScope scope) {
// first, verify the type selections...
final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
final EntityPersister entityDescriptor = mappingMetamodel.getEntityDescriptor(EntityOfBytes.class);
final JdbcTypeRegistry jdbcTypeRegistry = mappingMetamodel.getTypeConfiguration().getJdbcTypeRegistry();
{
final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapper");
assertThat(attribute.getJavaType().getJavaTypeClass(), equalTo(Byte.class));
final JdbcMapping jdbcMapping = attribute.getJdbcMapping();
assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(Byte.class));
assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(Types.TINYINT)));
}
{
final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("primitive");
assertThat(attribute.getJavaType().getJavaTypeClass(), equalTo(Byte.class));
final JdbcMapping jdbcMapping = attribute.getJdbcMapping();
assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(Byte.class));
assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(Types.TINYINT)));
}
// and try to use the mapping
scope.inTransaction((session) -> session.persist(new EntityOfBytes(1, (byte) 3, (byte) 5)));
scope.inTransaction((session) -> session.get(EntityOfBytes.class, 1));
}
use of org.hibernate.metamodel.spi.MappingMetamodelImplementor in project hibernate-orm by hibernate.
the class CharacterArrayMappingTests method verifyMappings.
@Test
public void verifyMappings(SessionFactoryScope scope) {
final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
final JdbcTypeRegistry jdbcRegistry = mappingMetamodel.getTypeConfiguration().getJdbcTypeRegistry();
final EntityPersister entityDescriptor = mappingMetamodel.getEntityDescriptor(EntityWithCharArrays.class);
{
final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("primitive");
final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
assertThat(jdbcMapping.getJdbcType(), equalTo(jdbcRegistry.getDescriptor(Types.VARCHAR)));
}
{
final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapper");
final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
assertThat(jdbcMapping.getJdbcType(), equalTo(jdbcRegistry.getDescriptor(Types.VARCHAR)));
}
{
final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("primitiveClob");
final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
assertThat(jdbcMapping.getJdbcType(), equalTo(jdbcRegistry.getDescriptor(Types.CLOB)));
}
{
final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapperClob");
final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
assertThat(jdbcMapping.getJdbcType(), equalTo(jdbcRegistry.getDescriptor(Types.CLOB)));
}
}
use of org.hibernate.metamodel.spi.MappingMetamodelImplementor in project hibernate-orm by hibernate.
the class CharacterMappingTests method testMappings.
@Test
public void testMappings(SessionFactoryScope scope) {
// first, verify the type selections...
final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
final JdbcTypeRegistry jdbcRegistry = mappingMetamodel.getTypeConfiguration().getJdbcTypeRegistry();
final EntityPersister entityDescriptor = mappingMetamodel.getEntityDescriptor(EntityOfCharacters.class);
{
final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapper");
assertThat(attribute.getJavaType().getJavaTypeClass(), equalTo(Character.class));
final JdbcMapping jdbcMapping = attribute.getJdbcMapping();
assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(Character.class));
assertThat(jdbcMapping.getJdbcType(), equalTo(jdbcRegistry.getDescriptor(Types.CHAR)));
}
{
final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("primitive");
assertThat(attribute.getJavaType().getJavaTypeClass(), equalTo(Character.class));
final JdbcMapping jdbcMapping = attribute.getJdbcMapping();
assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(Character.class));
assertThat(jdbcMapping.getJdbcType(), equalTo(jdbcRegistry.getDescriptor(Types.CHAR)));
}
// and try to use the mapping
scope.inTransaction((session) -> session.persist(new EntityOfCharacters(1, 'A', 'b')));
scope.inTransaction((session) -> session.get(EntityOfCharacters.class, 1));
}
use of org.hibernate.metamodel.spi.MappingMetamodelImplementor in project hibernate-orm by hibernate.
the class CoordinatingEntityNameResolver method resolveEntityName.
@Override
public String resolveEntityName(Object entity) {
String entityName = interceptor.getEntityName(entity);
if (entityName != null) {
return entityName;
}
final MappingMetamodelImplementor mappingMetamodel = sessionFactory.getRuntimeMetamodels().getMappingMetamodel();
for (EntityNameResolver resolver : mappingMetamodel.getEntityNameResolvers()) {
entityName = resolver.resolveEntityName(entity);
if (entityName != null) {
break;
}
}
if (entityName != null) {
return entityName;
}
// the old-time stand-by...
return entity.getClass().getName();
}
use of org.hibernate.metamodel.spi.MappingMetamodelImplementor in project hibernate-orm by hibernate.
the class JoinedSubclassEntityPersister method pruneForSubclasses.
@Override
public void pruneForSubclasses(TableGroup tableGroup, Set<String> treatedEntityNames) {
final Set<TableReference> retainedTableReferences = new HashSet<>(treatedEntityNames.size());
final Set<String> sharedSuperclassTables = new HashSet<>();
final MappingMetamodelImplementor metamodel = getFactory().getRuntimeMetamodels().getMappingMetamodel();
for (String treatedEntityName : treatedEntityNames) {
final JoinedSubclassEntityPersister subPersister = (JoinedSubclassEntityPersister) metamodel.findEntityDescriptor(treatedEntityName);
final String[] subclassTableNames = subPersister.getSubclassTableNames();
// In mathematical terms, sharedSuperclassTables will be the "intersection" of the table names of all treated entities
if (sharedSuperclassTables.isEmpty()) {
for (int i = 0; i < subclassTableNames.length; i++) {
if (subPersister.isClassOrSuperclassTable[i]) {
sharedSuperclassTables.add(subclassTableNames[i]);
}
}
} else {
sharedSuperclassTables.retainAll(Arrays.asList(subclassTableNames));
}
// todo (6.0): no need to resolve all table references, only the ones needed for cardinality
for (String subclassTableName : subclassTableNames) {
retainedTableReferences.add(tableGroup.resolveTableReference(null, subclassTableName, false));
}
}
final List<TableReferenceJoin> tableReferenceJoins = tableGroup.getTableReferenceJoins();
// i.e. with parenthesis around, as that means the table reference joins will be isolated
if (tableGroup.canUseInnerJoins() || tableGroup.isRealTableGroup()) {
final TableReferenceJoin[] oldJoins = tableReferenceJoins.toArray(new TableReferenceJoin[0]);
tableReferenceJoins.clear();
for (TableReferenceJoin oldJoin : oldJoins) {
final NamedTableReference joinedTableReference = oldJoin.getJoinedTableReference();
if (retainedTableReferences.contains(joinedTableReference)) {
if (oldJoin.getJoinType() != SqlAstJoinType.INNER && sharedSuperclassTables.contains(joinedTableReference.getTableExpression())) {
tableReferenceJoins.add(new TableReferenceJoin(true, joinedTableReference, oldJoin.getPredicate()));
} else {
tableReferenceJoins.add(oldJoin);
}
}
}
} else {
tableReferenceJoins.removeIf(join -> !retainedTableReferences.contains(join.getJoinedTableReference()));
}
}
Aggregations