use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class JoinWalker method walkEntityTree.
/**
* Walk the association tree for an entity, adding associations which should
* be join fetched to the {@link #associations} inst var. This form is the
* entry point into the walking for a given entity, starting the recursive
* calls into {@link #walkEntityTree(org.hibernate.persister.entity.OuterJoinLoadable, String, PropertyPath, int)}.
*
* @param persister The persister representing the entity to be walked.
* @param alias The (root) alias to use for this entity/persister.
* @param path The property path to the entity being walked
* @param currentDepth The current join depth
*
* @throws org.hibernate.MappingException ???
*/
private void walkEntityTree(final OuterJoinLoadable persister, final String alias, final PropertyPath path, final int currentDepth) throws MappingException {
int n = persister.countSubclassProperties();
for (int i = 0; i < n; i++) {
Type type = persister.getSubclassPropertyType(i);
if (type.isAssociationType()) {
walkEntityAssociationTree((AssociationType) type, persister, i, alias, path, persister.isSubclassPropertyNullable(i), currentDepth);
} else if (type.isComponentType()) {
walkComponentTree((CompositeType) type, i, 0, persister, alias, path.append(persister.getSubclassPropertyName(i)), currentDepth);
}
}
// if the entity has a composite identifier, see if we need to handle
// its sub-properties separately
final Type idType = persister.getIdentifierType();
if (idType.isComponentType()) {
final CompositeType cidType = (CompositeType) idType;
if (cidType.isEmbedded()) {
// explicitly at odds with the notion of "embedded composite". So we use that for now
if (persister.getEntityMetamodel().getIdentifierProperty().isEmbedded()) {
walkComponentTree(cidType, -1, 0, persister, alias, path, currentDepth);
}
}
}
}
use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class HibernateTraversableResolver method addAssociationsToTheSetForOneProperty.
private void addAssociationsToTheSetForOneProperty(String name, Type type, String prefix, SessionFactoryImplementor factory) {
if (type.isCollectionType()) {
CollectionType collType = (CollectionType) type;
Type assocType = collType.getElementType(factory);
addAssociationsToTheSetForOneProperty(name, assocType, prefix, factory);
} else //ToOne association
if (type.isEntityType() || type.isAnyType()) {
associations.add(prefix + name);
} else if (type.isComponentType()) {
CompositeType componentType = (CompositeType) type;
addAssociationsToTheSetForAllProperties(componentType.getPropertyNames(), componentType.getSubtypes(), (prefix.equals("") ? name : prefix + name) + ".", factory);
}
}
use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class InExpression method getTypedValues.
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
final ArrayList<TypedValue> list = new ArrayList<TypedValue>();
final Type type = criteriaQuery.getTypeUsingProjection(criteria, propertyName);
if (type.isComponentType()) {
final CompositeType compositeType = (CompositeType) type;
final Type[] subTypes = compositeType.getSubtypes();
for (Object value : values) {
for (int i = 0; i < subTypes.length; i++) {
final Object subValue = value == null ? null : compositeType.getPropertyValues(value, EntityMode.POJO)[i];
list.add(new TypedValue(subTypes[i], subValue));
}
}
} else {
for (Object value : values) {
list.add(criteriaQuery.getTypedValue(criteria, propertyName, value));
}
}
return list.toArray(new TypedValue[list.size()]);
}
use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class IdsClauseBuilder method quoteIdentifier.
protected String quoteIdentifier(Object... value) {
if (value.length == 1) {
return quoteIdentifier(value[0], identifierType);
} else {
if (identifierType instanceof CompositeType) {
CompositeType compositeType = (CompositeType) identifierType;
List<String> quotedIdentifiers = new ArrayList<>();
for (int i = 0; i < value.length; i++) {
quotedIdentifiers.add(quoteIdentifier(value[i], compositeType.getSubtypes()[i]));
}
return String.join(",", quotedIdentifiers);
} else {
throw new IllegalArgumentException("Composite identifier does not implement CompositeType");
}
}
}
use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class AbstractEntityPersister method initSubclassPropertyAliasesMap.
//This is really ugly, but necessary:
/**
* Must be called by subclasses, at the end of their constructors
*/
protected void initSubclassPropertyAliasesMap(PersistentClass model) throws MappingException {
// ALIASES
internalInitSubclassPropertyAliasesMap(null, model.getSubclassPropertyClosureIterator());
// aliases for identifier ( alias.id ); skip if the entity defines a non-id property named 'id'
if (!entityMetamodel.hasNonIdentifierPropertyNamedId()) {
subclassPropertyAliases.put(ENTITY_ID, getIdentifierAliases());
subclassPropertyColumnNames.put(ENTITY_ID, getIdentifierColumnNames());
}
// aliases named identifier ( alias.idname )
if (hasIdentifierProperty()) {
subclassPropertyAliases.put(getIdentifierPropertyName(), getIdentifierAliases());
subclassPropertyColumnNames.put(getIdentifierPropertyName(), getIdentifierColumnNames());
}
// aliases for composite-id's
if (getIdentifierType().isComponentType()) {
// Fetch embedded identifiers propertynames from the "virtual" identifier component
CompositeType componentId = (CompositeType) getIdentifierType();
String[] idPropertyNames = componentId.getPropertyNames();
String[] idAliases = getIdentifierAliases();
String[] idColumnNames = getIdentifierColumnNames();
for (int i = 0; i < idPropertyNames.length; i++) {
if (entityMetamodel.hasNonIdentifierPropertyNamedId()) {
subclassPropertyAliases.put(ENTITY_ID + "." + idPropertyNames[i], new String[] { idAliases[i] });
subclassPropertyColumnNames.put(ENTITY_ID + "." + getIdentifierPropertyName() + "." + idPropertyNames[i], new String[] { idColumnNames[i] });
}
// if (hasIdentifierProperty() && !ENTITY_ID.equals( getIdentifierPropertyName() ) ) {
if (hasIdentifierProperty()) {
subclassPropertyAliases.put(getIdentifierPropertyName() + "." + idPropertyNames[i], new String[] { idAliases[i] });
subclassPropertyColumnNames.put(getIdentifierPropertyName() + "." + idPropertyNames[i], new String[] { idColumnNames[i] });
} else {
// embedded composite ids ( alias.idname1, alias.idname2 )
subclassPropertyAliases.put(idPropertyNames[i], new String[] { idAliases[i] });
subclassPropertyColumnNames.put(idPropertyNames[i], new String[] { idColumnNames[i] });
}
}
}
if (entityMetamodel.isPolymorphic()) {
subclassPropertyAliases.put(ENTITY_CLASS, new String[] { getDiscriminatorAlias() });
subclassPropertyColumnNames.put(ENTITY_CLASS, new String[] { getDiscriminatorColumnName() });
}
}
Aggregations