use of org.hibernate.type.CollectionType in project hibernate-orm by hibernate.
the class AuditMetadataGenerator method addValueInSecondPass.
private void addValueInSecondPass(Element parent, Value value, CompositeMapperBuilder currentMapper, String entityName, EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData, boolean insertable, boolean processModifiedFlag) {
final Type type = value.getType();
if (type instanceof ComponentType) {
componentMetadataGenerator.addComponent(parent, propertyAuditingData, value, currentMapper, entityName, xmlMappingData, false);
// mod flag field has been already generated in first pass
return;
} else if (type instanceof ManyToOneType) {
toOneRelationMetadataGenerator.addToOne(parent, propertyAuditingData, value, currentMapper, entityName, insertable);
} else if (type instanceof OneToOneType) {
final OneToOne oneToOne = (OneToOne) value;
if (oneToOne.getReferencedPropertyName() != null) {
toOneRelationMetadataGenerator.addOneToOneNotOwning(propertyAuditingData, value, currentMapper, entityName);
} else {
// @OneToOne relation marked with @PrimaryKeyJoinColumn
toOneRelationMetadataGenerator.addOneToOnePrimaryKeyJoinColumn(propertyAuditingData, value, currentMapper, entityName, insertable);
}
} else if (type instanceof CollectionType) {
final CollectionMetadataGenerator collectionMetadataGenerator = new CollectionMetadataGenerator(this, (Collection) value, currentMapper, entityName, xmlMappingData, propertyAuditingData);
collectionMetadataGenerator.addCollection();
} else {
return;
}
addModifiedFlagIfNeeded(parent, propertyAuditingData, processModifiedFlag);
}
use of org.hibernate.type.CollectionType in project hibernate-orm by hibernate.
the class AbstractEmptinessExpression method getQueryableCollection.
protected QueryableCollection getQueryableCollection(String entityName, String propertyName, SessionFactoryImplementor factory) throws HibernateException {
final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister(entityName);
final Type type = ownerMapping.toType(propertyName);
if (!type.isCollectionType()) {
throw new MappingException("Property path [" + entityName + "." + propertyName + "] does not reference a collection");
}
final String role = ((CollectionType) type).getRole();
try {
return (QueryableCollection) factory.getCollectionPersister(role);
} catch (ClassCastException cce) {
throw new QueryException("collection role is not queryable: " + role);
} catch (Exception e) {
throw new QueryException("collection role not found: " + role);
}
}
use of org.hibernate.type.CollectionType in project hibernate-orm by hibernate.
the class Nullability method checkSubElementsNullability.
/**
* check sub elements-nullability. Returns property path that break
* nullability or null if none
*
* @param propertyType type to check
* @param value value to check
*
* @return property path
* @throws HibernateException error while getting subcomponent values
*/
private String checkSubElementsNullability(Type propertyType, Object value) throws HibernateException {
if (propertyType.isComponentType()) {
return checkComponentNullability(value, (CompositeType) propertyType);
}
if (propertyType.isCollectionType()) {
// persistent collections may have components
final CollectionType collectionType = (CollectionType) propertyType;
final Type collectionElementType = collectionType.getElementType(session.getFactory());
if (collectionElementType.isComponentType()) {
// check for all components values in the collection
final CompositeType componentType = (CompositeType) collectionElementType;
final Iterator itr = CascadingActions.getLoadedElementsIterator(session, collectionType, value);
while (itr.hasNext()) {
final Object compositeElement = itr.next();
if (compositeElement != null) {
return checkComponentNullability(compositeElement, componentType);
}
}
}
}
return null;
}
use of org.hibernate.type.CollectionType in project hibernate-orm by hibernate.
the class Cascade method cascadeCollection.
/**
* Cascade an action to a collection
*/
private static void cascadeCollection(final CascadingAction action, final CascadePoint cascadePoint, final EventSource eventSource, final int componentPathStackDepth, final Object parent, final Object child, final CascadeStyle style, final Object anything, final CollectionType type) {
final CollectionPersister persister = eventSource.getFactory().getCollectionPersister(type.getRole());
final Type elemType = persister.getElementType();
CascadePoint elementsCascadePoint = cascadePoint;
if (cascadePoint == CascadePoint.AFTER_INSERT_BEFORE_DELETE) {
elementsCascadePoint = CascadePoint.AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION;
}
//cascade to current collection elements
if (elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType()) {
cascadeCollectionElements(action, elementsCascadePoint, eventSource, componentPathStackDepth, parent, child, type, style, elemType, anything, persister.isCascadeDeleteEnabled());
}
}
use of org.hibernate.type.CollectionType in project hibernate-orm by hibernate.
the class IdentNode method resolveIndex.
public void resolveIndex(AST parent) throws SemanticException {
// currently un-needed overhead.
if (!(isResolved() && nakedPropertyRef)) {
throw new UnsupportedOperationException();
}
String propertyName = getOriginalText();
if (!getDataType().isCollectionType()) {
throw new SemanticException("Collection expected; [" + propertyName + "] does not refer to a collection property");
}
// TODO : most of below was taken verbatim from DotNode; should either delegate this logic or super-type it
CollectionType type = (CollectionType) getDataType();
String role = type.getRole();
QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection(role);
// DotNode uses null here...
String alias = null;
String columnTableAlias = getFromElement().getTableAlias();
JoinType joinType = JoinType.INNER_JOIN;
boolean fetch = false;
FromElementFactory factory = new FromElementFactory(getWalker().getCurrentFromClause(), getFromElement(), propertyName, alias, getFromElement().toColumns(columnTableAlias, propertyName, false), true);
FromElement elem = factory.createCollection(queryableCollection, role, joinType, fetch, true);
setFromElement(elem);
// Always add the collection's query spaces.
getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces());
}
Aggregations