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存储操作类
Version:
1.0.0
Author:
wisdomme
  • Field Details

    • GSON

      private static final com.google.gson.Gson GSON
    • storeLocation

      private final String storeLocation
    • type

      private final Class<T extends BaseDataEntity<String>> type
    • cache

      private final Map<Object,T extends BaseDataEntity<String>> cache
    • columnToFieldName

      private final Map<String,String> columnToFieldName
      SQL 列名(小写)→ Java 字段名。

      调用方一律用 @Column 里的 SQL 列名做查询(跨 17 个 Modules 共 52 处), 而 Gson 序列化出的 map 键是 Java 字段名,两者在 snake_case / camelCase 上对不上, 查询会静默零命中。这份映射把前者翻译成后者,做法与 AbstractRelationalDataOperator#getListHandler() 的读路径一致。见 issue #176。

  • Constructor Details

    • SimpleJsonDataOperator

      public SimpleJsonDataOperator(String storeLocation, Class<T> type)
  • Method Details

    • buildColumnToFieldName

      private static Map<String,String> buildColumnToFieldName(Class<?> type)
      从实体类上的 @Column 标注建立「SQL 列名 → Java 字段名」映射。 沿继承链收集,因此 BaseDataEntity 继承来的 @Column("id") 也在内。
      Parameters:
      type - 实体类型
      Returns:
      不可变映射,键为小写化的 SQL 列名
    • resolveColumn

      private String resolveColumn(String column)
      把调用方给的列名解析成 Gson 序列化后 map 里的键。

      命中 @Column 就换成对应的 Java 字段名;否则原样返回 —— 这样一来, 直接写 Java 字段名的旧调用、以及 JsonPathUtil 的点分隔嵌套路径(如 "a.b.c")都不受影响。

      Parameters:
      column - 调用方给的列名,可能是 SQL 列名、Java 字段名或嵌套路径
      Returns:
      可直接交给 JsonPathUtil 的键或路径
    • exist

      public boolean exist(T object)
      Description copied from interface: DataOperator
      Check if the data record exists.

      查询记录数据是否存在。

      Specified by:
      exist in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      object - Data record entity
      数据记录实体
      Returns:
      Whether the record exists
      记录是否存在
    • exist

      public boolean exist(WhereCondition... whereConditions)
      Description copied from interface: DataOperator
      Check if the data record exists.

      使用条件查询记录是否存在

      Specified by:
      exist in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      whereConditions - Conditions
      条件参数
      Returns:
      Whether the record exists
      记录是否存在
    • getById

      public T getById(Object id)
      Description copied from interface: DataOperator
      Get data record by ID.

      使用ID获取记录

      Specified by:
      getById in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      id - Record ID
      记录ID
      Returns:
      Data record
      数据记录
    • getAll

      public List<T> getAll()
      Description copied from interface: DataOperator
      Get all data record.

      查询所有记录

      Specified by:
      getAll in interface DataOperator<T extends BaseDataEntity<String>>
      Returns:
      Data record list
      数据记录列表
    • getAll

      public List<T> getAll(WhereCondition... whereConditions)
      Description copied from interface: DataOperator
      Get all data record by conditions.

      查询所有符合条件的记录

      Specified by:
      getAll in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      whereConditions - Conditions
      条件参数
      Returns:
      Data record list
      数据记录列表
    • getLike

      public List<T> getLike(String column, String value, DataOperator.LikeType likeType)
      Description copied from interface: DataOperator
      Fuzzy Query

      模糊查询

      Specified by:
      getLike in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      column - Column name
      列名
      value - Query value
      查询值
      likeType - Like type
      模糊查询类型
      DataOperator.LikeType
      Returns:
      Data record list
      数据记录列表
    • page

      public List<T> page(int page, int size, WhereCondition... whereConditions)
      Description copied from interface: DataOperator
      Get data record by page.

      分页查询

      Specified by:
      page in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      page - Page number
      页码
      size - Page size
      页大小
      whereConditions - Conditions
      条件参数
      Returns:
      Data record list
      数据记录列表
    • insert

      public void insert(T obj)
      Description copied from interface: DataOperator
      Insert data record.

      新增记录

      Specified by:
      insert in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      obj - Data record
      数据记录
    • del

      public void del(WhereCondition... whereConditions)
      Description copied from interface: DataOperator
      Delete data record by conditions.

      按照条件删除记录

      Specified by:
      del in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      whereConditions - Conditions
      条件参数
    • delById

      public void delById(Object id)
      Description copied from interface: DataOperator
      Delete data record by ID.

      按照ID删除记录

      Specified by:
      delById in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      id - Record ID
      记录ID
    • update

      public void update(String column, Object value, Object id)
      Description copied from interface: DataOperator
      Update one field of one record.

      更新某个记录的某个值

      Specified by:
      update in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      column - Column name
      列名
      value - New value
      新值
      id - Record ID
      记录ID
    • update

      public void update(T obj)
      Description copied from interface: DataOperator
      Update data record by object. It will not update the fields that the incoming entity does not have.

      使用实体更新记录。不会更新传入实体没有的字段。

      Specified by:
      update in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      obj - Data record
      数据记录
    • flush

      public void flush()
      Description copied from interface: Cached
      Persist cache object.

      持久化缓存对象

      Specified by:
      flush in interface Cached
    • gc

      public void gc()
      Description copied from interface: Cached
      Compare local with cache and delete local persistent files.

      对比本地与缓存,删除本地持久化文件

      Specified by:
      gc in interface Cached
    • transaction

      public <R> R transaction(Callable<R> action) throws Exception
      Description copied from interface: DataOperator
      Execute 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:
      transaction in interface DataOperator<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

      public void transaction(Runnable action)
      Description copied from interface: DataOperator
      Execute operations within a transaction (void variant).

      在事务中执行操作(无返回值)。

      Specified by:
      transaction in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      action - the operations to execute
    • insertAll

      public void insertAll(List<T> entities)
      Description copied from interface: DataOperator
      Insert multiple entities atomically. Uses JDBC batch for SQL backends.

      批量原子插入。SQL后端使用JDBC批处理。

      Specified by:
      insertAll in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      entities - the entities to insert
    • updateAll

      public void updateAll(List<T> entities) throws IllegalAccessException
      Description copied from interface: DataOperator
      Update multiple entities atomically. Uses JDBC batch for SQL backends.

      批量原子更新。SQL后端使用JDBC批处理。

      Specified by:
      updateAll in interface DataOperator<T extends BaseDataEntity<String>>
      Parameters:
      entities - the entities to update
      Throws:
      IllegalAccessException - if field access fails
    • conditionCal

      private boolean conditionCal(String data, String value, WhereCondition condition)
    • stripJsonQuotes

      private String stripJsonQuotes(String jsonValue)
      Remove JSON quotes from a serialized string value. e.g., "\"hello\"" becomes "hello"