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.core.repository.ConnectionGroupStateRepository.java

License:Apache License

/**
 * Finds connection group states.//w  ww  . j av  a  2  s  .c om
 *
 * @param connectionEntityAddress {@link String} entity address of the connection.
 * @param date {@link LocalDate} date of validity.
 * @return connection group state list
 */
public List<ConnectionGroupState> findConnectionGroupStates(String connectionEntityAddress, LocalDate date) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT cgs FROM ConnectionGroupState cgs ");
    sql.append("WHERE 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);
    query.setParameter("connectionEntityAddress", connectionEntityAddress);
    query.setParameter("date", date.toDateMidnight().toDate(), TemporalType.DATE);
    return query.getResultList();
}

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

License:Apache License

/**
 * Finds all the active connection groups at given moment.
 *
 * @param date {@link LocalDate}/*from  ww w  . j av a  2s  . c o  m*/
 * @param connectionGroupType {@link Class} optional type of {@link ConnectionGroup} wanted
 * @return a {@link java.util.List} of {@link ConnectionGroupState}
 */
@SuppressWarnings("unchecked")
public List<ConnectionGroupState> findActiveConnectionGroupStatesOfType(LocalDate date,
        Class<? extends ConnectionGroup> connectionGroupType) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT cgs ");
    sql.append("FROM ConnectionGroupState cgs ");
    sql.append("LEFT JOIN FETCH cgs.connectionGroup AS cg ");
    sql.append("WHERE cgs.validFrom <= :date ");
    sql.append("  AND cgs.validUntil > :date ");
    if (connectionGroupType != null) {
        sql.append("  AND TYPE(cg) = :connectionGroupType ");
    }
    Query query = entityManager.createQuery(sql.toString());
    query.setParameter("date", date.toDateMidnight().toDate(), TemporalType.DATE);
    if (connectionGroupType != null) {
        query.setParameter("connectionGroupType", connectionGroupType);
    }
    return query.getResultList();
}

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

License:Apache License

/**
 * Find ending connectionGroupStates.//  w w  w  .  ja v  a  2  s  .com
 *
 * @param endingDate date {@link LocalDate} period on which the Connection Group States are ending.
 * @param connectionGroupType {@link Class} type of ConnectionGroup one wants to retrieve.
 * @return a {@link List} of {@link ConnectionGroupState}.
 */
public List<ConnectionGroupState> findEndingConnectionGroupStates(LocalDate endingDate,
        Class<? extends ConnectionGroup> connectionGroupType) {
    StringBuilder sql = new StringBuilder();

    sql.append("SELECT cgs ");
    sql.append("FROM ConnectionGroupState cgs ");
    sql.append("  LEFT JOIN FETCH cgs.connectionGroup AS cg ");
    sql.append("WHERE cgs.validUntil = :endingDate ");
    sql.append("  AND TYPE(cg) = :connectionGroupType");

    return getEntityManager().createQuery(sql.toString(), ConnectionGroupState.class)
            .setParameter("endingDate", endingDate.toDateMidnight().toDate(), TemporalType.DATE)
            .setParameter("connectionGroupType", connectionGroupType).getResultList();
}

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

License:Apache License

/**
 * Finds the connections linked to a given list of connection group identifiers on a given period.
 *
 * @param connectionGroupIdentifiers {@link List} of {@link String} connection group usef identifiers.
 * @param period {@link LocalDate} period.
 * @return a {@link Map} of {@link ConnectionGroup} as key and {@link List} of {@link Connection} related to the connection
 * group./*w ww.j  a v a  2 s . c  o m*/
 */
public Map<ConnectionGroup, List<Connection>> findConnectionsWithConnectionGroups(
        List<String> connectionGroupIdentifiers, LocalDate period) {
    if (connectionGroupIdentifiers == null || connectionGroupIdentifiers.isEmpty()) {
        return new HashMap<>();
    }
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT cgs ");
    sql.append("FROM ConnectionGroupState cgs ");
    sql.append("  JOIN FETCH cgs.connectionGroup cg ");
    sql.append("  JOIN FETCH cgs.connection c ");
    sql.append("WHERE cgs.validFrom <= :date ");
    sql.append("  AND cgs.validUntil > :date ");
    sql.append("  AND cg.usefIdentifier IN :usefIdentifiers");
    List<ConnectionGroupState> connectionGroupStates = getEntityManager()
            .createQuery(sql.toString(), ConnectionGroupState.class)
            .setParameter("date", period.toDateMidnight().toDate(), TemporalType.DATE)
            .setParameter("usefIdentifiers", connectionGroupIdentifiers).getResultList();
    return connectionGroupStates.stream()
            .collect(Collectors.groupingBy(ConnectionGroupState::getConnectionGroup,
                    Collectors.mapping(ConnectionGroupState::getConnection, Collectors.toList())));
}

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

License:Apache License

/**
 * Finds the list of connection group states that were valid during the entire timeframe specified by startDate  and endDate.
 *
 * @param startDate {@link LocalDate} start date of validity.
 * @param endDate {@link LocalDate} end date of validity (inclusive)
 * @return a {@link List} of {@link ConnectionGroupState}.
 *///from www.  jav  a2 s  .c  o m
