Class JKDataAccessImpl
- All Implemented Interfaces:
 JKDataAccessService
- Direct Known Subclasses:
 H2DataAccess,JKOracleDataAccess,MysqlDataAccess
It includes features for executing SQL queries, managing transactions, and caching query results.
This class is designed to simplify database operations and enhance maintainability and performance in database-driven applications.
- Version:
 - 1.0
 - Author:
 - Dr. Jalal H. Kiswani
 
- 
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intRepresents the time duration, in milliseconds, for query execution acceptance.static final intRepresents the size of the buffer used for query log data storage.protected JKLoggerRepresents the logger for this class.static final intRepresents the maximum time duration, in milliseconds, allowed for query execution acceptance. - 
Constructor Summary
ConstructorsConstructorDescriptionThis method constructs a newJKDataAccessImplusing the default data source.JKDataAccessImpl(JKDataSource dataSource) This method constructs a newJKDataAccessImplusing the provided data source.JKDataAccessImpl(String dataSourcePrefix) This method constructs a newJKDataAccessImplusing the data source associated with the provided prefix. - 
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddQueryLog(String query, Instant startTimer, Instant endTimer) This method logs information about the execution of a database query.voidThis method begins a new database transaction.<T> TThis method executes a database operation defined by the providedJKCaller.This method executes a stored procedure or callable statement and returns a list of results.protected voidclose(Connection connection) This method is responsible for closing a JDBC Connection.protected voidThis method is responsible for closing aPreparedStatement.protected voidclose(PreparedStatement ps, Connection c) This method is responsible for closing both aPreparedStatementand a Connection.protected voidThis method is responsible for closing aResultSet.protected voidclose(ResultSet rs, PreparedStatement ps, Connection c) This method is responsible for closing aPreparedStatement,ResultSet, and a Connection.protected voidThis method is responsible for closing a Statement.voidcloseTransaction(boolean commit) This method closes the current database transaction, either committing or rolling it back based on the specified parameter.describeTable(String name) This method retrieves data about a database table and returns it as a map of column names to their corresponding data types.voidThis method drops a database table specified by its name.intThis method executes a database operation with the provided SQL statement and optional parameters.Object[]executeQueryAsArray(String query, Object... params) This method executes a SQL query and returns the result as an array of objects.executeQueryAsCachedRowSet(String query, Object... params) This method executes a database query and returns the result as aCachedRowSet.executeQueryAsIdValue(String query, Object... params) This method executes a database query and returns the result as a list ofJKDbIdValueobjects.executeQueryAsList(String query, Object... params) This method executes a query and returns the result as a List of rows, where each row is represented as a List of objects.executeQueryAsString(String query, Object... params) This method executes an SQL query and returns the result as a formatted string.executeQueryAsString(String query, String fieldSeparator, String recordsSepartor, Object... params) This method executes an SQL query and returns the result as a formatted string with custom separators.executeSingleOutputQuery(String query, Object... params) This method executes a database query that is expected to return a single value and retrieves that value.executeUpdate(JKUpdater updater) This method executes a database update operation using aJKUpdaterand returns the result.executeUpdate(JKUpdater updater, boolean ignoreRecordNotFoundException) This method executes an update operation using the providedJKUpdaterand allows for ignoring theJKRecordNotFoundException.executeUpdate(String sql, Object... objects) This method executes an SQL update statement with optional parameters and returns the result.<T> Tfind(String query, JKPopulator<T> populator, Object... params) This method executes an SQL query and maps the result to an object using a providedJKPopulator.<T> TfindAndCacheRecord(String key, String query, JKPopulator<T> populator, Object... params) This method executes an SQL query, maps the result to an object using a provided populator, and caches the mapped object using the specified table name.<T> TfindRecord(JKFinder finder) This method finds and retrieves a record from the database table based on the providedJKFindercriteria.<T> TfindRecord(JKFinder finder, String tableName, Object recordId) This method finds and retrieves a specific record from the specified database table using the providedJKFinderand record ID.static StringThis method retrieves the name of the caller method or class.protected ConnectionThis method is used to obtain a database connection from the configured data source.protected ConnectiongetConnection(boolean query) This method is used to obtain a database connection from the configured data source.protected JKDataSourceThis method returns theJKDataSourceinstance that is used for managing database connections in the context of this class.protected ObjectThis method retrieves the generated key from the givenPreparedStatement.<T> List<T>This method retrieves a list of objects based on the providedJKFindercriteria.<T> List<T>Gets the list.<T> List<T>getList(String query, JKPopulator<T> populator, Object... params) This method executes an SQL query and maps the result to a list of objects using a provided populator.<T> List<T>getListAndCache(String key, String query, JKPopulator<T> populator, Object... params) This method executes an SQL query, maps the result to a list of objects using a provided populator, and caches the result for future use.This method retrieves the next available ID for a specified table and field.This method retrieves the next available ID for a specified table and field based on a given condition.protected LonggetNextId(Connection connectoin, String tableName, String fieldName) This method is used to obtain the next available ID for a specific table and field in the database.protected LonggetNextId(Connection con, String tableName, String fieldName, String condition) This method is used to obtain the next available ID for a specific table and field in the database, based on the given condition.intgetRowsCount(String query, Object... params) This method retrieves the number of rows returned by a specified SQL query with optional parameters.This method retrieves the current system date and time from the database.booleanThis method checks whether the current instance is in an active transaction.booleanisTableExists(String tableName) This method checks whether the table with the provided name exists in the database or not.protected StringThis method loads and retrieves an SQL query or statement from a resource based on the provided key.protected PreparedStatementprepareQueryStatement(Connection connection, JKFinder finder) This method prepares aPreparedStatementfor executing a database query based on the criteria specified in the givenJKFinderinstance.protected PreparedStatementprepareQueryStatement(Connection connection, String sql, Object... params) This method is used to create a PreparedStatement for executing a parametric query with the provided SQL statement and parameters.protected PreparedStatementprepareStatement(Connection connection, boolean returnGeneratedKeys, JKUpdater updater) This method prepares aPreparedStatementfor executing SQL commands on the provided database connection.protected PreparedStatementprepareStatement(Connection connection, boolean returnGeneratedKeys, String sql, Object... params) This method prepares a PreparedStatement for executing a parametric SQL statement with the given SQL and parameters, optionally returning generated keys.protected PreparedStatementprepareStatement(Connection connection, String sql, Object... params) This method prepares a PreparedStatement for executing a parametric SQL statement with the given SQL and parameters.protected voidThis method prints the records from a ResultSet to the standard output stream (console).protected voidprintRecordResultSet(ResultSet rs, boolean all, PrintStream out) This method prints records from a ResultSet to a specified PrintStream.static voidThis method provides a way to clear the cache, removing all cached data and starting with an empty cache.voidThis method runs a SQL script from a specified file.protected PreparedStatementsetParams(PreparedStatement prepareStatement, Object... params) This method sets the parameters in aPreparedStatementbased on the provided parameter values.voidsetSession(JKSession session) This method is yet to be implemented (TBI).protected voidThis method writes a log entry with query information and execution duration.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.jk.data.dataaccess.core.JKDataAccessService
callAsSingleOutput, executeQueryAsDouble, executeQueryAsInteger, executeQueryAsListOfObjects, executeQueryAsListOfObjects, executeQueryAsLong, executeQueryAsMap, executeQueryAsRow, getTenantId 
- 
Field Details
- 
acceptedTimeInMillis
public static final int acceptedTimeInMillisRepresents the time duration, in milliseconds, for query execution acceptance.This constant represents accepted execution time for a query.
The value of this constant is retrieved from the application's configuration using the
JKConfigclass, specifically by calling theget()method to obtain an instance of the configuration, and then callingJKConfig.getPropertyAsInteger(String, int)to retrieve the configured value as an integer.If the configured property is not found or cannot be converted to an integer, a default value defined in
JKConstants.Databasewith the nameQUERY_EXEC_ACCEPTED_TIME_DEFAULTwill be used.- See Also:
 
 - 
