List of usage examples for org.hibernate.criterion Restrictions isNotNull
public static Criterion isNotNull(String propertyName)
From source file:com.yahoo.elide.datastores.hibernate3.filter.CriterionFilterOperation.java
License:Apache License
@Override public Criterion apply(FilterPredicate filterPredicate) { List<FilterPredicate.PathElement> path = filterPredicate.getPath(); /* If the predicate refers to a nested association, the restriction should be 'alias.fieldName' */ String alias;/* w w w . ja v a 2s .c om*/ if (path.size() > 1) { alias = getAlias(path); alias = alias + "." + path.get(path.size() - 1).getFieldName(); /* If the predicate refers to the root entity, the restriction should be 'fieldName' */ } else { alias = path.get(0).getFieldName(); } switch (filterPredicate.getOperator()) { case IN: if (filterPredicate.getValues().isEmpty()) { return Restrictions.sqlRestriction("(false)"); } return Restrictions.in(alias, filterPredicate.getValues()); case NOT: if (filterPredicate.getValues().isEmpty()) { return Restrictions.sqlRestriction("(true)"); } return Restrictions.not(Restrictions.in(alias, filterPredicate.getValues())); case PREFIX: return Restrictions.like(alias, filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case PREFIX_CASE_INSENSITIVE: return Restrictions.ilike(alias, filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case POSTFIX: return Restrictions.like(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)); case POSTFIX_CASE_INSENSITIVE: return Restrictions.ilike(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)); case INFIX: return Restrictions.like(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case INFIX_CASE_INSENSITIVE: return Restrictions.ilike(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case ISNULL: return Restrictions.isNull(alias); case NOTNULL: return Restrictions.isNotNull(alias); case LT: return Restrictions.lt(alias, filterPredicate.getValues().get(0)); case LE: return Restrictions.le(alias, filterPredicate.getValues().get(0)); case GT: return Restrictions.gt(alias, filterPredicate.getValues().get(0)); case GE: return Restrictions.ge(alias, filterPredicate.getValues().get(0)); case TRUE: return Restrictions.sqlRestriction("(true)"); case FALSE: return Restrictions.sqlRestriction("(false)"); default: throw new InvalidPredicateException("Operator not implemented: " + filterPredicate.getOperator()); } }
From source file:com.zutubi.pulse.master.model.persistence.hibernate.HibernateBuildResultDao.java
License:Apache License
public BuildResult findPreviousBuildResultWithRevision(final BuildResult result, final ResultState[] states) { return getHibernateTemplate().execute(new HibernateCallback<BuildResult>() { public BuildResult doInHibernate(Session session) throws HibernateException { Criteria criteria = getBuildResultCriteria(session, result.getProject(), states, false); criteria.add(Restrictions.lt("number", result.getNumber())); criteria.add(Restrictions.eq("userRevision", false)); criteria.add(Restrictions.isNotNull("revisionString")); criteria.setMaxResults(1);//from w ww . j a v a2s .c o m criteria.addOrder(Order.desc("number")); return (BuildResult) criteria.uniqueResult(); } }); }
From source file:com.zutubi.pulse.master.model.persistence.hibernate.HibernateBuildResultExpressions.java
License:Apache License
public static Criterion isPersonalBuild(boolean b) { return (b) ? Restrictions.isNotNull("user") : Restrictions.isNull("user"); }
From source file:Compras.reportePedidos.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: h = new Herramientas(usr, 0); h.session(sessionPrograma);//from ww w . j av a 2 s.com if (t_datos.getRowCount() > 0) { Session session = HibernateUtil.getSessionFactory().openSession(); javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" })); String ruta = null; if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { try { DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); session.beginTransaction().begin(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); PDF reporte = new PDF(); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); reporte.Abrir2(PageSize.LETTER.rotate(), "Reporte", ruta + ".pdf"); Font font = new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL); BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; float[] tam_pdf = new float[] { 15, 40, 130, 20, 15, 30, 20, 15 }; PdfPTable tabla = reporte.crearTabla(tam_pdf.length, tam_pdf, 100, Element.ALIGN_LEFT); cabeceraReporte(reporte, bf, tabla); Object no[]; int ren[]; if (t_datos.getSelectedRows().length > 0) { no = new Object[t_datos.getSelectedRows().length]; ren = t_datos.getSelectedRows(); for (int x = 0; x < t_datos.getSelectedRows().length; x++) { no[x] = (int) t_datos.getValueAt(ren[x], 0); } } else { no = new Object[t_datos.getRowCount()]; //ren =new int[t_datos.getRowCount()]; for (int x = 0; x < t_datos.getRowCount(); x++) { no[x] = (int) t_datos.getValueAt(x, 0); } } Pedido[] pedidos; if (autorizado.isSelected() == true) { pedidos = (Pedido[]) session.createCriteria(Pedido.class) .add(Restrictions.and( Restrictions.and(Restrictions.isNotNull("usuarioByAutorizo"), Restrictions.isNotNull("usuarioByAutorizo2")), Restrictions.in("idPedido", no))) .list().toArray(new Pedido[0]); } else { pedidos = (Pedido[]) session.createCriteria(Pedido.class) .add(Restrictions.in("idPedido", no)).list().toArray(new Pedido[0]); } if (pedidos.length > 0) { ArrayList ordena = new ArrayList(); for (int a = 0; a < pedidos.length; a++) { Pedido aux = pedidos[a]; if (aux.getTipoPedido().compareTo("Interno") == 0) { Partida[] par = (Partida[]) aux.getPartidas().toArray(new Partida[0]); for (int b = 0; b < par.length; b++) { Partida ren1 = par[b]; Renglon nuevo; if (ren1.getEjemplar() != null) nuevo = new Renglon("" + aux.getIdPedido(), ren1.getEjemplar().getIdParte(), ren1.getCatalogo().getNombre(), ren1.getCantPcp(), ren1.getMed(), ren1.getPcp(), "" + ren1.getOrdenByIdOrden().getIdOrden(), "" + ren1.getIdEvaluacion() + "-" + ren1.getSubPartida()); else nuevo = new Renglon("" + aux.getIdPedido(), "", ren1.getCatalogo().getNombre(), ren1.getCantPcp(), ren1.getMed(), ren1.getPcp(), "" + ren1.getOrdenByIdOrden().getIdOrden(), "" + ren1.getIdEvaluacion() + "-" + ren1.getSubPartida()); ordena.add(nuevo); } } if (aux.getTipoPedido().compareTo("Externo") == 0) { PartidaExterna[] par = (PartidaExterna[]) aux.getPartidaExternas() .toArray(new PartidaExterna[0]); for (int b = 0; b < par.length; b++) { PartidaExterna ren2 = par[b]; Renglon nuevo; nuevo = new Renglon("" + aux.getIdPedido(), ren2.getNoParte(), ren2.getDescripcion(), ren2.getCantidad(), ren2.getUnidad(), ren2.getCosto(), "", "" + "Ext"); ordena.add(nuevo); } } if (aux.getTipoPedido().compareTo("Adicional") == 0) { PartidaExterna[] par = (PartidaExterna[]) aux.getPartidaExternas() .toArray(new PartidaExterna[0]); for (int b = 0; b < par.length; b++) { PartidaExterna ren2 = par[b]; Renglon nuevo; nuevo = new Renglon("" + aux.getIdPedido(), ren2.getNoParte(), ren2.getDescripcion(), ren2.getCantidad(), ren2.getUnidad(), ren2.getCosto(), "" + aux.getOrden().getIdOrden(), "ADI"); ordena.add(nuevo); } } } Collections.sort(ordena, new Comparator() { @Override public int compare(Object o1, Object o2) { Renglon p1 = (Renglon) o1; Renglon p2 = (Renglon) o2; return new String(p1.np + p1.descripcion) .compareTo(new String(p2.np + p2.descripcion)); } }); for (int c = 0; c < ordena.size(); c++) { Renglon r1 = (Renglon) ordena.get(c); tabla.addCell(reporte.celda(r1.pedido, font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell( reporte.celda(r1.np, font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(r1.descripcion, font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(r1.cant), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell( reporte.celda(r1.med, font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(r1.precio), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("" + r1.orden, font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(r1.partida, font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } } tabla.setHeaderRows(2); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar2(ruta + ".pdf"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto."); } finally { if (session != null) if (session.isOpen()) session.close(); } } } } }
From source file:Compras.reportePedidos.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed // TODO add your handling code here: h = new Herramientas(usr, 0); h.session(sessionPrograma);//w w w . j a v a2 s .c o m if (t_datos.getRowCount() > 0) { Session session = HibernateUtil.getSessionFactory().openSession(); javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" })); String ruta = null; if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { File archivoXLS = new File(ruta + ".xls"); try { DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); session.beginTransaction().begin(); if (archivoXLS.exists()) archivoXLS.delete(); archivoXLS.createNewFile(); Workbook libro = new HSSFWorkbook(); FileOutputStream archivo = new FileOutputStream(archivoXLS); Sheet hoja = libro.createSheet("VALUACION"); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); Object no[]; int ren[]; if (t_datos.getSelectedRows().length > 0) { no = new Object[t_datos.getSelectedRows().length]; ren = t_datos.getSelectedRows(); for (int x = 0; x < t_datos.getSelectedRows().length; x++) { no[x] = (int) t_datos.getValueAt(ren[x], 0); } } else { no = new Object[t_datos.getRowCount()]; //ren =new int[t_datos.getRowCount()]; for (int x = 0; x < t_datos.getRowCount(); x++) { no[x] = (int) t_datos.getValueAt(x, 0); } } Pedido[] pedidos; if (autorizado.isSelected() == true) { pedidos = (Pedido[]) session.createCriteria(Pedido.class) .add(Restrictions.and( Restrictions.and(Restrictions.isNotNull("usuarioByAutorizo"), Restrictions.isNotNull("usuarioByAutorizo2")), Restrictions.in("idPedido", no))) .list().toArray(new Pedido[0]); } else { pedidos = (Pedido[]) session.createCriteria(Pedido.class) .add(Restrictions.in("idPedido", no)).list().toArray(new Pedido[0]); } if (pedidos.length > 0) { ArrayList ordena = new ArrayList(); for (int a = 0; a < pedidos.length; a++) { Pedido aux = pedidos[a]; if (aux.getTipoPedido().compareTo("Interno") == 0) { Partida[] par = (Partida[]) aux.getPartidas().toArray(new Partida[0]); for (int b = 0; b < par.length; b++) { Partida ren1 = par[b]; Renglon nuevo; if (ren1.getEjemplar() != null) nuevo = new Renglon("" + aux.getIdPedido(), ren1.getEjemplar().getIdParte(), ren1.getCatalogo().getNombre(), ren1.getCantPcp(), ren1.getMed(), ren1.getPcp(), "" + ren1.getOrdenByIdOrden().getIdOrden(), "" + ren1.getIdEvaluacion() + "-" + ren1.getSubPartida()); else nuevo = new Renglon("" + aux.getIdPedido(), "", ren1.getCatalogo().getNombre(), ren1.getCantPcp(), ren1.getMed(), ren1.getPcp(), "" + ren1.getOrdenByIdOrden().getIdOrden(), "" + ren1.getIdEvaluacion() + "-" + ren1.getSubPartida()); ordena.add(nuevo); } } if (aux.getTipoPedido().compareTo("Externo") == 0) { PartidaExterna[] par = (PartidaExterna[]) aux.getPartidaExternas() .toArray(new PartidaExterna[0]); for (int b = 0; b < par.length; b++) { PartidaExterna ren2 = par[b]; Renglon nuevo; nuevo = new Renglon("" + aux.getIdPedido(), ren2.getNoParte(), ren2.getDescripcion(), ren2.getCantidad(), ren2.getUnidad(), ren2.getCosto(), "", "" + "Ext"); ordena.add(nuevo); } } if (aux.getTipoPedido().compareTo("Adicional") == 0) { PartidaExterna[] par = (PartidaExterna[]) aux.getPartidaExternas() .toArray(new PartidaExterna[0]); for (int b = 0; b < par.length; b++) { PartidaExterna ren2 = par[b]; Renglon nuevo; nuevo = new Renglon("" + aux.getIdPedido(), ren2.getNoParte(), ren2.getDescripcion(), ren2.getCantidad(), ren2.getUnidad(), ren2.getCosto(), "" + aux.getOrden().getIdOrden(), "ADI"); ordena.add(nuevo); } } } Collections.sort(ordena, new Comparator() { @Override public int compare(Object o1, Object o2) { Renglon p1 = (Renglon) o1; Renglon p2 = (Renglon) o2; return new String(p1.np + p1.descripcion) .compareTo(new String(p2.np + p2.descripcion)); } }); for (int c = 0; c < ordena.size() + 1; c++) { Row fila = hoja.createRow(c); Cell celda0 = fila.createCell(0); Cell celda1 = fila.createCell(1); Cell celda2 = fila.createCell(2); Cell celda3 = fila.createCell(3); Cell celda4 = fila.createCell(4); Cell celda5 = fila.createCell(5); Cell celda6 = fila.createCell(6); Cell celda7 = fila.createCell(7); if (c == 0) { celda0.setCellValue("Pedido"); celda1.setCellValue("NP"); celda2.setCellValue("Descripcion"); celda3.setCellValue("Cant"); celda4.setCellValue("Med"); celda5.setCellValue("Precio"); celda6.setCellValue("Orden"); celda7.setCellValue("Partida"); } else { Renglon r1 = (Renglon) ordena.get(c - 1); celda0.setCellValue(r1.pedido); celda1.setCellValue(r1.np); celda2.setCellValue(r1.descripcion); celda3.setCellValue(formatoPorcentaje.format(r1.cant)); celda4.setCellValue(r1.med); celda5.setCellValue(formatoPorcentaje.format(r1.precio)); celda6.setCellValue("" + r1.orden); celda7.setCellValue(r1.partida); } } } libro.write(archivo); archivo.close(); Desktop.getDesktop().open(archivoXLS); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto."); } finally { if (session != null) if (session.isOpen()) session.close(); } } } } }
From source file:cz.jirutka.rsql.hibernate.AbstractCriterionBuilder.java
License:Open Source License
/** * Apply an "is not null" constraint to the named property. * * @param propertyPath property name prefixed with an association alias * @return Criterion/*from w w w . ja v a 2s . com*/ */ protected Criterion createIsNotNull(String propertyPath) { return Restrictions.isNotNull(propertyPath); }
From source file:de.arago.rike.svg.SVG.java
License:Open Source License
@Override protected boolean checkViewData(IDataWrapper data) { if (!SecurityHelper.isLoggedIn(data.getUser())) return false; if (data.getSessionAttribute("taskListFilter") == null) { data.setSessionAttribute("taskListFilter", new TaskListFilter() { @Override// w w w . jav a 2 s . c o m public void setDefaultOptions() { super.setDefaultOptions(); DataHelperRike<Milestone> helper = new DataHelperRike<Milestone>(Milestone.class); List<Milestone> list = helper.list(helper .filter().addOrder(Order.asc("dueDate")).add(Restrictions .and(Restrictions.isNotNull("dueDate"), Restrictions.ge("dueDate", new Date()))) .setMaxResults(1)); if (list.size() > 0) { setIsActive(true); setMilestone("milestone_" + list.get(0).getId().toString()); } } }); } Long nextUpdate = (Long) data.getSessionAttribute("nextUpdate"); if (nextUpdate == null || nextUpdate < System.currentTimeMillis() || data.getSessionAttribute("lastActivity") == null) { data.setSessionAttribute("nextUpdate", System.currentTimeMillis() + Long.parseLong(GlobalConfig.get(CHECK_PERIOD_SECONDS)) * 1000); data.setSessionAttribute("lastActivity", lastChange()); } if (data.getSessionAttribute("portletTitle") == null) { String milestone = ((TaskListFilter) data.getSessionAttribute("taskListFilter")).getMilestone(); data.setSessionAttribute("portletTitle", new PortletTitleWithMilestone(milestone, "Dependencies")); } return true; }
From source file:de.arago.rike.zombie.ZombieHelper.java
License:Open Source License
public static List<Task> getOverdueTasks() { DataHelperRike<Task> helper = new DataHelperRike<Task>(Task.class); Criteria crit = helper.filter().add(Restrictions.isNotNull("dueDate")) .add(Restrictions.lt("dueDate", new Date())) .add(Restrictions.ne("status", Task.Status.DONE.toString().toLowerCase())) .addOrder(Order.asc("dueDate")); return helper.list(crit); }
From source file:de.decidr.model.filters.EqualsFilter.java
License:Apache License
@Override public void apply(Criteria criteria) { if (propertyValue == null) { // checking against null is a special case if (include) { criteria.add(Restrictions.isNull(propertyName)); } else {/*from w ww. j av a 2 s .co m*/ criteria.add(Restrictions.isNotNull(propertyName)); } } else { if (include) { criteria.add(Restrictions.eq(propertyName, propertyValue)); } else { criteria.add((Restrictions.not(Restrictions.eq(propertyName, propertyValue)))); } } }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.AbstractLeafNode.java
License:Open Source License
/** * Returns the {@link Criterion} for the specified {@code effectivePropertyName} and {@code comparator}. * // w w w. j a va 2 s .c om * @param effectivePropertyName the property name path * @param comparator the comparator describing the compare operation * @param attrType string representation of the property's attribute type as in {@link BBAttribute#getTypeOfAttribute(String)} * @return the newly created {@link Criterion} for the specified {@code comparator} or {@code null} if the * comparator is not supported */ protected Criterion getCriterionForComparator(String effectivePropertyName, Comparator comparator, String attrType) { Criterion criterion = null; switch (comparator) { case EQ: criterion = Restrictions.eq(effectivePropertyName, getProcessedPattern()); break; case GEQ: criterion = Restrictions.ge(effectivePropertyName, getProcessedPattern()); break; case LEQ: criterion = Restrictions.le(effectivePropertyName, getProcessedPattern()); break; case GT: criterion = Restrictions.gt(effectivePropertyName, getProcessedPattern()); break; case LT: criterion = Restrictions.lt(effectivePropertyName, getProcessedPattern()); break; case LIKE: criterion = new IteraplanLikeExpression(effectivePropertyName, getProcessedPattern().toString(), true); break; case NOT_LIKE: criterion = Restrictions.not( new IteraplanLikeExpression(effectivePropertyName, getProcessedPattern().toString(), true)); break; case IS: // see Type#getSpecialPropertyHQLStrings criterion = "null".equals(getPattern()) ? Restrictions.isNull(effectivePropertyName) : Restrictions.isNotNull(effectivePropertyName); break; case ANY_ASSIGNMENT: criterion = getAnyAssignmentCriterion(effectivePropertyName, attrType); break; case NO_ASSIGNMENT: criterion = getNoAssignmentCriterion(effectivePropertyName, attrType); break; case NEQ: criterion = Restrictions.ne(effectivePropertyName, getProcessedPattern()); break; default: break; } return criterion; }