19 package org.turro.tags;
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.elephant.db.WhereClause;
29 import org.turro.jpa.Dao;
30 import org.turro.jpa.DaoUtil;
38 private final Dao oldTagDao, newTagDao;
43 wc.
addClause(
"where entityPath like '%/null'");
49 if(migration.isNecessary())
new Thread(migration,
"ElephantTag migration").start();
52 private boolean isNecessary() {
56 private void start() {
57 try(Stream<OldTagEntry> tags = oldTagDao.stream(OldTagEntry.class, getSelect())) {
58 tags.forEach((tag) -> {
59 tag.migrate(newTagDao);
64 private String getSelect() {
65 return "select new org.turro.tags.OldTagEntry(t.name, t.path) from TagIt t";
68 private TagMigration(Dao oldTagDao) {
69 this.oldTagDao = oldTagDao;
70 this.newTagDao =
new ElephantPU();
73 private static final ReentrantLock LOCK =
new ReentrantLock();
77 if(!LOCK.isLocked()) {
79 if(LOCK.tryLock(0, TimeUnit.SECONDS)) {
88 }
catch (InterruptedException ex) {
static String logMsg(String msg)
void addClause(String clause)
static boolean isEmpty(Dao dao, String table)
int executeUpdate(String query)
static Dao getDaoByPU(String pu)