maxAcceptedTimeInMillis
public static final int maxAcceptedTimeInMillisRepresents the maximum time duration, in milliseconds, allowed for query execution acceptance.This constant represents the upper limit of time within which a query execution is considered accepted.
The value of this constant is retrieved from the application's configuration using the
JKConfigclass, specifically by calling theget()method to obtain an instance of the configuration, and then callingJKConfig.getPropertyAsInteger(String, int)to retrieve the configured value as an integer.If the configured property is not found or cannot be converted to an integer, a default value defined in
JKConstants.Databasewith the nameQUERY_EXEC_MAX_TIME_DEFAULTwill be used.- See Also:
 
 - 
bufferSize
public static final int bufferSizeRepresents the size of the buffer used for query log data storage.This constant represents the size of the buffer used to store query log data.
It is retrieved from the application's configuration using the
JKConfigclass. Specifically, it is obtained by calling theget()method to obtain an instance of the configuration, and then callingJKConfig.getPropertyAsInteger(String, int)to retrieve the configured value as an integer.If the configured property is not found or cannot be converted to an integer, a default value defined in
JKConstants.Databasewith the nameQUERY_LOG_BUFFER_SIZE_DEFAULTwill be used.- See Also:
 
 - 
logger
Represents the logger for this class.This field holds an instance of the logger obtained from the
JKLoggerFactory. It is used for logging various messages and information related to the class.- See Also:
 
 
 - 
 - 
