Example usage for org.hibernate Query setTimestamp

List of usage examples for org.hibernate Query setTimestamp

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setTimestamp(String name, Date value) 

Source Link

Document

Bind the value and the time of a given Date object to a named query parameter.

Usage

From source file:com.appeligo.alerts.PendingAlert.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<PendingAlert> getExpiredAlerts() {
    Permissions.checkUser(Permissions.SUPERUSER);
    Session session = getSession();//from www.j a v  a2  s.c  om
    Query query = session.getNamedQuery("PendingAlert.getExpiredAlerts");
    query.setTimestamp("currentTime", new Date());
    return query.list();
}

From source file:com.appeligo.search.entity.Message.java

License:Apache License

/**
 * /* ww w. j  a v a  2 s.  co  m*/
 * @param max
 * @return
 */
@SuppressWarnings("unchecked")
public static List<Message> getUnsentMessages(int maxResults, int maxAttempts) {
    Session session = getSession();
    Query query = session.getNamedQuery("Message.getUnsent");
    query.setTimestamp("now", new Timestamp(System.currentTimeMillis()));
    query.setInteger("maxAttempts", maxAttempts);
    query.setMaxResults(maxResults);
    return query.list();
}

From source file:com.appeligo.search.entity.Message.java

License:Apache License

public static void deleteOldMessages(int days, int maxAttempts) {
    Session session = getSession();//from  w  w  w .  ja  va  2 s.  com
    Query query = session.getNamedQuery("Message.deleteOldMessages");
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, (0 - (days * 24)));
    query.setTimestamp("oldestSent", new Timestamp(cal.getTimeInMillis()));
    query.setInteger("maxAttempts", maxAttempts);
    query.executeUpdate();
}

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

License:Open Source License

public static void bindParameters(Query query, Object[] params) {
    int pos = 0;//  w  w w.j  a v  a  2s  .  c  om
    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:com.enonic.cms.store.dao.ContentIndexEntityDao.java

License:Open Source License

public List<ContentKey> findContentKeysByQuery(final String hqlQuery, final Map<String, Object> parameters,
        final boolean cacheable) {
    return executeListResult(ContentKey.class, new HibernateCallback() {

        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query compiled = session.createQuery(hqlQuery);
            compiled.setCacheable(cacheable);

            for (String key : parameters.keySet()) {
                Object value = parameters.get(key);
                if (value instanceof Date) {
                    compiled.setTimestamp(key, (Date) value);
                } else if (value instanceof String) {
                    compiled.setString(key, (String) value);
                } else if (value instanceof Boolean) {
                    compiled.setBoolean(key, (Boolean) value);
                } else if (value instanceof Long) {
                    compiled.setLong(key, (Long) value);
                } else if (value instanceof Integer) {
                    compiled.setInteger(key, (Integer) value);
                } else if (value instanceof Byte) {
                    compiled.setByte(key, (Byte) value);
                } else if (value instanceof byte[]) {
                    compiled.setBinary(key, (byte[]) value);
                } else if (value instanceof Float) {
                    compiled.setFloat(key, (Float) value);
                } else if (value instanceof Double) {
                    compiled.setDouble(key, (Double) value);
                } else if (value instanceof BigDecimal) {
                    compiled.setBigDecimal(key, (BigDecimal) value);
                } else if (value instanceof Short) {
                    compiled.setShort(key, (Short) value);
                } else if (value instanceof BigInteger) {
                    compiled.setBigInteger(key, (BigInteger) value);
                } else if (value instanceof Character) {
                    compiled.setCharacter(key, (Character) value);
                } else {
                    compiled.setParameter(key, value);
                }/*from   w  w  w .j ava2  s. c o m*/
            }

            final List result = compiled.list();

            LinkedHashSet<ContentKey> distinctContentKeySet = new LinkedHashSet<ContentKey>(result.size());

            for (Object value : result) {
                if (value instanceof ContentKey) {
                    distinctContentKeySet.add((ContentKey) value);
                } else {
                    Object[] valueList = (Object[]) value;
                    distinctContentKeySet.add(((ContentKey) valueList[0]));
                }
            }

            List<ContentKey> distinctContentKeyList = new ArrayList<ContentKey>(distinctContentKeySet.size());
            distinctContentKeyList.addAll(distinctContentKeySet);
            return distinctContentKeyList;
        }
    });
}

From source file:com.exilant.eGov.src.domain.GeneralLedger.java

License:Open Source License

