List of usage examples for org.hibernate Query setResultTransformer
@Deprecated Query<R> setResultTransformer(ResultTransformer transformer);
From source file:org.fourthline.konto.server.dao.EntryDAO.java
License:Open Source License
public Entry populateSplits(final Entry entry) { StringBuilder sb = new StringBuilder(); sb.append("select s, sa, eaUnit, saUnit from Entry e, Split s, "); sb.append("Account ea, MonetaryUnit eaUnit, Account sa, MonetaryUnit saUnit"); sb.append(" where s.entryId = :entryId"); sb.append(" and e.id = s.entryId"); sb.append(" and ea.id = e.accountId and sa.id = s.accountId"); sb.append(" and ea.monetaryUnitId = eaUnit.id and sa.monetaryUnitId = saUnit.id"); Query q = getCurrentSession().createQuery(sb.toString()); q.setLong("entryId", entry.getId()); q.setResultTransformer(new ResultTransformer() { @Override/*from w w w. j av a 2 s . c om*/ public Object transformTuple(Object[] objects, String[] strings) { Split split = (Split) objects[0]; split.setAccount((Account) objects[1]); split.setEntryMonetaryUnit((MonetaryUnit) objects[2]); split.setMonetaryUnit((MonetaryUnit) objects[3]); split.setEntry(entry); return split; } @Override public List transformList(List list) { return list; } }); entry.setSplits(q.list()); return entry; }
From source file:org.fourthline.konto.server.dao.EntryDAO.java
License:Open Source License
public Split getSplit(Long id) { StringBuilder sb = new StringBuilder(); sb.append("select s, sa, eaUnit, saUnit from Entry e, Split s, "); sb.append("Account ea, MonetaryUnit eaUnit, Account sa, MonetaryUnit saUnit"); sb.append(" where e.id = s.entryId"); sb.append(" and ea.id = e.accountId and sa.id = s.accountId"); sb.append(" and ea.monetaryUnitId = eaUnit.id and sa.monetaryUnitId = saUnit.id"); sb.append(" and s.id = :id"); Query q = getCurrentSession().createQuery(sb.toString()); q.setLong("id", id); q.setResultTransformer(new ResultTransformer() { @Override// w w w.j av a 2 s . co m public Object transformTuple(Object[] objects, String[] strings) { Split split = (Split) objects[0]; split.setAccount((Account) objects[1]); split.setEntryMonetaryUnit((MonetaryUnit) objects[2]); split.setMonetaryUnit((MonetaryUnit) objects[3]); return split; } @Override public List transformList(List list) { return list; } }); return (Split) q.uniqueResult(); }
From source file:org.fourthline.konto.server.dao.EntryDAO.java
License:Open Source License
public List<Entry> getEntries(final Account account, EntriesQueryCriteria criteria) { StringBuilder sb = new StringBuilder(); sb.append("select e, s, ea, sa, eaUnit, saUnit from Entry e, Split s, "); sb.append("Account ea, MonetaryUnit eaUnit, Account sa, MonetaryUnit saUnit"); sb.append(" where e.id = s.entryId"); sb.append(" and ea.id = e.accountId and sa.id = s.accountId"); sb.append(" and ea.monetaryUnitId = eaUnit.id and sa.monetaryUnitId = saUnit.id"); sb.append(" and (e.accountId = :accountId or s.accountId = :accountId)"); if (!criteria.isStringFilterEmpty()) sb.append(" and (lower(e.description) like :desc or lower(s.description) like :desc)"); if (criteria.getEffectiveOn() != null && criteria.getEffectiveOn().getStart() != null) sb.append(" and e.effectiveOn >= :effectiveOnStart"); if (criteria.getEffectiveOn() != null && criteria.getEffectiveOn().getEnd() != null) sb.append(" and e.effectiveOn <= :effectiveOnEnd"); sb.append(" order by "); if (criteria.getOrderBy() == null) { sb.append("e.effectiveOn desc"); } else if (criteria.getOrderBy().equals(Entry.Property.description)) { sb.append("e.description ").append(criteria.isSortAscending() ? "asc" : "desc"); sb.append(", s.description ").append(criteria.isSortAscending() ? "asc" : "desc"); } else if (criteria.getOrderBy().equals(Entry.Property.enteredOn)) { sb.append("e.enteredOn ").append(criteria.isSortAscending() ? "asc" : "desc"); } else {/*from w ww . j ava2 s.com*/ sb.append("e.effectiveOn ").append(criteria.isSortAscending() ? "asc" : "desc"); } sb.append(", e.enteredOn desc, s.enteredOn desc"); Query q = getCurrentSession().createQuery(sb.toString()); q.setLong("accountId", account.getId()); if (!criteria.isStringFilterEmpty()) q.setString("desc", criteria.getStringFilterWildcards()); if (criteria.getEffectiveOn() != null && criteria.getEffectiveOn().getStart() != null) q.setDate("effectiveOnStart", criteria.getEffectiveOn().getStart()); if (criteria.getEffectiveOn() != null && criteria.getEffectiveOn().getEnd() != null) q.setDate("effectiveOnEnd", criteria.getEffectiveOn().getEnd()); // TODO: Pagination? final Map<Long, Entry> entries = new LinkedHashMap(); q.setResultTransformer(new ResultTransformer() { @Override public Object transformTuple(Object[] objects, String[] strings) { Entry entry = (Entry) objects[0]; Split split = (Split) objects[1]; entry.setAccount((Account) objects[2]); split.setAccount((Account) objects[3]); split.setEntryMonetaryUnit((MonetaryUnit) objects[4]); split.setMonetaryUnit((MonetaryUnit) objects[5]); Entry existingEntry = entries.get(entry.getId()); if (existingEntry != null) { split.setEntry(existingEntry); existingEntry.getSplits().add(split); } else { // Clear the splits, this entry might have passed through // this transformer before (querying several times with the same PC) entry.getSplits().clear(); entry.getSplits().add(split); split.setEntry(entry); entries.put(entry.getId(), entry); } return null; } @Override public List transformList(List list) { return list; } }); q.list(); return new ArrayList(entries.values()); }
From source file:org.geomajas.plugin.deskmanager.service.common.GeodeskServiceImpl.java
License:Open Source License
public boolean geodeskExists(String publicId) { Query q = factory.getCurrentSession() .createQuery("select id from Geodesk l WHERE l.geodeskId = :id AND " + "l.deleted = false"); q.setParameter("id", publicId); q.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); Object result = q.uniqueResult(); return (result != null); }
From source file:org.geomajas.plugin.deskmanager.service.common.GeodeskServiceImpl.java
License:Open Source License
public boolean geodeskIdExists(String publicId) { Query q = factory.getCurrentSession().createQuery("select id from Geodesk l WHERE l.geodeskId = :id"); q.setParameter("id", publicId); q.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); Object result = q.uniqueResult(); return (result != null); }
From source file:org.geomajas.plugin.deskmanager.service.common.GeodeskServiceImpl.java
License:Open Source License
/** * Will throw a securityException if no accessrights, or not active. *//*www . ja v a2 s . c om*/ public Geodesk getGeodeskByPublicId(String id) throws GeomajasSecurityException { if (geodeskExists(id)) { if (((DeskmanagerSecurityContext) securityContext).isGeodeskUseAllowed(id)) { Query q = factory.getCurrentSession().createQuery("FROM Geodesk l WHERE l.geodeskId = :id AND " + "l.deleted = false AND " + "l.active = true AND l.blueprint.geodesksActive = true"); q.setParameter("id", id); q.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); Geodesk l = (Geodesk) q.uniqueResult(); if (l == null) { throw new GeomajasSecurityException(GdmLayout.EXCEPTIONCODE_GEODESKINACTIVE); } return l; } else { // FIXME: i18n throw new GeomajasSecurityException(ExceptionCode.COMMAND_ACCESS_DENIED, "Geodesk openen", securityContext.getUserName()); } } else { throw new GeomajasSecurityException(ExceptionCode.APPLICATION_NOT_FOUND, id); } }
From source file:org.geomajas.plugin.deskmanager.service.common.GeodeskServiceImpl.java
License:Open Source License
public Geodesk getGeodeskByPublicIdInternal(String id) { if (geodeskExists(id)) { Query q = factory.getCurrentSession().createQuery("FROM Geodesk l WHERE l.geodeskId = :id AND " + "l.deleted = false AND " + "l.active = true AND " + "l.blueprint.geodesksActive = true"); q.setParameter("id", id); q.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); return (Geodesk) q.uniqueResult(); } else {//from w w w . j a va2 s. c om return null; } }
From source file:org.geomajas.plugin.deskmanager.service.common.GeodeskServiceImpl.java
License:Open Source License
public String getGeodeskNameByPublicId(String id) throws GeomajasSecurityException { Query q = factory.getCurrentSession().createQuery("SELECT name FROM Geodesk l WHERE l.geodeskId = :id"); q.setParameter("id", id); q.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); String name = (String) q.uniqueResult(); return (name == null ? "??" : name); }
From source file:org.geomajas.plugin.deskmanager.service.common.GeodeskServiceImpl.java
License:Open Source License
/** * group can be null, in which case the geodesk will need to be public. *///from w w w . j a va 2 s. c o m public boolean isGeodeskUseAllowed(String id, Role role, Territory territory) { Query q; Geodesk desk = getGeodeskByPublicIdInternal(id); if (desk == null) { return false; } switch (role) { case ADMINISTRATOR: return true; case DESK_MANAGER: // Allow desk usage for the deskmanager return desk.getOwner().equals(territory); case CONSULTING_USER: case EDITING_USER: q = factory.getCurrentSession() .createQuery("select l.id from Geodesk l join l.groups as t with t.code like :code WHERE" + " l.geodeskId = :id AND l.deleted = false"); q.setParameter("code", territory.getCode()); break; case GUEST: q = factory.getCurrentSession().createQuery("select id from Geodesk l WHERE l.geodeskId = :id AND " + "l.publicc = true AND " + "l.deleted = false"); break; default: return false; } q.setParameter("id", id); q.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); Object result = q.uniqueResult(); return (result != null); }
From source file:org.inbio.neoportal.core.dao.impl.GeoLayerDAOImpl.java
License:Open Source License
@Override public List<GeoLayerCDTO> getGeoLayerByName(final String name) { Session session = getSessionFactory().getCurrentSession(); Query query = session.createQuery("from GeoLayer as gl" + " where gl.name = :name"); query.setParameter("name", name); //query.setResultTransformer(new GeoLayerTransformer()); query.setResultTransformer(new GeoLayerTransformer()); return query.list(); }