Example usage for javax.ejb TransactionAttributeType REQUIRED

List of usage examples for javax.ejb TransactionAttributeType REQUIRED

Introduction

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

Prototype

TransactionAttributeType REQUIRED

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

Click Source Link

Document

If a client invokes the enterprise bean's method while the client is associated with a transaction context, the container invokes the enterprise bean's method in the client's transaction context.

Usage

From source file:org.soulwing.credo.service.group.EditGroupServiceBean.java

/**
 * {@inheritDoc}/*  w  w  w. j  av a 2 s.  com*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public GroupEditor editGroup(Long id) throws NoSuchGroupException {
    return editorFactory.newEditor(id);
}

From source file:org.soulwing.credo.service.group.CreateGroupServiceBean.java

/**
 * {@inheritDoc}/*w w w . j  a  v  a 2  s.c om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void saveGroup(GroupEditor editor, Errors errors) throws EditException, NoSuchGroupException,
        GroupAccessException, PassphraseException, MergeConflictException {
    Validate.isTrue(editor instanceof ConfigurableGroupEditor);
    ((ConfigurableGroupEditor) editor).save(errors);
}

From source file:org.soulwing.credo.service.credential.EditCredentialServiceBean.java

/**
 * {@inheritDoc}/*from w  w w .  j a v a2 s. c o m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public CredentialEditor editCredential(Long id) throws NoSuchCredentialException {

    Credential credential = credentialRepository.findById(id);
    if (credential == null) {
        throw new NoSuchCredentialException();
    }

    return editorFactory.newEditor(credential);
}

From source file:org.soulwing.credo.service.request.EditCredentialRequestServiceBean.java

/**
 * {@inheritDoc}/*from w  w w  .j  a  v a  2 s  .co m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public CredentialRequestEditor editRequest(Long id) throws NoSuchCredentialException {

    CredentialRequest request = requestRepository.findById(id);
    if (request == null) {
        throw new NoSuchCredentialException();
    }

    return editorFactory.newEditor(request);
}

From source file:net.maxgigapop.mrs.driver.GenericRESTDriver.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void propagateDelta(DriverInstance driverInstance, DriverSystemDelta aDelta) {
    driverInstance = DriverInstancePersistenceManager.findById(driverInstance.getId());
    aDelta = (DriverSystemDelta) DeltaPersistenceManager.findById(aDelta.getId()); // refresh
    String subsystemBaseUrl = driverInstance.getProperty("subsystemBaseUrl");
    if (subsystemBaseUrl == null) {
        throw new EJBException(String.format("%s has no property key=subsystemBaseUrl", driverInstance));
    }/*w w  w .  j  av  a 2  s.  c om*/
    VersionItem refVI = aDelta.getReferenceVersionItem();
    if (refVI == null) {
        throw new EJBException(String.format("%s has no referenceVersionItem", aDelta));
    }
    try {
        // compose string body (delta) using JSONObject
        JSONObject deltaJSON = new JSONObject();
        deltaJSON.put("id", Long.toString(aDelta.getId()));
        deltaJSON.put("referenceVersion", refVI.getReferenceUUID());
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
        deltaJSON.put("creationTime", dateFormat.format(new Date()).toString());
        if (aDelta.getModelAddition() != null && aDelta.getModelAddition().getOntModel() != null) {
            String ttlModelAddition = ModelUtil.marshalOntModel(aDelta.getModelAddition().getOntModel());
            deltaJSON.put("modelAddition", ttlModelAddition);
        }
        if (aDelta.getModelReduction() != null && aDelta.getModelReduction().getOntModel() != null) {
            String ttlModelReduction = ModelUtil.marshalOntModel(aDelta.getModelReduction().getOntModel());
            deltaJSON.put("modelReduction", ttlModelReduction);
        }
        // push via REST POST
        URL url = new URL(String.format("%s/delta", subsystemBaseUrl));
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        String status = this.executeHttpMethod(url, conn, "POST", deltaJSON.toString());
        if (!status.toUpperCase().equals("CONFIRMED")) {
            throw new EJBException(
                    String.format("%s failed to push %s into CONFIRMED status", driverInstance, aDelta));
        }
    } catch (Exception e) {
        throw new EJBException(String.format("propagateDelta failed for %s with %s due to exception (%s)",
                driverInstance, aDelta, e.getMessage()));
    }
}

From source file:org.soulwing.credo.service.credential.EditCredentialServiceBean.java

