List of usage examples for org.joda.time LocalDate toDate
@SuppressWarnings("deprecation") public Date toDate()
java.util.Date
. 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 om * * @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 va 2 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(); }
From source file:energy.usef.core.repository.ConnectionGroupStateRepository.java
License:Apache License
/** * Finds connection group states./*from w w w.j a v a 2 s.co m*/ * * @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 w w w. j a v a2 s . co 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 ww .ja v a 2 s.c o m * * @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.//from w w w. j a v a 2s. c om */ 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 w w w . j a va 2 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 ww .java2s . co 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//www. j ava 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// ww w .j a va 2 s .co 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(); }