public List<ConnectionGroupState> findActiveConnectionGroupStates(LocalDate startDate, LocalDate endDate) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT cgs ");
    sql.append("FROM ConnectionGroupState cgs ");
    sql.append("  JOIN FETCH cgs.connectionGroup cg ");
    sql.append("  JOIN FETCH cgs.connection c ");
    sql.append("WHERE cgs.validFrom <= :startDate ");
    sql.append("  AND cgs.validUntil > :endDate ");
    return getEntityManager().createQuery(sql.toString(), ConnectionGroupState.class)
            .setParameter("startDate", startDate.toDateMidnight().toDate(), TemporalType.DATE)
            .setParameter("endDate", endDate.toDateMidnight().toDate(), TemporalType.DATE).getResultList();
}

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

License:Apache License

/**
 * Finds the list of connection group states which have an overlapping validity with the given period.
 *
 * @param startDate {@link LocalDate} start date of validity (inclusive).
 * @param endDate {@link LocalDate} end date of validity (inclusive).
 * @return a {@link List} of {@link ConnectionGroupState}.
 *//*from  w w w  . j  a v a2  s.c o  m*/
public List<ConnectionGroupState> findConnectionGroupStatesWithOverlappingValidity(LocalDate startDate,
        LocalDate endDate) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT cgs ");
    sql.append("FROM ConnectionGroupState cgs ");
    sql.append("  JOIN FETCH cgs.connectionGroup cg ");
    sql.append("  JOIN FETCH cgs.connection c ");
    sql.append("WHERE cgs.validFrom <= :endDate ");
    sql.append("  AND cgs.validUntil > :startDate ");
    // valid until of a CGS is an excluded upper bound, so it has to be strictly bigger than the start date.
    return getEntityManager().createQuery(sql.toString(), ConnectionGroupState.class)
            .setParameter("startDate", startDate.toDateMidnight().toDate(), TemporalType.DATE)
            .setParameter("endDate", endDate.toDateMidnight().toDate(), TemporalType.DATE).getResultList();
}

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

License:Apache License

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

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

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

License:Apache License

/**
 * Finds the list of connections for a moment in time.
 *
 * @param date period//from  w w w .jav a2s . c  o m
 * @param connectionEntityList (Optional) list of connection entity addresses
 * @return
 */
public List<Connection> findActiveConnections(LocalDate date, Optional<List<String>> connectionEntityList) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT distinct cgs.connection FROM ConnectionGroupState cgs ");
    sql.append(" WHERE cgs.validFrom <= :date ");
    sql.append(" AND cgs.validUntil > :date ");
    if (connectionEntityList.isPresent()) {
        sql.append(" AND cgs.connection.entityAddress IN :connectionList ");
    }
    TypedQuery<Connection> query = entityManager.createQuery(sql.toString(), Connection.class);
    query.setParameter("date", date.toDateMidnight().toDate());
    if (connectionEntityList.isPresent()) {
        query.setParameter("connectionList", connectionEntityList.get());
    }
    return query.getResultList();
}

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

License:Apache License

/**
 * Finds the connection count for a specified usef identifier at a given moment.
 *
 * @param usefIdentifier {@link String} usef identifier.
 * @param period {@link LocalDate} validity period.
 * @return a {@link Long}.//from   w  w  w .  j  av a2 s .com
 */
public Long findConnectionCountByUsefIdentifier(String usefIdentifier, LocalDate period) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT COUNT(cgs.connection) ");
    sql.append("FROM ConnectionGroupState cgs ");
    sql.append("WHERE cgs.validFrom <= :date ");
    sql.append(" AND cgs.connectionGroup.usefIdentifier = :usefIdentifier ");
    sql.append(" AND cgs.validUntil > :date ");
    return entityManager.createQuery(sql.toString(), Long.class).setParameter("usefIdentifier", usefIdentifier)
            .setParameter("date", period.toDateMidnight().toDate(), TemporalType.DATE).getSingleResult();
}

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

License:Apache License

/**
 * Find {@link Connection} per {@link ConnectionGroup}.
 *
 * @param usefIdentifier {@link String} usef identifier of the Connection group.
 * @param date {@link org.joda.time.LocalDateTime} validity time.
 * @return a {@link java.util.List} of {@link Connection}s.
 *///from   www . j av a  2  s  . c  o  m
public List<Connection> findConnectionsForConnectionGroup(String usefIdentifier, LocalDate date) {
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT cgs.connection FROM ConnectionGroupState cgs ");
    sql.append(" WHERE cgs.validFrom <= :date ");
    sql.append(" AND cgs.connectionGroup.usefIdentifier = :usefIdentifier");
    sql.append(" AND cgs.validUntil > :date ");
    return entityManager.createQuery(sql.toString(), Connection.class)
            .setParameter("date", date.toDateMidnight().toDate(), TemporalType.DATE)
            .setParameter("usefIdentifier", usefIdentifier).getResultList();

}