Example usage for org.joda.time LocalDate toDateMidnight

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

Introduction

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

Prototype

@Deprecated
public DateMidnight toDateMidnight() 

Source Link

Document

Converts this LocalDate to a DateMidnight in the default time zone.

Usage

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.
 */// ww w.  ja  v  a2  s .c om
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   ww  w.  j  av a  2 s . c om
 *
 * @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./*w  w w .  j a  v  a  2  s .  co  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  .  j  a v a  2 s.c om
 * @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 a  2s. com*/
 * @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  . java2s.  c o  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   w  ww. java  2  s  .c o  m
 * @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}.
 *///w w  w  . ja v a  2s .co m
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();
}

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

License:Apache License

/**
 * Find connection group state.//from w  w w  .  j  a va2  s . c o m
 *
 * @param usefIdentifier USEF identifier
 * @param connectionEntityAddress connection entity address
 * @param period date
 * @return connection group state
 */
public ConnectionGroupState findConnectionGroupState(String usefIdentifier, String connectionEntityAddress,
        LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT cgs FROM ConnectionGroupState cgs ");
    sql.append("WHERE cgs.connectionGroup.usefIdentifier = :usefIdentifier ");
    sql.append("  AND cgs.connection.entityAddress = :connectionEntityAddress ");
    sql.append("  AND cgs.validFrom <= :date ");
    sql.append("  AND cgs.validUntil > :date ");

    TypedQuery<ConnectionGroupState> query = entityManager
            .createQuery(sql.toString(), ConnectionGroupState.class)
            .setParameter("usefIdentifier", usefIdentifier)
            .setParameter("connectionEntityAddress", connectionEntityAddress)
            .setParameter("date", period.toDateMidnight().toDate(), TemporalType.DATE);

    List<ConnectionGroupState> results = query.getResultList();
    if (results.size() == 1) {
        return results.get(0);
    }
    return null;
}

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

License:Apache License

/**
 * Find connection group state.//from w w w  . j  a  v a2  s .c o m
 *
 * @param usefIdentifier USEF identifier
 * @param period date
 * @return connection group state
 */
public List<ConnectionGroupState> findConnectionGroupStatesByUsefIdentifier(String usefIdentifier,
        LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT cgs FROM ConnectionGroupState cgs ");
    sql.append("WHERE cgs.connectionGroup.usefIdentifier = :usefIdentifier ");
    sql.append("  AND cgs.validFrom <= :date ");
    sql.append("  AND cgs.validUntil > :date ");

    TypedQuery<ConnectionGroupState> query = entityManager
            .createQuery(sql.toString(), ConnectionGroupState.class)
            .setParameter("usefIdentifier", usefIdentifier)
            .setParameter("date", period.toDateMidnight().toDate(), TemporalType.DATE);

    return query.getResultList();
}