use of org.hibernate.NotYetImplementedFor6Exception in project hibernate-orm by hibernate.
the class MappingModelCreationHelper method interpretPluralAttributeMappingKeyDescriptor.
private static void interpretPluralAttributeMappingKeyDescriptor(PluralAttributeMappingImpl attributeMapping, Collection bootValueMapping, CollectionPersister collectionDescriptor, ManagedMappingType declaringType, Dialect dialect, MappingModelCreationProcess creationProcess) {
ModelPart attributeMappingSubPart = null;
if (!StringHelper.isEmpty(collectionDescriptor.getMappedByProperty())) {
attributeMappingSubPart = ((ModelPartContainer) attributeMapping.getElementDescriptor().getPartMappingType()).findSubPart(collectionDescriptor.getMappedByProperty(), null);
}
if (attributeMappingSubPart instanceof ToOneAttributeMapping) {
final ToOneAttributeMapping referencedAttributeMapping = (ToOneAttributeMapping) attributeMappingSubPart;
setReferencedAttributeForeignKeyDescriptor(attributeMapping, referencedAttributeMapping, referencedAttributeMapping.findContainingEntityMapping().getEntityPersister(), collectionDescriptor.getMappedByProperty(), dialect, creationProcess);
return;
}
final KeyValue bootValueMappingKey = bootValueMapping.getKey();
final Type keyType = bootValueMappingKey.getType();
final ModelPart fkTarget;
final String lhsPropertyName = collectionDescriptor.getCollectionType().getLHSPropertyName();
final boolean isReferenceToPrimaryKey = lhsPropertyName == null;
final ManagedMappingType keyDeclaringType;
if (collectionDescriptor.getElementType().isEntityType()) {
keyDeclaringType = ((QueryableCollection) collectionDescriptor).getElementPersister();
} else {
// This is not "really correct" but it is as good as it gets.
// The key declaring type serves as declaring type for the inverse model part of a FK.
// Most of the time, there is a proper managed type, but not for basic collections.
// Since the declaring type is needed for certain operations, we use the one from the target side of the FK
keyDeclaringType = declaringType;
}
if (isReferenceToPrimaryKey) {
fkTarget = collectionDescriptor.getOwnerEntityPersister().getIdentifierMapping();
} else {
fkTarget = declaringType.findAttributeMapping(lhsPropertyName);
}
if (keyType instanceof BasicType) {
assert bootValueMappingKey.getColumnSpan() == 1;
assert fkTarget instanceof BasicValuedModelPart;
final BasicValuedModelPart simpleFkTarget = (BasicValuedModelPart) fkTarget;
final String tableExpression = getTableIdentifierExpression(bootValueMappingKey.getTable(), creationProcess);
final SelectableMapping keySelectableMapping = SelectableMappingImpl.from(tableExpression, bootValueMappingKey.getSelectables().get(0), (JdbcMapping) keyType, dialect, creationProcess.getSqmFunctionRegistry());
attributeMapping.setForeignKeyDescriptor(new SimpleForeignKeyDescriptor(keyDeclaringType, simpleFkTarget, null, keySelectableMapping, simpleFkTarget, isReferenceToPrimaryKey, ((SimpleValue) bootValueMappingKey).isConstrained()));
} else if (fkTarget instanceof EmbeddableValuedModelPart) {
final EmbeddedForeignKeyDescriptor embeddedForeignKeyDescriptor = buildEmbeddableForeignKeyDescriptor((EmbeddableValuedModelPart) fkTarget, bootValueMapping, keyDeclaringType, collectionDescriptor.getAttributeMapping(), false, dialect, creationProcess);
attributeMapping.setForeignKeyDescriptor(embeddedForeignKeyDescriptor);
} else {
throw new NotYetImplementedFor6Exception("Support for " + fkTarget.getClass() + " foreign keys not yet implemented: " + bootValueMapping.getRole());
}
}
use of org.hibernate.NotYetImplementedFor6Exception in project hibernate-orm by hibernate.
the class MappingModelCreationHelper method interpretMapKey.
private static CollectionPart interpretMapKey(Collection bootValueMapping, CollectionPersister collectionDescriptor, String tableExpression, String sqlAliasStem, Dialect dialect, MappingModelCreationProcess creationProcess) {
assert bootValueMapping instanceof IndexedCollection;
final IndexedCollection indexedCollection = (IndexedCollection) bootValueMapping;
final Value bootMapKeyDescriptor = indexedCollection.getIndex();
if (bootMapKeyDescriptor instanceof BasicValue) {
final BasicValue basicValue = (BasicValue) bootMapKeyDescriptor;
final SelectableMapping selectableMapping = SelectableMappingImpl.from(tableExpression, basicValue.getSelectables().get(0), basicValue.resolve().getJdbcMapping(), dialect, creationProcess.getSqmFunctionRegistry());
return new BasicValuedCollectionPart(collectionDescriptor, CollectionPart.Nature.INDEX, basicValue.resolve().getValueConverter(), selectableMapping);
}
if (bootMapKeyDescriptor instanceof Component) {
final Component component = (Component) bootMapKeyDescriptor;
final CompositeType compositeType = (CompositeType) component.getType();
final EmbeddableMappingTypeImpl mappingType = EmbeddableMappingTypeImpl.from(component, compositeType, inflightDescriptor -> new EmbeddedCollectionPart(collectionDescriptor, CollectionPart.Nature.INDEX, inflightDescriptor, // parent-injection
component.getParentProperty(), tableExpression, sqlAliasStem), creationProcess);
return (CollectionPart) mappingType.getEmbeddedValueMapping();
}
if (bootMapKeyDescriptor instanceof OneToMany || bootMapKeyDescriptor instanceof ToOne) {
final EntityType indexEntityType = (EntityType) collectionDescriptor.getIndexType();
final EntityPersister associatedEntity = creationProcess.getEntityPersister(indexEntityType.getAssociatedEntityName());
final EntityCollectionPart indexDescriptor = new EntityCollectionPart(collectionDescriptor, CollectionPart.Nature.INDEX, bootMapKeyDescriptor, associatedEntity, creationProcess);
creationProcess.registerInitializationCallback("PluralAttributeMapping( " + bootValueMapping.getRole() + ") - index descriptor", () -> {
indexDescriptor.finishInitialization(collectionDescriptor, bootValueMapping, indexEntityType.getRHSUniqueKeyPropertyName(), creationProcess);
return true;
});
return indexDescriptor;
}
throw new NotYetImplementedFor6Exception("Support for plural attributes with index type [" + bootMapKeyDescriptor + "] not yet implemented");
}
use of org.hibernate.NotYetImplementedFor6Exception in project hibernate-orm by hibernate.
the class MappingMetamodelImpl method resolveMappingExpressible.
@Override
public MappingModelExpressible<?> resolveMappingExpressible(SqmExpressible<?> sqmExpressible, Function<NavigablePath, TableGroup> tableGroupLocator) {
if (sqmExpressible instanceof SqmPath) {
final SqmPath<?> sqmPath = (SqmPath<?>) sqmExpressible;
final NavigablePath navigablePath = sqmPath.getNavigablePath();
if (navigablePath.getParent() != null) {
final TableGroup parentTableGroup = tableGroupLocator.apply(navigablePath.getParent());
return parentTableGroup.getModelPart().findSubPart(navigablePath.getLocalName(), null);
}
return tableGroupLocator.apply(navigablePath.getParent()).getModelPart();
}
if (sqmExpressible instanceof BasicType<?>) {
return (BasicType<?>) sqmExpressible;
}
if (sqmExpressible instanceof BasicSqmPathSource<?>) {
return getTypeConfiguration().getBasicTypeForJavaType(((BasicSqmPathSource<?>) sqmExpressible).getJavaType());
}
if (sqmExpressible instanceof SqmFieldLiteral) {
return getTypeConfiguration().getBasicTypeForJavaType(((SqmFieldLiteral<?>) sqmExpressible).getJavaType());
}
if (sqmExpressible instanceof CompositeSqmPathSource) {
throw new NotYetImplementedFor6Exception("Resolution of embedded-valued SqmExpressible nodes not yet implemented");
}
if (sqmExpressible instanceof EmbeddableTypeImpl) {
return (MappingModelExpressible<?>) sqmExpressible;
}
if (sqmExpressible instanceof EntityDomainType<?>) {
return getEntityDescriptor(((EntityDomainType<?>) sqmExpressible).getHibernateEntityName());
}
if (sqmExpressible instanceof TupleType<?>) {
final MappingModelExpressible<?> mappingModelExpressible = tupleTypeCache.get(sqmExpressible);
if (mappingModelExpressible != null) {
return mappingModelExpressible;
}
final TupleType<?> tupleType = (TupleType<?>) sqmExpressible;
final MappingModelExpressible<?>[] components = new MappingModelExpressible<?>[tupleType.componentCount()];
for (int i = 0; i < components.length; i++) {
components[i] = resolveMappingExpressible(tupleType.get(i), tableGroupLocator);
}
final MappingModelExpressible<?> createdMappingModelExpressible = new TupleMappingModelExpressible(components);
final MappingModelExpressible<?> existingMappingModelExpressible = tupleTypeCache.putIfAbsent(tupleType, createdMappingModelExpressible);
return existingMappingModelExpressible == null ? createdMappingModelExpressible : existingMappingModelExpressible;
}
return null;
}
use of org.hibernate.NotYetImplementedFor6Exception in project hibernate-orm by hibernate.
the class AbstractEmbeddableInitializer method determineParentInstance.
private Object determineParentInstance(RowProcessingState processingState) {
// or at least the fetch-parent of the collection could get passed.
if (fetchParentAccess != null) {
// the embeddable being initialized is a fetch, so use the fetchParentAccess
// to get the parent reference
//
// at the moment, this uses the legacy behavior of injecting the "first
// containing entity" as the parent. however,
// todo (6.x) - allow injection of containing composite as parent if
// it is the direct parent
final FetchParentAccess firstEntityDescriptorAccess = fetchParentAccess.findFirstEntityDescriptorAccess();
return firstEntityDescriptorAccess.getInitializedInstance();
}
// Otherwise, fallback to determining the parent-initializer by path
// todo (6.0) - this is the part that should be "subsumed" based on the
// comment above
final NavigablePath parentPath = navigablePath.getParent();
if (parentPath == null) {
return null;
}
final Initializer parentInitializer = processingState.resolveInitializer(parentPath);
if (parentInitializer instanceof CollectionInitializer) {
return ((CollectionInitializer) parentInitializer).getCollectionInstance().getOwner();
}
if (parentInitializer instanceof EntityInitializer) {
return ((EntityInitializer) parentInitializer).getEntityInstance();
}
throw new NotYetImplementedFor6Exception(getClass());
}
use of org.hibernate.NotYetImplementedFor6Exception in project hibernate-orm by hibernate.
the class MultiNaturalIdLoaderStandard method multiLoad.
@Override
public <K> List<E> multiLoad(K[] naturalIds, MultiNaturalIdLoadOptions options, SharedSessionContractImplementor session) {
if (naturalIds == null) {
throw new IllegalArgumentException("`naturalIds` is null");
}
if (naturalIds.length == 0) {
return Collections.emptyList();
}
if (LoadingLogger.LOGGER.isTraceEnabled()) {
LoadingLogger.LOGGER.tracef("Starting multi natural-id loading for `%s`", entityDescriptor.getEntityName());
}
final SessionFactoryImplementor sessionFactory = session.getFactory();
final int maxBatchSize;
if (options.getBatchSize() != null && options.getBatchSize() > 0) {
maxBatchSize = options.getBatchSize();
} else {
maxBatchSize = session.getJdbcServices().getJdbcEnvironment().getDialect().getDefaultBatchLoadSizingStrategy().determineOptimalBatchLoadSize(entityDescriptor.getNaturalIdMapping().getJdbcTypeCount(), naturalIds.length, sessionFactory.getSessionFactoryOptions().inClauseParameterPaddingEnabled());
}
final int batchSize = Math.min(maxBatchSize, naturalIds.length);
final LockOptions lockOptions = (options.getLockOptions() == null) ? new LockOptions(LockMode.NONE) : options.getLockOptions();
final MultiNaturalIdLoadingBatcher batcher = new MultiNaturalIdLoadingBatcher(entityDescriptor, entityDescriptor.getNaturalIdMapping(), batchSize, (naturalId, session1) -> {
// todo (6.0) : use this to help create the ordered results
return entityDescriptor.getNaturalIdMapping().normalizeInput(naturalId, session);
}, session.getLoadQueryInfluencers(), lockOptions, sessionFactory);
final List<E> results = batcher.multiLoad(naturalIds, options, session);
if (results.size() == 1) {
return results;
}
if (options.isOrderReturnEnabled()) {
throw new NotYetImplementedFor6Exception(getClass());
}
return results;
}
Aggregations