Class DbAdminRepository
java.lang.Object
tech.ailef.dbadmin.external.dbmapping.DbAdminRepository
Implements the basic CRUD operations (and some more)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.long
count
(DbObjectSchema schema) long
count
(DbObjectSchema schema, String query, Set<QueryFilter> queryFilters) Counts the elements that match the fuzzy searchcreate
(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 objectvoid
delete
(DbObjectSchema schema, String id) Delete a specific objectfindAll
(DbObjectSchema schema, int page, int pageSize, String sortKey, String sortOrder) Find all the objects in the schema.findById
(DbObjectSchema schema, Object id) Find an object by IDsearch
(DbObjectSchema schema, String query) Fuzzy search on primary key value and display namesearch
(DbObjectSchema schema, String query, int page, int pageSize, String sortKey, String sortOrder, Set<QueryFilter> queryFilters) Fuzzy search on primary key value and display namevoid
update
(DbObjectSchema schema, Map<String, String> params, Map<String, org.springframework.web.multipart.MultipartFile> files) Update an existing object with new values.
-
Constructor Details
-
DbAdminRepository
public DbAdminRepository()
-
-
Method Details
-
findById
Find an object by ID- Parameters:
schema
- the schema where to lookid
- the primary key value- Returns:
- an optional with the object with the specified primary key value
-
count
-
count
Counts the elements that match the fuzzy search- Parameters:
schema
-query
-- Returns:
-
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 itemparams
- the String-valued params coming from the HTML formfiles
- 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 relationshipid
- the primary key of the entity where these relationships have to be attached toparams
- 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
Fuzzy search on primary key value and display name- Parameters:
schema
-query
-- Returns:
-
delete
Delete a specific object- Parameters:
schema
-id
-
-