Constructor Details
- 
JKDataAccessImpl
public JKDataAccessImpl()This method constructs a newJKDataAccessImplusing the default data source. - 
JKDataAccessImpl
This method constructs a newJKDataAccessImplusing the data source associated with the provided prefix.- Parameters:
 dataSourcePrefix- Specifies the prefix associated with the data source.
 - 
JKDataAccessImpl
This method constructs a newJKDataAccessImplusing the provided data source.- Parameters:
 dataSource- Specifies the data source of this instance.
 
 - 
 - 
Method Details
- 
close
This method is responsible for closing a JDBC Connection.- Parameters:
 connection- Specifies the JDBC Connection to be closed.
 - 
close
This method is responsible for closing aPreparedStatement.- Parameters:
 ps- Specifies thePreparedStatementto be closed.
 - 
close
This method is responsible for closing both aPreparedStatementand a Connection.- Parameters:
 ps- Specifies thePreparedStatementto be closed.c- Specifies the JDBC Connection to be closed.
 - 
close
This method is responsible for closing aResultSet.- Parameters:
 rs- Specifies theResultSetto be closed.
 - 
close
This method is responsible for closing aPreparedStatement,ResultSet, and a Connection.- Parameters:
 rs- Specifies theResultSetto be closed.ps- Specifies thePreparedStatementto be closed.c- Specifies the JDBC Connection to be closed.
 - 
close
This method is responsible for closing a Statement.- Parameters:
 ps- Specifies the Statement to be closed.
 - 
executeQueryAsCachedRowSet
This method executes a database query and returns the result as aCachedRowSet.- Specified by:
 executeQueryAsCachedRowSetin interfaceJKDataAccessService- Parameters:
 query- Specifies the SQL query to execute.params- Specifies the optional parameters to bind to the query.- Returns:
 - the 
CachedRowSetcontaining the query results. 
 - 
executeQueryAsIdValue
This method executes a database query and returns the result as a list ofJKDbIdValueobjects.- Specified by:
 executeQueryAsIdValuein interfaceJKDataAccessService- Parameters:
 query- Specifies the SQL query to execute.params- Specifies the optional parameters to bind to the query.- Returns:
 - a list of 
JKDbIdValueobjects representing the query results 
 - 
executeQueryAsString
This method executes an SQL query and returns the result as a formatted string.- Specified by:
 executeQueryAsStringin interfaceJKDataAccessService- Parameters:
 query- Specifies the SQL query to execute.params- Specifies the optional parameters to be used in the SQL query.- Returns:
 - the formatted string representation of the query result.
 
 - 
executeQueryAsString
public String executeQueryAsString(String query, String fieldSeparator, String recordsSepartor, Object... params) This method executes an SQL query and returns the result as a formatted string with custom separators.- Specified by:
 executeQueryAsStringin interfaceJKDataAccessService- Parameters:
 query- Specifies the SQL query to execute.fieldSeparator- Specifies the separator used to separate fields in the result.recordsSepartor- Specifies the separator used to separate records in the result.params- Specifies the optional parameters to be used in the SQL query.- Returns:
 - the formatted string representation of the query result with custom separators.
 
 - 
