19 package org.turro.log;
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 oldLogDao, newLogDao;
41 if(migration.isNecessary())
new Thread(migration,
"ElephantLog migration").start();
44 private boolean isNecessary() {
48 private void start() {
49 try(Stream<OldLogEntry> logs = oldLogDao.stream(OldLogEntry.class, getSelect())) {
50 logs.forEach((log) -> {
51 log.migrate(newLogDao);
56 private String getSelect() {
57 return "select new org.turro.log.OldLogEntry("
58 +
"case when l.logType = 'LOG_INFO' then 0 "
59 +
"when l.logType = 'LOG_WARNING' then 1 "
60 +
"when l.logType = 'LOG_SEVERE' then 2 "
62 +
"l.path, l.idUser, l.name, l.dateLog, l.comment, l.data) from LogEntry l";
65 private SystemLogMigration(Dao oldLogDao) {
66 this.oldLogDao = oldLogDao;
67 this.newLogDao =
new ElephantPU();
70 private static final ReentrantLock LOCK =
new ReentrantLock();
74 if(!LOCK.isLocked()) {
76 if(LOCK.tryLock(0, TimeUnit.SECONDS)) {
85 }
catch (InterruptedException ex) {
static String logMsg(String msg)
static boolean isEmpty(Dao dao, String table)
static Dao getDaoByPU(String pu)