List of usage examples for org.hibernate Query setCalendar
@Deprecated @SuppressWarnings("unchecked") default Query<R> setCalendar(String name, Calendar value)
From source file:com.cloud.bridge.util.QueryHelper.java
License:Open Source License
public static void bindParameters(Query query, Object[] params) { int pos = 0;/* www . j av a2 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:com.ikon.dao.ActivityDAO.java
License:Open Source License
/** * Find by filter//from www . j ava 2 s. c om */ @SuppressWarnings("unchecked") public static List<Activity> findByFilter(ActivityFilter filter) throws DatabaseException { log.debug("findByFilter({})", filter); String qs = "from Activity a where a.date between :begin and :end "; if (filter.getUser() != null && !filter.getUser().equals("")) qs += "and a.user=:user "; if (filter.getAction() != null && !filter.getAction().equals("")) qs += "and a.action=:action "; if (filter.getItem() != null && !filter.getItem().equals("")) { qs += "and a.item=:item "; } qs += "order by a.date"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setCalendar("begin", filter.getBegin()); q.setCalendar("end", filter.getEnd()); if (filter.getUser() != null && !filter.getUser().equals("")) q.setString("user", filter.getUser()); if (filter.getAction() != null && !filter.getAction().equals("")) q.setString("action", filter.getAction()); if (filter.getItem() != null && !filter.getItem().equals("")) q.setString("item", filter.getItem()); List<Activity> ret = q.list(); log.debug("findByFilter: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.DashboardDAO.java
License:Open Source License
/** * Create dashboard stats/*ww w . j a v a 2s .c o m*/ */ public static void createIfNew(Dashboard db) throws DatabaseException { String qs = "from Dashboard db where db.user=:user and db.source=:source " + "and db.node=:node and db.date=:date"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setString("user", db.getUser()); q.setString("source", db.getSource()); q.setString("node", db.getNode()); q.setCalendar("date", db.getDate()); if (q.list().isEmpty()) { session.save(db); } HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.DashboardDAO.java
License:Open Source License
/** * Delete old visited node//from w ww .j a va 2 s . c o m */ public static void purgeOldVisitedNode(String user, String source, String node, Calendar date) throws DatabaseException { log.debug("purgeOldVisitedNode({}, {}, {}, {})", new Object[] { user, source, node, date }); String qs = "delete from Dashboard db where db.user=:user and db.source=:source " + "and db.node=:node and db.date=:date"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setString("user", user); q.setString("source", source); q.setString("node", node); q.setCalendar("date", date); q.executeUpdate(); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("purgeOldVisitedNode: void"); }
From source file:com.ikon.module.db.DbDashboardModule.java
License:Open Source License
/** * Get top documents/*from ww w . j av a2 s. c o m*/ */ @SuppressWarnings("unchecked") private ArrayList<DashboardDocumentResult> getTopDocuments(String user, String source, String qs, Calendar date) throws RepositoryException, DatabaseException { log.debug("getTopDocuments({}, {}, {}, {})", new Object[] { user, source, qs, (date != null ? date.getTime() : "null") }); ArrayList<DashboardDocumentResult> al = new ArrayList<DashboardDocumentResult>(); Session session = null; int cont = 0; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs).setFetchSize(MAX_RESULTS); if (date != null) { q.setCalendar("date", date); } // While there is more query results and the MAX_RESULT limit has reached for (Iterator<Object[]> it = q.iterate(); it.hasNext() && cont < MAX_RESULTS; cont++) { Object[] obj = it.next(); String resItem = (String) obj[0]; Calendar resDate = (Calendar) obj[1]; try { NodeDocument nDoc = NodeDocumentDAO.getInstance().findByPk(resItem); // String docPath = NodeBaseDAO.getInstance().getPathFromUuid(nDoc.getUuid()); // Only documents from taxonomy // Already filtered in the query // if (docPath.startsWith("/openkm:root")) { Document doc = BaseDocumentModule.getProperties(user, nDoc); DashboardDocumentResult vo = new DashboardDocumentResult(); vo.setDocument(doc); vo.setDate(resDate); vo.setVisited(false); al.add(vo); // } } catch (PathNotFoundException e) { // Do nothing } } } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("getTopDocuments: {}", al); return al; }
From source file:com.openkm.dao.DashboardActivityDAO.java
License:Open Source License
/** * Purge one month old activity/*from www . jav a 2 s . co m*/ */ public static synchronized void purge() throws DatabaseException { log.debug("purge()"); String qs = "delete DashboardActivity da where da.date < :date"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); Calendar cal = Calendar.getInstance(); cal.add(Calendar.MONTH, -1); q.setCalendar("date", cal); q.executeUpdate(); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("purge: void"); }
From source file:com.openkm.extension.dao.MessageDAO.java
License:Open Source License
/** * Mark message as seen/* w ww.j a v a 2s. com*/ */ public static void markSeen(long msgId) throws DatabaseException { log.debug("markSeen({})", msgId); String qs = "update MessageReceived msg set msg.seenDate=:seenDate where msg.id=:id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setLong("id", msgId); q.setCalendar("seenDate", Calendar.getInstance()); q.executeUpdate(); log.debug("markSeen: void"); } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.extension.dao.ProposedQueryDAO.java
License:Open Source License
/** * Mark proposed as seen/* ww w.j a v a 2 s.com*/ */ public static void markSeen(long pqId) throws DatabaseException { log.debug("markSeen({})", pqId); String qs = "update ProposedQueryReceived pq set pq.seenDate=:seenDate where pq.id=:id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setLong("id", pqId); q.setCalendar("seenDate", Calendar.getInstance()); q.executeUpdate(); log.debug("markSeen: void"); } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.extension.dao.ProposedSubscriptionDAO.java
License:Open Source License
/** * Mark proposed as seen//from w w w.j a va 2 s . co m */ public static void markSeen(int psId) throws DatabaseException { log.debug("markSeen({})", psId); String qs = "update ProposedSubscriptionReceived ps set ps.seenDate=:seenDate where ps.id=:id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setInteger("id", psId); q.setCalendar("seenDate", Calendar.getInstance()); q.executeUpdate(); log.debug("markSeen: void"); } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.openkm.module.db.DbDashboardModule.java
License:Open Source License
/** * Get top documents/*from ww w. j av a 2 s . c om*/ */ @SuppressWarnings("unchecked") private ArrayList<DashboardDocumentResult> getTopDocuments(String user, String source, String qs, Calendar date) throws RepositoryException, DatabaseException { log.debug("getTopDocuments({}, {}, {}, {})", new Object[] { user, source, qs, (date != null ? date.getTime() : "null") }); ArrayList<DashboardDocumentResult> al = new ArrayList<DashboardDocumentResult>(); Cache docResultCache = CacheProvider.getInstance().getCache(CACHE_DASHBOARD_TOP_DOCUMENTS); String key = source + ":" + Config.SYSTEM_USER; Element elto = docResultCache.get(key); if (elto != null) { log.debug("Get '{}' from cache", source); al = (ArrayList<DashboardDocumentResult>) elto.getValue(); } else { log.debug("Get '{}' from database", source); Session session = null; int cont = 0; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs).setFetchSize(MAX_RESULTS); if (date != null) { q.setCalendar("date", date); } // While there is more query results and the MAX_RESULT limit has reached for (Iterator<Object[]> it = q.iterate(); it.hasNext() && cont < MAX_RESULTS; cont++) { Object[] obj = it.next(); String resItem = (String) obj[0]; Calendar resDate = (Calendar) obj[1]; try { NodeDocument nDoc = NodeDocumentDAO.getInstance().findByPk(resItem); // String docPath = NodeBaseDAO.getInstance().getPathFromUuid(nDoc.getUuid()); // Only documents from taxonomy // Already filtered in the query // if (docPath.startsWith("/okm:root")) { Document doc = BaseDocumentModule.getProperties(user, nDoc); DashboardDocumentResult vo = new DashboardDocumentResult(); vo.setDocument(doc); vo.setDate(resDate); vo.setVisited(false); al.add(vo); // } } catch (PathNotFoundException e) { // Do nothing } } docResultCache.put(new Element(key, al)); } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } } log.debug("getTopDocuments: {}", al); return al; }