executeUpdate
This method executes a database update operation using aJKUpdaterand returns the result.- Specified by:
 executeUpdatein interfaceJKDataAccessService- Parameters:
 updater- Specifies theJKUpdaterobject that defines the update operation.- Returns:
 - the result of the update operation, which can be a generated key or another relevant value.
 - Throws:
 JKDataAccessException
 - 
prepareStatement
protected PreparedStatement prepareStatement(Connection connection, boolean returnGeneratedKeys, JKUpdater updater) throws SQLException This method prepares aPreparedStatementfor executing SQL commands on the provided database connection. It offers the option to specify whether generated keys should be returned after execution.- Parameters:
 connection- Specifies the database connection on which thePreparedStatementwill be prepared.returnGeneratedKeys- Indicates whether to return generated keys after executing the SQL command (true) or not (false).updater- Specifies the updater.- Returns:
 - a 
PreparedStatementready for executing SQL commands. - Throws:
 SQLException- if a database access error occurs or the SQL command is invalid.
 - 
prepareQueryStatement
protected PreparedStatement prepareQueryStatement(Connection connection, JKFinder finder) throws SQLException This method prepares aPreparedStatementfor executing a database query based on the criteria specified in the givenJKFinderinstance.- Parameters:
 connection- Specifies the database connection on which thePreparedStatementwill be prepared.finder- Specifies theJKFinderinstance representing the query criteria.- Returns:
 - a 
PreparedStatementready for executing the database query. - Throws:
 SQLException- if a database access error occurs or the query is invalid.
 - 
executeUpdate
This method executes an update operation using the providedJKUpdaterand allows for ignoring theJKRecordNotFoundException.- Specified by:
 executeUpdatein interfaceJKDataAccessService- Parameters:
 updater- Specifies theJKUpdaterobject responsible for specifying the update operationignoreRecordNotFoundException- Indicates whether to ignore theJKRecordNotFoundExceptionif no records are affected by the update- Returns:
 - the generated key if applicable, or null.
 
 - 
execute
This method executes a database operation with the provided SQL statement and optional parameters.- Specified by:
 executein interfaceJKDataAccessService- Parameters:
 statement- Specifies the SQL statement to execute.params- Specifies the parameters to be bound to the SQL statement.- Returns:
 - the number of rows affected by the operation.
 - Throws:
 JKDataAccessException
 - 
executeQueryAsArray
This method executes a SQL query and returns the result as an array of objects.- Specified by:
 executeQueryAsArrayin interfaceJKDataAccessService- Parameters:
 query- Specifies the SQL query to execute.params- Specifies the optional parameters to be used in the query.- Returns:
 - an array of objects representing the result of the query.
 
 - 
executeQueryAsList
This method executes a query and returns the result as a List of rows, where each row is represented as a List of objects.- Specified by:
 executeQueryAsListin interfaceJKDataAccessService- Parameters:
 query- Specifies the SQL query to be executed.params- Specifies the optional parameters to be used in the query.- Returns:
 - the list of rows, where each row is represented as a List of Objects.
 
 - 
executeSingleOutputQuery
This method executes a database query that is expected to return a single value and retrieves that value.- Specified by:
 executeSingleOutputQueryin interfaceJKDataAccessService- Parameters:
 query- Specifies the SQL query to execute.params- Specifies the parameters to be bound to the SQL query.- Returns:
 - the single value returned by the query, or null if no value is found.
 
 - 
findRecord
This method finds and retrieves a record from the database table based on the providedJKFindercriteria.- Specified by:
 findRecordin interfaceJKDataAccessService- Type Parameters:
 T- Specifies the type of the record object.- Parameters:
 finder- Specifies theJKFinderinstance specifying the criteria for the record retrieval.- Returns:
 - the retrieved record as an object of type 
T, ornullif the record is not found. 
 - 
findRecord
This method finds and retrieves a specific record from the specified database table using the providedJKFinderand record ID.- Specified by:
 findRecordin interfaceJKDataAccessService- Type Parameters:
 T- Specifies the type of the record object.- Parameters:
 finder- Specifies theJKFinderinstance specifying the criteria for the record retrieval.tableName- Specifies the name of the database table from which to retrieve the record.recordId- Specifies the unique identifier of the record to be retrieved.- Returns:
 - the retrieved record as an object of type 
