List of usage examples for org.joda.time LocalDate LocalDate
public LocalDate(Object instant)
From source file:br.edu.unirio.pm.dao.VendasDAO.java
public LocalDate obterDataDaVendaMaisAntiga() throws SQLException { try {// w w w . java2 s.c o m consulta = SELECT_MIN_DATA; LocalDate dataVendaMaisAntiga = LocalDate.now(); FabricaConexao.iniciarConexao(); comando = FabricaConexao.criarComando(consulta); resultado = comando.executeQuery(); while (resultado.next()) dataVendaMaisAntiga = new LocalDate(resultado.getDate(1)); return dataVendaMaisAntiga; } finally { FabricaConexao.fecharComando(comando); FabricaConexao.fecharConexao(); } }
From source file:c4a.platform.services.wsServices.java
@GET @Path("getCareReceivers") @Consumes("application/json") @Produces("application/json") public C4ACareReceiversResponse getJson() throws IOException { /**/* w w w. j a v a 2s . c o m*/ * ****************Variables************* */ System.out.println("******************start*****************"); C4ACareReceiversResponse response = new C4ACareReceiversResponse(); TypedQuery query; TypedQuery query_crProfile; TypedQuery query_users; TypedQuery query_frailty; List<UserInRole> userinroleparamsList; List<CrProfile> crprofileparamsList; List<CareProfile> careprofileparamsList; List<FrailtyStatusTimeline> frailtyparamsList; ArrayList<C4ACareReceiverListResponse> itemList; SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); /** * ****************Action************* */ // if (em == null) { // init(); // } query_users = (TypedQuery) em.createQuery("SELECT u FROM UserInRole u Where u.roleId.id =1"); userinroleparamsList = query_users.getResultList(); if (userinroleparamsList.isEmpty()) { response.setMessage("No users found"); response.setResponseCode(0); return response; } else { itemList = new ArrayList<C4ACareReceiverListResponse>(); for (UserInRole users : userinroleparamsList) { response.setMessage("success"); response.setResponseCode(10); System.out.println("id " + users.getId() + "name " + users.getUserInSystemId().getUsername()); query_crProfile = (TypedQuery) em .createQuery("SELECT c FROM CrProfile c Where c.userInRoleId.id = :userId "); query_crProfile.setParameter("userId", users.getId()); //we use list to avoid "not found" exception crprofileparamsList = query_crProfile.getResultList(); int age = 0; if (!crprofileparamsList.isEmpty()) { LocalDate birthDate = new LocalDate(crprofileparamsList.get(0).getBirthDate()); Years age2 = Years.yearsBetween(birthDate, new LocalDate()); age = age2.getYears(); // System.out.println("age2 " + age2.getYears()); // System.out.println("user name " + crprofileparamsList.get(0).getUserInRoleId().getId() // + " birthDate " + birthDate); } query = (TypedQuery) em.createQuery("SELECT c FROM CareProfile c WHERE c.userInRole.id = :userId "); query.setParameter("userId", users.getId()); //we use list to avoid "not found" exception careprofileparamsList = query.getResultList(); //************************************** String frailtyStatus = null; String frailtyNotice = null; char attention = 0; String textline = null; char interventionstatus = 0; String interventionDate = null; String detectionStatus = null; String detectionDate = null; if (!careprofileparamsList.isEmpty()) { // frailtyStatus = careprofileparamsList.get(0).getFrailtyStatus(); // frailtyNotice = careprofileparamsList.get(0).getFrailtyNotice(); attention = careprofileparamsList.get(0).getAttentionStatus(); textline = careprofileparamsList.get(0).getIndividualSummary(); interventionstatus = careprofileparamsList.get(0).getInterventionStatus(); interventionDate = sdf.format(careprofileparamsList.get(0).getLastInterventionDate()); // detectionStatus = careprofileparamsList.get(0).getDetectionStatus(); // detectionDate = sdf.format(new Date(careprofileparamsList.get(0).getLastDetection() * 1000)); // System.out.println("user id " + careprofileparamsList.get(0).getUserInRoleId() // + " frailty status " + careprofileparamsList.get(0).getFrailtyStatus()); } query_frailty = (TypedQuery) em.createQuery( "SELECT f FROM FrailtyStatusTimeline f WHERE f.frailtyStatusTimelinePK.userInRoleId = :userId "); query_frailty.setParameter("userId", users.getId()); //we use list to avoid "not found" exception frailtyparamsList = query_frailty.getResultList(); if (!frailtyparamsList.isEmpty()) { frailtyStatus = frailtyparamsList.get(0).getFrailtyStatus().getFrailtyStatus(); frailtyNotice = frailtyparamsList.get(0).getFrailtyNotice(); // System.out.println("user id " + frailtyparamsList.get(0).getFrailtyStatusTimelinePK().getUserInRoleId() // + " frailty status " + frailtyparamsList.get(0).getFrailtyStatus().getFrailtyStatus()); } itemList.add(new C4ACareReceiverListResponse(users.getId(), age, frailtyStatus, frailtyNotice, attention, textline, interventionstatus, interventionDate, detectionStatus, detectionDate)); } //detectionVariables loop response.setItemList(itemList); } //end detectionVariables is empty return response; }
From source file:ca.ualberta.physics.cssdp.dao.type.PersistentLocalDate.java
License:Apache License
@Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { Date date = rs.getDate(names[0]); if (date != null) { LocalDate localDate = new LocalDate(date); return localDate; } else {/* w ww.j a v a2 s .c o m*/ return null; } }
From source file:cache.BreakerCache.java
Vector<ElectricalValue> get_data(Breaker breaker, LocalDate startDate, LocalDate endDate, BaseCache cache) throws NoActiveDbConnectionException, NoItemSelectedException { Vector<ElectricalValue> toreturn = new Vector<>(); LocalDate currdate = null;/*w ww. j a v a 2 s . c o m*/ int cacheditems = 0; int totalitems = 0; currdate = new LocalDate(startDate); while (currdate.isBefore(endDate)) { YearCache wanted_year = null; for (YearCache yc : years) { if (yc.year == currdate.getYear()) { wanted_year = yc; break; } } if (wanted_year == null) { wanted_year = new YearCache(currdate.getYear()); years.add(wanted_year); } MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1]; DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1]; if (wanted_day.data != null) { cacheditems++; } totalitems++; currdate = currdate.plusDays(1); } if (cacheditems / totalitems > 0.9) { currdate = new LocalDate(startDate); while (currdate.isBefore(endDate)) { YearCache wanted_year = null; for (YearCache yc : years) { if (yc.year == currdate.getYear()) { wanted_year = yc; break; } } if (wanted_year == null) { wanted_year = new YearCache(currdate.getYear()); years.add(wanted_year); } MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1]; DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1]; cache.cache_day(wanted_day); if (wanted_day.data == null) { wanted_day.data = LoadDataFromDB.get_data(breaker, currdate, currdate.plusDays(1)); } toreturn.addAll(wanted_day.data); currdate = currdate.plusDays(1); } } else { toreturn = LoadDataFromDB.get_data(breaker, startDate, endDate); currdate = new LocalDate(startDate); YearCache wanted_year = null; for (YearCache yc : years) { if (yc.year == currdate.getYear()) { wanted_year = yc; break; } } if (wanted_year == null) { wanted_year = new YearCache(currdate.getYear()); years.add(wanted_year); } MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1]; DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1]; currdate = currdate.plusDays(1); Vector<ElectricalValue> daydata = new Vector<>(); for (int i = 0; i < toreturn.size(); i++) { if (toreturn.get(i).datetime.toLocalDate().isBefore(currdate)) { daydata.add(toreturn.get(i)); } else { if (daydata.size() > 0) { wanted_day.data = daydata; cache.cache_day(wanted_day); daydata = new Vector<>(); } wanted_year = null; for (YearCache yc : years) { if (yc.year == currdate.getYear()) { wanted_year = yc; break; } } if (wanted_year == null) { wanted_year = new YearCache(currdate.getYear()); years.add(wanted_year); } wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1]; wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1]; currdate = currdate.plusDays(1); } } } return toreturn; }
From source file:cache.TransformerCache.java
Vector<ElectricalValue> get_data(Transformer transformer, LocalDate startDate, LocalDate endDate, BaseCache cache) throws NoActiveDbConnectionException, NoItemSelectedException { Vector<ElectricalValue> toreturn = new Vector<>(); LocalDate currdate = null;/* w ww .j a va 2s . com*/ int cacheditems = 0; int totalitems = 0; currdate = new LocalDate(startDate); while (currdate.isBefore(endDate)) { YearCache wanted_year = null; for (YearCache yc : years) { if (yc.year == currdate.getYear()) { wanted_year = yc; break; } } if (wanted_year == null) { wanted_year = new YearCache(currdate.getYear()); years.add(wanted_year); } MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1]; DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1]; if (wanted_day.data != null) { cacheditems++; } totalitems++; currdate = currdate.plusDays(1); } if (cacheditems / totalitems > 0.9) { currdate = new LocalDate(startDate); while (currdate.isBefore(endDate)) { YearCache wanted_year = null; for (YearCache yc : years) { if (yc.year == currdate.getYear()) { wanted_year = yc; break; } } if (wanted_year == null) { wanted_year = new YearCache(currdate.getYear()); years.add(wanted_year); } MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1]; DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1]; cache.cache_day(wanted_day); if (wanted_day.data == null) { wanted_day.data = LoadDataFromDB.get_data(transformer, currdate, currdate.plusDays(1)); } toreturn.addAll(wanted_day.data); currdate = currdate.plusDays(1); } } else { toreturn = LoadDataFromDB.get_data(transformer, startDate, endDate); currdate = new LocalDate(startDate); YearCache wanted_year = null; for (YearCache yc : years) { if (yc.year == currdate.getYear()) { wanted_year = yc; break; } } if (wanted_year == null) { wanted_year = new YearCache(currdate.getYear()); years.add(wanted_year); } MonthCache wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1]; DayCache wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1]; currdate = currdate.plusDays(1); Vector<ElectricalValue> daydata = new Vector<>(); for (int i = 0; i < toreturn.size(); i++) { if (toreturn.get(i).datetime.toLocalDate().isBefore(currdate)) { daydata.add(toreturn.get(i)); } else { if (daydata.size() > 0) { wanted_day.data = daydata; cache.cache_day(wanted_day); daydata = new Vector<>(); } wanted_year = null; for (YearCache yc : years) { if (yc.year == currdate.getYear()) { wanted_year = yc; break; } } if (wanted_year == null) { wanted_year = new YearCache(currdate.getYear()); years.add(wanted_year); } wanted_month = wanted_year.months[currdate.getMonthOfYear() - 1]; wanted_day = wanted_month.days[currdate.getDayOfMonth() - 1]; currdate = currdate.plusDays(1); } } } return toreturn; }
From source file:ch.thp.time.utilties.database.LocalDateConverter.java
License:Apache License
@Override public Object convertDataValueToObjectValue(Object dataValue, Session session) { return dataValue == null ? null : new LocalDate((Date) dataValue); }
From source file:ch.thp.time.utilties.database.LocalDateConverter.java
License:Apache License
@Override public Object convertObjectValueToDataValue(Object objectValue, Session session) { return objectValue == null ? null : new LocalDate(((Date) objectValue).getTime()); }
From source file:cherry.foundation.type.mybatis.JodaLocalDateTypeHandler.java
License:Apache License
@Override public LocalDate getNullableResult(ResultSet rs, String columnName) throws SQLException { Date date = rs.getDate(columnName); if (date == null) { return null; }/*from w ww.java 2 s . c o m*/ return new LocalDate(date.getTime()); }
From source file:cherry.foundation.type.mybatis.JodaLocalDateTypeHandler.java
License:Apache License
@Override public LocalDate getNullableResult(ResultSet rs, int columnIndex) throws SQLException { Date date = rs.getDate(columnIndex); if (date == null) { return null; }// www . j a v a 2 s. c o m return new LocalDate(date.getTime()); }
From source file:cherry.foundation.type.mybatis.JodaLocalDateTypeHandler.java
License:Apache License
@Override public LocalDate getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { Date date = cs.getDate(columnIndex); if (date == null) { return null; }/*from www . j av a2s . c o m*/ return new LocalDate(date.getTime()); }