use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class Example method addComponentTypedValues.
protected void addComponentTypedValues(String path, Object component, CompositeType type, List<TypedValue> list, Criteria criteria, CriteriaQuery criteriaQuery) {
if (component != null) {
final String[] propertyNames = type.getPropertyNames();
final Type[] subtypes = type.getSubtypes();
final Object[] values = type.getPropertyValues(component, getEntityMode(criteria, criteriaQuery));
for (int i = 0; i < propertyNames.length; i++) {
final Object value = values[i];
final Type subtype = subtypes[i];
final String subpath = StringHelper.qualify(path, propertyNames[i]);
if (isPropertyIncluded(value, subpath, subtype)) {
if (subtype.isComponentType()) {
addComponentTypedValues(subpath, value, (CompositeType) subtype, list, criteria, criteriaQuery);
} else {
addPropertyTypedValue(value, subtype, list);
}
}
}
}
}
use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class Example method appendComponentCondition.
protected void appendComponentCondition(String path, Object component, CompositeType type, Criteria criteria, CriteriaQuery criteriaQuery, StringBuilder buf) {
if (component != null) {
final String[] propertyNames = type.getPropertyNames();
final Object[] values = type.getPropertyValues(component, getEntityMode(criteria, criteriaQuery));
final Type[] subtypes = type.getSubtypes();
for (int i = 0; i < propertyNames.length; i++) {
final String subPath = StringHelper.qualify(path, propertyNames[i]);
final Object value = values[i];
if (isPropertyIncluded(value, subPath, subtypes[i])) {
final Type subtype = subtypes[i];
if (subtype.isComponentType()) {
appendComponentCondition(subPath, value, (CompositeType) subtype, criteria, criteriaQuery, buf);
} else {
appendPropertyCondition(subPath, value, criteria, criteriaQuery, buf);
}
}
}
}
}
use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class Example method getTypedValues.
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
final EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(criteriaQuery.getEntityName(criteria));
final String[] propertyNames = meta.getPropertyNames();
final Type[] propertyTypes = meta.getPropertyTypes();
final Object[] values = meta.getPropertyValues(exampleEntity);
final List<TypedValue> list = new ArrayList<TypedValue>();
for (int i = 0; i < propertyNames.length; i++) {
final Object value = values[i];
final Type type = propertyTypes[i];
final String name = propertyNames[i];
final boolean isVersionProperty = i == meta.getVersionProperty();
if (!isVersionProperty && isPropertyIncluded(value, name, type)) {
if (propertyTypes[i].isComponentType()) {
addComponentTypedValues(name, value, (CompositeType) type, list, criteria, criteriaQuery);
} else {
addPropertyTypedValue(value, type, list);
}
}
}
return list.toArray(new TypedValue[list.size()]);
}
use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class Example method toSqlString.
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
final StringBuilder buf = new StringBuilder().append('(');
final EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(criteriaQuery.getEntityName(criteria));
final String[] propertyNames = meta.getPropertyNames();
final Type[] propertyTypes = meta.getPropertyTypes();
final Object[] propertyValues = meta.getPropertyValues(exampleEntity);
for (int i = 0; i < propertyNames.length; i++) {
final Object propertyValue = propertyValues[i];
final String propertyName = propertyNames[i];
final boolean isVersionProperty = i == meta.getVersionProperty();
if (!isVersionProperty && isPropertyIncluded(propertyValue, propertyName, propertyTypes[i])) {
if (propertyTypes[i].isComponentType()) {
appendComponentCondition(propertyName, propertyValue, (CompositeType) propertyTypes[i], criteria, criteriaQuery, buf);
} else {
appendPropertyCondition(propertyName, propertyValue, criteria, criteriaQuery, buf);
}
}
}
if (buf.length() == 1) {
buf.append("1=1");
}
return buf.append(')').toString();
}
use of org.hibernate.type.CompositeType 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;
}
Aggregations