T, ornullif the record is not found. 
 - 
getConnection
This method is used to obtain a database connection from the configured data source.- Returns:
 - the database connection from the data source.
 
 - 
getConnection
This method is used to obtain a database connection from the configured data source.- Parameters:
 query- Indicates whether the connection will be used for executing a query (true) or not (false).- Returns:
 - the database connection from the data source.
 
 - 
getDataSource
This method returns theJKDataSourceinstance that is used for managing database connections in the context of this class.- Returns:
 - the 
JKDataSourceassociated with this class. 
 - 
getGeneratedKey
This method retrieves the generated key from the givenPreparedStatement.- Parameters:
 ps- Specifies thePreparedStatementfrom which to retrieve the generated key.- Returns:
 - the generated key value obtained from the executed
         
PreparedStatement - Throws:
 SQLException- if a database access error occurs or this method is called on a closed {PreparedStatement}
 - 
getNextId
protected Long getNextId(Connection connectoin, String tableName, String fieldName) throws JKDataAccessException This method is used to obtain the next available ID for a specific table and field in the database.- Parameters:
 connectoin- Specifies the database Connection to use for the query.tableName- Specifies the name of the database table from which to retrieve the next ID.fieldName- Specifies the name of the field in the table to which the ID belongs.- Returns:
 - the next available ID for the specified table and field, subject to the given condition.
 - Throws:
 JKDataAccessException- if data access operations fail, encounter issues, or are denied due to various reasons.
 - 
getNextId
This method is used to obtain the next available ID for a specific table and field in the database, based on the given condition.- Parameters:
 con- Specifies the database Connection to use for the query.tableName- Specifies the name of the database table from which to retrieve the next ID.fieldName- Specifies the name of the field in the table to which the ID belongs.condition- Specifies the condition to apply when determining the next available ID.- Returns:
 - the next available ID for the specified table and field, subject to the given condition.
 
 - 
getNextId
This method retrieves the next available ID for a specified table and field.- Specified by:
 getNextIdin interfaceJKDataAccessService- Parameters:
 tableName- Specifies the name of the database table.fieldName- Specifies the name of the field for which the next ID is needed.- Returns:
 - the next available ID for the specified table and field.
 
 - 
getNextId
This method retrieves the next available ID for a specified table and field based on a given condition.- Specified by:
 getNextIdin interfaceJKDataAccessService- Parameters:
 tableName- Specifies the name of the database table.fieldName- Specifies the name of the field for which the next ID is needed.condition- Specifies the condition that filters the records to determine the next ID.- Returns:
 - the next available ID for the specified table, field, and condition.
 
 - 
getRowsCount
This method retrieves the number of rows returned by a specified SQL query with optional parameters.- Specified by:
 getRowsCountin interfaceJKDataAccessService- Parameters:
 query- Specifies the SQL query for which row count is to be determined.params- Specifies the optional parameters to be used in the SQL query.- Returns:
 - the number of rows returned by the specified SQL query.
 
 - 
getSystemDate
This method retrieves the current system date and time from the database.- Specified by:
 getSystemDatein interfaceJKDataAccessService- Returns:
 - a 
Dateobject representing the current system date and time 
 - 
getList
This method retrieves a list of objects based on the providedJKFindercriteria.- Specified by:
 getListin interfaceJKDataAccessService- Type Parameters:
 T- Specifies the type of the record object.- Parameters:
 finder- Specifies theJKFinderinstance specifying the criteria for the record retrieval.- Returns:
 - a list of objects that match the criteria defined in the
         
JKFinder. 
 - 
getList
Gets the list.- Specified by:
 getListin interfaceJKDataAccessService- Type Parameters:
 T- the generic type- Parameters:
 finder- the finderkey- the key- Returns:
 - the list
 
 - 
prepareQueryStatement
protected PreparedStatement prepareQueryStatement(Connection connection, String sql, Object... params) throws SQLException This method is used to create a PreparedStatement for executing a parametric query with the provided SQL statement and parameters.- Parameters:
 connection- Specifies the database Connection to use for preparing the statement.sql- Specifies the SQL statement to prepare, with place-holders for parameters.params- Specifies the parameters to set in the prepared statement.- Returns:
 - a 
