Search in sources :

Example 16 with TypedValue

use of org.hibernate.engine.spi.TypedValue in project hibernate-orm by hibernate.

the class DWithinExpression method getTypedValues.

@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    final SpatialDialect spatialDialect = ExpressionUtil.getSpatialDialect(criteriaQuery, SpatialFunction.dwithin);
    TypedValue typedDistanceValue = new TypedValue(StandardBasicTypes.DOUBLE, distance);
    if (spatialDialect instanceof OracleSpatial10gDialect) {
        typedDistanceValue = new TypedValue(StandardBasicTypes.STRING, "distance=" + distance);
    }
    return new TypedValue[] { criteriaQuery.getTypedValue(criteria, propertyName, geometry), typedDistanceValue };
}
Also used : SpatialDialect(org.hibernate.spatial.SpatialDialect) OracleSpatial10gDialect(org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect) TypedValue(org.hibernate.engine.spi.TypedValue)

Example 17 with TypedValue

use of org.hibernate.engine.spi.TypedValue in project hibernate-orm by hibernate.

the class CriteriaQueryTranslator method getQueryParameters.

public QueryParameters getQueryParameters() {
    final RowSelection selection = new RowSelection();
    selection.setFirstRow(rootCriteria.getFirstResult());
    selection.setMaxRows(rootCriteria.getMaxResults());
    selection.setTimeout(rootCriteria.getTimeout());
    selection.setFetchSize(rootCriteria.getFetchSize());
    final LockOptions lockOptions = new LockOptions();
    final Map<String, LockMode> lockModeMap = rootCriteria.getLockModes();
    for (final String key : lockModeMap.keySet()) {
        final Criteria subcriteria = getAliasedCriteria(key);
        lockOptions.setAliasSpecificLockMode(getSQLAlias(subcriteria), lockModeMap.get(key));
    }
    final List<Object> values = new ArrayList<Object>();
    final List<Type> types = new ArrayList<Type>();
    final Iterator<CriteriaImpl.Subcriteria> subcriteriaIterator = rootCriteria.iterateSubcriteria();
    while (subcriteriaIterator.hasNext()) {
        final CriteriaImpl.Subcriteria subcriteria = subcriteriaIterator.next();
        final LockMode lm = subcriteria.getLockMode();
        if (lm != null) {
            lockOptions.setAliasSpecificLockMode(getSQLAlias(subcriteria), lm);
        }
        if (subcriteria.getWithClause() != null) {
            final TypedValue[] tv = subcriteria.getWithClause().getTypedValues(subcriteria, this);
            for (TypedValue aTv : tv) {
                values.add(aTv.getValue());
                types.add(aTv.getType());
            }
        }
    }
    // Type and value gathering for the WHERE clause needs to come AFTER lock mode gathering,
    // because the lock mode gathering loop now contains join clauses which can contain
    // parameter bindings (as in the HQL WITH clause).
    final Iterator<CriteriaImpl.CriterionEntry> iter = rootCriteria.iterateExpressionEntries();
    while (iter.hasNext()) {
        final CriteriaImpl.CriterionEntry ce = iter.next();
        final TypedValue[] tv = ce.getCriterion().getTypedValues(ce.getCriteria(), this);
        for (TypedValue aTv : tv) {
            values.add(aTv.getValue());
            types.add(aTv.getType());
        }
    }
    final Object[] valueArray = values.toArray();
    final Type[] typeArray = ArrayHelper.toTypeArray(types);
    return new QueryParameters(typeArray, valueArray, lockOptions, selection, rootCriteria.isReadOnlyInitialized(), (rootCriteria.isReadOnlyInitialized() && rootCriteria.isReadOnly()), rootCriteria.getCacheable(), rootCriteria.getCacheRegion(), rootCriteria.getComment(), rootCriteria.getQueryHints(), rootCriteria.isLookupByNaturalKey(), rootCriteria.getResultTransformer());
}
Also used : LockOptions(org.hibernate.LockOptions) CriteriaImpl(org.hibernate.internal.CriteriaImpl) ArrayList(java.util.ArrayList) LockMode(org.hibernate.LockMode) Criteria(org.hibernate.Criteria) QueryParameters(org.hibernate.engine.spi.QueryParameters) RowSelection(org.hibernate.engine.spi.RowSelection) StringRepresentableType(org.hibernate.type.StringRepresentableType) CollectionType(org.hibernate.type.CollectionType) JoinType(org.hibernate.sql.JoinType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) TypedValue(org.hibernate.engine.spi.TypedValue)

Example 18 with TypedValue

use of org.hibernate.engine.spi.TypedValue in project hibernate-orm by hibernate.

the class SimpleSubqueryExpression method getTypedValues.

@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    final TypedValue[] subQueryTypedValues = super.getTypedValues(criteria, criteriaQuery);
    final TypedValue[] result = new TypedValue[subQueryTypedValues.length + 1];
    System.arraycopy(subQueryTypedValues, 0, result, 1, subQueryTypedValues.length);
    result[0] = new TypedValue(getTypes()[0], value);
    return result;
}
Also used : TypedValue(org.hibernate.engine.spi.TypedValue)

Example 19 with TypedValue

use of org.hibernate.engine.spi.TypedValue 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()]);
}
Also used : CompositeType(org.hibernate.type.CompositeType) Type(org.hibernate.type.Type) ArrayList(java.util.ArrayList) TypedValue(org.hibernate.engine.spi.TypedValue) CompositeType(org.hibernate.type.CompositeType)

Example 20 with TypedValue

use of org.hibernate.engine.spi.TypedValue in project hibernate-orm by hibernate.

the class Example method addPropertyTypedValue.

protected void addPropertyTypedValue(Object value, Type type, List<TypedValue> list) {
    if (value != null) {
        if (value instanceof String) {
            String string = (String) value;
            if (isIgnoreCaseEnabled) {
                string = string.toLowerCase(Locale.ROOT);
            }
            if (isLikeEnabled) {
                string = matchMode.toMatchString(string);
            }
            value = string;
        }
        list.add(new TypedValue(type, value));
    }
}
Also used : TypedValue(org.hibernate.engine.spi.TypedValue)

Aggregations

TypedValue (org.hibernate.engine.spi.TypedValue)24 Type (org.hibernate.type.Type)9 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)3 CompositeType (org.hibernate.type.CompositeType)3 QueryException (org.hibernate.QueryException)2 RowSelection (org.hibernate.engine.spi.RowSelection)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 JoinType (org.hibernate.sql.JoinType)2 AssociationType (org.hibernate.type.AssociationType)2 CollectionType (org.hibernate.type.CollectionType)2 StringRepresentableType (org.hibernate.type.StringRepresentableType)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Serializable (java.io.Serializable)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1