Package energy.eddie.dataneeds.services
Class DataNeedsDbService
java.lang.Object
energy.eddie.dataneeds.services.DataNeedsDbService
- All Implemented Interfaces:
DataNeedsService
@Component
@ConditionalOnProperty(value="eddie.data-needs-config.data-need-source",
havingValue="DATABASE")
public class DataNeedsDbService
extends Object
implements DataNeedsService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteById(String id) voidenableOrDisableDataNeed(String id, boolean isEnabled) Enables or disables a data need.booleanexistsById(String id) findAll()Returns a list of all data needs saved in the database.Fetches the data need with the passed ID from the underlying persistence layer.Gets a data need by its id.Returns a list of all data needs with only their name and ID.static <T> TinitializeAndUnproxy(T entity) Hibernate always responds with a proxy object instead of the actual implementation.saveNewDataNeed(DataNeed newDataNeed) Saves the new data need in the database and sets a UUID asDataNeed.id().
-
Constructor Details
-
DataNeedsDbService
-
-
Method Details
-
initializeAndUnproxy
public static <T> T initializeAndUnproxy(T entity) Hibernate always responds with a proxy object instead of the actual implementation. That way it is possible to lazily load parts of the object, but a proxy is not part of the inheritance tree, making it impossible to use theinstanceofoperator. This method unpacks the hibernate proxy to its actual implementation.- Type Parameters:
T- The type of the object to unproxy- Parameters:
entity- The object to unproxy- Returns:
- the actual object and not the proxy
-
getDataNeedIdsAndNames
Description copied from interface:DataNeedsServiceReturns a list of all data needs with only their name and ID.- Specified by:
getDataNeedIdsAndNamesin interfaceDataNeedsService
-
findById
Description copied from interface:DataNeedsServiceFetches the data need with the passed ID from the underlying persistence layer.- Specified by:
findByIdin interfaceDataNeedsService- Parameters:
id- The ID of the data need to get.- Returns:
- The data need or an empty Optional if there is no data need with the given ID.
-
getById
Description copied from interface:DataNeedsServiceGets a data need by its id. If it cannot be found throwsEntityNotFoundException. Should only be used when sure that the data need exists- Specified by:
getByIdin interfaceDataNeedsService- Parameters:
id- The ID of the data need to get.- Returns:
- the data need
-
enableOrDisableDataNeed
Enables or disables a data need.- Parameters:
id- The ID of the data need to enable or disable.isEnabled- If the data need should be enabled or disabled.
-
saveNewDataNeed
Saves the new data need in the database and sets a UUID asDataNeed.id().- Parameters:
newDataNeed- Data need to save in the database.- Returns:
- Persisted data need.
-
findAll
Returns a list of all data needs saved in the database. -
existsById
-
deleteById
-