Class DbAdminRepository

java.lang.Object
tech.ailef.dbadmin.external.dbmapping.DbAdminRepository

@Component public class DbAdminRepository extends Object
Implements the basic CRUD operations (and some more)
  • Constructor Details

    • DbAdminRepository

      public DbAdminRepository()
  • Method Details

    • findById

      public Optional<DbObject> findById(DbObjectSchema schema, Object id)
      Find an object by ID
      Parameters:
      schema - the schema where to look
      id - the primary key value
      Returns:
      an optional with the object with the specified primary key value
    • count

      public long count(DbObjectSchema schema)
    • count

      public long count(DbObjectSchema schema, String query, Set<QueryFilter> queryFilters)
      Counts the elements that match the fuzzy search
      Parameters:
      schema -
      query -
      Returns:
    • search

      public List<DbObject> search(DbObjectSchema schema, String query, Set<QueryFilter> queryFilters)
    • findAll

      public PaginatedResult<DbObject> findAll(DbObjectSchema schema, int page, int pageSize, String sortKey, String sortOrder)
      Find all the objects in the schema. Only returns a single page of results based on the input parameters.
      Parameters:
      schema -
      page -
      pageSize -
      sortKey -
      sortOrder -
      Returns:
    • update

      @Transactional("transactionManager") public void update(DbObjectSchema schema, Map<String,String> params, Map<String,org.springframework.web.multipart.MultipartFile> files)
      Update an existing object with new values. We don't use the "standard" JPA repository save method in this case (like we do on create) because we need to handle several edge cases in terms of how missing values are handled and also ReadOnly fields. For this reason, we also need to call the validation manually.
      Parameters:
      schema - the schema where we need to update an item
      params - the String-valued params coming from the HTML form
      files - the file params coming from the HTML form
    • attachManyToMany

      @Transactional("transactionManager") public void attachManyToMany(DbObjectSchema schema, Object id, Map<String,List<String>> params)
      Attaches multiple many to many relationships to an object, parsed from a multi -valued map.
      Parameters:
      schema - the entity class that owns this relationship
      id - the primary key of the entity where these relationships have to be attached to
      params - the multi-valued map containing the many-to-many relationships
    • create

      @Transactional("transactionManager") public Object create(DbObjectSchema schema, Map<String,String> values, Map<String,org.springframework.web.multipart.MultipartFile> files, String primaryKey)
      Create a new object with the specific primary key and values, returns the primary key of the created object
      Parameters:
      schema -
      values -
      primaryKey -
    • search

      public PaginatedResult<DbObject> search(DbObjectSchema schema, String query, int page, int pageSize, String sortKey, String sortOrder, Set<QueryFilter> queryFilters)
      Fuzzy search on primary key value and display name
      Parameters:
      schema -
      query -
      Returns:
    • search

      public List<DbObject> search(DbObjectSchema schema, String query)
      Fuzzy search on primary key value and display name
      Parameters:
      schema -
      query -
      Returns:
    • delete

      @Transactional("transactionManager") public void delete(DbObjectSchema schema, String id)
      Delete a specific object
      Parameters:
      schema -
      id -