Fixed most reported issues by SonarCloud.

This commit is contained in:
Toxic Dreamz
2020-08-15 21:47:39 +04:00
parent e7e3ace01f
commit 31471acb69
190 changed files with 1426 additions and 661 deletions
@@ -29,9 +29,6 @@ package com.iluwatar.unitofwork;
* @param <T> Any generic entity
*/
public interface IUnitOfWork<T> {
String INSERT = "INSERT";
String DELETE = "DELETE";
String MODIFY = "MODIFY";
/**
* Any register new operation occurring on UnitOfWork is only going to be performed on commit.
@@ -52,20 +52,20 @@ public class StudentRepository implements IUnitOfWork<Student> {
@Override
public void registerNew(Student student) {
LOGGER.info("Registering {} for insert in context.", student.getName());
register(student, IUnitOfWork.INSERT);
register(student, UnitActions.INSERT.getActionValue());
}
@Override
public void registerModified(Student student) {
LOGGER.info("Registering {} for modify in context.", student.getName());
register(student, IUnitOfWork.MODIFY);
register(student, UnitActions.MODIFY.getActionValue());
}
@Override
public void registerDeleted(Student student) {
LOGGER.info("Registering {} for delete in context.", student.getName());
register(student, IUnitOfWork.DELETE);
register(student, UnitActions.DELETE.getActionValue());
}
private void register(Student student, String operation) {
@@ -86,21 +86,21 @@ public class StudentRepository implements IUnitOfWork<Student> {
return;
}
LOGGER.info("Commit started");
if (context.containsKey(IUnitOfWork.INSERT)) {
if (context.containsKey(UnitActions.INSERT.getActionValue())) {
commitInsert();
}
if (context.containsKey(IUnitOfWork.MODIFY)) {
if (context.containsKey(UnitActions.MODIFY.getActionValue())) {
commitModify();
}
if (context.containsKey(IUnitOfWork.DELETE)) {
if (context.containsKey(UnitActions.DELETE.getActionValue())) {
commitDelete();
}
LOGGER.info("Commit finished.");
}
private void commitInsert() {
var studentsToBeInserted = context.get(IUnitOfWork.INSERT);
var studentsToBeInserted = context.get(UnitActions.INSERT.getActionValue());
for (var student : studentsToBeInserted) {
LOGGER.info("Saving {} to database.", student.getName());
studentDatabase.insert(student);
@@ -108,7 +108,7 @@ public class StudentRepository implements IUnitOfWork<Student> {
}
private void commitModify() {
var modifiedStudents = context.get(IUnitOfWork.MODIFY);
var modifiedStudents = context.get(UnitActions.MODIFY.getActionValue());
for (var student : modifiedStudents) {
LOGGER.info("Modifying {} to database.", student.getName());
studentDatabase.modify(student);
@@ -116,7 +116,7 @@ public class StudentRepository implements IUnitOfWork<Student> {
}
private void commitDelete() {
var deletedStudents = context.get(IUnitOfWork.DELETE);
var deletedStudents = context.get(UnitActions.DELETE.getActionValue());
for (var student : deletedStudents) {
LOGGER.info("Deleting {} to database.", student.getName());
studentDatabase.delete(student);
@@ -0,0 +1,18 @@
package com.iluwatar.unitofwork;
public enum UnitActions {
INSERT("INSERT"),
DELETE("DELETE"),
MODIFY("MODIFY")
;
private final String actionValue;
UnitActions(String actionValue) {
this.actionValue = actionValue;
}
public String getActionValue() {
return actionValue;
}
}