PreparedStatementready for executing the parametric query. - Throws:
 SQLException- if a database access error occurs or this method is called on a closed Connection.
 - 
prepareStatement
protected PreparedStatement prepareStatement(Connection connection, String sql, Object... params) throws SQLException This method prepares a PreparedStatement for executing a parametric SQL statement with the given SQL and parameters.- Parameters:
 connection- Specifies the database Connection to use for preparing the statement.sql- Specifies the SQL statement to prepare, with place-holders for parameters.params- Specifies the parameters to set in the prepared statement.- Returns:
 - a 
PreparedStatementready for executing the parametric SQL statement. - Throws:
 SQLException- if a database access error occurs or this method is called on a closed Connection.
 - 
prepareStatement
protected PreparedStatement prepareStatement(Connection connection, boolean returnGeneratedKeys, String sql, Object... params) throws SQLException This method prepares a PreparedStatement for executing a parametric SQL statement with the given SQL and parameters, optionally returning generated keys.- Parameters:
 connection- Specifies the database Connection to use for preparing the statement.returnGeneratedKeys- Indicates whether to return any auto-generated keys produced by the statement execution (true) or not (false).sql- Specifies the SQL statement to prepare, with place-holders for parameters.params- Specifies the parameters to set in the prepared statement.- Returns:
 - a 
PreparedStatementready for executing the parametric SQL statement. - Throws:
 SQLException- if a database access error occurs or this method is called on a closed Connection.
 - 
setParams
protected PreparedStatement setParams(PreparedStatement prepareStatement, Object... params) throws SQLException This method sets the parameters in aPreparedStatementbased on the provided parameter values.- Parameters:
 prepareStatement- Specifies thePreparedStatementin which to set the parameter values.params- Specifies the parameter values to set in thePreparedStatement.- Returns:
 - the same 
PreparedStatementwith parameters set. - Throws:
 SQLException- if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access error occurs;this method is called on a closedPreparedStatementorthe type of the given object is ambiguous.
 - 
printRecordResultSet
This method prints the records from a ResultSet to the standard output stream (console).- Parameters:
 rs- Specifies theResultSetcontaining the records to be printed.
 - 
printRecordResultSet
This method prints records from a ResultSet to a specified PrintStream.- Parameters:
 rs- Specifies theResultSetcontaining the records to be printed.all- Indicates whether to print all records or not.out- Specifies thePrintStreamto which records should be printed.
 - 
resetCache
public static void resetCache()This method provides a way to clear the cache, removing all cached data and starting with an empty cache. - 
runScript
This method runs a SQL script from a specified file.- Specified by:
 runScriptin interfaceJKDataAccessService- Parameters:
 fileName- Specifies the name of the file containing the SQL script to execute.
 - 
isTableExists
This method checks whether the table with the provided name exists in the database or not.- Specified by:
 isTableExistsin interfaceJKDataAccessService- Parameters:
 tableName- Specifies the table name in the database.- Returns:
 - true, if the table exists, false otherwise.
 
 - 
setSession
This method is yet to be implemented (TBI).- Parameters:
 session- Specifies the method parameter (TBI).
 - 
describeTable
This method retrieves data about a database table and returns it as a map of column names to their corresponding data types.- Specified by:
 describeTablein interfaceJKDataAccessService- Parameters:
 name- Specifies the name of the table to describe.- Returns:
 - the map containing column names as keys and their corresponding data types as values.
 
 - 
dropTable
This method drops a database table specified by its name.- Specified by:
 dropTablein interfaceJKDataAccessService- Parameters:
 tableName- Specifies the name of the table to drop.
 - 
executeUpdate
This method executes an SQL update statement with optional parameters and returns the result.- Specified by:
 executeUpdatein interfaceJKDataAccessService- Parameters:
 sql- Specifies the SQL update statement to execute.objects- Specifies an optional array of parameters to be used in the SQL statement.- Returns:
 - the object representing the result of the update operation.
 
 - 
find
This method executes an SQL query and maps the result to an object using a providedJKPopulator.- Specified by:
 findin interfaceJKDataAccessService- Type Parameters:
 T- Specifies the type of objects.- Parameters:
 query- Specifies the SQL query to execute.populator- Specifies theJKPopulatorinstance responsible for mapping the query result to an objectparams- Specifies the optional parameters to be used in the SQL query.- Returns:
 - an object resulting from the query execution and mapping.
 
 - 
