19 package org.turro.related;
21 import java.util.concurrent.TimeUnit;
22 import java.util.concurrent.locks.ReentrantLock;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import java.util.stream.Stream;
26 import org.turro.elephant.context.ElephantContext;
27 import org.turro.elephant.db.ElephantPU;
28 import org.turro.jpa.Dao;
29 import org.turro.jpa.DaoUtil;
37 private final Dao oldRelatedDao, newRelatedDao;
41 if(migration.isNecessary())
new Thread(migration,
"ElephantRelated migration").start();
44 private boolean isNecessary() {
48 private void start() {
49 try(Stream<OldRelatedEntry> related = oldRelatedDao.stream(OldRelatedEntry.class, getSelect())) {
50 related.forEach((relation) -> {
51 relation.migrate(newRelatedDao);
56 private String getSelect() {
57 return "select new org.turro.related.OldRelatedEntry(origin, destination, description, unbreakable, creation) from RelatedPaths";
60 private RelatedMigration(Dao oldRelatedDao) {
61 this.oldRelatedDao = oldRelatedDao;
62 this.newRelatedDao =
new ElephantPU();
65 private static final ReentrantLock LOCK =
new ReentrantLock();
69 if(!LOCK.isLocked()) {
71 if(LOCK.tryLock(0, TimeUnit.SECONDS)) {
80 }
catch (InterruptedException ex) {
static String logMsg(String msg)
static boolean isEmpty(Dao dao, String table)
static Dao getDaoByPU(String pu)