Skip to content
Snippets Groups Projects

Prototype with correct simple product - Error Logging fix

Merged Adrian Kuhn requested to merge prototypeWithCorrectSimpleProduct into master
1 file
+ 36
12
Compare changes
  • Side-by-side
  • Inline
@@ -26,6 +26,8 @@ import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ErrorLogger {
@@ -64,8 +66,10 @@ public class ErrorLogger {
Element exceptionElement = createAndAppendElement(entry, "exception", "");
exceptionElement.setAttribute("type", exception.getClass().getCanonicalName());
String constraintName = (Objects.nonNull(exception.getConstraintName())) ?
exception.getConstraintName() : "unknown";
String constraintName = getConstraintName(exception.getSQLException().getMessage());
createAndAppendElement(exceptionElement, "constraintName", constraintName);
createAndAppendElement(exceptionElement, "cause", exception.getSQLException().getMessage());
createAndAppendElement(exceptionElement, "entity", entity.getClass().getCanonicalName());
@@ -79,7 +83,7 @@ public class ErrorLogger {
public void logError(EntityExistsException entityExistsException, Object entity)
{
// File logFile = new File(pathToLogFile) ;
System.out.println(entityExistsException + "\n" + entity);
}
/**
@@ -142,7 +146,7 @@ public class ErrorLogger {
try {
Source source = new DOMSource(errorDoc);
StreamResult result = new StreamResult(new OutputStreamWriter(
new FileOutputStream(errorFile), StandardCharsets.ISO_8859_1));
new FileOutputStream(errorFile), StandardCharsets.UTF_8));
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(source, result);
} catch (FileNotFoundException | TransformerException e) {
@@ -152,14 +156,18 @@ public class ErrorLogger {
public void printStatistics()
{
generateAndPrintErrorStatistic("Root.Entities.ShopEntity",
new String[] {"PRIMARY","unique_address"});
generateAndPrintErrorStatistic("Root.Entities.ConditionsEntity",
new String[] {"PRIMARY", "unique_conditions_entry", "unknown"});
generateAndPrintErrorStatistic("Root.Entities.ReviewEntity",
new String[] {"PRIMARY","review_unique_constraint", "unknown"});
generateAndPrintErrorStatistic("Root.Entities.ProductEntity",
new String[] {"PRIMARY","unique_productNr"});
generateAndPrintErrorStatistic("Root.Entities.ShopEntity", new String[]{"Unique-Constraint »shop_pk«"});
generateAndPrintErrorStatistic("Root.Entities.ConditionEntity", new String[]{"Unique-Constraint »condition_pk«",
"Unique-Constraint »condition_unique_offer«",
"Check-Constraint »condition_currency_check«",
"Check-Constraint »condition_price_check«",
"Check-Constraint »condition_price_multiplier_check«",
"Check-Constraint »condition_state_check«"});
generateAndPrintErrorStatistic("Root.Entities.ReviewEntity", new String[]{"Unique-Constraint »review_pk«",
"Unique-Constraint »review_unique_constraint«",
"Check-Constraint »review_helpful_check«",
"Check-Constraint »review_rating_check«"});
generateAndPrintErrorStatistic("Root.Entities.ProductEntity", new String[]{"Unique-Constraint »product_pk«"});
}
private void generateAndPrintErrorStatistic(String entityName, String[] constraintArray)
@@ -180,6 +188,10 @@ public class ErrorLogger {
+ " - count: "
+ Objects.requireNonNull(xPathQuery(queryConstraint)).getLength());
}
System.out.println(
"CONSTRAINT VIOLATION: UNKNOWN"
+ " - count: "
+ Objects.requireNonNull(xPathQuery(getErrorsOfConstraintName(entityName, "unknown"))).getLength());
System.out.println("UNKNOWN CONSTRAINT VIOLATION");
printUnknownConstraintViolations(entityName);
System.out.println("################################################################\n");
@@ -226,4 +238,16 @@ public class ErrorLogger {
return null;
}
private String getConstraintName(String message)
{
String pattern = "(?<=verletzt )(.*)";
Pattern reg = Pattern.compile(pattern);
Matcher matcher = reg.matcher(message);
if (matcher.find()) {
return matcher.group();
} else {
return "unknown";
}
}
}
Loading