getList
This method executes an SQL query and maps the result to a list of objects using a provided populator.- Specified by:
 getListin interfaceJKDataAccessService- Type Parameters:
 T- Specifies the type of objects.- Parameters:
 query- Specifies the SQL query to execute.populator- Specifies theJKPopulatorinstance responsible for mapping the query result to an object.params- Specifies the optional parameters to be used in the SQL query.- Returns:
 - the list of objects resulting from the query execution and mapping.
 
 - 
findAndCacheRecord
public <T> T findAndCacheRecord(String key, String query, JKPopulator<T> populator, Object... params) This method executes an SQL query, maps the result to an object using a provided populator, and caches the mapped object using the specified table name.- Specified by:
 findAndCacheRecordin interfaceJKDataAccessService- Type Parameters:
 T- Specifies the type of objects.- Parameters:
 key- Specifies the name of the table associated with the cached record.query- Specifies the SQL query to execute.populator- Specifies theJKPopulatorinstance responsible for mapping the query result to an object.params- Specifies the optional parameters to be used in the SQL query.- Returns:
 - an object resulting from the query execution and mapping, cached under the specified table name.
 
 - 
getListAndCache
public <T> List<T> getListAndCache(String key, String query, JKPopulator<T> populator, Object... params) This method executes an SQL query, maps the result to a list of objects using a provided populator, and caches the result for future use.- Specified by:
 getListAndCachein interfaceJKDataAccessService- Type Parameters:
 T- Specifies the type of objects.- Parameters:
 key- Specifies the name of the table associated with the query.query- Specifies the SQL query to execute.populator- Specifies theJKPopulatorinstance responsible for mapping the query result to an object.params- Specifies the optional parameters to be used in the SQL query.- Returns:
 - the list of objects resulting from the query execution and mapping.
 
 - 
beginTransaction
public void beginTransaction()This method begins a new database transaction.- Specified by:
 beginTransactionin interfaceJKDataAccessService
 - 
isInTransaction
public boolean isInTransaction()This method checks whether the current instance is in an active transaction.- Returns:
 - true, if the current instance is in an active transaction, false otherwise.
 
 - 
closeTransaction
public void closeTransaction(boolean commit) This method closes the current database transaction, either committing or rolling it back based on the specified parameter.- Specified by:
 closeTransactionin interfaceJKDataAccessService- Parameters:
 commit- Indicates whether the transaction will be committed (true), or if it will be rolled back (false).
 - 
addQueryLog
This method logs information about the execution of a database query.- Parameters:
 query- Specifies the SQL query being executed.startTimer- Specifies the time stamp when the query execution started.endTimer- Specifies the time stamp when the query execution finished.
 - 
getCaller
This method retrieves the name of the caller method or class.- Returns:
 - the string representing the name of the caller method or class.
 
 - 
writeLog
This method writes a log entry with query information and execution duration.- Parameters:
 query- Specifies the SQL query or operation to log.duration- Specifies the duration of query execution in milliseconds.caller- Specifies the name or context of the caller method or class.
 - 
call
This method executes a stored procedure or callable statement and returns a list of results.- Specified by:
 callin interfaceJKDataAccessService- Parameters:
 call- Specifies the name or identifier of the stored procedure to execute.params- Specifies the list of parameters to pass to the stored procedure.types- Specifies the list of parameter types corresponding to the parameters.- Returns:
 - a list of results returned by the stored procedure, or an empty list if no results are returned.
 
 - 
call
This method executes a database operation defined by the providedJKCaller.- Specified by:
 callin interfaceJKDataAccessService- Type Parameters:
 T- Specifies the type of the result returned by the database operation.- Parameters:
 caller- Specifies theJKCallerthat defines the database operation.- Returns:
 - the result of the database operation.
 
 - 
loadSql
This method loads and retrieves an SQL query or statement from a resource based on the provided key.- Parameters:
 sql- Specifies the key or identifier of the SQL query or statement to retrieve.- Returns:
 - the SQL query or statement as a string.
 
 
 -