Class SimpleJsonDataOperator<T extends BaseDataEntity<String>>
java.lang.Object
com.ultikits.ultitools.interfaces.impl.data.json.SimpleJsonDataOperator<T>
- Type Parameters:
T- Data type inherited from BaseDataEntity (数据类型,继承自BaseDataEntity)
- All Implemented Interfaces:
Cached,DataOperator<T>
public class SimpleJsonDataOperator<T extends BaseDataEntity<String>>
extends Object
implements DataOperator<T>, Cached
Simple Json data operator.
简单Json存储操作类
简单Json存储操作类
- Version:
- 1.0.0
- Author:
- wisdomme
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.ultikits.ultitools.interfaces.DataOperator
DataOperator.LikeType -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildColumnToFieldName(Class<?> type) 从实体类上的@Column标注建立「SQL 列名 → Java 字段名」映射。 沿继承链收集,因此BaseDataEntity继承来的@Column("id")也在内。private booleanconditionCal(String data, String value, WhereCondition condition) 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.voidflush()Persist cache object.voidgc()Compare local with cache and delete local persistent files.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 QueryvoidInsert data record.voidInsert multiple entities atomically.page(int page, int size, WhereCondition... whereConditions) Get data record by page.private StringresolveColumn(String column) 把调用方给的列名解析成 Gson 序列化后 map 里的键。private StringstripJsonQuotes(String jsonValue) Remove JSON quotes from a serialized string value.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
-
GSON
private static final com.google.gson.Gson GSON -
storeLocation
-
type
-
cache
-
columnToFieldName
SQL 列名(小写)→ Java 字段名。调用方一律用
@Column里的 SQL 列名做查询(跨 17 个 Modules 共 52 处), 而 Gson 序列化出的 map 键是 Java 字段名,两者在 snake_case / camelCase 上对不上, 查询会静默零命中。这份映射把前者翻译成后者,做法与AbstractRelationalDataOperator#getListHandler()的读路径一致。见 issue #176。
-
-
Constructor Details
-
SimpleJsonDataOperator
-
-
Method Details
-
buildColumnToFieldName
从实体类上的@Column标注建立「SQL 列名 → Java 字段名」映射。 沿继承链收集,因此BaseDataEntity继承来的@Column("id")也在内。- Parameters:
type- 实体类型- Returns:
- 不可变映射,键为小写化的 SQL 列名
-
resolveColumn
把调用方给的列名解析成 Gson 序列化后 map 里的键。命中
@Column就换成对应的 Java 字段名;否则原样返回 —— 这样一来, 直接写 Java 字段名的旧调用、以及JsonPathUtil的点分隔嵌套路径(如"a.b.c")都不受影响。- Parameters:
column- 调用方给的列名,可能是 SQL 列名、Java 字段名或嵌套路径- Returns:
- 可直接交给
JsonPathUtil的键或路径
-
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
数据记录
-
flush
public void flush()Description copied from interface:CachedPersist cache object.持久化缓存对象
-
gc
public void gc()Description copied from interface:CachedCompare local with cache and delete local persistent files.对比本地与缓存,删除本地持久化文件
-
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
-
conditionCal
-
stripJsonQuotes
Remove JSON quotes from a serialized string value. e.g., "\"hello\"" becomes "hello"
-