Package com.jk.data.dataaccess.core
Interface JKDataAccessService
- All Known Implementing Classes:
H2DataAccess
,JKDataAccessImpl
,JKOracleDataAccess
,MysqlDataAccess
public interface JKDataAccessService
This interface defines methods for interacting with a database, executing
queries, and managing transactions.
- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
-
Method Summary
Modifier and TypeMethodDescriptionvoid
This method begins a new database transaction.<T> T
This method executes a database operation defined by the providedJKCaller
.This method executes a database stored procedure or function and returns the result as a list.default <T> T
This method executes a database stored procedure or function and returns a single output value.void
closeTransaction
(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.void
This method drops a database table specified by its name.int
This 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
.default double
executeQueryAsDouble
(String query, Object... params) This method executes an SQL query and returns the result as a double value.executeQueryAsIdValue
(String sql, Object... params) This method executes a database query and returns the result as a list ofJKDbIdValue
objects.default int
executeQueryAsInteger
(String query, Object... params) This method executes an SQL query and returns the result as an integer value.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.default <T> List<T>
executeQueryAsListOfObjects
(Class<T> clas, String query, Object... params) This method executes an SQL query and returns the result as a list of objects of the specified class.default <T> List<T>
executeQueryAsListOfObjects
(Class<T> clas, Map<String, Object> fieldsMapping, String query, Object... params) This method executes an SQL query and returns the result as a list of objects of the specified class.default long
executeQueryAsLong
(String query, Object... params) This method executes an SQL query and returns the result as a long value.executeQueryAsMap
(String sql, Object... params) This method executes a SQL query and returns the result as a map where keys are objects and values are of typeT
.default Object[]
executeQueryAsRow
(String query, Object... params) This method executes an SQL query and returns the result as an array representing a single row.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 aJKUpdater
and returns the result.executeUpdate
(JKUpdater updater, boolean ignoreRecordNotFoundException) This method executes an update operation using the providedJKUpdater
and allows for ignoring theJKRecordNotFoundException
.executeUpdate
(String sql, Object... objects) This method executes an SQL update statement with optional parameters and returns the result.<T> T
find
(String query, JKPopulator<T> populator, Object... params) This method executes an SQL query and maps the result to an object using a providedJKPopulator
.<T> T
findAndCacheRecord
(String tableName, 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> T
findRecord
(JKFinder finder) This method finds and retrieves a record from the database table based on the providedJKFinder
criteria.<T> T
findRecord
(JKFinder finder, String tableName, Object recordId) This method finds and retrieves a specific record from the specified database table using the providedJKFinder
and record ID.<T> List<T>
This method retrieves a list of objects based on the providedJKFinder
criteria.<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 tableName, 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.int
getRowsCount
(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.default String
This method gets the tenant identifier (ID).boolean
isTableExists
(String tableName) This method checks whether the table with the provided name exists in the database or not.void
This method runs a SQL script from a specified file.
-
Method Details
-
executeQueryAsCachedRowSet
This method executes a database query and returns the result as aCachedRowSet
.- Parameters:
query
- Specifies the SQL query to execute.params
- Specifies the optional parameters to bind to the query.- Returns:
- the
CachedRowSet
containing the query results.
-
executeQueryAsIdValue
This method executes a database query and returns the result as a list ofJKDbIdValue
objects.- Parameters:
sql
- Specifies the SQL query to execute.params
- Specifies the optional parameters to bind to the query.- Returns:
- a list of
JKDbIdValue
objects representing the query results
-
executeUpdate
This method executes a database update operation using aJKUpdater
and returns the result.- Parameters:
updater
- Specifies theJKUpdater
object that defines the update operation.- Returns:
- the result of the update operation, which can be a generated key or another relevant value.
-
execute
This method executes a database operation with the provided SQL statement and optional parameters.- Parameters:
sql
- 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.
-
executeSingleOutputQuery
This method executes a database query that is expected to return a single value and retrieves that value.- 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.
-
getNextId
This method retrieves the next available ID for a specified table and field.- 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.- 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.- 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.
-
executeQueryAsString
This method executes an SQL query and returns the result as a formatted string.- 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
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.- 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 an update operation using the providedJKUpdater
and allows for ignoring theJKRecordNotFoundException
.- Parameters:
updater
- Specifies theJKUpdater
object responsible for specifying the update operationignoreRecordNotFoundException
- Indicates whether to ignore theJKRecordNotFoundException
if no records are affected by the update- Returns:
- the generated key if applicable, or null.
-
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.- 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.
-
findRecord
This method finds and retrieves a specific record from the specified database table using the providedJKFinder
and record ID.- Type Parameters:
T
- Specifies the type of the record object.- Parameters:
finder
- Specifies theJKFinder
instance 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
, ornull
if the record is not found.
-
findRecord
This method finds and retrieves a record from the database table based on the providedJKFinder
criteria.- Type Parameters:
T
- Specifies the type of the record object.- Parameters:
finder
- Specifies theJKFinder
instance specifying the criteria for the record retrieval.- Returns:
- the retrieved record as an object of type
T
, ornull
if the record is not found.
-
getSystemDate
Date getSystemDate()This method retrieves the current system date and time from the database.- Returns:
- a
Date
object representing the current system date and time
-
getList
This method retrieves a list of objects based on the providedJKFinder
criteria.- Type Parameters:
T
- Specifies the type of the record object.- Parameters:
finder
- Specifies theJKFinder
instance specifying the criteria for the record retrieval.- Returns:
- a list of objects that match the criteria defined in the
JKFinder
.
-
getList
Gets the list.- Type Parameters:
T
- the generic type- Parameters:
finder
- the finderkey
- the key- Returns:
- the list
-
executeQueryAsArray
This method executes a SQL query and returns the result as an array of objects.- 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.
-
isTableExists
This method checks whether the table with the provided name exists in the database or not.- Parameters:
tableName
- Specifies the table name in the database.- Returns:
- true, if the table exists, false otherwise.
-
runScript
This method runs a SQL script from a specified file.- Parameters:
fileName
- Specifies the name of the file containing the SQL script to execute.
-
dropTable
This method drops a database table specified by its name.- Parameters:
string
- Specifies the name of the table to drop.
-
executeUpdate
This method executes an SQL update statement with optional parameters and returns the result.- 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.
-
executeQueryAsLong
This method executes an SQL query and returns the result as a long value.- Parameters:
query
- Specifies the SQL query to execute.params
- Specifies the optional parameters to be used in the SQL query.- Returns:
- the result of the query as a long value.
-
executeQueryAsDouble
This method executes an SQL query and returns the result as a double value.- Parameters:
query
- Specifies the SQL query to execute.params
- Specifies the optional parameters to be used in the SQL query.- Returns:
- the result of the query as a double value.
-
executeQueryAsRow
This method executes an SQL query and returns the result as an array representing a single row.- Parameters:
query
- Specifies the SQL query to execute.params
- Specifies the optional parameters to be used in the SQL query.- Returns:
- an array representing a single row of the query result, or null if no rows were found.
-
executeQueryAsListOfObjects
This method executes an SQL query and returns the result as a list of objects of the specified class.- Type Parameters:
T
- Specifies the type of objects to be created and returned.- Parameters:
clas
- Specifies the class representing the type of objects to be created from the query result.query
- Specifies the SQL query to execute.params
- Specifies the optional parameters to be used in the SQL query.- Returns:
- a list of objects of the specified class representing the query result.
-
executeQueryAsListOfObjects
default <T> List<T> executeQueryAsListOfObjects(Class<T> clas, Map<String, Object> fieldsMapping, String query, Object... params) This method executes an SQL query and returns the result as a list of objects of the specified class.- Type Parameters:
T
- Specifies the type of objects to be created and returned.- Parameters:
clas
- Specifies the class representing the type of objects to be created from the query result.fieldsMapping
- Specifies a map that defines the mapping between field names in the query result and properties in the target class.query
- Specifies the SQL query to execute.params
- Specifies the optional parameters to be used in the SQL query.- Returns:
- the list of objects of the specified class representing the query result.
-
executeQueryAsInteger
This method executes an SQL query and returns the result as an integer value.- Parameters:
query
- Specifies the SQL query to execute.params
- Specifies the optional parameters to be used in the SQL query.- Returns:
- the integer representing the query result.
-
find
This method executes an SQL query and maps the result to an object using a providedJKPopulator
.- Type Parameters:
T
- Specifies the type of objects.- Parameters:
query
- Specifies the SQL query to execute.populator
- Specifies theJKPopulator
instance 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.
-
findAndCacheRecord
<T> T findAndCacheRecord(String tableName, 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.- Type Parameters:
T
- Specifies the type of objects.- Parameters:
tableName
- Specifies the name of the table associated with the cached record.query
- Specifies the SQL query to execute.populator
- Specifies theJKPopulator
instance 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.
-
getList
This method executes an SQL query and maps the result to a list of objects using a provided populator.- Type Parameters:
T
- Specifies the type of objects.- Parameters:
query
- Specifies the SQL query to execute.populator
- Specifies theJKPopulator
instance 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.
-
getListAndCache
<T> List<T> getListAndCache(String tableName, 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.- Type Parameters:
T
- Specifies the type of objects.- Parameters:
tableName
- Specifies the name of the table associated with the query.query
- Specifies the SQL query to execute.populator
- Specifies theJKPopulator
instance 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.
-
describeTable
This method retrieves data about a database table and returns it as a map of column names to their corresponding data types.- 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.
-
beginTransaction
void beginTransaction()This method begins a new database transaction. -
closeTransaction
void closeTransaction(boolean commit) This method closes the current database transaction, either committing or rolling it back based on the specified parameter.- Parameters:
commit
- Indicates whether the transaction will be committed (true), or if it will be rolled back (false).
-
executeQueryAsMap
This method executes a SQL query and returns the result as a map where keys are objects and values are of typeT
.- Type Parameters:
T
- Specifies the type of objects.- Parameters:
sql
- Specifies the SQL query to execute.params
- Specifies the optional parameters to be used in the SQL query- Returns:
- the map containing the query results with keys as objects and values
of type
T
.
-
getTenantId
This method gets the tenant identifier (ID).- Returns:
- the tenant identifier (ID).
-
call
This method executes a database stored procedure or function and returns the result as a list.- Parameters:
call
- Specifies the name of the stored procedure or function to call.params
- Specifies the parameters to pass to the stored procedure or function.outClasses
- Specifies the classes of the output parameters.- Returns:
- the list containing the result of the stored procedure or function execution.
-
callAsSingleOutput
This method executes a database stored procedure or function and returns a single output value.- Type Parameters:
T
- Specifies the type of the output value.- Parameters:
call
- Specifies the name of the stored procedure or function to call.params
- Specifies the parameters to pass to the stored procedure or function.outClasses
- Specifies the classes of the output parameters.- Returns:
- the single output value of the stored procedure or function execution.
-
call
This method executes a database operation defined by the providedJKCaller
.- Type Parameters:
T
- Specifies the type of the result returned by the database operation.- Parameters:
caller
- Specifies theJKCaller
that defines the database operation.- Returns:
- the result of the database operation.
-