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.model.Udi.java

License:Apache License

public void setValidFrom(LocalDate validFrom) {
    if (validFrom == null) {
        this.validFrom = null;
    } else {//from  w w  w .jav a 2s .co m
        this.validFrom = validFrom.toDateMidnight().toDate();
    }
}

From source file:energy.usef.agr.model.Udi.java

License:Apache License

public void setValidUntil(LocalDate validUntil) {
    if (validUntil == null) {
        this.validUntil = null;
    } else {//from   www.j  ava2s.  c  o m
        this.validUntil = validUntil.toDateMidnight().toDate();
    }
}

From source file:energy.usef.agr.repository.device.capability.DeviceCapabilityRepository.java

License:Apache License

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

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

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

License:Apache License

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

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

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

License:Apache License

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

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

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

License:Apache License

/**
 * Finds the Elements which are related to active {@link Connection}.
 *
 * @param period/*from  w w w.j  a  va  2  s  .  c o  m*/
 * @return
 */
public List<Element> findActiveElementsForPeriod(LocalDate period) {
    StringBuilder queryString = new StringBuilder();
    queryString.append("SELECT DISTINCT e FROM Element e, ConnectionGroupState cgs ");
    queryString.append("WHERE e.connectionEntityAddress = cgs.connection.entityAddress ");
    queryString.append("AND cgs.validFrom <= :period AND cgs.validUntil > :period ");

    return entityManager.createQuery(queryString.toString(), Element.class)
            .setParameter("period", period.toDateMidnight().toDate(), TemporalType.DATE).getResultList();
}

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

License:Apache License

/**
 * Find all {@link PowerContainer}'s for a period on the {@link ConnectionGroup} Level.
 * Possible to filter for a specific {@link ConnectionGroup}.
 *
 * @param period                  the given period.
 * @param optionalConnectionGroup Optional {@link ConnectionGroup}
 * @return List of {@link PowerContainer} objects mapped per {@link ConnectionGroup}
 *//*  ww w  .ja  va  2 s .  c o m*/
public Map<ConnectionGroup, List<PowerContainer>> findConnectionGroupPowerContainers(LocalDate period,
        Optional<ConnectionGroup> optionalConnectionGroup) {
    StringBuilder queryString = new StringBuilder("SELECT cgpc FROM ConnectionGroupPowerContainer cgpc ");
    queryString.append(" WHERE cgpc.connectionGroup.usefIdentifier IN ");
    queryString.append(buildFindActiveConnectionGroups(optionalConnectionGroup));
    queryString.append(" AND cgpc.period = :period ");

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

    if (optionalConnectionGroup.isPresent()) {
        query.setParameter(USEF_IDENTIFIER, optionalConnectionGroup.get().getUsefIdentifier());
    }

    return query.getResultList().stream().collect(Collectors.groupingBy(
            powerContainer -> ((ConnectionGroupPowerContainer) powerContainer).getConnectionGroup()));
}

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

License:Apache License

/**
 * Finds all {@link PowerContainer}'s for a period and a list of connection entity addresses, grouped by Connection.
 *
 * @param period               The period for which this should be done.
 * @param connectionEntityList An {@link List} of connection entity addresses, null if not applicable.
 * @param connectionGroup      The {@link ConnectionGroup}, if applicable.
 * @return A {@link Map} with the {@link Connection} mapped to a list of {@link PowerContainer} objects.
 *///from  w  w w .j  a  va2s . c o  m
public Map<Connection, List<PowerContainer>> findConnectionPowerContainers(LocalDate period,
        Optional<List<String>> connectionEntityList, Optional<ConnectionGroup> connectionGroup) {

    StringBuilder queryString = new StringBuilder();
    queryString.append("SELECT DISTINCT cpc FROM ConnectionPowerContainer cpc ");
    queryString.append("  JOIN FETCH cpc.connection conn, ConnectionGroupState cgs ");
    queryString.append("WHERE conn.entityAddress = cgs.connection.entityAddress ");
    queryString.append("  AND cpc.period = :period ");
    queryString.append("  AND cgs.validFrom <= :period AND cgs.validUntil > :period ");
    if (connectionEntityList.isPresent()) {
        queryString.append("AND conn.entityAddress IN :connectionList ");
    }
    if (connectionGroup.isPresent()) {
        queryString.append("AND cgs.connectionGroup.usefIdentifier = :usefIdentifier ");
    }

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

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

    return query.getResultList().stream().collect(Collectors
            .groupingBy(powerContainer -> ((ConnectionPowerContainer) powerContainer).getConnection()));
}

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

License:Apache License

/**
 * Finds all {@link PowerContainer}'s for the UDI level for the current period and optional connection entity address list,
 * grouped by Udi./*from   ww w .ja va 2 s . com*/
 *
 * @param period               The period for which this should be done.
 * @param connectionEntityList A {@link List} of connection entity addresses, null if not applicable.
 * @param connectionGroup The {@link ConnectionGroup}, if applicable.
 * @return List of {@link PowerContainer} objects mapped per {@link Udi}.
 */
public Map<Udi, List<PowerContainer>> findUdiPowerContainers(LocalDate period,
        Optional<List<String>> connectionEntityList, Optional<ConnectionGroup> connectionGroup) {
    StringBuilder queryString = new StringBuilder();
    queryString.append("SELECT DISTINCT upc FROM UdiPowerContainer upc JOIN FETCH upc.udi udi ");
    queryString.append(" JOIN udi.connection conn, ConnectionGroupState cgs ");
    queryString.append("WHERE conn.entityAddress = cgs.connection.entityAddress ");
    queryString.append("AND upc.period = :period ");
    queryString.append("AND cgs.validFrom <= :period AND cgs.validUntil > :period ");
    if (connectionEntityList.isPresent()) {
        queryString.append("AND conn.entityAddress IN :connectionList ");
    }
    if (connectionGroup.isPresent()) {
        queryString.append("AND cgs.connectionGroup.usefIdentifier = :usefIdentifier ");
    }

    TypedQuery<PowerContainer> query = getEntityManager()
            .createQuery(queryString.toString(), PowerContainer.class)
            .setParameter("period", period.toDateMidnight().toDate(), TemporalType.DATE);
    if (connectionEntityList.isPresent()) {
        query.setParameter("connectionList", connectionEntityList.get());
    }
    if (connectionGroup.isPresent()) {
        query.setParameter(USEF_IDENTIFIER, connectionGroup.get().getUsefIdentifier());
    }

    return query.getResultList().stream()
            .collect(Collectors.groupingBy(powerContainer -> ((UdiPowerContainer) powerContainer).getUdi()));
}

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

License:Apache License

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

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