Example usage for javax.ejb TransactionAttributeType REQUIRES_NEW

List of usage examples for javax.ejb TransactionAttributeType REQUIRES_NEW

Introduction

In this page you can find the example usage for javax.ejb TransactionAttributeType REQUIRES_NEW.

Prototype

TransactionAttributeType REQUIRES_NEW

To view the source code for javax.ejb TransactionAttributeType REQUIRES_NEW.

Click Source Link

Document

The container must invoke an enterprise bean method whose transaction attribute is set to REQUIRES_NEW with a new transaction context.

Usage

From source file:be.fedict.eid.pkira.blm.model.contracts.ContractRepositoryBean.java

/**
 * {@inheritDoc}//from  w w  w.  j a va2s.c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void persistCertificate(Certificate certificate) {
    if (findCertificate(certificate.getIssuer(), certificate.getSerialNumber()) != null) {
        // certificate already exists!
        throw new RuntimeException("Duplicate certificate in database: " + certificate.getIssuer() + "/"
                + certificate.getSerialNumber());
    }

    entityManager.persist(certificate);
    entityManager.flush();
}

From source file:dk.dma.msinm.legacy.nm.LegacyNmImportService.java

/**
 * Imports the NtM template and returns the message if it was imported
 * @param template the NtM template/* w  ww .j  av  a2 s.c  om*/
 * @param weekStartDate the start date of the week
 * @param txt a log of the import
 * @return the message actually imported
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Message importMessage(Message template, Date weekStartDate, StringBuilder txt) {
    // Check if the message already exists
    Message message = messageService.findBySeriesIdentifier(template.getSeriesIdentifier().getMainType(),
            template.getSeriesIdentifier().getNumber(), template.getSeriesIdentifier().getYear(),
            template.getSeriesIdentifier().getAuthority());
    if (message != null) {
        log.warn("Message " + template.getSeriesIdentifier() + " already exists. Skipping");
        txt.append("Skipping existing NtM: " + template.getSeriesIdentifier() + "\n");
        return null;
    }

    // Fill out missing fields
    template.setValidFrom(weekStartDate);
    template.setPriority(Priority.NONE);
    template.setStatus(Status.PUBLISHED);

    // Some NM's do not have descriptions. Use the (html'ified) title instead
    template.getDescs().forEach(desc -> desc.setDescription(
            StringUtils.defaultIfBlank(desc.getDescription(), TextUtils.txt2html(desc.getTitle()))));

    try {
        // Make sure all charts are saved
        List<Chart> charts = findOrCreateCharts(template.getCharts());
        template.setCharts(charts);

        // Make sure the area, and parent areas, exists
        Area area = findOrCreateArea(template.getArea());
        template.setArea(area);

        // Save the message
        message = messageService.saveMessage(template);
        txt.append("Saved NtM: " + template.getSeriesIdentifier() + "\n");
    } catch (Exception e) {
        txt.append("Error saving NtM: " + template.getSeriesIdentifier() + "\n");
        log.error("Failed saving message " + message, e);
    }
    return message;
}

From source file:gwap.rest.NewPicture.java

@POST
@Path("/newpicture")
@Consumes(MediaType.APPLICATION_JSON)/*  w  ww .j  av a  2  s  .c  om*/
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@Transactional

public Response createNewpicture(String string) {
    JSONObject payload = parse(string);
    ArtResource artResource = createPicture(payload);

    artResource.setOrigin(ArtResource.ORIGIN_APP_USER);

    VirtualTagging virtualTagging = new VirtualTagging();
    virtualTagging.setResource(artResource);
    entityManager.persist(virtualTagging);

    VirtualTaggingType virtualTaggingType = entityManager.find(VirtualTaggingType.class,
            Long.parseLong(payload.get("topic").toString()));
    virtualTagging.getVirtualTaggingTypes().add(virtualTaggingType);

    entityManager.flush();

    log.info("Created picture: #0", artResource.getId());

    return Response.status(Response.Status.CREATED).build();
}

From source file:be.fedict.trust.service.dao.bean.AuditDAOBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public AuditEntity logAudit(String message) {
    AuditEntity audit = new AuditEntity(message);
    this.entityManager.persist(audit);
    LOG.debug("audit: date=" + audit.getAuditDate().toString() + " message=" + audit.getMessage());
    return audit;
}

From source file:be.fedict.eid.pkira.blm.model.contracts.ContractRepositoryBean.java

