Example usage for org.hibernate SQLQuery setSerializable

List of usage examples for org.hibernate SQLQuery setSerializable

Introduction

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

Prototype

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

Source Link

Document

Bind a positional binary-valued parameter using serialization.

Usage

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.AbstractDAO.java

License:Apache License

/**
 * Executes given <var>sql</var>.
 * <p>/*w  w  w.  ja  v  a  2s.  com*/
 * Should be an <code>INSERT</code> or <code>UPDATE</code> statement.
 * </p>
 */
protected final void executeUpdate(final String sql, final Serializable... parameters) {
    getHibernateTemplate().execute(new HibernateCallback() {

        //
        // HibernateCallback
        //

        public final Object doInHibernate(final Session session) throws HibernateException, SQLException {
            final SQLQuery sqlQuery = session.createSQLQuery(sql);
            for (int i = 0; i < parameters.length; i++) {
                Serializable parameter = parameters[i];
                if (parameter instanceof Long) {
                    sqlQuery.setLong(i, (Long) parameter);
                } else if (parameter instanceof Integer) {
                    sqlQuery.setInteger(i, (Integer) parameter);
                } else if (parameter instanceof Character) {
                    sqlQuery.setCharacter(i, (Character) parameter);
                } else if (parameter instanceof Date) {
                    sqlQuery.setDate(i, (Date) parameter);
                } else {
                    sqlQuery.setSerializable(i, parameter);
                }
            }
            sqlQuery.executeUpdate();
            return null;
        }
    });
}