Search in sources :

Example 11 with TypedValue

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

the class PositionalParameterSpecification method bind.

/**
 * Bind the appropriate value into the given statement at the specified position.
 *
 * @param statement The statement into which the value should be bound.
 * @param qp The defined values for the current query execution.
 * @param session The session against which the current execution is occuring.
 * @param position The position from which to start binding value(s).
 *
 * @return The number of sql bind positions "eaten" by this bind operation.
 */
@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 12 with TypedValue

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

the class NamedParameterInformationImpl 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 13 with TypedValue

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

the class AbstractLoadPlanBasedLoader method bindNamedParameters.

/**
 * Bind named parameters to the JDBC prepared statement.
 * <p/>
 * This is a generic implementation, the problem being that in the
 * general case we do not know enough information about the named
 * parameters to perform this in a complete manner here.  Thus this
 * is generally overridden on subclasses allowing named parameters to
 * apply the specific behavior.  The most usual limitation here is that
 * we need to assume the type span is always one...
 *
 * @param statement The JDBC prepared statement
 * @param namedParams A map of parameter names to values
 * @param startIndex The position from which to start binding parameter values.
 * @param session The originating session.
 * @return The number of JDBC bind positions actually bound during this method execution.
 * @throws SQLException Indicates problems performing the binding.
 * @throws org.hibernate.HibernateException Indicates problems delegating binding to the types.
 */
protected int bindNamedParameters(final PreparedStatement statement, final Map namedParams, final int startIndex, final SharedSessionContractImplementor session) throws SQLException, HibernateException {
    if (namedParams != null) {
        // assumes that types are all of span 1
        final Iterator itr = namedParams.entrySet().iterator();
        final boolean debugEnabled = log.isDebugEnabled();
        int result = 0;
        while (itr.hasNext()) {
            final Map.Entry e = (Map.Entry) itr.next();
            final String name = (String) e.getKey();
            final TypedValue typedval = (TypedValue) e.getValue();
            final int[] locs = getNamedParameterLocs(name);
            for (int loc : locs) {
                if (debugEnabled) {
                    log.debugf("bindNamedParameters() %s -> %s [%s]", typedval.getValue(), name, loc + startIndex);
                }
                typedval.getType().nullSafeSet(statement, typedval.getValue(), loc + startIndex, session);
            }
            result += locs.length;
        }
        return result;
    } else {
        return 0;
    }
}
Also used : Iterator(java.util.Iterator) Map(java.util.Map) TypedValue(org.hibernate.engine.spi.TypedValue)

Example 14 with TypedValue

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

the class SubqueryExpression method getTypedValues.

@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    // the following two lines were added to ensure that this.params is not null, which
    // can happen with two-deep nested subqueries
    final SessionFactoryImplementor factory = criteriaQuery.getFactory();
    createAndSetInnerQuery(criteriaQuery, factory);
    final Type[] ppTypes = params.getPositionalParameterTypes();
    final Object[] ppValues = params.getPositionalParameterValues();
    final TypedValue[] tv = new TypedValue[ppTypes.length];
    for (int i = 0; i < ppTypes.length; i++) {
        tv[i] = new TypedValue(ppTypes[i], ppValues[i]);
    }
    return tv;
}
Also used : Type(org.hibernate.type.Type) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) TypedValue(org.hibernate.engine.spi.TypedValue)

Example 15 with TypedValue

use of org.hibernate.engine.spi.TypedValue in project ysoserial by frohoff.

the class Hibernate1 method makeCaller.

static Object makeCaller(Object tpl, Object getters) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldException, Exception, ClassNotFoundException {
    PojoComponentTuplizer tup = Reflections.createWithoutConstructor(PojoComponentTuplizer.class);
    Reflections.getField(AbstractComponentTuplizer.class, "getters").set(tup, getters);
    ComponentType t = Reflections.createWithConstructor(ComponentType.class, AbstractType.class, new Class[0], new Object[0]);
    Reflections.setFieldValue(t, "componentTuplizer", tup);
    Reflections.setFieldValue(t, "propertySpan", 1);
    Reflections.setFieldValue(t, "propertyTypes", new Type[] { t });
    TypedValue v1 = new TypedValue(t, null);
    Reflections.setFieldValue(v1, "value", tpl);
    Reflections.setFieldValue(v1, "type", t);
    TypedValue v2 = new TypedValue(t, null);
    Reflections.setFieldValue(v2, "value", tpl);
    Reflections.setFieldValue(v2, "type", t);
    return Gadgets.makeMap(v1, v2);
}
Also used : ComponentType(org.hibernate.type.ComponentType) AbstractComponentTuplizer(org.hibernate.tuple.component.AbstractComponentTuplizer) PojoComponentTuplizer(org.hibernate.tuple.component.PojoComponentTuplizer) 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