List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.ikon.dao.DatabaseMetadataDAO.java
License:Open Source License
/** * Find by pk// w ww .java 2 s . c o m */ public static DatabaseMetadataValue findValueByPk(String table, long id) throws DatabaseException { log.debug("findValueByPk({}, {})", table, id); String qs = "from DatabaseMetadataValue dmv where dmv.table=:table and dmv.id=:id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setString("table", table); q.setLong("id", id); DatabaseMetadataValue ret = (DatabaseMetadataValue) q.setMaxResults(1).uniqueResult(); log.debug("findValueByPk: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.DatabaseMetadataDAO.java
License:Open Source License
/** * Get next sequence number/* w ww. j ava2 s .c om*/ */ public static long getNextSequenceValue(String table, String column) throws DatabaseException { log.debug("getNextSequenceValue({}, {})", table, column); String qs = "from DatabaseMetadataSequence dms where dms.table=:table and dms.column=:column"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setString("table", table); q.setString("column", column); DatabaseMetadataSequence dms = (DatabaseMetadataSequence) q.setMaxResults(1).uniqueResult(); if (dms != null) { // Update already created sequence dms.setValue(dms.getValue() + 1); session.update(dms); } else { // First sequence use: starts with 1 dms = new DatabaseMetadataSequence(); dms.setTable(table); dms.setColumn(column); dms.setValue(1); session.save(dms); } HibernateUtil.commit(tx); log.debug("getNextSequenceValue: {}", dms.getValue()); return dms.getValue(); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.extension.DropboxDAO.java
License:Open Source License
/** * Find by pk//from w ww. j a v a2 s . c o m */ public DropboxToken findByPk(String usrId) throws DatabaseException { log.debug("findByPk({})", usrId); String qs = "from DropboxToken dbt where dbt.user=:user"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setString("user", usrId); DropboxToken ret = (DropboxToken) q.setMaxResults(1).uniqueResult(); HibernateUtil.commit(tx); log.debug("findByPk: {}", ret); return ret; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.LanguageDAO.java
License:Open Source License
/** * Update language in database/*from w w w. j ava 2s.c om*/ */ public static void update(Language lang) throws DatabaseException { log.debug("update({})", lang); String qs = "select lg.imageContent, lg.imageMime from Language lg where lg.id=:id"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); if (lang.getImageContent() == null || lang.getImageContent().length() == 0) { Query q = session.createQuery(qs); q.setParameter("id", lang.getId()); Object[] data = (Object[]) q.setMaxResults(1).uniqueResult(); lang.setImageContent((String) data[0]); lang.setImageMime((String) data[1]); } session.update(lang); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("update: void"); }
From source file:com.ikon.dao.LanguageDAO.java
License:Open Source License
/** * Get translation/*from w ww . ja v a 2 s . c o m*/ */ public static String getTranslation(String lang, String module, String key) throws DatabaseException { log.debug("getTranslation({}, {}, {})", new Object[] { module, lang, key }); String qs = "select tr.text from Translation tr where tr.translationId.key=:key " + "and tr.translationId.language=:lang and tr.translationId.module=:module"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setString("key", key); q.setString("module", module); q.setString("lang", lang); String ret = (String) q.setMaxResults(1).uniqueResult(); log.debug("getTranslation: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.MailAccountDAO.java
License:Open Source License
/** * Update// w ww . j ava2 s . co m */ public static void update(MailAccount ma) throws DatabaseException { log.debug("update({})", ma); String qs = "select ma.mailPassword from MailAccount ma where ma.id=:id"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setParameter("id", ma.getId()); String pass = (String) q.setMaxResults(1).uniqueResult(); ma.setMailPassword(pass); session.update(ma); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("update: void"); }
From source file:com.ikon.dao.MailAccountDAO.java
License:Open Source License
/** * Find by pk/*from ww w .j a va 2 s. c o m*/ */ public static MailAccount findByPk(long maId) throws DatabaseException { log.debug("findByPk({})", maId); String qs = "from MailAccount ma where ma.id=:id"; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); Query q = session.createQuery(qs); q.setLong("id", maId); MailAccount ret = (MailAccount) q.setMaxResults(1).uniqueResult(); log.debug("findByPk: {}", ret); return ret; } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.MimeTypeDAO.java
License:Open Source License
/** * Update//from w w w . ja v a 2 s . co m */ public static void update(MimeType mt) throws DatabaseException { log.debug("update({})", mt); String qs = "select mt.imageContent, mt.imageMime from MimeType mt where mt.id=:id"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); if (mt.getImageContent() == null || mt.getImageContent().length() == 0) { Query q = session.createQuery(qs); q.setParameter("id", mt.getId()); Object[] data = (Object[]) q.setMaxResults(1).uniqueResult(); mt.setImageContent((String) data[0]); mt.setImageMime((String) data[1]); } session.update(mt); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("update: void"); }
From source file:com.ikon.dao.MimeTypeDAO.java
License:Open Source License
/** * Find by name/*from w w w . j a v a 2 s . c o m*/ */ public static MimeType findByName(String name) throws DatabaseException { log.debug("findByName({})", name); String qs = "from MimeType mt where mt.name=:name"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qs); q.setString("name", name); MimeType ret = (MimeType) q.setMaxResults(1).uniqueResult(); HibernateUtil.commit(tx); log.debug("findByName: {}", ret); return ret; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }
From source file:com.ikon.dao.NodeBaseDAO.java
License:Open Source License
/** * Get node UUID from path. This is the old one which calculates the uuid. *//* ww w . j a va 2 s . c om*/ private String calculateUuidFromPath(Session session, String path) throws PathNotFoundException, HibernateException { log.debug("calculateUuidFromPath({}, {})", session, path); String qs = "select nb.uuid from NodeBase nb where nb.parent=:parent and nb.name=:name"; Query q = session.createQuery(qs); String uuid = Config.ROOT_NODE_UUID; String name = ""; for (StringTokenizer st = new StringTokenizer(path, "/"); st.hasMoreTokens();) { name = st.nextToken(); q.setString("name", name); q.setString("parent", uuid); uuid = (String) q.setMaxResults(1).uniqueResult(); if (uuid == null) { throw new PathNotFoundException(path); } } log.debug("calculateUuidFromPath: {}", uuid); return uuid; }