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.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
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.Transaction;
import de.hsadmin.core.qserv.Processor;
import de.hsadmin.core.qserv.QueueTask;
import de.hsadmin.core.util.Config;
public class PacTasksServlet extends HttpServlet
@ -106,17 +110,33 @@ public class PacTasksServlet extends HttpServlet
messageCount++;
try {
final TextMessage txtMessage = (TextMessage) jmsMessage;
System.out.println(txtMessage.getText());
// transaction = new Transaction("pactasks");
// transaction.beginTransaction();
// EntityManager em = transaction.getEntityManager();
// em.clear();
// em.persist(persistentQT);
// em.flush();
// transaction.commitTransaction();
final String message = txtMessage.getText();
System.out.println(message);
final String[] parts = message.split(":");
transaction = new Transaction("pactasks");
transaction.beginTransaction();
final EntityManager em = transaction.getEntityManager();
final Query qPac = em.createQuery("SELECT p FROM Pacs p WHERE p.name = :name");
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) {
errorCount++;
// if (transaction != null) transaction.rollbackTransaction();
if (transaction != null) transaction.rollbackTransaction();
throw new TechnicalException(e);
} finally {
if (transaction != null) transaction.close();