Java Code Examples for org.hibernate.Query#setCalendar()

The following examples show how to use org.hibernate.Query#setCalendar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProposedSubscriptionDAO.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Mark proposed as seen
 */
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);
	}
}
 
Example 2
Source File: MessageDAO.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Mark message as seen
 */
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);
	}
}
 
Example 3
Source File: ProposedQueryDAO.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Mark proposed as seen
 */
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);
	}
}
 
Example 4
Source File: DashboardActivityDAO.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Purge one month old activity
 */
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");
}
 
Example 5
Source File: DashboardDAO.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create dashboard stats
 */
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);
	}
}
 
Example 6
Source File: DashboardDAO.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Delete old visited node
 */
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");
}
 
Example 7
Source File: ActivityDAO.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find by filter
 */
@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);
	}
}