perform pac-processor

This commit is contained in:
Peter Hormanns 2016-11-17 13:24:43 +01:00
parent c8e98c6fd4
commit fca58de78a

View File

@ -17,6 +17,8 @@ import javax.jms.TextMessage;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.NamingException; import javax.naming.NamingException;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -24,6 +26,8 @@ import javax.servlet.http.HttpServletResponse;
import de.hsadmin.core.model.TechnicalException; import de.hsadmin.core.model.TechnicalException;
import de.hsadmin.core.model.Transaction; import de.hsadmin.core.model.Transaction;
import de.hsadmin.core.qserv.Processor;
import de.hsadmin.core.qserv.QueueTask;
import de.hsadmin.core.util.Config; import de.hsadmin.core.util.Config;
public class PacTasksServlet extends HttpServlet public class PacTasksServlet extends HttpServlet
@ -106,17 +110,33 @@ public class PacTasksServlet extends HttpServlet
messageCount++; messageCount++;
try { try {
final TextMessage txtMessage = (TextMessage) jmsMessage; final TextMessage txtMessage = (TextMessage) jmsMessage;
System.out.println(txtMessage.getText()); final String message = txtMessage.getText();
// transaction = new Transaction("pactasks"); System.out.println(message);
// transaction.beginTransaction(); final String[] parts = message.split(":");
// EntityManager em = transaction.getEntityManager(); transaction = new Transaction("pactasks");
// em.clear(); transaction.beginTransaction();
// em.persist(persistentQT); final EntityManager em = transaction.getEntityManager();
// em.flush(); final Query qPac = em.createQuery("SELECT p FROM Pacs p WHERE p.name = :name");
// transaction.commitTransaction(); qPac.setParameter("name", parts[1]);
final Pac pac = (Pac) qPac.getSingleResult();
final PacProcessorFactory factory = new PacProcessorFactory();
Processor proc = null;
if ("pac.add".equals(parts[0])) {
proc = factory.createCreateProcessor(em, pac);
}
if ("pac.update".equals(parts[0])) {
proc = factory.createUpdateProcessor(em, pac);
}
if ("pac.delete".equals(parts[0])) {
proc = factory.createDeleteProcessor(em, pac);
}
transaction.enqueue(pac.getHiveName(), new QueueTask(pac.owningUser(em), parts[0] + ":" + parts[1], message, proc));
em.clear();
em.flush();
transaction.commitTransaction();
} catch (Exception e) { } catch (Exception e) {
errorCount++; errorCount++;
// if (transaction != null) transaction.rollbackTransaction(); if (transaction != null) transaction.rollbackTransaction();
throw new TechnicalException(e); throw new TechnicalException(e);
} finally { } finally {
if (transaction != null) transaction.close(); if (transaction != null) transaction.close();