Example usage for org.joda.time LocalDate toDate

List of usage examples for org.joda.time LocalDate toDate

Introduction

In this page you can find the example usage for org.joda.time LocalDate toDate.

Prototype

@SuppressWarnings("deprecation")
public Date toDate() 

Source Link

Document

Get the date time as a java.util.Date.

Usage

From source file:energy.usef.agr.repository.UdiEventRepository.java

License:Apache License

/**
 * Finds all the {@link UdiEvent} entities for the given period.
 *
 * @param period {@link LocalDate} period.
 * @return a {@link List} of {@link UdiEvent}.
 *///  w w  w.  ja v a  2 s  .  c  o m
public List<UdiEvent> findUdiEventsForPeriod(LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT ue ");
    sql.append("FROM UdiEvent ue ");
    sql.append("WHERE ue.period = :period ");
    return getEntityManager().createQuery(sql.toString(), UdiEvent.class)
            .setParameter("period", period.toDateMidnight().toDate(), TemporalType.DATE).getResultList();
}

From source file:energy.usef.agr.repository.UdiEventRepository.java

License:Apache License

/**
 * Delete all {@link UdiEvent} objects for a certain date.
 *
 * @param period/*from w w  w.ja va  2s.  c o m*/
 * @return the number of {@link UdiEvent} objects deleted.
 */
public int cleanup(LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("DELETE FROM UdiEvent ue ");
    sql.append("WHERE ue.period = :period)");

    return entityManager.createQuery(sql.toString()).setParameter("period", period.toDateMidnight().toDate())
            .executeUpdate();
}

From source file:energy.usef.agr.repository.UdiRepository.java

License:Apache License

/**
 * Finds the Udis which are part of the portfolio on the given period.
 *
 * @param period {@link LocalDate} period.
 * @return a {@link List} of {@link Udi} entities.
 *///from  w ww  .j  ava  2  s  . c  o m
public Map<String, Udi> findActiveUdisMappedPerEndpoint(LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT udi ");
    sql.append("FROM Udi udi ");
    sql.append("WHERE udi.validFrom <= :period AND udi.validUntil > :period ");

    return getEntityManager().createQuery(sql.toString(), Udi.class)
            .setParameter("period", period.toDateMidnight().toDate(), TemporalType.DATE).getResultList()
            .stream().collect(Collectors.toMap(Udi::getEndpoint, Function.identity()));
}

From source file:energy.usef.agr.repository.UdiRepository.java

License:Apache License

/**
 * Finds the Udis which are part of the portfolio on the given period.
 * Grouped per Connection./*from w w  w  . ja  va 2  s.  c o  m*/
 *
 * @param period the given period.
 * @param connectionEntityList An optional {@link List} of connection entity addresses. Null if not applicable.
 * @return List of {@link Udi} mapped per {@link Connection}.
 */
public Map<Connection, List<Udi>> findActiveUdisPerConnection(LocalDate period,
        Optional<List<String>> connectionEntityList) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT DISTINCT udi FROM Udi udi ");
    sql.append(" JOIN udi.connection conn, ConnectionGroupState cgs ");
    sql.append("WHERE conn.entityAddress = cgs.connection.entityAddress ");
    sql.append(" AND udi.validFrom <= :period AND udi.validUntil > :period ");
    sql.append("  AND cgs.validFrom <= :period AND cgs.validUntil > :period ");
    if (connectionEntityList.isPresent()) {
        sql.append("  AND conn.entityAddress IN :connectionList ");
    }

    TypedQuery<Udi> query = getEntityManager().createQuery(sql.toString(), Udi.class).setParameter("period",
            period.toDateMidnight().toDate(), TemporalType.DATE);

    if (connectionEntityList.isPresent()) {
        query.setParameter("connectionList", connectionEntityList.get());
    }

    return query.getResultList().stream().collect(Collectors.groupingBy(Udi::getConnection));
}

From source file:energy.usef.agr.repository.UdiRepository.java

License:Apache License

/**
 * Finds a Udi by its endpoint.//from ww w  .j a v  a  2s.c  o  m
 *
 * @param udiEndpoint {@link String} the endpoint of the Udi.
 * @return a {@link Udi} entity or <code>null</code> if none or multiple exist.
 */
public Udi findByEndpoint(String udiEndpoint, LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT udi ");
    sql.append("FROM Udi udi ");
    sql.append("WHERE udi.endpoint = :endpoint ");
    sql.append(" AND udi.validFrom <= :period AND udi.validUntil > :period ");
    List<Udi> udis = getEntityManager().createQuery(sql.toString(), Udi.class)
            .setParameter("endpoint", udiEndpoint)
            .setParameter("period", period.toDateMidnight().toDate(), TemporalType.DATE).getResultList();
    if (udis.size() != 1) {
        return null;
    }
    return udis.get(0);
}

