List of usage examples for org.joda.time LocalDate toDateMidnight
@Deprecated
public DateMidnight toDateMidnight()
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 . j a v a2 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//www. j ava 2 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 w w w .j a v a2 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// ww w . j a v a2 s. co 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} *///from w w w.ja v a2s . co 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. *//* ww w.j ava 2s .co 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 w w w .j ava 2 s . co m*/ * * @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//from ww w .j a va 2s. com * @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(); }
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}. *///from www . j av a 2s .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// w w w .ja va 2 s . c om * @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(); }