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;
}
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);
}
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());
}
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());
}
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());
}
Aggregations