sistemato timout delle transazioni nell'upload

This commit is contained in:
2015-12-27 10:28:00 +01:00
parent 6b0f74ea88
commit f678e1b787
3 changed files with 74 additions and 21 deletions

View File

@@ -279,7 +279,6 @@ public class PacmanServiceEJB implements PacmanServiceView
{
criteriaQuery.select(builder.count(entity));
}
TypedQuery<Long> query = em.createQuery(criteriaQuery);
return em.createQuery(criteriaQuery).getSingleResult();
}

View File

@@ -10,9 +10,13 @@ import org.jpacrepo.model.PkgName;
import org.jpacrepo.pacbase.Parser;
import org.jpacrepo.persistence.QueryEngine;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.inject.Inject;
import javax.persistence.*;
import javax.transaction.UserTransaction;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import java.io.*;
@@ -26,11 +30,14 @@ import java.util.logging.Logger;
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Singleton
@TransactionManagement(TransactionManagementType.BEAN)
public class PacmanWebService
{
@PersistenceContext(unitName = "jpacrepo_pu")
private EntityManager em;
@Resource
private UserTransaction ut;
@Context
private UriInfo uriInfo;
@@ -187,6 +194,7 @@ public class PacmanWebService
IOUtils.copy(input, fos);
fos.close();
ut.begin();
PkgData pkg = serviceParser.parseFile(file);
TypedQuery<PkgName> nquery = em.createQuery(nameQuery, PkgName.class);
@@ -198,13 +206,15 @@ public class PacmanWebService
}
em.persist(pkg);
log.log(Level.INFO, String.format("Persisiting package %s", pkg.fileName));
log.log(Level.INFO, String.format("Persisting package %s", pkg.fileName));
URI pkgUri = uriInfo.getAbsolutePathBuilder().path(pkg.fileName).build();
ut.commit();
return Response.created(pkgUri).build();
}
catch (Exception e)
{
Files.delete(file.toPath());
ut.rollback();
throw e;
}
}