/**
 * {@inheritDoc}/* www  .  j a  v  a  2s. co  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void persistContract(AbstractContract contract) {
    entityManager.persist(contract);
}

From source file:org.rhq.enterprise.server.alert.CachedConditionManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void processCachedConditionMessage(AbstractAlertConditionMessage conditionMessage,
        Integer definitionId) {/*from w  ww. j a  v  a 2 s  .  c o m*/
    /*
     * note that ctime is the time when the condition was known to be true, not the time we're persisting the
     * condition log message
     */
    if (conditionMessage instanceof ActiveAlertConditionMessage) {
        ActiveAlertConditionMessage activeConditionMessage = (ActiveAlertConditionMessage) conditionMessage;

        if (alertDefinitionManager.isEnabled(definitionId) == false) {
            if (log.isDebugEnabled()) {
                log.debug("AlertDefinition[id=" //
                        + activeConditionMessage.getAlertConditionId() //
                        + "] was already disabled " //
                        + "(likely due to recovery logic disablement on earlier messages in this process batch), " //
                        + "ignoring " //
                        + activeConditionMessage);
            }
            return;
        }

        alertConditionLogManager.updateUnmatchedLogByAlertConditionId(
                activeConditionMessage.getAlertConditionId(), activeConditionMessage.getTimestamp(),
                activeConditionMessage.getValue());

        alertConditionLogManager
                .checkForCompletedAlertConditionSet(activeConditionMessage.getAlertConditionId());
    } else if (conditionMessage instanceof InactiveAlertConditionMessage) {
        // first do some bookkeeping by removing partially matched condition logs 
        alertConditionLogManager.removeUnmatchedLogByAlertConditionId(conditionMessage.getAlertConditionId());

        // then create a NEGATIVE dampening event, to breakup any contiguous POSITIVE events for correct processing
        AlertDefinition flyWeightDefinition = new AlertDefinition();
        flyWeightDefinition.setId(definitionId);
        AlertDampeningEvent event = new AlertDampeningEvent(flyWeightDefinition,
                AlertDampeningEvent.Type.NEGATIVE);
        entityManager.persist(event);
    } else {
        log.error("Unsupported message type sent to consumer for processing: "
                + conditionMessage.getClass().getSimpleName());
    }
}

From source file:be.fedict.eid.pkira.blm.model.reporting.ReportManagerBean.java

/**
 * {@inheritDoc}//from   www. jav a  2  s .  c  o m
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void addLineToReport(AbstractContract contract, boolean success) {
    ReportEntry entry = reportEntryHome.getInstance();
    entry.setCertificateAuthorityName(contract.getCertificateDomain().getCertificateAuthority().getName());
    entry.setCertificateDomainName(contract.getCertificateDomain().getName());
    entry.setSubject(contract.getSubject());
    entry.setRequester(contract.getRequesterName());
    entry.setSuccess(success);
    entry.setMonth(new SimpleDateFormat("yyyy-MM").format(new Date()));
    entry.setContractType(mapToContractType(contract));

    reportEntryHome.persist();
}

From source file:org.rhq.enterprise.server.alert.AlertConditionManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Integer getAlertDefinitionByConditionIdInNewTransaction(int alertConditionId) {
    try {// w w w . ja  va  2 s  . c o m
        Query query = entityManager.createNamedQuery(AlertDefinition.QUERY_FIND_DEFINITION_ID_BY_CONDITION_ID);
        query.setParameter("alertConditionId", alertConditionId);
        Integer alertDefinitionId = (Integer) query.getSingleResult();
        return alertDefinitionId;
    } catch (NoResultException nre) {
        return null; // we always want this method to return
    }
}

From source file:org.cesecore.core.ejb.log.OldLogSessionBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@Override//from  w w w.  j a v a  2 s.c o m
public boolean log(Admin admin, int caid, int module, Date time, String username, Certificate certificate,
        int event, String comment, Exception exception) {
    String uid = null;
    if (certificate != null) {
        uid = CertTools.getSerialNumberAsString(certificate) + "," + CertTools.getIssuerDN(certificate);
    }
    String admindata = admin.getAdminData();
    if ((event == LogConstants.EVENT_INFO_ADMINISTRATORLOGGEDIN)
            && StringUtils.contains(comment, "external CA")) {
        admindata += " : SubjectDN : \""
                + CertTools.getSubjectDN(admin.getAdminInformation().getX509Certificate()) + "\"";
    }
    int id = -1;
    final int RETRIES = 16; // Very low chance of starvation
    for (int i = 0; i < RETRIES && id == -1; i++) {
        try {
            id = logConfigurationSession.getAndIncrementRowCount();
        } catch (RuntimeException e) {
            if (log.isDebugEnabled()) {
                log.debug("Unable to get next sequential log entry row number: ", e);
            }
        }
    }
    if (id == -1) {
        if (log.isDebugEnabled()) {
            log.debug("Failed to allocate next sequential log entry row number after " + RETRIES + " tries.");
        }
        return false;
    } else {
        entityManager.persist(new LogEntryData(id, admin.getAdminType(), admindata, caid, module, time,
                username, uid, event, comment));
        return true;
    }
}

From source file:org.rhq.enterprise.server.test.StrippedDownStartupBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void init() {
    secureNaming();
}