19 package org.turro.log;
21 import java.util.Date;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Optional;
26 import java.util.stream.Stream;
27 import org.turro.string.Strings;
28 import org.turro.elephant.db.ElephantPU;
29 import org.turro.elephant.entities.db.SystemLog;
30 import org.turro.jpa.Dao;
31 import org.turro.path.Path;
32 import org.turro.sql.SqlClause;
40 public long getCountOf(String comment, String entityPath, Date since) {
41 return Optional.ofNullable(
42 SqlClause.select(
"sum(counts)").from(
"SystemLog")
44 .startIf(!Strings.isBlank(comment))
45 .and().equal(
"comment", comment)
47 .startIf(!Strings.isBlank(entityPath))
48 .and().equal(
"entityPath", entityPath)
50 .startIf(since !=
null)
51 .and().greaterOrEqual(
"dateLog", since)
54 .singleResult(Long.class))
59 SqlClause.delete(
"SystemLog")
61 .equal(
"entityPath", entityPath)
62 .or().startsWith(
"entityPath", entityPath +
"/")
64 .and().notIn(
"comment", List.of(
"cleanup",
"deleted"))
72 try(Stream<String> stream = SqlClause.select(
"distinct entityPath").from(
"SystemLog")
73 .where().startsWith(
"entityPath",
"/" + root +
"/")
74 .and().notIn(
"comment", List.of(
"cleanup",
"deleted"))
76 .stream(String.class)) {
77 return new HashSet<>(stream.map(path -> Path.pathFrom(path).getTill(2)).toList());
84 return SqlClause.select(
"l").from(
"SystemLog l")
85 .where().equal(
"l.comment", comment)
86 .and().equal(
"l.entityPath", entityPath)
87 .and(
"l.dateLog =").sub(
88 SqlClause.select(
"min(l2.dateLog)").from(
"SystemLog l2")
89 .where(
"l2.comment = l.comment")
90 .and(
"l2.entityPath = l.entityPath")
91 .groupBy(
"l2.comment, l2.entityPath"))
97 return SqlClause.select(
"l").from(
"SystemLog l")
98 .where().equal(
"l.comment", comment)
99 .and().equal(
"l.entityPath", entityPath)
100 .and(
"l.dateLog =").sub(
101 SqlClause.select(
"max(l2.dateLog)").from(
"SystemLog l2")
102 .where(
"l2.comment = l.comment")
103 .and(
"l2.entityPath = l.entityPath")
104 .groupBy(
"l2.comment, l2.entityPath"))
113 private Dao getDao() {
void cleanup(String entityPath)
long getCountOf(String comment, String entityPath, Date since)
SystemLog lastEntry(String entityPath, String comment)
static Set< String > getAllPaths(String root)
SystemLog firstEntry(String entityPath, String comment)