Example usage for org.hibernate Query setSerializable

List of usage examples for org.hibernate Query setSerializable

Introduction

In this page you can find the example usage for org.hibernate Query setSerializable.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setSerializable(String name, Serializable val) 

Source Link

Document

Bind a named binary-valued parameter using serialization.

Usage

From source file:com.cloud.bridge.util.QueryHelper.java

License:Open Source License

public static void bindParameters(Query query, Object[] params) {
    int pos = 0;//from  w  w w .j  a  va 2 s  .c  o  m
    if (params != null && params.length > 0) {
        for (Object param : params) {
            if (param instanceof Byte)
                query.setByte(pos++, ((Byte) param).byteValue());
            else if (param instanceof Short)
                query.setShort(pos++, ((Short) param).shortValue());
            else if (param instanceof Integer)
                query.setInteger(pos++, ((Integer) param).intValue());
            else if (param instanceof Long)
                query.setLong(pos++, ((Long) param).longValue());
            else if (param instanceof Float)
                query.setFloat(pos++, ((Float) param).floatValue());
            else if (param instanceof Double)
                query.setDouble(pos++, ((Double) param).doubleValue());
            else if (param instanceof Boolean)
                query.setBoolean(pos++, ((Boolean) param).booleanValue());
            else if (param instanceof Character)
                query.setCharacter(pos++, ((Character) param).charValue());
            else if (param instanceof Date)
                query.setDate(pos++, (Date) param);
            else if (param instanceof Calendar)
                query.setCalendar(pos++, (Calendar) param);
            else if (param instanceof CalendarDateParam)
                query.setCalendarDate(pos++, ((CalendarDateParam) param).dateValue());
            else if (param instanceof TimestampParam)
                query.setTimestamp(pos++, ((TimestampParam) param).timestampValue());
            else if (param instanceof TimeParam)
                query.setTime(pos++, ((TimeParam) param).timeValue());
            else if (param instanceof String)
                query.setString(pos++, (String) param);
            else if (param instanceof TextParam)
                query.setText(pos++, ((TextParam) param).textValue());
            else if (param instanceof byte[])
                query.setBinary(pos++, (byte[]) param);
            else if (param instanceof BigDecimal)
                query.setBigDecimal(pos++, (BigDecimal) param);
            else if (param instanceof BigInteger)
                query.setBigInteger(pos++, (BigInteger) param);
            else if (param instanceof Locale)
                query.setLocale(pos++, (Locale) param);
            else if (param instanceof EntityParam)
                query.setEntity(pos++, ((EntityParam) param).entityValue());
            else if (param instanceof Serializable)
                query.setSerializable(pos++, (Serializable) param);
            else
                query.setEntity(pos++, param);
        }
    }
}

From source file:it.eng.spagobi.analiticalmodel.document.dao.BIObjectDAOHibImpl.java

License:Mozilla Public License

public BIObject loadBIObjectForDetail(String path) throws EMFUserError {
    logger.debug("IN");
    BIObject biObject = null;/*from  w ww. j av  a2s . co  m*/
    Session aSession = null;
    Transaction tx = null;
    try {
        aSession = getSession();
        tx = aSession.beginTransaction();
        //String hql = " from SbiObjects where path = '" + path + "'";
        String hql = " from SbiObjects where path = ? ";

        Query hqlQuery = aSession.createQuery(hql);
        hqlQuery.setSerializable(0, path);

        SbiObjects hibObject = (SbiObjects) hqlQuery.uniqueResult();
        if (hibObject == null)
            return null;
        biObject = toBIObject(hibObject);
        tx.commit();
    } catch (HibernateException he) {
        logger.error(he);
        if (tx != null)
            tx.rollback();
        throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
    } finally {
        if (aSession != null) {
            if (aSession.isOpen())
                aSession.close();
        }
    }
    logger.debug("OUT");
    return biObject;
}