Interface PluginRepository<T>

Type Parameters:
T - the entity type

public interface PluginRepository<T>
Repository interface for CRUD operations on plugin database tables.

Provides a JPA-like interface for data access without exposing raw SQL. All operations are automatically scoped to the plugin's namespace.

Example:


@Entity
public class UserSetting {
    private Long id;
    private Long userId;
    private String settingName;
    private String settingValue;
    // getters and setters...
}

// Usage
PluginRepository<UserSetting> repo = db.getRepository("user_settings", UserSetting.class);

// Save
UserSetting setting = new UserSetting();
setting.setUserId(12345L);
setting.setSettingName("theme");
setting.setSettingValue("dark");
setting = repo.save(setting);  // id is set after save

// Find
Optional<UserSetting> found = repo.findById(setting.getId());
List<UserSetting> userSettings = repo.findBy("user_id", 12345L);

// Update
setting.setSettingValue("light");
repo.save(setting);

// Delete
repo.deleteById(setting.getId());

  • Method Details

    • save

      T save(T entity)
      Save an entity (insert or update).

      If the entity has a null or zero id, it will be inserted. Otherwise, it will be updated.

      Parameters:
      entity - the entity to save
      Returns:
      the saved entity with id populated
    • saveAll

      List<T> saveAll(Iterable<T> entities)
      Save multiple entities in a batch.
      Parameters:
      entities - the entities to save
      Returns:
      the saved entities
    • findById

      Optional<T> findById(long id)
      Find an entity by its ID.
      Parameters:
      id - the entity ID
      Returns:
      the entity if found
    • findAll

      List<T> findAll()
      Find all entities.
      Returns:
      list of all entities
    • findAll

      List<T> findAll(int limit, int offset)
      Find all entities with pagination.
      Parameters:
      limit - maximum number of results
      offset - number of results to skip
      Returns:
      list of entities
    • findBy

      List<T> findBy(String column, Object value)
      Find entities where a column equals a value.
      Parameters:
      column - the column name
      value - the value to match
      Returns:
      matching entities
    • findBy

      List<T> findBy(String column, Object value, int limit, int offset)
      Find entities where a column equals a value, with pagination.
      Parameters:
      column - the column name
      value - the value to match
      limit - maximum results
      offset - results to skip
      Returns:
      matching entities
    • findByAll

      List<T> findByAll(Map<String,Object> conditions)
      Find entities matching multiple column conditions (AND).
      Parameters:
      conditions - map of column -> value
      Returns:
      matching entities
    • findOneBy

      Optional<T> findOneBy(String column, Object value)
      Find one entity where a column equals a value.
      Parameters:
      column - the column name
      value - the value to match
      Returns:
      the first matching entity
    • findOneByAll

      Optional<T> findOneByAll(Map<String,Object> conditions)
      Find one entity matching multiple conditions.
      Parameters:
      conditions - map of column -> value
      Returns:
      the first matching entity
    • existsById

      boolean existsById(long id)
      Check if an entity with the given ID exists.
      Parameters:
      id - the entity ID
      Returns:
      true if exists
    • existsBy

      boolean existsBy(String column, Object value)
      Check if any entity matches the condition.
      Parameters:
      column - the column name
      value - the value to match
      Returns:
      true if any match exists
    • count

      long count()
      Count all entities.
      Returns:
      total count
    • countBy

      long countBy(String column, Object value)
      Count entities matching a condition.
      Parameters:
      column - the column name
      value - the value to match
      Returns:
      matching count
    • deleteById

      boolean deleteById(long id)
      Delete an entity by ID.
      Parameters:
      id - the entity ID
      Returns:
      true if deleted, false if not found
    • delete

      boolean delete(T entity)
      Delete an entity.
      Parameters:
      entity - the entity to delete (must have id)
      Returns:
      true if deleted
    • deleteAll

      int deleteAll(Iterable<T> entities)
      Delete multiple entities.
      Parameters:
      entities - the entities to delete
      Returns:
      number of entities deleted
    • deleteBy

      int deleteBy(String column, Object value)
      Delete entities matching a condition.
      Parameters:
      column - the column name
      value - the value to match
      Returns:
      number of entities deleted
    • deleteAll

      int deleteAll()
      Delete all entities in the table.

      Warning: This deletes ALL data in the table!

      Returns:
      number of entities deleted
    • query

      QueryBuilder<T> query()
      Create a query builder for more complex queries.
      Returns:
      a new query builder
    • getTableName

      String getTableName()
      Get the table name (without prefix).
      Returns:
      table name
    • getEntityClass

      Class<T> getEntityClass()
      Get the entity class.
      Returns:
      entity class