List of usage examples for org.hibernate Query setTimestamp
@Deprecated @SuppressWarnings("unchecked") default Query<R> setTimestamp(String name, Date value)
From source file:de.nava.informa.impl.hibernate.ChannelBuilder.java
License:Open Source License
public ItemSourceIF createItemSource(String name, String location, Date timestamp) { Query query = session.createQuery( "from ItemSource as src where src.name = ? and src.location = ? and src.timestamp = ? "); query.setString(0, name);//from w w w. j a va2 s.c om query.setString(1, location); query.setTimestamp(2, timestamp); ItemSourceIF obj = (ItemSourceIF) query.uniqueResult(); if (obj == null) { obj = new ItemSource(null, name, location, timestamp); session.save(obj); } return obj; }
From source file:de.uzk.hki.da.core.RepairService.java
License:Open Source License
public synchronized Object fetchObjectForAudit() { Session session = null;//from w ww.j a va2s. c o m Object objectToAudit = null; try { String nodeName = this.node.getName(); session = HibernateUtil.openSession(); Calendar now = Calendar.getInstance(); now.add(Calendar.HOUR_OF_DAY, -24); try { Query query = session .createQuery("from Object o where o.initial_node = ?1 and o.last_checked < ?2 and " + "o.object_state = ?3 " + "order by o.last_checked asc"); query.setParameter("1", nodeName); query.setTimestamp("2", now.getTime()); query.setParameter("3", Object.ObjectStatus.ArchivedAndValidAndNotInWorkflow); @SuppressWarnings("unchecked") List<Object> obbiList = query.list(); if (obbiList.size() > 0) { objectToAudit = (Object) obbiList.get(0); for (Package p : objectToAudit.getPackages()) { p.getCopies().size(); } objectToAudit.setObject_state(Object.ObjectStatus.UnderAudit); Transaction trans = session.beginTransaction(); session.save(objectToAudit); trans.commit(); } } finally { session.close(); } return objectToAudit; } catch (IndexOutOfBoundsException e) { if (session != null) session.close(); return null; } }
From source file:de.xwic.sandbox.server.installer.DirectQuery.java
License:Apache License
/** * @param query/* www .ja va 2s . c o m*/ * @param params */ private static void setParams(Query query, Object... params) { if (null != params) { for (int i = 0; i < params.length; i++) { if (params[i] instanceof String) { query.setString(i, (String) params[i]); } else if (params[i] instanceof Integer) { query.setInteger(i, (Integer) params[i]); } else if (params[i] instanceof Double) { query.setDouble(i, (Double) params[i]); } else if (params[i] instanceof Date) { query.setTimestamp(i, (Date) params[i]); } else { throw new IllegalArgumentException("Param type not supported #" + i); } } } }
From source file:dtx.oa.rbac.dao.UserDao.java
@Override public boolean updateUser(User user) { user.setPassword(StringUtil.getMD5String(user.getPassword())); Session session = HibernateUtil.getSession(); session.beginTransaction();//from w ww . java 2 s . c o m Query query = session.createQuery( "UPDATE User user SET user.password=:pwd,user.status=:status,user.remark=:remark,user.loginTime=:login_time,user.loginIp=:login_ip WHERE user.uuid=:id"); query.setString("pwd", user.getPassword()); query.setBoolean("status", user.getStatus()); query.setString("remark", user.getRemark()); query.setString("id", user.getUuid()); query.setString("login_ip", user.getLoginIp()); query.setTimestamp("login_time", user.getLoginTime()); int result = query.executeUpdate(); session.getTransaction().commit(); return result > 0; }
From source file:dtx.oa.rbac.dao.UserDao.java
@Override public boolean updateLoginMessage(User user) { Session session = HibernateUtil.getSession(); session.beginTransaction();/*from w w w .java 2 s.c o m*/ Query query = session.createQuery( "UPDATE User user SET user.loginTime=:login_time,user.loginIp=:login_ip WHERE user.uuid=:id"); query.setTimestamp("login_time", new Timestamp(System.currentTimeMillis())); query.setString("login_ip", user.getLoginIp()); query.setString("id", user.getUuid()); int result = query.executeUpdate(); session.getTransaction().commit(); return result > 0; }
From source file:edu.amrita.aview.audit.daos.UserActionDAO.java
/** * Gets the future license validation count. * * @param currentTime the current time// w w w.ja v a 2 s. c om * @param licValId the lic val id * @return the future license validation count * @throws AViewException */ public static int getFutureLicenseValidationCount(java.sql.Timestamp currentTime, int licValId) throws AViewException { Session session = null; int validationsCount = 0; try { session = HibernateUtils.getAuditHibernateConnection(); String queryStr = "select count(*) from UserAction ua where ua.actionId = :actionId and ua.createdDate >= :currTime"; Query query = session.createQuery(queryStr); query.setInteger("actionId", licValId); query.setTimestamp("currTime", currentTime); List list = query.list(); validationsCount = Integer.parseInt(list.get(0).toString()); } catch (HibernateException he) { processException(he); } finally { HibernateUtils.closeConnection(session); } return validationsCount; }
From source file:edu.depaul.armada.dao.ContainerDaoHibernate.java
License:Open Source License
@Override public void deleteOldData(int interval) { Query query = sessionFactory.getCurrentSession() .createQuery("delete from Container c where c.timestamp <= :timestamp"); Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR, interval * -1); query.setTimestamp("timestamp", new Timestamp(cal.getTimeInMillis())); query.executeUpdate();//from www .j a v a 2 s . c o m }
From source file:edu.depaul.armada.dao.ContainerLogDaoHibernate.java
License:Open Source License
@Override public void deleteOldData(int interval) { Query query = sessionFactory.getCurrentSession() .createQuery("delete from ContainerLog c where c.timestamp <= :timestamp"); Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR, interval * -1); query.setTimestamp("timestamp", new Timestamp(cal.getTimeInMillis())); query.executeUpdate();//www . j a va 2s .c o m }
From source file:edu.monash.merc.dao.GeneDAO.java
License:Open Source License
/** * {@inheritDoc}/*from w w w.j a va 2 s. c om*/ */ @SuppressWarnings("unchecked") public List<Gene> getGenesByDBSChromVersion(DbAcType dbAcType, ChromType chromType, Date versionTime) { String gQueryBase = "SELECT g FROM Gene g JOIN g.dbSource dbs WHERE dbs.dbName = :dbName AND g.createdTime = :createdTime AND "; List<String> allNamedChroms = ChromType.allNamedChmTypes(); if (chromType.equals(ChromType.CHMOTHER)) { gQueryBase += "g.chromosome NOT IN (:chromosomes)"; } else { gQueryBase += "g.chromosome = :chromosome"; } Query gQuery = this.session().createQuery(gQueryBase); gQuery.setString("dbName", dbAcType.type()); if (chromType.equals(ChromType.CHMOTHER)) { gQuery.setParameterList("chromosomes", allNamedChroms); } else { gQuery.setString("chromosome", chromType.chm()); } gQuery.setTimestamp("createdTime", versionTime); return gQuery.list(); }
From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java
License:Apache License
/** * @see edu.ur.ir.institution.InstitutionalItemDAO#getItems(edu.ur.ir.institution.InstitutionalCollection, java.util.Date, java.util.Date) *///from w w w .j a v a 2 s. co m @SuppressWarnings("unchecked") public List<InstitutionalItem> getItems(final InstitutionalCollection collection, final Date startDate, final Date endDate) { log.debug("Trying dates " + startDate + " and " + endDate); List<InstitutionalItem> foundItems = (List<InstitutionalItem>) hbCrudDAO.getHibernateTemplate() .execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = null; q = session.getNamedQuery("getInstitutionalCollectionItemsByAcceptedDateRange"); q.setLong(0, collection.getId()); q.setTimestamp(1, startDate); q.setTimestamp(2, endDate); return q.list(); } }); return foundItems; }