Skip to content

Commit 9465d69

Browse files
author
bretislav.wajtr
committed
Added proper javadoc to DataRepository interface and moved getProjectsWithCostsUsingNativeQuery.sql under jooq/queries directory to indicate that this file is used only by jOOQ implementation.
1 parent 044db0a commit 9465d69

3 files changed

Lines changed: 85 additions & 6 deletions

File tree

src/main/java/com/clevergang/dbtests/repository/api/DataRepository.java

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,131 @@
1414
*/
1515
public interface DataRepository {
1616

17-
// companies
17+
// Companies
1818

19+
/**
20+
* @param pid Primary key of the company record to be found
21+
* @return Should return full record of the Company record identified by pid
22+
*/
1923
Company findCompany(Integer pid);
2024

25+
/**
26+
* @param pid Primary key of the company record to be found
27+
* @return Should return full record of the Company record identified by pid. A static (non-prepared) statement should be used for that.
28+
*/
2129
Company findCompanyUsingSimpleStaticStatement(Integer pid);
2230

23-
// departments
2431

32+
33+
// Departments
34+
35+
/**
36+
* @param pid Primary key of the Department record to be found
37+
* @return Should return full record of the Department record identified by pid
38+
*/
2539
Department findDepartment(Integer pid);
2640

41+
/**
42+
* Should return full records of all Departments assigned to the Company (passed in as parameter).
43+
* @param company Full Company record
44+
* @return List of Departments
45+
*/
2746
List<Department> findDepartmentsOfCompany(Company company);
2847

48+
/**
49+
* Should immediately delete Departments passed in as parameter from database. Should do it in most efficient way (preferably as batch operation).
50+
* We expect that the deletions were already performed in database upon return from this method.
51+
*
52+
* @param departmentsToDelete Full records of Departments to be deleted
53+
*/
2954
void deleteDepartments(List<Department> departmentsToDelete);
3055

56+
/**
57+
* Should immediately update Department records passed in as parameter. Should do it in most efficient way (preferably as batch operation).
58+
* We expect that the updates were already performed in database upon return from this method (meaning all required SQL statements were already
59+
* executed and are not deferred to a later time).
60+
*
61+
* @param departmentsToUpdate Full records of Departments to be updated. Update all fields of Department, identified by Department.getPid()
62+
*/
3163
void updateDepartments(List<Department> departmentsToUpdate);
3264

65+
/**
66+
* Should immediately insert Department records passed in as parameter. Should do it in most efficient way (preferably as batch operation).
67+
* We expect that the inserts were already performed in database upon return from this method (meaning all required SQL statements were already
68+
* executed and are not deferred to a later time).
69+
*
70+
* @param departmentsToInsert Full records of Departments to be inserted. Records should have getPid()==null
71+
*/
3372
void insertDepartments(List<Department> departmentsToInsert);
3473

35-
// projects
74+
75+
76+
77+
// Projects
3678

3779
/**
3880
* Insert project and return PID of newly created item
81+
*
3982
* @param project Project to be inserted
4083
* @return PID of new record in database
4184
*/
4285
Integer insertProject(Project project);
4386

4487
/**
45-
* Insert projects and return all PIDs of newly created records.
88+
* Should immediately insert Project records passed in as parameter. Should do it in most efficient way (preferably as batch operation).
89+
* We expect that the inserts were already performed in database upon return from this method (meaning all required SQL statements were already
90+
* executed and are not deferred to a later time).
91+
*
4692
* @param projects New projects to insert
4793
* @return List of PIDs of newly created records.
4894
*/
4995
List<Integer> insertProjects(List<Project> projects);
5096

97+
/**
98+
* Execute following query: get all projects, where the total cost of the project per month is greater than parameter totalCostBoundary. In the same result set
99+
* get all companies participating on such project along with cost of the project for the company.
100+
*/
51101
List<ProjectsWithCostsGreaterThanOutput> getProjectsWithCostsGreaterThan(int totalCostBoundary);
52102

53-
// employees
54103

104+
105+
// Employees
106+
107+
/**
108+
* @param pid Primary key of the employee record to be found
109+
* @return Should return full record of the Employee record identified by pid
110+
*/
55111
Employee findEmployee(Integer pid);
56112

113+
114+
/**
115+
* Execute following query and return all Employee records satisfying following condition: salary of the employee
116+
* is greater than parameter minSalary
117+
*/
57118
List<Employee> employeesWithSalaryGreaterThan(Integer minSalary);
58119

120+
121+
/**
122+
* Should immediately update Employee record passed in as parameter. Should do it in most efficient way.
123+
* We expect that the update was already performed in database upon return from this method (meaning SQL statement was already
124+
* executed and is not deferred to a later time).
125+
*
126+
* @param employeeToUpdate Full records of Employee to be updated. Update all fields of Employee, identified by Employee.getPid()
127+
*/
59128
void updateEmployee(Employee employeeToUpdate);
60129

130+
131+
/**
132+
* Register new employee and create company and department if required - use stored procedure register_employee (see register_employee.sql)
133+
* to perform the operation.
134+
*
135+
* @return Newly created PIDs of records (output of the stored procedure)
136+
*/
61137
RegisterEmployeeOutput callRegisterEmployee(String name, String surname, String email, BigDecimal salary,
62138
String departmentName, String companyName);
63139

140+
/**
141+
* @return Return count of records in Project table
142+
*/
64143
Integer getProjectsCount();
65144
}

src/main/java/com/clevergang/dbtests/repository/impl/jooq/JooqDataRepositoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public Integer getProjectsCount() {
211211

212212
private List<ProjectsWithCostsGreaterThanOutput> getProjectsWithCostsUsingNativeQuery(int totalCostBoundary) {
213213
// FIXME: We should cache loaded scripts in real production code!
214-
String query = loadSQLScript("queries/getProjectsWithCostsUsingNativeQuery.sql");
214+
String query = loadSQLScript("jooq/queries/getProjectsWithCostsUsingNativeQuery.sql");
215215

216216
return create
217217
.resultQuery(query, totalCostBoundary)

src/main/resources/queries/getProjectsWithCostsUsingNativeQuery.sql renamed to src/main/resources/jooq/queries/getProjectsWithCostsUsingNativeQuery.sql

File renamed without changes.

0 commit comments

Comments
 (0)