19 package org.turro.forum;
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.entities.db.Topic;
29 import org.turro.jpa.Dao;
30 import org.turro.jpa.DaoUtil;
38 private final Dao oldForumDao, newForumDao;
39 private String currentEntity =
null;
40 private Topic currentTopic =
null;
44 if(migration.isNecessary())
new Thread(migration,
"ElephantForum migration").start();
47 private boolean isNecessary() {
51 private void start() {
52 try(Stream<CommentItEntry> comments = oldForumDao.stream(CommentItEntry.class, getSelect())) {
53 comments.forEach((comment) -> {
54 if(comment.getEntityPath().equals(currentEntity)) {
55 comment.migratePost(newForumDao, currentTopic);
57 currentTopic = comment.migrateTopic(newForumDao);
58 currentEntity = comment.getEntityPath();
64 private String getSelect() {
65 return "select new org.turro.forum.CommentItEntry(t.path, t.creator.id, t.dateCreation, t.body) " +
66 "from CommentIt t where t.creator is not null and t.path like '/dossier/%' " +
70 private ForumMigration(Dao oldForumDao) {
71 this.oldForumDao = oldForumDao;
72 this.newForumDao =
new ElephantPU();
75 private static final ReentrantLock LOCK =
new ReentrantLock();
79 if(!LOCK.isLocked()) {
81 if(LOCK.tryLock(0, TimeUnit.SECONDS)) {
90 }
catch (InterruptedException ex) {
static String logMsg(String msg)
static boolean isEmpty(Dao dao, String table)
static Dao getDaoByPU(String pu)