Search in sources :

Example 6 with TypedValue

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

the class SessionImpl method getFilterQueryPlan.

private FilterQueryPlan getFilterQueryPlan(Object collection, String filter, QueryParameters parameters, boolean shallow) throws HibernateException {
    if (collection == null) {
        throw new NullPointerException("null collection passed to filter");
    }
    CollectionEntry entry = persistenceContext.getCollectionEntryOrNull(collection);
    final CollectionPersister roleBeforeFlush = (entry == null) ? null : entry.getLoadedPersister();
    FilterQueryPlan plan = null;
    if (roleBeforeFlush == null) {
        // if it was previously unreferenced, we need to flush in order to
        // get its state into the database in order to execute query
        flush();
        entry = persistenceContext.getCollectionEntryOrNull(collection);
        CollectionPersister roleAfterFlush = (entry == null) ? null : entry.getLoadedPersister();
        if (roleAfterFlush == null) {
            throw new QueryException("The collection was unreferenced");
        }
        plan = getFactory().getQueryPlanCache().getFilterQueryPlan(filter, roleAfterFlush.getRole(), shallow, getLoadQueryInfluencers().getEnabledFilters());
    } else {
        // otherwise, we only need to flush if there are in-memory changes
        // to the queried tables
        plan = getFactory().getQueryPlanCache().getFilterQueryPlan(filter, roleBeforeFlush.getRole(), shallow, getLoadQueryInfluencers().getEnabledFilters());
        if (autoFlushIfRequired(plan.getQuerySpaces())) {
            // might need to run a different filter entirely after the flush
            // because the collection role may have changed
            entry = persistenceContext.getCollectionEntryOrNull(collection);
            CollectionPersister roleAfterFlush = (entry == null) ? null : entry.getLoadedPersister();
            if (roleBeforeFlush != roleAfterFlush) {
                if (roleAfterFlush == null) {
                    throw new QueryException("The collection was dereferenced");
                }
                plan = getFactory().getQueryPlanCache().getFilterQueryPlan(filter, roleAfterFlush.getRole(), shallow, getLoadQueryInfluencers().getEnabledFilters());
            }
        }
    }
    if (parameters != null) {
        parameters.getNamedParameters().put(CollectionFilterKeyParameterSpecification.PARAM_KEY, new TypedValue(entry.getLoadedPersister().getKeyType(), entry.getLoadedKey()));
    }
    return plan;
}
Also used : FilterQueryPlan(org.hibernate.engine.query.spi.FilterQueryPlan) QueryException(org.hibernate.QueryException) CollectionEntry(org.hibernate.engine.spi.CollectionEntry) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) TypedValue(org.hibernate.engine.spi.TypedValue)

Example 7 with TypedValue

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

the class CriteriaQueryTranslator method getTypedValue.

/**
 * Get the a typed value for the given property value.
 */
@Override
public TypedValue getTypedValue(Criteria subcriteria, String propertyName, Object value) throws HibernateException {
    // Detect discriminator values...
    if (value instanceof Class) {
        final Class entityClass = (Class) value;
        final Queryable q = SessionFactoryHelper.findQueryableUsingImports(sessionFactory, entityClass.getName());
        if (q != null) {
            final Type type = q.getDiscriminatorType();
            String stringValue = q.getDiscriminatorSQLValue();
            if (stringValue != null && stringValue.length() > 2 && stringValue.startsWith("'") && stringValue.endsWith("'")) {
                // remove the single quotes
                stringValue = stringValue.substring(1, stringValue.length() - 1);
            }
            // Convert the string value into the proper type.
            if (type instanceof StringRepresentableType) {
                final StringRepresentableType nullableType = (StringRepresentableType) type;
                value = nullableType.fromStringValue(stringValue);
            } else {
                throw new QueryException("Unsupported discriminator type " + type);
            }
            return new TypedValue(type, value);
        }
    }
    // Otherwise, this is an ordinary value.
    return new TypedValue(getTypeUsingProjection(subcriteria, propertyName), value);
}
Also used : 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) QueryException(org.hibernate.QueryException) StringRepresentableType(org.hibernate.type.StringRepresentableType) Queryable(org.hibernate.persister.entity.Queryable) TypedValue(org.hibernate.engine.spi.TypedValue)

Example 8 with TypedValue

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

the class NamedParamBinder method bind.

@Override
public int bind(PreparedStatement statement, QueryParameters qp, SharedSessionContractImplementor session, int position) throws SQLException {
    final TypedValue typedValue = qp.getNamedParameters().get(name);
    typedValue.getType().nullSafeSet(statement, typedValue.getValue(), position, session);
    return typedValue.getType().getColumnSpan(session.getFactory());
}
Also used : TypedValue(org.hibernate.engine.spi.TypedValue)

Example 9 with TypedValue

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

the class PositionalParamBinder method bind.

@Override
public int bind(PreparedStatement statement, QueryParameters qp, SharedSessionContractImplementor session, int position) throws SQLException {
    final TypedValue typedValue = qp.getNamedParameters().get(Integer.toString(label));
    typedValue.getType().nullSafeSet(statement, typedValue.getValue(), position, session);
    return typedValue.getType().getColumnSpan(session.getFactory());
}
Also used : TypedValue(org.hibernate.engine.spi.TypedValue)

Example 10 with TypedValue

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

the class PositionalParameterInformationImpl method bind.

@Override
public int bind(PreparedStatement statement, QueryParameters qp, SharedSessionContractImplementor session, int position) throws SQLException {
    final TypedValue typedValue = qp.getNamedParameters().get(Integer.toString(label));
    typedValue.getType().nullSafeSet(statement, typedValue.getValue(), position, session);
    return typedValue.getType().getColumnSpan(session.getFactory());
}
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