/**
 * {@inheritDoc}/*from w ww. ja va2 s .  com*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void saveCredential(CredentialEditor editor, Errors errors) throws CredentialException,
        NoSuchCredentialException, GroupAccessException, PassphraseException, MergeConflictException {

    Validate.isTrue(editor instanceof SaveableCredentialEditor);
    ((SaveableCredentialEditor) editor).save(errors);
}

From source file:org.soulwing.credo.service.request.EditCredentialRequestServiceBean.java

/**
 * {@inheritDoc}/*from ww  w  .  ja  va 2 s  .c o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void saveRequest(CredentialRequestEditor editor, Errors errors) throws CredentialRequestException,
        NoSuchCredentialException, GroupAccessException, PassphraseException, MergeConflictException {

    Validate.isTrue(editor instanceof SaveableRequestEditor);
    ((SaveableRequestEditor) editor).save(errors);
}

From source file:gov.medicaid.screening.dao.impl.AccreditedBirthCentersLicenseDAOBean.java

/**
 * This method gets the accredited birth centers.
 * //from   w  ww  . j av a 2s. c om
 * @return the search result with the accredited birth centers
 * @throws ParsingException
 *             if any parsing errors are encountered
 * @throws ServiceException
 *             for any other exceptions encountered
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public SearchResult<AccreditedBirthCenter> getAccreditedBirthCenters()
        throws ParsingException, ServiceException {
    String signature = "AccreditedBirthCentersLicenseDAOBean#getAccreditedBirthCenters";
    LogUtil.traceEntry(getLog(), signature, new String[] {}, new Object[] {});

    try {
        SearchResult<AccreditedBirthCenter> results = doSearch();
        return LogUtil.traceExit(getLog(), signature, results);
    } catch (URISyntaxException e) {
        LogUtil.traceError(getLog(), signature, e);
        throw new ServiceException(ErrorCode.MITA50001.getDesc(), e);
    } catch (IOException e) {
        LogUtil.traceError(getLog(), signature, e);
        throw new ServiceException(ErrorCode.MITA50001.getDesc(), e);
    }
}

From source file:be.fedict.eid.pkira.blm.model.mail.MailHandlerBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void onMessage(Message arg0) {
    ObjectMessage objectMessage = (ObjectMessage) arg0;
    try {/*w  w w.  j  av a 2 s.  co m*/
        Mail mail = (Mail) objectMessage.getObject();

        // Get properties
        String mailProtocol = getMailProtocol();
        String mailServer = getSmtpServer();
        String mailUser = getSmtpUser();
        String mailPort = getSmtpPort();
        String mailPassword = getSmtpPassword();

        // Initialize a mail session
        Properties props = new Properties();
        props.put("mail." + mailProtocol + ".host", mailServer);
        props.put("mail." + mailProtocol + ".port", mailPort);
        Session session = Session.getInstance(props);

        // Create the message
        MimeMessage msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(mail.getSender()));
        for (String recipient : mail.getRecipients()) {
            msg.addRecipient(RecipientType.TO, new InternetAddress(recipient));
        }
        msg.setSubject(mail.getSubject(), "UTF-8");

        Multipart multipart = new MimeMultipart();
        msg.setContent(multipart);

        // Set the email message text and attachment
        MimeBodyPart messagePart = new MimeBodyPart();
        messagePart.setContent(mail.getBody(), mail.getContentType());
        multipart.addBodyPart(messagePart);

        if (mail.getAttachmentData() != null) {
            ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource(mail.getAttachmentData(),
                    mail.getAttachmentContentType());
            DataHandler dataHandler = new DataHandler(byteArrayDataSource);
            MimeBodyPart attachmentPart = new MimeBodyPart();
            attachmentPart.setDataHandler(dataHandler);
            attachmentPart.setFileName(mail.getAttachmentFileName());

            multipart.addBodyPart(attachmentPart);
        }

        // Open transport and send message
        Transport transport = session.getTransport(mailProtocol);
        if (StringUtils.isNotBlank(mailUser)) {
            transport.connect(mailUser, mailPassword);
        } else {
            transport.connect();
        }
        msg.saveChanges();
        transport.sendMessage(msg, msg.getAllRecipients());
    } catch (JMSException e) {
        errorLogger.logError(ApplicationComponent.MAIL, "Cannot handle the object message from the queue", e);
        throw new RuntimeException(e);
    } catch (MessagingException e) {
        errorLogger.logError(ApplicationComponent.MAIL, "Cannot send a mail message", e);
        throw new RuntimeException(e);
    }
}

From source file:eu.europa.ec.fisheries.uvms.rules.service.bean.TemplateEngine.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void evaluateFacts(List<AbstractFact> facts) throws RulesValidationException {
    if (CollectionUtils.isEmpty(facts)) {
        throw new RulesValidationException("No facts available for validation");
    }//from   w  w  w.  j  a va2 s .  c om
    ruleEvaluator.setExceptionsList(new ArrayList<AbstractFact>());
    ruleEvaluator.validateFact(facts);
    facts.addAll(ruleEvaluator.getExceptionsList());
}