@SuppressWarnings("deprecation")
@Transactional// www.j a  v a2  s. c o m
public void insert() throws SQLException, TaskFailedException {
    final EGovernCommon commommethods = new EGovernCommon();
    Query pst = null;
    try {
        effectiveDate = String.valueOf(commommethods.getCurrentDate());
        Date dt = new Date();
        final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        final SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
        dt = sdf.parse(effectiveDate);
        effectiveDate = formatter.format(dt);

        description = commommethods.formatString(description);
        setId(String.valueOf(PrimaryKeyGenerator.getNextKey("GeneralLedger")));

        if (functionId == null || functionId.equals(""))
            functionId = null;
        String insertQuery;
        insertQuery = "INSERT INTO generalledger (id, voucherLineID, effectiveDate, glCodeID, "
                + "glCode, debitAmount, creditAmount,";
        insertQuery += "description,voucherHeaderId,functionId) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        if (LOGGER.isInfoEnabled())
            LOGGER.info(insertQuery);
        pst = persistenceService.getSession().createSQLQuery(insertQuery);
        pst.setBigInteger(0, BigInteger.valueOf(Long.valueOf(id)));
        pst.setBigInteger(1,
                voucherLineId == null ? BigInteger.ZERO : BigInteger.valueOf(Long.valueOf(voucherLineId)));
        pst.setTimestamp(2, dt);
        pst.setBigInteger(3,
                glCodeId.equalsIgnoreCase("null") ? null : BigInteger.valueOf(Long.valueOf(glCodeId)));
        pst.setString(4, glCode);
        pst.setDouble(5, debitAmount.equalsIgnoreCase("null") ? null : Double.parseDouble(debitAmount));
        pst.setDouble(6, creditAmount.equalsIgnoreCase("null") ? null : Double.parseDouble(creditAmount));
        pst.setString(7, description);
        pst.setBigInteger(8, voucherHeaderId.equalsIgnoreCase("null") ? null
                : BigInteger.valueOf(Long.valueOf(voucherHeaderId)));
        pst.setBigInteger(9, functionId == null ? null : BigInteger.valueOf(Long.valueOf(functionId)));
        pst.executeUpdate();
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw taskExc;
    } finally {
    }

}

From source file:com.flipkart.flux.dao.StatesDAOImpl.java

License:Apache License

@Override
@Transactional/*from  ww  w.ja  va  2  s  . c  o m*/
@SelectDataSource(DataSourceType.READ_ONLY)
public List findErroredStates(String stateMachineName, Timestamp fromTime, Timestamp toTime, String stateName) {
    Query query;
    if (stateName == null) {
        query = currentSession().createQuery(
                "select state.stateMachineId, state.id, state.status from StateMachine sm join sm.states state "
                        + "where sm.id between (select min(id) from StateMachine where createdAt >= :fromTime) and (select max(id) from StateMachine where createdAt <= :toTime) "
                        + "and sm.name = :stateMachineName and state.status in ('errored', 'sidelined', 'cancelled')");
    } else {
        query = currentSession().createQuery(
                "select state.stateMachineId, state.id, state.status from StateMachine sm join sm.states state "
                        + "where sm.id between (select min(id) from StateMachine where createdAt >= :fromTime) and (select max(id) from StateMachine where createdAt <= :toTime) "
                        + "and sm.name = :stateMachineName and state.name = :stateName and state.status in ('errored', 'sidelined', 'cancelled')");
        query.setString("stateName", stateName);
    }

    query.setString("stateMachineName", stateMachineName);
    query.setTimestamp("fromTime", fromTime);
    query.setTimestamp("toTime", toTime);

    return query.list();
}

From source file:com.glaf.jbpm.util.HibernateUtils.java

License:Apache License

public static void fillParameters(Query query, List<Object> values) {
    if (values == null || values.size() == 0) {
        return;//from  www .  jav  a 2  s.c  o m
    }
    for (int i = 0; i < values.size(); i++) {
        Object object = values.get(i);
        int index = i;
        if (object != null) {
            if (object instanceof java.sql.Date) {
                java.sql.Date sqlDate = (java.sql.Date) object;
                query.setDate(index, sqlDate);
            } else if (object instanceof java.sql.Time) {
                java.sql.Time sqlTime = (java.sql.Time) object;
                query.setTime(index, sqlTime);
            } else if (object instanceof java.sql.Timestamp) {
                Timestamp datetime = (Timestamp) object;
                query.setTimestamp(index, datetime);
            } else if (object instanceof java.util.Date) {
                Timestamp datetime = DateUtils.toTimestamp((java.util.Date) object);
                query.setTimestamp(index, datetime);
            } else {
                query.setParameter(index, object);
            }
        } else {
            query.setParameter(index, null);
        }
    }
}

From source file:com.knowbout.epg.entities.NetworkSchedule.java

License:Apache License

public static int deleteAfter(Date date) {
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("NetworkSchedule.deleteByDate");
    query.setTimestamp("date", date);
    int count = query.executeUpdate();
    return count;
}

From source file:com.knowbout.epg.entities.Program.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<Program> selectByModificationDate(Date date) {
    Session session = HibernateUtil.currentSession();
    Query query = session.getNamedQuery("Program.selectAfterModifiedDate");
    query.setTimestamp("date", date);
    List<Program> list = query.list();
    return list;//from   w w w  .  ja  va  2 s. c om

}