List of usage examples for org.joda.time LocalDate toDateMidnight
@Deprecated
public DateMidnight toDateMidnight()
From source file:energy.usef.core.repository.PtuStateRepository.java
License:Apache License
/** * Finds the PTU States.//from ww w . ja v a 2 s .c om * * @param ptuDate PTU date * @param usefIdentifier USEF identifier * @return */ @SuppressWarnings("unchecked") public List<PtuState> findPtuStates(LocalDate ptuDate, String usefIdentifier) { List<PtuState> results = entityManager .createQuery("SELECT p FROM PtuState p WHERE p.ptuContainer.ptuDate = :ptuDate AND " + "p.connectionGroup.usefIdentifier = :usefIdentifier") .setParameter("ptuDate", ptuDate.toDateMidnight().toDate()) .setParameter("usefIdentifier", usefIdentifier).getResultList(); if (results == null || results.isEmpty()) { results = new ArrayList<>(); } return results; }
From source file:energy.usef.core.repository.PtuStateRepository.java
License:Apache License
/** * Finds the PTU States./*from ww w .ja v a 2s . com*/ * * @param startDate start Date * @param endDate end Date * @param regimes * @return */ @SuppressWarnings("unchecked") public List<PtuState> findPtuStates(LocalDate startDate, LocalDate endDate, RegimeType... regimes) { List<PtuState> results = entityManager.createQuery( "SELECT p FROM PtuState p WHERE p.ptuContainer.ptuDate >= :startDate AND p.ptuContainer.ptuDate <= :endDate AND p.regime IN :regimes") .setParameter("startDate", startDate.toDateMidnight().toDate()) .setParameter("endDate", endDate.toDateMidnight().toDate()) .setParameter("regimes", Arrays.asList(regimes)).getResultList(); if (results == null || results.isEmpty()) { results = new ArrayList<>(); } return results; }
From source file:energy.usef.core.repository.PtuStateRepository.java
License:Apache License
/** * Delete all {@link PtuState}s for a certain date. * * @param period//from w w w .ja va2 s .c om * @return the number of {@link PtuState}s deleted. */ public int cleanup(LocalDate period) { StringBuilder sql = new StringBuilder(); sql.append("DELETE FROM PtuState ps "); sql.append("WHERE ps.ptuContainer IN (SELECT pc FROM PtuContainer pc WHERE pc.ptuDate = :ptuDate)"); return entityManager.createQuery(sql.toString()).setParameter("ptuDate", period.toDateMidnight().toDate()) .executeUpdate(); }
From source file:energy.usef.core.repository.SignedMessageHashRepository.java
License:Apache License
/** * Delete all {@link SignedMessageHash}s for a certain date. * * @param period//from www .j a v a2 s . c o m * @return the number of {@link SignedMessageHash}s deleted. */ public int cleanup(LocalDate period) { LocalDate endDate = period.plusDays(1); Date start = new Date(period.toDateMidnight().getMillis()); Date end = new Date(endDate.toDateMidnight().getMillis()); String sql = "DELETE FROM SignedMessageHash o WHERE o.creationTime >= :start AND o.creationTime < :end"; return entityManager.createQuery(sql).setParameter("start", start).setParameter("end", end).executeUpdate(); }
From source file:energy.usef.core.util.DateTimeUtil.java
License:Apache License
/** * Calculate the number of minutes of a specific date. Only the date part (year, month and day) is used to calculate the number * of minutes. The number of minutes is calculated from midnight to midnight the next day. For a default day this method return * 24 * 60 = 1440. If on this day a summer- or wintertime switch occurs, the number of minutes are different. * * @param date the date time which includes the timezone. When setting the DateTime with the default constructor, the * default timezone where the application runs, is used. * @return the number of minutes for the day (date part) of the dateTime parameter. */// ww w . j a va 2 s. co m public static Integer getMinutesOfDay(LocalDate date) { Duration duration = new Interval(date.toDateMidnight(), date.plusDays(1).toDateMidnight()).toDuration(); return (int) duration.getStandardSeconds() / SECONDS_PER_MINUTE; }
From source file:energy.usef.dso.model.AggregatorOnConnectionGroupState.java
License:Apache License
public void setValidFrom(LocalDate validFrom) { this.validFrom = validFrom == null ? null : validFrom.toDateMidnight().toDate(); }
From source file:energy.usef.dso.model.AggregatorOnConnectionGroupState.java
License:Apache License
public void setValidUntil(LocalDate validUntil) { this.validUntil = validUntil == null ? null : validUntil.toDateMidnight().toDate(); }
From source file:energy.usef.dso.repository.AggregatorOnConnectionGroupStateRepository.java
License:Apache License
/** * Get Aggregators by CongestionPointAddress. * * @param congestionPointAddress {@link String} entity address of the congestion point. * @param dateTime {@link org.joda.time.LocalDateTime} validity moment of the {@link AggregatorOnConnectionGroupState}. * @return list of {@link Aggregator}./*from ww w.j ava 2 s. c o m*/ */ public List<Aggregator> getAggregatorsByCongestionPointAddress(String congestionPointAddress, LocalDate dateTime) { StringBuilder sql = new StringBuilder(); sql.append("SELECT DISTINCT state.aggregator "); sql.append("FROM AggregatorOnConnectionGroupState state "); sql.append("WHERE state.congestionPointConnectionGroup.usefIdentifier = :congestionPointEntityAddress "); sql.append(" AND state.validFrom <= :date "); sql.append(" AND state.validUntil > :date "); return entityManager.createQuery(sql.toString(), Aggregator.class) .setParameter("congestionPointEntityAddress", congestionPointAddress) .setParameter("date", dateTime.toDateMidnight().toDate(), TemporalType.DATE).getResultList(); }
From source file:energy.usef.dso.repository.AggregatorOnConnectionGroupStateRepository.java
License:Apache License
/** * Find the {@link AggregatorOnConnectionGroupState}s for this congestionPoint in a moment in time. * * @param congestionPointAddress {@link String} entity address of the congestion point. * @param date {@link org.joda.time.LocalDate} validity moment of the states. * @return list of AggregatorOnConnectionGroupState elements *//*w w w . j a v a2 s . com*/ public List<AggregatorOnConnectionGroupState> findAggregatorOnConnectionGroupStateByCongestionPointAddress( String congestionPointAddress, LocalDate date) { StringBuilder sql = new StringBuilder(); sql.append("SELECT DISTINCT state "); sql.append("FROM AggregatorOnConnectionGroupState state "); sql.append("WHERE state.congestionPointConnectionGroup.usefIdentifier = :congestionPointEntityAddress "); sql.append(" AND state.validFrom <= :date "); sql.append(" AND state.validUntil > :date "); return entityManager.createQuery(sql.toString(), AggregatorOnConnectionGroupState.class) .setParameter("congestionPointEntityAddress", congestionPointAddress) .setParameter("date", date.toDateMidnight().toDate(), TemporalType.DATE).getResultList(); }
From source file:energy.usef.dso.repository.AggregatorOnConnectionGroupStateRepository.java
License:Apache License
/** * Counts the {@link AggregatorOnConnectionGroupState}s for this congestionPoint in a moment in time. * * @param entityAddress The congestion Point Entity Address. * @param date The day./*from w w w . ja v a 2 s . co m*/ * @return the number of active aggregators for congestion point on given moment in time. */ public long countActiveAggregatorsForCongestionPointOnDay(String entityAddress, LocalDate date) { StringBuilder sql = new StringBuilder(); sql.append("SELECT COUNT ( DISTINCT state.aggregator.domain) "); sql.append("FROM AggregatorOnConnectionGroupState state "); sql.append("WHERE state.congestionPointConnectionGroup.usefIdentifier = :congestionPointEntityAddress "); sql.append(" AND state.validFrom <= :date "); sql.append(" AND state.validUntil > :date "); return entityManager.createQuery(sql.toString(), Long.class) .setParameter("congestionPointEntityAddress", entityAddress) .setParameter("date", date.toDateMidnight().toDate(), TemporalType.DATE).getSingleResult(); }