3#ifndef OCPP_V2_DATABASE_HANDLER_HPP
4#define OCPP_V2_DATABASE_HANDLER_HPP
6#include "ocpp/v2/types.hpp"
9#include <ocpp/common/support_older_cpp_versions.hpp>
11#include <ocpp/common/database/database_connection.hpp>
12#include <ocpp/common/database/database_handler_common.hpp>
13#include <ocpp/v2/ocpp_types.hpp>
14#include <ocpp/v2/transaction.hpp>
16#include <everest/logging.hpp>
89 OperationalStatusEnum operational_status,
bool replace) = 0;
142 virtual std::unique_ptr<EnhancedTransaction>
transaction_get(
const int32_t evse_id) = 0;
153 const ChargingStateEnum charging_state) = 0;
170 const ChargingLimitSourceEnum charging_limit_source = ChargingLimitSourceEnum::CSO) = 0;
183 const std::optional<ClearChargingProfile>& criteria) = 0;
186 virtual std::vector<ReportedChargingProfile>
199 virtual ChargingLimitSourceEnum get_charging_limit_source_for_profile(
const int profile_id) = 0;
201 virtual std::unique_ptr<common::SQLiteStatementInterface> new_statement(
const std::string& sql) = 0;
206 void init_sql()
override;
208 void inintialize_enum_tables();
209 void init_enum_table_inner(
const std::string& table_name,
const int begin,
const int end,
210 std::function<std::string(
int)> conversion);
211 template <
typename T>
212 void init_enum_table(
const std::string& table_name, T begin, T end, std::function<std::string(T)> conversion);
216 void insert_availability(int32_t evse_id, int32_t connector_id, OperationalStatusEnum operational_status,
218 OperationalStatusEnum get_availability(int32_t evse_id, int32_t connector_id);
221 DatabaseHandler(std::unique_ptr<common::DatabaseConnectionInterface> database,
222 const fs::path& sql_migration_files_path);
238 bool replace)
override;
241 OperationalStatusEnum operational_status,
bool replace)
override;
250 const std::vector<v2::AuthorizationData>& local_authorization_list)
override;
263 std::unique_ptr<EnhancedTransaction>
transaction_get(
const int32_t evse_id)
override;
266 const ChargingStateEnum charging_state)
override;
273 const ChargingLimitSourceEnum charging_limit_source = ChargingLimitSourceEnum::CSO)
override;
278 const std::optional<ClearChargingProfile>& criteria)
override;
279 std::vector<ReportedChargingProfile>
285 ChargingLimitSourceEnum get_charging_limit_source_for_profile(
const int profile_id)
override;
287 std::unique_ptr<common::SQLiteStatementInterface> new_statement(
const std::string& sql)
override;
Contains a DateTime implementation that can parse and create RFC 3339 compatible strings.
Definition: types.hpp:109
Definition: database_handler_common.hpp:24
Definition: database_handler.hpp:27
virtual std::map< int32_t, std::vector< v2::ChargingProfile > > get_all_charging_profiles_group_by_evse()=0
Retrieves all ChargingProfiles grouped by EVSE ID.
virtual void delete_local_authorization_list_entry(const IdToken &id_token)=0
Deletes the authorization list entry with the given id_tag.
virtual int32_t get_local_authorization_list_version()=0
Returns the version in the AUTH_LIST_VERSION table.
virtual void transaction_metervalues_clear(const std::string &transaction_id)=0
Remove all metervalue entries linked to transaction with id transaction_id.
virtual int32_t get_local_authorization_list_number_of_entries()=0
Get the number of entries currently in the authorization list.
virtual void transaction_delete(const std::string &transaction_id)=0
Clear all the transactions from the TRANSACTIONS table.
virtual std::vector< MeterValue > transaction_metervalues_get_all(const std::string &transaction_id)=0
Get all metervalues linked to transaction with id transaction_id.
virtual void authorization_cache_insert_entry(const std::string &id_token_hash, const IdTokenInfo &id_token_info)=0
Inserts cache entry.
virtual void insert_or_update_local_authorization_list(const std::vector< v2::AuthorizationData > &local_authorization_list)=0
Inserts or updates a local authorization list entries local_authorization_list to the AUTH_LIST table...
virtual void delete_charging_profile_by_transaction_id(const std::string &transaction_id)=0
Deletes the profiles with the given transaction_id.
virtual void authorization_cache_clear()=0
Deletes all entries of the AUTH_CACHE table. Returns true if the operation was successful,...
virtual void transaction_update_id_token_sent(const std::string &transaction_id, bool id_token_sent)=0
Update the id_token_sent of the given transaction id in the database.
virtual OperationalStatusEnum get_evse_availability(int32_t evse_id)=0
Retrieve persisted operational settings for an EVSE.
virtual void clear_local_authorization_list()=0
Deletes all entries of the AUTH_LIST table.
virtual void authorization_cache_delete_expired_entries(std::optional< std::chrono::seconds > auth_cache_lifetime)=0
Removes all entries from the cache that have passed their expiry date or auth cache lifetime.
virtual void insert_or_update_local_authorization_list_entry(const IdToken &id_token, const IdTokenInfo &id_token_info)=0
Inserts or updates a local authorization list entry to the AUTH_LIST table.
virtual std::vector< ReportedChargingProfile > get_charging_profiles_matching_criteria(const std::optional< int32_t > evse_id, const ChargingProfileCriterion &criteria)=0
Get all profiles from table CHARGING_PROFILES matching profile_id or criteria.
virtual void insert_connector_availability(int32_t evse_id, int32_t connector_id, OperationalStatusEnum operational_status, bool replace)=0
Persist operational settings for a connector.
virtual std::optional< v2::IdTokenInfo > get_local_authorization_list_entry(const IdToken &id_token)=0
Returns the IdTagInfo of the given id_tag if it exists in the AUTH_LIST table, else std::nullopt.
virtual OperationalStatusEnum get_connector_availability(int32_t evse_id, int32_t connector_id)=0
Retrieve persisted operational settings for a connector.
virtual void transaction_insert(const EnhancedTransaction &transaction, int32_t evse_id)=0
Inserts a transaction with the given parameters to the TRANSACTIONS table.
virtual size_t authorization_cache_get_binary_size()=0
Get the binary size of the authorization cache table.
virtual void transaction_update_charging_state(const std::string &transaction_id, const ChargingStateEnum charging_state)=0
Update the charging state of the given transaction id in the database.
virtual std::vector< v2::ChargingProfile > get_charging_profiles_for_evse(const int evse_id)=0
Retrieves the charging profiles stored on evse_id.
virtual void insert_or_update_local_authorization_list_version(int32_t version)=0
Inserts or updates the given version in the AUTH_LIST_VERSION table.
virtual std::unique_ptr< EnhancedTransaction > transaction_get(const int32_t evse_id)=0
Gets a transaction from the database if one can be found using evse_id.
virtual bool clear_charging_profiles_matching_criteria(const std::optional< int32_t > profile_id, const std::optional< ClearChargingProfile > &criteria)=0
Deletes all profiles from table CHARGING_PROFILES matching profile_id or criteria.
virtual void insert_or_update_charging_profile(const int evse_id, const v2::ChargingProfile &profile, const ChargingLimitSourceEnum charging_limit_source=ChargingLimitSourceEnum::CSO)=0
charging profiles
virtual void authorization_cache_update_last_used(const std::string &id_token_hash)=0
Updates the last_used field in the entry.
virtual void insert_evse_availability(int32_t evse_id, OperationalStatusEnum operational_status, bool replace)=0
Persist operational settings for an EVSE.
virtual void insert_cs_availability(OperationalStatusEnum operational_status, bool replace)=0
Persist operational settings for the charging station.
virtual bool delete_charging_profile(const int profile_id)=0
Deletes the profile with the given profile_id.
virtual bool clear_charging_profiles()=0
Deletes all profiles from table CHARGING_PROFILES.
virtual void authorization_cache_delete_nr_of_oldest_entries(size_t nr_to_remove)=0
Removes up to nr_to_remove items from the cache starting from the least recently used.
virtual OperationalStatusEnum get_cs_availability()=0
Retrieve persisted operational settings for the charging station.
virtual std::optional< AuthorizationCacheEntry > authorization_cache_get_entry(const std::string &id_token_hash)=0
Gets cache entry for given id_token_hash if present.
virtual void authorization_cache_delete_entry(const std::string &id_token_hash)=0
Deletes the cache entry for the given id_token_hash.
virtual void transaction_update_seq_no(const std::string &transaction_id, int32_t seq_no)=0
Update the sequence number of the given transaction id in the database.
virtual std::vector< v2::ChargingProfile > get_all_charging_profiles()=0
Retrieves all ChargingProfiles.
virtual void transaction_metervalues_insert(const std::string &transaction_id, const MeterValue &meter_value)=0
Inserts a meter_value to the database linked to transaction with id transaction_id.
Definition: database_handler.hpp:204
std::optional< v2::IdTokenInfo > get_local_authorization_list_entry(const IdToken &id_token) override
Returns the IdTagInfo of the given id_tag if it exists in the AUTH_LIST table, else std::nullopt.
Definition: database_handler.cpp:328
std::vector< ReportedChargingProfile > get_charging_profiles_matching_criteria(const std::optional< int32_t > evse_id, const ChargingProfileCriterion &criteria) override
Get all profiles from table CHARGING_PROFILES matching profile_id or criteria.
Definition: database_handler.cpp:848
void authorization_cache_clear() override
Deletes all entries of the AUTH_CACHE table. Returns true if the operation was successful,...
Definition: database_handler.cpp:194
std::optional< AuthorizationCacheEntry > authorization_cache_get_entry(const std::string &id_token_hash) override
Gets cache entry for given id_token_hash if present.
Definition: database_handler.cpp:132
int32_t get_local_authorization_list_number_of_entries() override
Get the number of entries currently in the authorization list.
Definition: database_handler.cpp:355
virtual void insert_cs_availability(OperationalStatusEnum operational_status, bool replace) override
Persist operational settings for the charging station.
Definition: database_handler.cpp:602
bool delete_charging_profile(const int profile_id) override
Deletes the profile with the given profile_id.
Definition: database_handler.cpp:763
void transaction_update_charging_state(const std::string &transaction_id, const ChargingStateEnum charging_state) override
Update the charging state of the given transaction id in the database.
Definition: database_handler.cpp:698
size_t authorization_cache_get_binary_size() override
Get the binary size of the authorization cache table.
Definition: database_handler.cpp:200
void insert_or_update_local_authorization_list_entry(const IdToken &id_token, const IdTokenInfo &id_token_info) override
Inserts or updates a local authorization list entry to the AUTH_LIST table.
Definition: database_handler.cpp:280
virtual void insert_evse_availability(int32_t evse_id, OperationalStatusEnum operational_status, bool replace) override
Persist operational settings for an EVSE.
Definition: database_handler.cpp:610
void transaction_update_seq_no(const std::string &transaction_id, int32_t seq_no) override
Update the sequence number of the given transaction id in the database.
Definition: database_handler.cpp:686
void authorization_cache_update_last_used(const std::string &id_token_hash) override
Updates the last_used field in the entry.
Definition: database_handler.cpp:119
virtual std::map< int32_t, std::vector< v2::ChargingProfile > > get_all_charging_profiles_group_by_evse() override
Retrieves all ChargingProfiles grouped by EVSE ID.
Definition: database_handler.cpp:966
virtual OperationalStatusEnum get_connector_availability(int32_t evse_id, int32_t connector_id) override
Retrieve persisted operational settings for a connector.
Definition: database_handler.cpp:628
void authorization_cache_delete_entry(const std::string &id_token_hash) override
Deletes the cache entry for the given id_token_hash.
Definition: database_handler.cpp:151
bool clear_charging_profiles_matching_criteria(const std::optional< int32_t > profile_id, const std::optional< ClearChargingProfile > &criteria) override
Deletes all profiles from table CHARGING_PROFILES matching profile_id or criteria.
Definition: database_handler.cpp:789
void delete_local_authorization_list_entry(const IdToken &id_token) override
Deletes the authorization list entry with the given id_tag.
Definition: database_handler.cpp:317
virtual OperationalStatusEnum get_cs_availability() override
Retrieve persisted operational settings for the charging station.
Definition: database_handler.cpp:606
virtual OperationalStatusEnum get_evse_availability(int32_t evse_id) override
Retrieve persisted operational settings for an EVSE.
Definition: database_handler.cpp:616
std::unique_ptr< EnhancedTransaction > transaction_get(const int32_t evse_id) override
Gets a transaction from the database if one can be found using evse_id.
Definition: database_handler.cpp:657
void authorization_cache_delete_expired_entries(std::optional< std::chrono::seconds > auth_cache_lifetime) override
Removes all entries from the cache that have passed their expiry date or auth cache lifetime.
Definition: database_handler.cpp:174
std::vector< v2::ChargingProfile > get_all_charging_profiles() override
Retrieves all ChargingProfiles.
Definition: database_handler.cpp:951
std::vector< v2::ChargingProfile > get_charging_profiles_for_evse(const int evse_id) override
Retrieves the charging profiles stored on evse_id.
Definition: database_handler.cpp:934
void authorization_cache_insert_entry(const std::string &id_token_hash, const IdTokenInfo &id_token_info) override
Inserts cache entry.
Definition: database_handler.cpp:99
std::vector< MeterValue > transaction_metervalues_get_all(const std::string &transaction_id) override
Get all metervalues linked to transaction with id transaction_id.
Definition: database_handler.cpp:476
void transaction_update_id_token_sent(const std::string &transaction_id, bool id_token_sent) override
Update the id_token_sent of the given transaction id in the database.
Definition: database_handler.cpp:711
void clear_local_authorization_list() override
Deletes all entries of the AUTH_LIST table.
Definition: database_handler.cpp:348
void transaction_metervalues_clear(const std::string &transaction_id) override
Remove all metervalue entries linked to transaction with id transaction_id.
Definition: database_handler.cpp:569
void transaction_insert(const EnhancedTransaction &transaction, int32_t evse_id) override
Inserts a transaction with the given parameters to the TRANSACTIONS table.
Definition: database_handler.cpp:635
virtual void insert_connector_availability(int32_t evse_id, int32_t connector_id, OperationalStatusEnum operational_status, bool replace) override
Persist operational settings for a connector.
Definition: database_handler.cpp:621
void transaction_delete(const std::string &transaction_id) override
Clear all the transactions from the TRANSACTIONS table.
Definition: database_handler.cpp:723
int32_t get_local_authorization_list_version() override
Returns the version in the AUTH_LIST_VERSION table.
Definition: database_handler.cpp:268
void insert_or_update_charging_profile(const int evse_id, const v2::ChargingProfile &profile, const ChargingLimitSourceEnum charging_limit_source=ChargingLimitSourceEnum::CSO) override
charging profiles
Definition: database_handler.cpp:732
void authorization_cache_delete_nr_of_oldest_entries(size_t nr_to_remove) override
Removes up to nr_to_remove items from the cache starting from the least recently used.
Definition: database_handler.cpp:162
bool clear_charging_profiles() override
Deletes all profiles from table CHARGING_PROFILES.
Definition: database_handler.cpp:785
void transaction_metervalues_insert(const std::string &transaction_id, const MeterValue &meter_value) override
Inserts a meter_value to the database linked to transaction with id transaction_id.
Definition: database_handler.cpp:366
void delete_charging_profile_by_transaction_id(const std::string &transaction_id) override
Deletes the profiles with the given transaction_id.
Definition: database_handler.cpp:775
void insert_or_update_local_authorization_list_version(int32_t version) override
Inserts or updates the given version in the AUTH_LIST_VERSION table.
Definition: database_handler.cpp:256
void insert_or_update_local_authorization_list(const std::vector< v2::AuthorizationData > &local_authorization_list) override
Inserts or updates a local authorization list entries local_authorization_list to the AUTH_LIST table...
Helper class for retrieving authorization cache entries from the database.
Definition: database_handler.hpp:22
Definition: ocpp_types.hpp:219
Definition: ocpp_types.hpp:755
Struct that enhances the OCPP Transaction by some meta data and functionality.
Definition: transaction.hpp:16
Definition: ocpp_types.hpp:86
Definition: ocpp_types.hpp:36
Definition: ocpp_types.hpp:436