List of usage examples for org.hibernate Query setDate
@Deprecated @SuppressWarnings("unchecked") default Query<R> setDate(String name, Date val)
From source file:classroom.filmfestival_c.Movies17.java
@SuppressWarnings("unchecked") protected static Element getTable(Query q, Date date) throws DocumentException { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100f);// w w w . j av a 2 s .com PdfPCell cell = new PdfPCell(new Phrase(date.toString(), NORMALWHITE)); cell.setBackgroundColor(BLACK); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); q.setDate(0, date); java.util.List<FestivalScreening> screenings = q.list(); for (FestivalScreening screening : screenings) { addScreening(table, screening); } return table; }
From source file:classroom.filmfestival_c.Movies19.java
@SuppressWarnings("unchecked") protected static void createSheet(Session session, Date date, PdfWriter writer) { Query q; q = session.createQuery(//from w w w . j a v a2 s . c o m "select distinct screening.id.place from FestivalScreening as screening where id.day=? order by screening.id.place"); q.setDate(0, date); List<String> places = q.list(); Rectangle art = writer.getBoxSize("art"); // initialize the dimensions for this day float top = art.getTop(); float row_height = art.getHeight() / places.size(); if (row_height > 70) { row_height = 70; } float column_width = art.getWidth() / COLUMNS; float left = art.getLeft() + column_width; float minute = (2f * column_width) / 60f; // content drawGrid(writer, places, date.toString(), left, column_width, top, row_height); q = session.createQuery("from FestivalScreening where id.day=? order by id.time, id.place"); q.setDate(0, date); List<FestivalScreening> screenings = q.list(); for (FestivalScreening screening : screenings) { try { drawMovie(writer, screening, places, minute, left, top, row_height); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } } }
From source file:com.app.inventario.dao.seguridad.IntentosLoginDAOImpl.java
public void actualizarIntentosFallidos(String usuario) throws HibernateException { try {//ww w . j a v a2s. co m //this.iniciaOperacion(); IntentosLogin intento = this.obtenerIntentoLogin(usuario); if (intento == null) { IntentosLogin intentoAux = new IntentosLogin(usuario, 1, new Date()); session.save(intentoAux); } else { if (intento.getCantidadIntentos() < 3) { Query query = session.createQuery( "UPDATE IntentosLogin SET cantidadIntentos = :cantidadIntentos, ultimoAcceso = :ultimoAcceso WHERE usuario = :username"); query.setInteger("cantidadIntentos", intento.getCantidadIntentos() + 1); query.setDate("ultimoAcceso", new Date()); query.setString("username", usuario); query.executeUpdate(); } else if (intento.getCantidadIntentos() + 1 == 3) { Query query = session .createQuery("UPDATE Usuario SET noBloqueado = false WHERE username = :usuario"); query.setParameter("usuario", intento.getUsuario()); query.executeUpdate(); } } } catch (HibernateException he) { this.manejaExcepcion(he); } finally { } }
From source file:com.bloatit.data.DaoTeam.java
License:Open Source License
public long getRecentHistoryCount(final int numberOfDays) { final Query size = SessionManager.getNamedQuery("team.getRecentHistory.size"); size.setEntity("team", this); size.setDate("date", DateUtils.nowMinusSomeDays(numberOfDays)); return (Long) size.uniqueResult(); }
From source file:com.bolao.persistencia.dao.ApostadorDAO.java
public List<Apostador> list(ModoConsulta mc, Object object) { Session session = HibernateFactory.getSessionFactory(); session.beginTransaction();/*from w w w .ja v a2 s . c o m*/ if (mc == ModoConsulta.DEFAULT || object == null) { lista.clear(); Query query = session.createQuery(" from Apostador"); lista = query.list(); } else if (mc == ModoConsulta.NOME_APOSTADOR && object != null) { lista.clear(); Query query = session.createQuery(" from Apostador where nome like :XNOME"); query.setString("XNOME", "%" + String.valueOf(object) + "%"); lista = query.list(); } else if (mc == ModoConsulta.DATA_NASC && object != null) { lista.clear(); Query query = session.createQuery(" from Apostador where datanascimento =:XDATA"); query.setDate("XDATA", conversorData.converterData(String.valueOf(object))); lista = query.list(); } else if (mc == ModoConsulta.EMAIL && object != null) { lista.clear(); Query query = session.createQuery(" from Apostador where email like :XEMAIL"); query.setString("XEMAIL", "%" + String.valueOf(object) + "%"); lista = query.list(); } else if (mc == ModoConsulta.APELIDO && object != null) { lista.clear(); Query query = session.createQuery(" from Apostador where apelido like :XAPELIDO"); query.setString("XAPELIDO", "%" + String.valueOf(object) + "%"); lista = query.list(); } session.getTransaction().commit(); session.close(); return lista; }
From source file:com.bolao.persistencia.dao.TimeDAO.java
public List<Time> list(ModoConsulta modoConsulta, Object object, Object dataObject) { try {/*from w ww. j a v a 2 s . c o m*/ Session session = HibernateFactory.getSessionFactory(); session.beginTransaction(); if (modoConsulta == ModoConsulta.CIDADE && object != null && !object.toString().isEmpty()) { lista.clear(); Query query = session .createQuery(" from Time t where t.cidade like :XCIDADE order by t.codigo,t.cidade "); query.setString("XCIDADE", "%" + String.valueOf(object) + "%"); lista = query.list(); } else if (modoConsulta == ModoConsulta.CODIGO && object != null && !object.toString().isEmpty()) { lista.clear(); Query query = session .createQuery(" from Time t where t.codigo =:xcodigo order by t.cidade asc,t.codigo desc"); query.setInteger("xcodigo", Integer.parseInt(String.valueOf(object))); lista = query.list(); } else if (modoConsulta == ModoConsulta.DATA_CADASTRO && object != null && !object.toString().isEmpty() && dataObject != null && !dataObject.toString().isEmpty()) { lista.clear(); Query query = session.createQuery( " from Time t where t.datacadastro between :XDATAINI AND :XDATAFIM order by t.cidade asc,t.codigo desc"); query.setDate("XDATAINI", conversorData.converterData(String.valueOf(object))); query.setDate("XDATAFIM", conversorData.converterData(String.valueOf(dataObject))); lista = query.list(); } else if (modoConsulta == ModoConsulta.DATA_FUNDACAO && object != null && !object.toString().isEmpty() && dataObject != null && !dataObject.toString().isEmpty()) { lista.clear(); Query query = session.createQuery( " from Time t where t.datafundacao between :XDATAINI AND :XDATAFIM order by t.cidade asc,t.codigo desc"); query.setDate("XDATAINI", conversorData.converterData(String.valueOf(object))); query.setDate("XDATAFIM", conversorData.converterData(String.valueOf(dataObject))); lista = query.list(); } else if (modoConsulta == ModoConsulta.DEFAULT || object == null || object.toString().isEmpty()) { lista.clear(); Query query = session.createQuery(" from Time t order by t.codigo,t.cidade "); lista = query.list(); } else if (modoConsulta == ModoConsulta.EMAIL && object != null && !object.toString().isEmpty()) { lista.clear(); Query query = session .createQuery(" from Time t where t.email like :XEMAIL order by t.codigo,t.cidade"); query.setString("XEMAIL", "%" + String.valueOf(object) + "%"); lista = query.list(); } else if (modoConsulta == ModoConsulta.ENDERECO && object != null && !object.toString().isEmpty()) { lista.clear(); Query query = session .createQuery(" from Time t where t.endereco like :XENDERECO order by t.codigo,t.cidade"); query.setString("XENDERECO", "%" + String.valueOf(object) + "%"); lista = query.list(); } else if (modoConsulta == ModoConsulta.SITE && object != null && !object.toString().isEmpty()) { lista.clear(); Query query = session .createQuery(" from Time t where t.site like :XSITE order by t.codigo,t.cidade"); query.setString("XSITE", "%" + String.valueOf(object) + "%"); lista = query.list(); } else if (modoConsulta == ModoConsulta.TELEFONE && object != null && !object.toString().isEmpty()) { lista.clear(); Query query = session .createQuery(" from Time t where t.telefone like :XTELEFONE order by t.codigo,t.cidade"); query.setString("XTELEFONE", "%" + String.valueOf(object) + "%"); lista = query.list(); } else if (modoConsulta == ModoConsulta.TIME && object != null && !object.toString().isEmpty()) { lista.clear(); Query query = session .createQuery(" from Time t where t.nome like :XNOME order by t.codigo,t.cidade"); query.setString("XNOME", "%" + String.valueOf(object) + "%"); lista = query.list(); } else if (modoConsulta == ModoConsulta.DESCRICAO && object != null && !object.toString().isEmpty()) { lista.clear(); Query query = session .createQuery(" from Time t where t.descricao like :XNOME order by t.codigo,t.cidade"); query.setString("XNOME", "%" + String.valueOf(object) + "%"); lista = query.list(); } session.getTransaction().commit(); session.close(); } catch (Exception e) { } return lista; }
From source file:com.candy.db.StockEodProc.java
/** * query and return ordered by date historical data * @param symbol/*from ww w. j a v a 2 s . c o m*/ * @param startCal * @param endCal * @return */ public List<Stockeod> getHisStockData(String symbol, Calendar startCal, Calendar endCal) { try { begin(); Query q = getSession().createQuery( "from Stockeod where symbol = :symbol and sdate <= :endDate and sdate >= :startDate order by sdate asc"); q.setString("symbol", symbol); q.setDate("endDate", new java.sql.Date(endCal.getTimeInMillis())); q.setDate("startDate", new java.sql.Date(startCal.getTimeInMillis())); List<Stockeod> results = q.list(); commit(); if (!results.isEmpty()) { return results; } else { return null; } } catch (HibernateException e) { return null; } }
From source file:com.cloud.bridge.util.QueryHelper.java
License:Open Source License
public static void bindParameters(Query query, Object[] params) { int pos = 0;//from w ww . java 2 s. co m if (params != null && params.length > 0) { for (Object param : params) { if (param instanceof Byte) query.setByte(pos++, ((Byte) param).byteValue()); else if (param instanceof Short) query.setShort(pos++, ((Short) param).shortValue()); else if (param instanceof Integer) query.setInteger(pos++, ((Integer) param).intValue()); else if (param instanceof Long) query.setLong(pos++, ((Long) param).longValue()); else if (param instanceof Float) query.setFloat(pos++, ((Float) param).floatValue()); else if (param instanceof Double) query.setDouble(pos++, ((Double) param).doubleValue()); else if (param instanceof Boolean) query.setBoolean(pos++, ((Boolean) param).booleanValue()); else if (param instanceof Character) query.setCharacter(pos++, ((Character) param).charValue()); else if (param instanceof Date) query.setDate(pos++, (Date) param); else if (param instanceof Calendar) query.setCalendar(pos++, (Calendar) param); else if (param instanceof CalendarDateParam) query.setCalendarDate(pos++, ((CalendarDateParam) param).dateValue()); else if (param instanceof TimestampParam) query.setTimestamp(pos++, ((TimestampParam) param).timestampValue()); else if (param instanceof TimeParam) query.setTime(pos++, ((TimeParam) param).timeValue()); else if (param instanceof String) query.setString(pos++, (String) param); else if (param instanceof TextParam) query.setText(pos++, ((TextParam) param).textValue()); else if (param instanceof byte[]) query.setBinary(pos++, (byte[]) param); else if (param instanceof BigDecimal) query.setBigDecimal(pos++, (BigDecimal) param); else if (param instanceof BigInteger) query.setBigInteger(pos++, (BigInteger) param); else if (param instanceof Locale) query.setLocale(pos++, (Locale) param); else if (param instanceof EntityParam) query.setEntity(pos++, ((EntityParam) param).entityValue()); else if (param instanceof Serializable) query.setSerializable(pos++, (Serializable) param); else query.setEntity(pos++, param); } } }
From source file:com.connexience.server.model.datasets.queries.temporal.enactors.AbsoluteTimeRangeQueryEnactor.java
License:Open Source License
@Override public JSONContainer performQuery() throws ConnexienceException { Session session = null;/*from w w w . j a v a 2 s. c o m*/ try { session = sessionProvider.getSession(); AbsoluteTimeRangeQuery q = (AbsoluteTimeRangeQuery) query; Query hqlQuery = session.createQuery( "from JsonDataRow as obj where obj.itemId=:itemid and obj.collectionTime>=:starttime and obj.collectionTime<=:endtime order by obj.id asc"); hqlQuery.setLong("itemid", item.getId()); hqlQuery.setDate("starttime", q.getStartDate()); hqlQuery.setDate("endtime", q.getEndDate()); List rows = hqlQuery.list(); if (q.getKeyArray() != null && q.getKeyArray().length > 0) { return DatasetsUtils.createResultFromList(rows, q.getKeyArray()); } else { return DatasetsUtils.createResultFromList(rows, null); } } catch (Exception e) { throw new ConnexienceException("Error performing query: " + e.getMessage(), e); } finally { sessionProvider.closeSession(session); } }
From source file:com.connexience.server.model.datasets.queries.temporal.enactors.LatestByAbsoluteTimeQueryEnactor.java
License:Open Source License
@Override public JSONContainer performQuery() throws ConnexienceException { Session session = null;//from www . j a v a 2 s . com try { session = sessionProvider.getSession(); LatestByAbsoluteTimeQuery q = (LatestByAbsoluteTimeQuery) query; Query hqlQuery = session.createQuery( "from JsonDataRow as obj where obj.itemId=:itemid and obj.collectionTime>:collectiontime order by obj.id asc"); hqlQuery.setLong("itemid", item.getId()); hqlQuery.setDate("collectiontime", q.getStartDate()); List rows = hqlQuery.list(); if (q.getKeyArray() != null && q.getKeyArray().length > 0) { return DatasetsUtils.createResultFromList(rows, q.getKeyArray()); } else { return DatasetsUtils.createResultFromList(rows, null); } } catch (Exception e) { throw new ConnexienceException("Error performing query: " + e.getMessage(), e); } finally { sessionProvider.closeSession(session); } }