Class AbstractRelationalDataOperator<T extends BaseDataEntity<String>>
java.lang.Object
com.ultikits.ultitools.interfaces.impl.data.AbstractRelationalDataOperator<T>
- Type Parameters:
T- the entity type
- All Implemented Interfaces:
DataOperator<T>
- Direct Known Subclasses:
MysqlDataOperator,SQLiteDataOperator
public abstract class AbstractRelationalDataOperator<T extends BaseDataEntity<String>>
extends Object
implements DataOperator<T>
Abstract base class for relational database data operators.
This class extracts common logic from MySQL and SQLite implementations, providing a unified implementation for CRUD operations. Only the database-specific SQL dialect differences need to be overridden.
- Since:
- 6.2.0
- Author:
- wisdomme
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classNested classes/interfaces inherited from interface com.ultikits.ultitools.interfaces.DataOperator
DataOperator.LikeType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DataSourceprivate static final com.google.gson.Gsonprivate static final Loggerprotected final org.apache.commons.dbutils.QueryRunnerprotected final Stringprotected TransactionManager -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractRelationalDataOperator(DataSource dataSource, Class<T> type) Creates a new data operator. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringbuildColumnDefinitions(Class<T> type) Builds the column definitions portion of CREATE TABLE.protected abstract StringcreateTableSqlFromClazz(Class<T> type) Creates the SQL statement to create the table.voiddel(WhereCondition... whereConditions) Delete data record by conditions.voidDelete data record by ID.booleanexist(WhereCondition... whereConditions) Check if the data record exists.booleanCheck if the data record exists.getAll()Get all data record.getAll(WhereCondition... whereConditions) Get all data record by conditions.Get data record by ID.getLike(String column, String value, DataOperator.LikeType likeType) Fuzzy Queryprivate voidInitializes the database table.voidInsert data record.voidInsert multiple entities atomically.page(int page, int size, WhereCondition... whereConditions) Get data record by page.voidsetTransactionManager(TransactionManager transactionManager) Sets the transaction manager for transaction-aware operations.voidtransaction(Runnable action) Execute operations within a transaction (void variant).<R> Rtransaction(Callable<R> action) Execute operations within a transaction.voidUpdate one field of one record.voidUpdate data record by object.voidUpdate multiple entities atomically.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.ultikits.ultitools.interfaces.DataOperator
query
-
Field Details
-
LOGGER
-
GSON
private static final com.google.gson.Gson GSON -
type
-
dataSource
-
tableName
-
queryRunner
protected final org.apache.commons.dbutils.QueryRunner queryRunner -
transactionManager
-
-
Constructor Details
-
AbstractRelationalDataOperator
Creates a new data operator.- Parameters:
dataSource- the data source to usetype- the entity class
-
-
Method Details
-
setTransactionManager
Sets the transaction manager for transaction-aware operations.- Parameters:
transactionManager- the transaction manager
-
initializeTable
private void initializeTable()Initializes the database table. -
getListHandler
-
exist
Description copied from interface:DataOperatorCheck if the data record exists.查询记录数据是否存在。
- Specified by:
existin interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
object- Data record entity
数据记录实体- Returns:
- Whether the record exists
记录是否存在
-
exist
Description copied from interface:DataOperatorCheck if the data record exists.使用条件查询记录是否存在
- Specified by:
existin interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
whereConditions- Conditions
条件参数- Returns:
- Whether the record exists
记录是否存在
-
getById
Description copied from interface:DataOperatorGet data record by ID.使用ID获取记录
- Specified by:
getByIdin interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
id- Record ID
记录ID- Returns:
- Data record
数据记录
-
getAll
Description copied from interface:DataOperatorGet all data record.查询所有记录
- Specified by:
getAllin interfaceDataOperator<T extends BaseDataEntity<String>>- Returns:
- Data record list
数据记录列表
-
getAll
Description copied from interface:DataOperatorGet all data record by conditions.查询所有符合条件的记录
- Specified by:
getAllin interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
whereConditions- Conditions
条件参数- Returns:
- Data record list
数据记录列表
-
getLike
Description copied from interface:DataOperatorFuzzy Query模糊查询
- Specified by:
getLikein interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
column- Column name
列名value- Query value
查询值likeType- Like type
模糊查询类型DataOperator.LikeType- Returns:
- Data record list
数据记录列表
-
page
Description copied from interface:DataOperatorGet data record by page.分页查询
- Specified by:
pagein interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
page- Page number
页码size- Page size
页大小whereConditions- Conditions
条件参数- Returns:
- Data record list
数据记录列表
-
insert
Description copied from interface:DataOperatorInsert data record.新增记录
- Specified by:
insertin interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
obj- Data record
数据记录
-
del
Description copied from interface:DataOperatorDelete data record by conditions.按照条件删除记录
- Specified by:
delin interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
whereConditions- Conditions
条件参数
-
delById
Description copied from interface:DataOperatorDelete data record by ID.按照ID删除记录
- Specified by:
delByIdin interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
id- Record ID
记录ID
-
update
Description copied from interface:DataOperatorUpdate one field of one record.更新某个记录的某个值
- Specified by:
updatein interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
column- Column name
列名value- New value
新值id- Record ID
记录ID
-
update
Description copied from interface:DataOperatorUpdate data record by object. It will not update the fields that the incoming entity does not have.使用实体更新记录。不会更新传入实体没有的字段。
- Specified by:
updatein interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
obj- Data record
数据记录- Throws:
IllegalAccessException- Please referIllegalAccessException
-
transaction
Description copied from interface:DataOperatorExecute operations within a transaction. All operations commit together or roll back on exception. For SQL backends, uses database transactions. For JSON, uses snapshot-based rollback.在事务中执行操作。所有操作一起提交或在异常时回滚。
- Specified by:
transactionin interfaceDataOperator<T extends BaseDataEntity<String>>- Type Parameters:
R- the return type- Parameters:
action- the operations to execute- Returns:
- the result of the action
- Throws:
Exception- if the action fails
-
transaction
Description copied from interface:DataOperatorExecute operations within a transaction (void variant).在事务中执行操作(无返回值)。
- Specified by:
transactionin interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
action- the operations to execute
-
insertAll
Description copied from interface:DataOperatorInsert multiple entities atomically. Uses JDBC batch for SQL backends.批量原子插入。SQL后端使用JDBC批处理。
- Specified by:
insertAllin interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
entities- the entities to insert
-
updateAll
Description copied from interface:DataOperatorUpdate multiple entities atomically. Uses JDBC batch for SQL backends.批量原子更新。SQL后端使用JDBC批处理。
- Specified by:
updateAllin interfaceDataOperator<T extends BaseDataEntity<String>>- Parameters:
entities- the entities to update- Throws:
IllegalAccessException- if field access fails
-
getColumnMappings
-
createTableSqlFromClazz
Creates the SQL statement to create the table.Override this method to customize table creation for different databases.
- Parameters:
type- the entity class- Returns:
- the CREATE TABLE SQL statement
-
buildColumnDefinitions
Builds the column definitions portion of CREATE TABLE.
-