List of usage examples for org.joda.time LocalDate toDate
@SuppressWarnings("deprecation") public Date toDate()
java.util.Date
. From source file:energy.usef.dso.repository.AggregatorOnConnectionGroupStateRepository.java
License:Apache License
/** * Finds all the {@link AggregatorOnConnectionGroupState} entities with a validUntil date equal to the specified date. * * @param usefIdentifier {@link String} USEF identifier of the {@link ConnectionGroup}. * @param initializationDate {@link LocalDate} date. * @return a {@link List} of {@link AggregatorOnConnectionGroupState}. *///from w w w .jav a 2s . com public List<AggregatorOnConnectionGroupState> findEndingAggregatorOnConnectionGroupStates(String usefIdentifier, LocalDate initializationDate) { StringBuilder sql = new StringBuilder(); sql.append("SELECT state "); sql.append("FROM AggregatorOnConnectionGroupState state "); sql.append("WHERE state.congestionPointConnectionGroup.usefIdentifier = :usefIdentifier "); sql.append(" AND state.validUntil = :date "); return getEntityManager().createQuery(sql.toString(), AggregatorOnConnectionGroupState.class) .setParameter("usefIdentifier", usefIdentifier) .setParameter("date", initializationDate.toDateMidnight().toDate(), TemporalType.DATE) .getResultList(); }
From source file:energy.usef.dso.repository.AggregatorOnConnectionGroupStateRepository.java
License:Apache License
/** * Finds the {@link AggregatorOnConnectionGroupState} entities with an overlap over the given period. * * @param startDate {@link LocalDate} start date of the period. * @param endDate {@link LocalDate} end date of the period (inclusive). * @return a {@link List} of {@link AggregatorOnConnectionGroupState}. */// w w w. j ava2s. c o m public List<AggregatorOnConnectionGroupState> findAggregatorsWithOverlappingActivityForPeriod( LocalDate startDate, LocalDate endDate) { StringBuilder sql = new StringBuilder(); sql.append("SELECT state "); sql.append("FROM AggregatorOnConnectionGroupState state "); sql.append(" JOIN FETCH state.aggregator a "); sql.append(" JOIN FETCH state.congestionPointConnectionGroup c "); sql.append("WHERE state.validFrom <= :endDate "); sql.append(" AND state.validUntil > :startDate "); // valid until of a state is an excluded upper bound, so it has to be strictly bigger than the start date. return getEntityManager().createQuery(sql.toString(), AggregatorOnConnectionGroupState.class) .setParameter("startDate", startDate.toDateMidnight().toDate(), TemporalType.DATE) .setParameter("endDate", endDate.toDateMidnight().toDate(), TemporalType.DATE).getResultList(); }
From source file:energy.usef.dso.repository.ConnectionMeterEventRepository.java
License:Apache License
/** * This method finds all ConnectionMeterEvents for a certain period that where active in that period. * * @param fromDate from date/* ww w . j a v a2s . c o m*/ * @param endDate end date * * @return connection meter event list */ @SuppressWarnings("unchecked") public List<ConnectionMeterEvent> findConnectionMeterEventsForPeriod(LocalDate fromDate, LocalDate endDate) { StringBuilder queryString = new StringBuilder(); queryString.append("SELECT cme FROM ConnectionMeterEvent cme "); queryString.append(" WHERE cme.dateTime >= :fromDate "); // it is inclusive because i add a day to the endDate queryString.append(" AND cme.dateTime < :endDate "); Query query = getEntityManager().createQuery(queryString.toString()); query.setParameter("fromDate", fromDate.toDateMidnight().toDateTime().toDate(), TemporalType.TIMESTAMP); query.setParameter("endDate", endDate.plusDays(1).toDateMidnight().toDateTime().toDate(), TemporalType.TIMESTAMP); return query.getResultList(); }
From source file:energy.usef.dso.repository.ConnectionMeterEventRepository.java
License:Apache License
/** * Finds connections not related to ConnectionMeterEvents. * /*from ww w.ja v a 2 s . com*/ * @param date date * @param connectionIncludeList connection include list * @return connection list */ public List<Connection> findConnectionsNotRelatedToConnectionMeterEvents(LocalDate date, List<String> connectionIncludeList) { StringBuilder sql = new StringBuilder(); sql.append("SELECT distinct cgs.connection FROM ConnectionGroupState cgs"); sql.append(" WHERE cgs.validFrom <= :startDate"); sql.append(" AND cgs.validUntil >= :startDate"); sql.append(" AND cgs.connection NOT IN "); sql.append( " (SELECT cme.connection FROM ConnectionMeterEvent cme WHERE cme.dateTime >= :startTime AND cme.dateTime < :endTime)"); sql.append(" AND cgs.connection.entityAddress IN :connectionIncludeList"); TypedQuery<Connection> query = entityManager.createQuery(sql.toString(), Connection.class); query.setParameter("startDate", date.toDateMidnight().toDate()); query.setParameter("startTime", date.toDateMidnight().toDateTime().toDate(), TemporalType.TIMESTAMP); query.setParameter("endTime", date.plusDays(1).toDateMidnight().toDateTime().toDate(), TemporalType.TIMESTAMP); query.setParameter("connectionIncludeList", connectionIncludeList); return query.getResultList(); }
From source file:energy.usef.dso.repository.ConnectionMeterEventRepository.java
License:Apache License
/** * This method finds a Connection for a given connection entity address and a certain period. * * @param entityAddress connection entity address * @param date date/*w w w . j ava2 s . c o m*/ * * @return connection if exists, null otherwise */ @SuppressWarnings("unchecked") public Connection findConnectionForConnectionMeterEventsPeriod(String entityAddress, LocalDate date) { StringBuilder queryString = new StringBuilder(); queryString.append("SELECT cme.connection FROM ConnectionMeterEvent cme "); queryString.append(" WHERE cme.dateTime >= :fromTime "); queryString.append(" AND cme.dateTime < :endTime "); queryString.append(" AND cme.connection.entityAddress = :entityAddress "); Query query = getEntityManager().createQuery(queryString.toString()); query.setParameter("fromTime", date.toDateMidnight().toDateTime().toDate(), TemporalType.TIMESTAMP); query.setParameter("endTime", date.plusDays(1).toDateMidnight().toDateTime().toDate(), TemporalType.TIMESTAMP); query.setParameter("entityAddress", entityAddress); List<Connection> connections = query.getResultList(); if (connections.isEmpty()) { return null; } return connections.get(0); }
From source file:energy.usef.dso.repository.GridSafetyAnalysisRepository.java
License:Apache License
/** * Finds the {@link GridSafetyAnalysis} entities for the given parameters with disposition requested for at least one of the * ptu's.//from w w w. ja v a 2 s . c om * * @param congestionPointEntityAddress {@link String} related Congestion Point entity address. * @param ptuDate {@link LocalDate} Period of the PTU. * @return a {@link List} of {@link GridSafetyAnalysis}. */ @SuppressWarnings("unchecked") public List<GridSafetyAnalysis> findGridSafetyAnalysisWithDispositionRequested( String congestionPointEntityAddress, LocalDate ptuDate) { StringBuilder subqueryExists = new StringBuilder(); subqueryExists.append("SELECT 1 "); subqueryExists.append("FROM GridSafetyAnalysis gsa2 "); subqueryExists.append("WHERE gsa2.connectionGroup.usefIdentifier = :entityAddress "); subqueryExists.append(" AND gsa2.ptuContainer.ptuDate = :ptuDate "); subqueryExists.append(" AND gsa2.disposition = :dispositionRequested "); StringBuilder sql = new StringBuilder(); sql.append("SELECT gsa "); sql.append("FROM GridSafetyAnalysis gsa "); sql.append("WHERE gsa.connectionGroup.usefIdentifier = :entityAddress "); sql.append(" AND gsa.ptuContainer.ptuDate = :ptuDate "); sql.append(" AND EXISTS (").append(subqueryExists).append(") "); sql.append("ORDER BY gsa.ptuContainer.ptuIndex"); return getEntityManager().createQuery(sql.toString()) .setParameter("entityAddress", congestionPointEntityAddress) .setParameter("ptuDate", ptuDate.toDateMidnight().toDate()) .setParameter("dispositionRequested", DispositionAvailableRequested.REQUESTED).getResultList(); }
From source file:energy.usef.dso.repository.GridSafetyAnalysisRepository.java
License:Apache License
/** * Finds the {@link GridSafetyAnalysis} entities for a given day. * * @param congestionPointEntityAddress {@link String} related Congestion Point entity address. * @param ptuDate {@link LocalDate} Period of the PTU. * @return a {@link List} of {@link GridSafetyAnalysis}. *//*from w w w. j ava 2 s . com*/ @SuppressWarnings("unchecked") public List<GridSafetyAnalysis> findGridSafetyAnalysis(String congestionPointEntityAddress, LocalDate ptuDate) { StringBuilder sql = new StringBuilder(); sql.append("SELECT gsa "); sql.append("FROM GridSafetyAnalysis gsa "); sql.append("WHERE gsa.connectionGroup.usefIdentifier = :entityAddress "); sql.append(" AND gsa.ptuContainer.ptuDate = :ptuDate "); sql.append("ORDER BY gsa.ptuContainer.ptuIndex"); return getEntityManager().createQuery(sql.toString()) .setParameter("entityAddress", congestionPointEntityAddress) .setParameter("ptuDate", ptuDate.toDateMidnight().toDate()).getResultList(); }
From source file:energy.usef.dso.repository.GridSafetyAnalysisRepository.java
License:Apache License
/** * Finds the {@link GridSafetyAnalysis} entities used in calculations to find optimal flex offer combinations required * to place flex orders./* www . j a va2 s. c o m*/ * * @param currentDate current date * @return a {@link List} of {@link GridSafetyAnalysis}. */ @SuppressWarnings("unchecked") public List<GridSafetyAnalysis> findGridSafetyAnalysisRelatedToFlexOffers(LocalDate currentDate) { // Include the GridSafetyAnalysis only if there are FlexOffers that are ACCEPTED for the ConnectionGroup on that date. StringBuilder subqueryInPtuDates = new StringBuilder(); subqueryInPtuDates.append("SELECT pbm1.period FROM PlanboardMessage pbm1 "); subqueryInPtuDates.append("WHERE pbm1.documentType = :documentType "); subqueryInPtuDates.append("AND pbm1.documentStatus = :acceptedDocumentStatus "); subqueryInPtuDates.append("AND pbm1.connectionGroup.usefIdentifier = gsa.connectionGroup.usefIdentifier "); // Exclude the GridSafetyAnalysis if there are FlexOffers that are already PROCESSED for the ConnectionGroup on that date. StringBuilder subqueryNotInPtuDates = new StringBuilder(); subqueryNotInPtuDates.append("SELECT pbm2.period FROM PlanboardMessage pbm2 "); subqueryNotInPtuDates.append("WHERE pbm2.documentType = :documentType "); subqueryNotInPtuDates.append("AND pbm2.documentStatus = :processedDocumentStatus "); subqueryNotInPtuDates .append("AND pbm2.connectionGroup.usefIdentifier = gsa.connectionGroup.usefIdentifier "); StringBuilder sql = new StringBuilder(); sql.append("SELECT gsa "); sql.append("FROM GridSafetyAnalysis gsa "); sql.append("WHERE gsa.ptuContainer.ptuDate IN (").append(subqueryInPtuDates).append(") "); sql.append("AND gsa.ptuContainer.ptuDate NOT IN (").append(subqueryNotInPtuDates).append(") "); sql.append("AND gsa.ptuContainer.ptuDate >= :currentDate "); return getEntityManager().createQuery(sql.toString()).setParameter("documentType", DocumentType.FLEX_OFFER) .setParameter("acceptedDocumentStatus", DocumentStatus.ACCEPTED) .setParameter("processedDocumentStatus", DocumentStatus.PROCESSED) .setParameter("currentDate", currentDate.toDateMidnight().toDate()).getResultList(); }
From source file:energy.usef.dso.repository.GridSafetyAnalysisRepository.java
License:Apache License
/** * Delete all {@link GridSafetyAnalysis} objects for a certain date. * * @param period/*from w w w.j a va 2s . c om*/ * @return the number of {@link GridSafetyAnalysis} objects deleted. */ public int cleanup(LocalDate period) { StringBuilder sql = new StringBuilder(); sql.append("DELETE FROM GridSafetyAnalysis gsa "); sql.append("WHERE gsa.ptuContainer IN (SELECT pc FROM PtuContainer pc WHERE pc.ptuDate = :ptuDate)"); return entityManager.createQuery(sql.toString()).setParameter("ptuDate", period.toDateMidnight().toDate()) .executeUpdate(); }
From source file:energy.usef.dso.repository.GridSafetyAnalysisRepository.java
License:Apache License
/** * Delete all {@link GridSafetyAnalysis} objects for a certain date and congestion point. * * @param entityAddress//from w w w . j a v a2 s. co m * @param period */ public int deletePreviousGridSafetyAnalysis(String entityAddress, LocalDate period) { StringBuilder sql = new StringBuilder(); sql.append("DELETE FROM GridSafetyAnalysis gsa "); sql.append("WHERE gsa.connectionGroup.usefIdentifier = :entityAddress "); sql.append("AND gsa.ptuContainer IN (SELECT pc FROM PtuContainer pc WHERE pc.ptuDate = :ptuDate)"); return getEntityManager().createQuery(sql.toString()).setParameter("entityAddress", entityAddress) .setParameter("ptuDate", period.toDateMidnight().toDate()).executeUpdate(); }