-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 3.5.2: Introduce DAO interfaces to clarify interface with dat…
…a layer.
- Loading branch information
Showing
20 changed files
with
262 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/org/keen/solar/financial/dal/PowerCostDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.keen.solar.financial.dal; | ||
|
||
import org.keen.solar.financial.domain.PowerCost; | ||
|
||
public interface PowerCostDao { | ||
|
||
/** | ||
* Persists the given PowerCost to the repository. | ||
*/ | ||
void save(PowerCost powerCost); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/keen/solar/financial/dal/PowerCostDaoSpringDataImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.keen.solar.financial.dal; | ||
|
||
import org.keen.solar.financial.domain.PowerCost; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class PowerCostDaoSpringDataImpl implements PowerCostDao { | ||
|
||
private final PowerCostRepository repository; | ||
|
||
public PowerCostDaoSpringDataImpl(PowerCostRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
|
||
@Override | ||
public void save(PowerCost powerCost) { | ||
repository.save(powerCost); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.keen.solar.financial.dal; | ||
|
||
import org.keen.solar.financial.domain.Tariff; | ||
|
||
import java.time.DayOfWeek; | ||
import java.time.LocalTime; | ||
|
||
public interface TariffDao { | ||
|
||
/** | ||
* Retrieves the feed-in tariff for the given day and time, effective | ||
* as at {@code epochTime}. | ||
* | ||
* @param dayOfWeek the day of the week to retrieve the tariff for | ||
* @param localTime the time of day to retrieve the tariff for | ||
* @param epochTime the epoch time that the tariff is effective for | ||
* @return the feed-in tariff | ||
*/ | ||
Tariff getEffectiveFeedInTariff(DayOfWeek dayOfWeek, LocalTime localTime, long epochTime); | ||
|
||
/** | ||
* Retrieves the usage tariff for the given day and time, effective | ||
* as at {@code epochTime}. | ||
* | ||
* @param dayOfWeek the day of the week to retrieve the tariff for | ||
* @param localTime the time of day to retrieve the tariff for | ||
* @param epochTime the epoch time that the tariff is effective for | ||
* @return the usage tariff | ||
*/ | ||
Tariff getEffectiveUsageTariff(DayOfWeek dayOfWeek, LocalTime localTime, long epochTime); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/keen/solar/financial/dal/TariffDaoSpringDataImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.keen.solar.financial.dal; | ||
|
||
import org.keen.solar.financial.domain.Tariff; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.DayOfWeek; | ||
import java.time.LocalTime; | ||
|
||
@Component | ||
public class TariffDaoSpringDataImpl implements TariffDao { | ||
|
||
private final TariffRepository repository; | ||
|
||
public TariffDaoSpringDataImpl(TariffRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
@Override | ||
public Tariff getEffectiveFeedInTariff(DayOfWeek dayOfWeek, LocalTime localTime, long epochTime) { | ||
return repository.findEffectiveFeedInTariff(dayOfWeek, localTime, epochTime); | ||
} | ||
|
||
@Override | ||
public Tariff getEffectiveUsageTariff(DayOfWeek dayOfWeek, LocalTime localTime, long epochTime) { | ||
return repository.findEffectiveUsageTariff(dayOfWeek, localTime, epochTime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/org/keen/solar/solcast/forecast/dal/ForecastDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.keen.solar.solcast.forecast.dal; | ||
|
||
import org.keen.solar.solcast.forecast.domain.GenerationForecast; | ||
|
||
import java.util.Collection; | ||
|
||
public interface ForecastDao { | ||
|
||
/** | ||
* Persists the given forecasts to the repository, updating them if they exist. | ||
*/ | ||
void save(Collection<GenerationForecast> forecasts); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/keen/solar/solcast/forecast/dal/ForecastDaoSpringDataImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.keen.solar.solcast.forecast.dal; | ||
|
||
import org.keen.solar.solcast.forecast.domain.GenerationForecast; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Collection; | ||
|
||
@Component | ||
public class ForecastDaoSpringDataImpl implements ForecastDao { | ||
|
||
private final ForecastRepository repository; | ||
|
||
public ForecastDaoSpringDataImpl(ForecastRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
@Override | ||
public void save(Collection<GenerationForecast> forecasts) { | ||
// Retrieve the id for any existing forecast for the same period so that it gets updated in the database, | ||
// rather than inserted. | ||
// Not particularly efficient, given that each forecast is retrieved individually from the database. | ||
// Spring Data JDBC doesn't provide a mechanism to write queries that take collections as parameters. | ||
forecasts.forEach(forecast -> { | ||
GenerationForecast existingForecast = repository.findByPeriodEnd(forecast.getPeriod_end_epoch()); | ||
if (existingForecast != null) { | ||
forecast.setId(existingForecast.getId()); | ||
} | ||
}); | ||
repository.saveAll(forecasts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/org/keen/solar/string/dal/StringPowerDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.keen.solar.string.dal; | ||
|
||
import org.keen.solar.string.domain.StringPower; | ||
|
||
public interface StringPowerDao { | ||
|
||
/** | ||
* Persists the given StringPower to the repository. | ||
*/ | ||
void save(StringPower stringPower); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/keen/solar/string/dal/StringPowerDaoSpringDataImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.keen.solar.string.dal; | ||
|
||
import org.keen.solar.string.domain.StringPower; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class StringPowerDaoSpringDataImpl implements StringPowerDao { | ||
|
||
private final StringPowerRepository repository; | ||
|
||
public StringPowerDaoSpringDataImpl(StringPowerRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
@Override | ||
public void save(StringPower stringPower) { | ||
repository.save(stringPower); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/org/keen/solar/system/dal/CurrentPowerDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.keen.solar.system.dal; | ||
|
||
import org.keen.solar.system.domain.CurrentPower; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public interface CurrentPowerDao { | ||
|
||
/** | ||
* Returns all CurrentPowers not yet uploaded to Solcast. | ||
*/ | ||
List<CurrentPower> getNotUploaded(); | ||
|
||
/** | ||
* Persists the given CurrentPower to the repository. | ||
*/ | ||
void save(CurrentPower currentPower); | ||
|
||
/** | ||
* Persists the given CurrentPowers to the repository. | ||
*/ | ||
void save(Collection<CurrentPower> currentPowers); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/keen/solar/system/dal/CurrentPowerDaoSpringDataImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.keen.solar.system.dal; | ||
|
||
import org.keen.solar.system.domain.CurrentPower; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
@Component | ||
public class CurrentPowerDaoSpringDataImpl implements CurrentPowerDao { | ||
|
||
private final CurrentPowerRepository repository; | ||
|
||
public CurrentPowerDaoSpringDataImpl(CurrentPowerRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
@Override | ||
public List<CurrentPower> getNotUploaded() { | ||
return repository.findByUploaded(false); | ||
} | ||
|
||
@Override | ||
public void save(CurrentPower currentPower) { | ||
repository.save(currentPower); | ||
} | ||
|
||
@Override | ||
public void save(Collection<CurrentPower> currentPowers) { | ||
repository.saveAll(currentPowers); | ||
} | ||
} |
Oops, something went wrong.