List of usage examples for org.hibernate.criterion Restrictions ne
public static SimpleExpression ne(String propertyName, Object value)
From source file:dk.teachus.backend.dao.hibernate.HibernatePeriodDAO.java
License:Apache License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)// ww w . ja v a 2 s .c o m public Periods getPeriods(Teacher teacher, boolean onlyFinal) { DetachedCriteria c = DetachedCriteria.forClass(PeriodImpl.class); c.add(Restrictions.eq("teacher", teacher)); c.createCriteria("teacher").add(Restrictions.eq("active", true)); if (onlyFinal) { c.add(Restrictions.eq("status", Status.FINAL)); } else { c.add(Restrictions.ne("status", Status.DELETED)); } c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); List<Period> result = getHibernateTemplate().findByCriteria(c); Periods periods = new PeriodsImpl(); periods.setPeriods(result); return periods; }
From source file:edu.emory.library.tast.dm.Dictionary.java
License:Open Source License
public static List loadAll(Class clazz, Session sess, String orderBy) { boolean sessionProvided = sess != null; Transaction transaction = null;/*from w ww . j a va 2 s.com*/ if (!sessionProvided) { sess = HibernateConn.getSession(); transaction = sess.beginTransaction(); } List rigs = sess.createCriteria(clazz).addOrder(Order.asc(orderBy)).add(Restrictions.ne("name", "hidden")) .list(); if (!sessionProvided) { transaction.commit(); sess.close(); } return rigs; }
From source file:edu.nps.moves.mmowgli.db.ActionPlan.java
License:Open Source License
public static Criteria adjustCriteriaToOmitActionPlansTL(Criteria crit, User me) { Move thisMove = Move.getCurrentMoveTL(); if (me.isAdministrator() || Game.getTL().isShowPriorMovesActionPlans()) ;//from w w w . j a va 2 s. co m else { crit.createAlias("createdInMove", "MOVE").add(Restrictions.eq("MOVE.number", thisMove.getNumber())); } if (!me.isAdministrator()) crit.add(Restrictions.ne("hidden", true)); return crit; }
From source file:edu.nps.moves.mmowgli.db.Card.java
License:Open Source License
public static Criteria adjustCriteriaToOmitCardsTL(Criteria crit, User me) { // 2 conflicting requirements: // 1: if guest and we're in prep phase, don't allow viewing of current moves cards; // 2: if game doesn't allow prior card viewing, don't show old moves cards; // since the combination of the 2 would potentially prohibit viewing all cards, only use one at at time. // since the guest case is the special and most unfrequent one one, check for it first Move thisMove = Move.getCurrentMoveTL(); boolean canSeeCurrent = true; // not used anymore !MovePhase.isGuestAndIsPreparePhaseTL(me); boolean canSeePast = me.isAdministrator() || Game.getTL().isShowPriorMovesCards(); if (!canSeeCurrent && !canSeePast) { crit.add(Restrictions.eq("factCard", true)); // effectively hides everything since we don't do fact cards } else {//from w w w. j a va 2 s.c o m if (!canSeeCurrent) { crit.createAlias("createdInMove", "MOVE").add(Restrictions.ne("MOVE.number", thisMove.getNumber())); } if (!canSeePast) { crit.createAlias("createdInMove", "MOVE").add(Restrictions.eq("MOVE.number", thisMove.getNumber())); } } return crit; }
From source file:edu.nps.moves.mmowgli.export.CardVisualizerBuilder.java
License:Open Source License
@SuppressWarnings("unchecked") public JsonObject buildJsonTree(Move roundToShow) // null if all { cardDays.clear();//from w ww. j ava2s . com rootDays.clear(); HSess.init(); // Scan all cards to get master, ordered list of game days, i.e., days when cards were played ; same for only root cards Criteria crit = HSess.get().createCriteria(Card.class); crit.add(Restrictions.ne("hidden", true)); List<Card> lis = crit.list(); HSess.close(); for (Card cd : lis) { String ds = mangleCardDate(cd); cardDays.add(ds); if (cd.getParentCard() == null) { rootDays.add(ds); } } JsonObjectBuilder treeBuilder = null; JsonArrayBuilder rootArray = null; try { treeBuilder = Json.createObjectBuilder(); treeBuilder.add("type", "Mmowgli Card Tree"); treeBuilder.add("text", "Click on a card to zoom in, center to zoom out."); treeBuilder.add("color", "white"); treeBuilder.add("value", "1"); treeBuilder.add("cardGameDays", createGameDaysArray(cardDays, STRINGDATE)); treeBuilder.add("cardGameDaysLong", createGameDaysArray(cardDays, LONGDATE)); treeBuilder.add("rootGameDays", createGameDaysArray(rootDays, STRINGDATE)); treeBuilder.add("rootGameDaysLong", createGameDaysArray(rootDays, LONGDATE)); rootArray = Json.createArrayBuilder(); HSess.init(); crit = HSess.get().createCriteria(Card.class); crit.add(Restrictions.isNull("parentCard")); // Gets only the top level crit.add(Restrictions.ne("hidden", true)); CardIncludeFilter filter = roundToShow == null ? new AllNonHiddenCards() : new CardsInSingleMove(roundToShow); lis = crit.list(); HSess.close(); for (Card c : lis) { int rootDayIndex = getRootDayIndex(c); addCard(c.getId(), rootArray, filter, rootDayIndex); } } catch (Throwable ex) { System.err.println(ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage()); } treeBuilder.add("children", rootArray); return treeBuilder == null ? null : treeBuilder.build(); }
From source file:edu.nps.moves.mmowgli.export.GameExporter.java
License:Open Source License
@SuppressWarnings("unchecked") private void addSeedCards(Element root, Session sess, Game g) { Element seedCardsElem = createAppend(root, "SeedCards"); //addElementWithText(seedCardsElem,"ScreenShot","seedcardsScreenShot.png"); Criteria criteria = sess.createCriteria(Card.class).setMaxResults(10).add(Restrictions.ne("hidden", true)) .addOrder(Order.asc("id")); List<Card> lis = (List<Card>) criteria.list(); int n = 0;/*from ww w.jav a2s . co m*/ for (Card cd : lis) { String typ = cd.getCardType().getTitle(); typ = typ.replaceAll("\\W", ""); // remove non chars String txt = cd.getText(); addElementWithText(seedCardsElem, typ + "SeedCard" + (n + 1), txt == null ? "" : txt); n++; } }
From source file:es.emergya.bbdd.dao.IncidenciaHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public List<Incidencia> getOpened() { List<Incidencia> res = new LinkedList<Incidencia>(); try {/*from w ww. j av a 2 s.co m*/ Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Incidencia.class).createCriteria("estado") .add(Restrictions.ne("id", 3l)).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); res = (List<Incidencia>) criteria.list(); for (Incidencia i : res) if (i != null) { if (i.getCreador() != null) i.getCreador().getId(); if (i.getEstado() != null) i.getEstado().getId(); if (i.getCategoria() != null) i.getCategoria().getId(); } } catch (Throwable t) { log.error(t, t); } return res; }
From source file:es.emergya.bbdd.dao.IncidenciaHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public List<Incidencia> getByExample(Incidencia f) { try {//from w w w . ja va 2s . c om Session currentSession = getSession(); currentSession.clear(); Criteria criteria = currentSession.createCriteria(Incidencia.class).addOrder(Order.asc("titulo")); // titulo if (f.getTitulo() != null && f.getTitulo().trim().length() > 0) { criteria.add(Restrictions.ilike("titulo", LogicConstants.getGenericString(f.getTitulo()))); } // prioridad if (f.getPrioridad() != null) { criteria.add(Restrictions.eq("prioridad", f.getPrioridad())); } // categoria if (f.getCategoria() != null) { criteria.createAlias("categoria", "cat") .add(Restrictions.eq("cat.identificador", f.getCategoria().getIdentificador())); } // estado if (f.getEstado() != null) { criteria.createAlias("estado", "est") .add(Restrictions.eq("est.identificador", f.getEstado().getIdentificador())); } else { criteria.createAlias("estado", "est").add(Restrictions.ne("est.id", 3l)); } List<Incidencia> res = new LinkedList<Incidencia>(); res = criteria.list(); for (Incidencia i : res) if (i != null) { if (i.getCreador() != null) i.getCreador().getId(); if (i.getEstado() != null) i.getEstado().getId(); if (i.getCategoria() != null) i.getCategoria().getId(); } return res; } catch (Throwable t) { log.error("Error extrayendo las categorias de las incidencias", t); } return new LinkedList<Incidencia>(); }
From source file:es.emergya.bbdd.dao.IncidenciaHome.java
License:Open Source License
/** * Actualiza los estados de las incidencias que NO se encuentren en el array * y cuyo estado no es ya el pasado como parmetro. * // w w w . j a va 2 s .c o m * @param idsIncidencias * Array de ids de incidencias * @param estado * Estado a establecer */ @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class) public void updateEstadosIncidencias(Long[] idsIncidencias, String estado) { if (idsIncidencias != null && idsIncidencias.length > 0) { EstadoIncidencia estadoObj = getEstadoIncidenciaByIdentificador(estado); if (estado != null) { Criteria crit = getSession().createCriteria(Incidencia.class) .add(Restrictions.not(Restrictions.in("id", idsIncidencias))) .add(Restrictions.ne("estado", estadoObj)); List<Incidencia> resultado = crit.list(); for (Incidencia inc : resultado) { if (log.isTraceEnabled()) { log.trace("Actualizamos el estado de la incidencia " + inc.getId() + " a " + estado); } inc.setEstado(estadoObj); getSession().update(inc); } } else { log.error("El estado " + estado + " no se encuentra en la base de datos"); } } }
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED) public Recurso[] getNotAsigned(Patrulla p) { Recurso[] res = new Recurso[0]; try {// ww w . j a v a2 s . co m if (p == null || p.getId() == null) { return getByFilter(filter).toArray(new Recurso[0]); } log.debug("getNotAsigned(" + p.getId() + ")"); Session currentSession = getSession(); currentSession.clear(); Criterion rhs = Restrictions.isNull("patrullas"); Criterion lhs = Restrictions.ne("patrullas", currentSession.load(Patrulla.class, p.getId())); Criteria criteria = currentSession.createCriteria(Recurso.class) .add(Restrictions.eq("habilitado", true)).add(Restrictions.or(lhs, rhs)); criteria = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); res = ((List<Recurso>) criteria.list()).toArray(new Recurso[0]); for (Recurso r : res) try { r.getPatrullas().getId(); } catch (Throwable t) { } } catch (Throwable t) { log.error(t, t); } return res; }