19 package org.turro.publication.command;
21 import java.util.concurrent.TimeUnit;
22 import java.util.concurrent.locks.ReentrantLock;
23 import java.util.stream.Stream;
24 import org.turro.jpa.Dao;
25 import org.turro.jpa.DaoUtil;
26 import org.turro.log.WebLoggers;
27 import org.turro.publication.db.PublicationPU;
28 import org.turro.publication.entity.PublicationCategory;
29 import org.turro.publication.entity.PublicationConstraint;
30 import org.turro.string.Strings;
40 if(migration.isNecessary())
new Thread(migration,
"ElephantPublication migration").start();
43 private boolean isNecessary() {
47 private void start() {
48 try(Stream<PublicationCategory> categories =
new PublicationPU().stream(PublicationCategory.class,
"select p from PublicationCategory p")) {
49 categories.forEach((category) -> {
50 if(!Strings.isBlank(category.getConditionedBy())) {
51 PublicationConstraint constraint = new PublicationConstraint();
52 constraint.setPublicationCategory(category);
53 constraint.setKeyId(category.getConditionedBy());
54 constraint.setOptional(true);
55 category.getConstraints().add(constraint);
56 dao.saveObject(category);
62 private final Dao dao;
64 private PublicationMigration() {
65 this.dao =
new PublicationPU();
68 private static final ReentrantLock LOCK =
new ReentrantLock();
72 if(!LOCK.isLocked()) {
74 if(LOCK.tryLock(0, TimeUnit.SECONDS)) {
83 }
catch (InterruptedException ex) {
static boolean isEmpty(Dao dao, String table)
static WebLoggers severe(Object entity)
WebLoggers exception(Throwable throwable)