List of usage examples for org.hibernate.criterion Projections property
public static PropertyProjection property(String propertyName)
From source file:com.klistret.cmdb.dao.RelationDAOImpl.java
License:Open Source License
/** * Finds relations based on XPath expressions * // www.j av a 2 s. c om */ public List<Relation> find(List<String> expressions, int start, int limit) { try { logger.debug("Finding relations by expression from start position [{}] with limit [{}]", start, limit); if (expressions == null) throw new ApplicationException("Expressions parameter is null", new IllegalArgumentException()); Criteria criteria = new XPathCriteria(expressions, getSession()).getCriteria(); String alias = criteria.getAlias(); criteria.setProjection(Projections.projectionList().add(Projections.property(alias + ".id")) .add(Projections.property(alias + ".type")).add(Projections.property(alias + ".source")) .add(Projections.property(alias + ".destination")) .add(Projections.property(alias + ".fromTimeStamp")) .add(Projections.property(alias + ".toTimeStamp")) .add(Projections.property(alias + ".createId")) .add(Projections.property(alias + ".createTimeStamp")) .add(Projections.property(alias + ".updateTimeStamp")) .add(Projections.property(alias + ".version")) .add(Projections.property(alias + ".configuration"))); criteria.setFirstResult(start); criteria.setMaxResults(limit); criteria.setFetchSize(limit); Object[] results = criteria.list().toArray(); List<Relation> relations = new ArrayList<Relation>(results.length); logger.debug("Results length [{}]", results.length); for (int index = 0; index < results.length; index++) { Object[] row = (Object[]) results[index]; Relation relation = new Relation(); relation.setId((Long) row[0]); relation.setType((RelationType) row[1]); relation.setSource((Element) row[2]); relation.setDestination((Element) row[3]); relation.setFromTimeStamp((Date) row[4]); relation.setToTimeStamp((Date) row[5]); relation.setCreateId((String) row[6]); relation.setCreateTimeStamp((Date) row[7]); relation.setUpdateTimeStamp((Date) row[8]); relation.setVersion((Long) row[9]); relation.setConfiguration((com.klistret.cmdb.ci.commons.Relation) row[10]); relations.add(relation); } results = null; return relations; } catch (StaleStateException e) { throw new ApplicationException( "Relation(s) found are stale which means newer version exists (Hibernate)."); } catch (HibernateException e) { throw new InfrastructureException(e.getMessage(), e); } }
From source file:com.kodemore.hibernate.criteria.KmCriteria.java
License:Open Source License
public void select(String name) { Projection e; e = Projections.property(getFullName(name)); addProjection(e); }
From source file:com.kodemore.hibernate.criteria.KmCriteria.java
License:Open Source License
public void selectDistinct(String name) { Projection e; e = Projections.property(getFullName(name)); e = Projections.distinct(e); addProjection(e); }
From source file:com.koylubaevnt.library.db.DataHelper.java
private DataHelper() { sessionFactory = HibernateUtil.getSessionFactory(); bookProjectionList = Projections.projectionList(); bookProjectionList.add(Projections.property("id"), "id"); bookProjectionList.add(Projections.property("name"), "name"); bookProjectionList.add(Projections.property("image"), "image"); bookProjectionList.add(Projections.property("genre"), "genre"); bookProjectionList.add(Projections.property("pageCount"), "pageCount"); bookProjectionList.add(Projections.property("isbn"), "isbn"); bookProjectionList.add(Projections.property("publisher"), "publisher"); bookProjectionList.add(Projections.property("author"), "author"); bookProjectionList.add(Projections.property("publishYear"), "publishYear"); bookProjectionList.add(Projections.property("descr"), "descr"); prepareCriterias();//w w w . jav a 2 s.com runCountCriteria(); }
From source file:com.library.Database.DataHelper.java
private Criteria getCriteriaWithProjection() { return getSession().createCriteria(Book.class).setProjection(Projections.projectionList() .add(Projections.property("id"), "id").add(Projections.property("isbn"), "isbn") .add(Projections.property("name"), "name").add(Projections.property("author"), "author") .add(Projections.property("genre"), "genre").add(Projections.property("publisher"), "publisher") .add(Projections.property("descr"), "descr").add(Projections.property("publishYear"), "publishYear") .add(Projections.property("pageCount"), "pageCount")).addOrder(Order.asc("name")); }
From source file:com.library.Database.DataHelper.java
public List<Book> getAllBooks(int firstNote, int notesNumber) { getSession().beginTransaction();//from w ww . j a v a 2 s . com totalBooksNumber = getSession().createCriteria(Book.class).setProjection(Projections.property("id")).list() .size(); List<Book> books = getCriteriaWithProjection().setFirstResult(firstNote).setMaxResults(notesNumber) .setResultTransformer(Transformers.aliasToBean(Book.class)).list(); getSession().getTransaction().commit(); return books; }
From source file:com.library.Database.DataHelper.java
public List<Book> getBooksByGenre(Long genreId, int firstNote, int notesNumber) { getSession().beginTransaction();/*from w w w . j a v a 2 s. c o m*/ totalBooksNumber = getSession().createCriteria(Book.class).add(Restrictions.eq("genre.id", genreId)) .setProjection(Projections.property("id")).list().size(); List<Book> books = getCriteriaWithProjection().add(Restrictions.eq("genre.id", genreId)) .setFirstResult(firstNote).setMaxResults(notesNumber) .setResultTransformer(Transformers.aliasToBean(Book.class)).list(); getSession().getTransaction().commit(); return books; }
From source file:com.library.Database.DataHelper.java
public List<Book> getBookByAuthor(String authorName, int firstNote, int notesNumber) { getSession().beginTransaction();//from www.j a v a2 s . com totalBooksNumber = getSession().createCriteria(Book.class).setProjection(Projections.property("id")) .createCriteria("author").add(Restrictions.ilike("fio", authorName, MatchMode.ANYWHERE)).list() .size(); List<Book> books = getCriteriaWithProjection().createCriteria("author") .add(Restrictions.ilike("fio", authorName, MatchMode.ANYWHERE)).setFirstResult(firstNote) .setMaxResults(notesNumber).setResultTransformer(Transformers.aliasToBean(Book.class)).list(); getSession().getTransaction().commit(); return books; }
From source file:com.library.Database.DataHelper.java
private Object getFieldValue(String field, Long id) { getSession().beginTransaction();/*w ww. j a v a2s . co m*/ Object bloob = getSession().createCriteria(Book.class).setProjection(Projections.property(field)) .add(Restrictions.eq("id", id)).uniqueResult(); getSession().getTransaction().commit(); return bloob; }
From source file:com.library.Database.DataHelper.java
private List<Book> getBookList(String field, String value, MatchMode matchMode, int firstNote, int notesNumber) { getSession().beginTransaction();/*from ww w . j av a 2 s .c o m*/ totalBooksNumber = getSession().createCriteria(Book.class).setProjection(Projections.property("id")) .add(Restrictions.ilike(field, value, matchMode)).list().size(); List<Book> books = getCriteriaWithProjection().add(Restrictions.ilike(field, value, matchMode)) .setFirstResult(firstNote).setMaxResults(notesNumber) .setResultTransformer(Transformers.aliasToBean(Book.class)).list(); getSession().getTransaction().commit(); return books; }