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 Summary
Modifier and TypeMethodDescriptionlongcount()Count all entities.longCount entities matching a condition.booleanDelete an entity.intDelete all entities in the table.intDelete multiple entities.intDelete entities matching a condition.booleandeleteById(long id) Delete an entity by ID.booleanCheck if any entity matches the condition.booleanexistsById(long id) Check if an entity with the given ID exists.findAll()Find all entities.findAll(int limit, int offset) Find all entities with pagination.Find entities where a column equals a value.Find entities where a column equals a value, with pagination.Find entities matching multiple column conditions (AND).findById(long id) Find an entity by its ID.Find one entity where a column equals a value.findOneByAll(Map<String, Object> conditions) Find one entity matching multiple conditions.Get the entity class.Get the table name (without prefix).query()Create a query builder for more complex queries.Save an entity (insert or update).Save multiple entities in a batch.
-
Method Details
-
save
-
saveAll
-
findById
-
findAll
-
findAll
-
findBy
-
findBy
-
findByAll
-
findOneBy
-
findOneByAll
-
existsById
boolean existsById(long id) Check if an entity with the given ID exists.- Parameters:
id- the entity ID- Returns:
- true if exists
-
existsBy
-
count
long count()Count all entities.- Returns:
- total count
-
countBy
-
deleteById
boolean deleteById(long id) Delete an entity by ID.- Parameters:
id- the entity ID- Returns:
- true if deleted, false if not found
-
delete
Delete an entity.- Parameters:
entity- the entity to delete (must have id)- Returns:
- true if deleted
-
deleteAll
-
deleteBy
-
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
-
getEntityClass
-