19 package org.turro.cleanup;
21 import java.util.Collections;
23 import java.util.stream.Collectors;
24 import java.util.stream.Stream;
25 import org.turro.path.Path;
26 import org.turro.sql.IDao;
27 import org.turro.sql.SqlClause;
39 this.console = console;
56 return Collections.EMPTY_SET;
59 protected Set<String>
getOrphans(Set<String> entities, Set<String> mapped) {
60 mapped.removeAll(entities);
65 if(!entities.isEmpty()) {
66 for(Commons common : Commons.values()) {
68 getOrphans(entities, mapped).forEach(entityPath -> {
77 protected <T> Set<String> getEntityPaths(IDao dao, Class<T> idClass, String table, String field, String root) {
78 try(Stream<T> stream = SqlClause.select(
"distinct d." + field).from(table +
" d")
79 .dao(dao).stream(idClass)) {
80 return stream.map(
id -> Path.of(root, String.valueOf(
id)).getPath())
81 .collect(Collectors.toSet());
void cleanOrphansFor(String root, Set< String > entities)
void setConsole(ICleanupConsole console)
Set< String > getOrphans(Set< String > entities, Set< String > mapped)
ICleanupConsole getConsole()
void cleanFromCommons(String entityPath, CleanupMode mode, Set< Commons > commons)
Set< String > pathsForRoot(String root, Commons common)
static void executeForCommons(String entityPath, ICleanupConsole console, CleanupMode mode, Set< IElephantCleanup.Commons > commons)
static Set< String > getEntityPathsFor(String root, IElephantCleanup.Commons common)