From source file:energy.usef.agr.repository.UdiRepository.java

License:Apache License

/**
 * Delete all {@link Udi} objects for a certain date.
 *
 * @param period//from  w w w  . ja  v a  2s  . c  o  m
 * @return the number of {@link Udi} objects deleted.
 */
public int cleanup(LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("DELETE FROM Udi u ");
    sql.append("WHERE u.validUntil = :validUntil)");

    return entityManager.createQuery(sql.toString())
            .setParameter("validUntil", period.toDateMidnight().plusDays(1).toDate()).executeUpdate();
}

From source file:energy.usef.core.repository.BrpConnectionGroupRepository.java

License:Apache License

/**
 * Finds all {@link BrpConnectionGroup} active for the specific time.
 *
 * @param date date time//  www .j av  a2  s.c o m
 * @return {@link BrpConnectionGroup} list
 */
public List<BrpConnectionGroup> findActiveBrpConnectionGroups(LocalDate date) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT DISTINCT cgs.connectionGroup ");
    sql.append("FROM ConnectionGroupState cgs JOIN TREAT(cgs.connectionGroup AS BrpConnectionGroup) ");
    sql.append("WHERE cgs.validFrom <= :date ");
    sql.append("AND cgs.validUntil > :date ");
    Query query = entityManager.createQuery(sql.toString());
    query.setParameter("date", date.toDateMidnight().toDate());

    @SuppressWarnings("unchecked")
    List<BrpConnectionGroup> results = query.getResultList();
    if (results == null) {
        results = new ArrayList<>();
    }
    return results;
}

From source file:energy.usef.core.repository.CongestionPointConnectionGroupRepository.java

License:Apache License

/**
 * Finds all {@link CongestionPointConnectionGroup} active for the specific time.
 *
 * @param date date time//w  w  w.j  a  v  a  2s.co m
 * @return {@link CongestionPointConnectionGroup} list
 */
public List<CongestionPointConnectionGroup> findActiveCongestionPointConnectionGroup(LocalDate date) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT DISTINCT cg ");
    sql.append("FROM ConnectionGroupState cgs ");
    sql.append("  JOIN cgs.connectionGroup cg ");
    sql.append("WHERE cgs.validFrom <= :date ");
    sql.append("  AND cgs.validUntil > :date ");
    sql.append("  AND TYPE(cg) = CongestionPointConnectionGroup ");

    return (List<CongestionPointConnectionGroup>) entityManager.createQuery(sql.toString())
            .setParameter("date", date.toDateMidnight().toDate(), TemporalType.DATE).getResultList();
}

From source file:energy.usef.core.repository.ConnectionGroupRepository.java

License:Apache License

/**
 * Finds all the ConnectionGroups related to the connectionAdresses for a specific time.
 *
 * @param connectionAddresses//from   ww  w .j  a  v  a  2 s.c  om
 * @param date {@link LocalDate} period of validity (usually a day).
 * @return a {@link List} of {@link ConnectionGroup}.
 */
public List<ConnectionGroup> findConnectionGroupsWithConnections(List<String> connectionAddresses,
        LocalDate date) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT cgs.connectionGroup FROM ConnectionGroupState cgs ");
    sql.append(" WHERE cgs.validFrom <= :date ");
    sql.append(" AND cgs.connection.entityAddress IN(:connectionAddresses) ");
    sql.append(" AND cgs.validUntil > :date ");
    return entityManager.createQuery(sql.toString(), ConnectionGroup.class)
            .setParameter("connectionAddresses", connectionAddresses)
            .setParameter("date", date.toDateMidnight().toDate(), TemporalType.DATE).getResultList();
}

From source file:energy.usef.core.repository.ConnectionGroupRepository.java

License:Apache License

/**
 * Finds all the ConnectionGroups which had connections for that dateTime.
 *
 * @param date {@link LocalDate} period of validity (usually a day).
 * @return a {@link List} of {@link ConnectionGroup}.
 *///from   ww w  .  j a  v  a2s.  c om
public List<ConnectionGroup> findAllForDateTime(LocalDate date) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT cgs.connectionGroup FROM ConnectionGroupState cgs ");
    sql.append("WHERE cgs.validFrom <= :date ");
    sql.append("  AND cgs.validUntil > :date ) ");
    return entityManager.createQuery(sql.toString(), ConnectionGroup.class)
            .setParameter("date", date.toDateMidnight().toDate()).getResultList();
}