Search in sources :

Example 1 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project eap-additional-testsuite by jboss-set.

the class SFSB method setupConfig.

@TransactionAttribute(TransactionAttributeType.NEVER)
public void setupConfig() {
    // static {
    try {
        // prepare the configuration
        Configuration configuration = new Configuration().setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
        configuration.getProperties().put(AvailableSettings.JTA_PLATFORM, JBossAppServerJtaPlatform.class);
        configuration.getProperties().put(AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jta");
        configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
        configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS");
        // fetch the properties
        Properties properties = new Properties();
        configuration = configuration.configure("hibernate.cfg.xml");
        properties.putAll(configuration.getProperties());
        Environment.verifyProperties(properties);
        ConfigurationHelper.resolvePlaceHolders(properties);
        sessionFactory = configuration.buildSessionFactory();
    } catch (Throwable ex) {
        // Make sure you log the exception, as it might be swallowed
        ex.printStackTrace();
        throw new ExceptionInInitializerError(ex);
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) Properties(java.util.Properties) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 2 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project Payara by payara.

the class TransactionAttributeHandler method postProcessAnnotation.

/**
 * Set the default value (from class type annotation) on all
 * methods that don't have a value.
 */
public void postProcessAnnotation(AnnotationInfo ainfo, EjbContext ejbContext) throws AnnotationProcessorException {
    EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
    TransactionAttribute taAn = (TransactionAttribute) ainfo.getAnnotation();
    ContainerTransaction containerTransaction = getContainerTransaction(taAn.value());
    Class classAn = (Class) ainfo.getAnnotatedElement();
    Set txBusMethods = ejbDesc.getTxBusinessMethodDescriptors();
    for (Object mdObj : txBusMethods) {
        MethodDescriptor md = (MethodDescriptor) mdObj;
        // override by xml
        if (classAn.equals(ejbContext.getDeclaringClass(md)) && ejbDesc.getContainerTransactionFor(md) == null) {
            ejbDesc.setContainerTransactionFor(md, containerTransaction);
        }
    }
}
Also used : Set(java.util.Set) TransactionAttribute(javax.ejb.TransactionAttribute) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

Example 3 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project quickstart by wildfly.

the class CustomerManagerEJB method createCustomer.

@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void createCustomer(String name) throws RemoteException, JMSException {
    logMessageManager.logCreateCustomer(name);
    Customer c1 = new Customer();
    c1.setName(name);
    entityManager.persist(c1);
    invoiceManager.createInvoice(name);
    // after the fact but before the transaction is committed.
    if (!nameIsValid(name)) {
        throw new EJBException("Invalid name: customer names should only contain letters & '-'");
    }
}
Also used : Customer(org.jboss.as.quickstarts.cmt.model.Customer) EJBException(javax.ejb.EJBException) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 4 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project UVMS-ActivityModule-APP by UnionVMS.

the class MovementModuleServiceBean method getMovement.

/**
 * {@inheritDoc}
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public List<MovementType> getMovement(List<String> vesselIds, Date startDate, Date endDate) throws ServiceException {
    try {
        MovementQuery movementQuery = new MovementQuery();
        addListCriteria(vesselIds, movementQuery);
        addRangeCriteria(startDate, endDate, movementQuery);
        movementQuery.setExcludeFirstAndLastSegment(true);
        String request = MovementModuleRequestMapper.mapToGetMovementMapByQueryRequest(movementQuery);
        String moduleMessage = movementProducer.sendModuleMessage(request, activityConsumer.getDestination());
        TextMessage response = activityConsumer.getMessage(moduleMessage, TextMessage.class);
        if (response != null && !isUserFault(response)) {
            List<MovementMapResponseType> mapResponseTypes = MovementModuleResponseMapper.mapToMovementMapResponse(response);
            List<MovementType> movements = new ArrayList<>();
            for (MovementMapResponseType movementMap : mapResponseTypes) {
                movements.addAll(movementMap.getMovements());
            }
            return movements;
        } else {
            throw new ServiceException("FAILED TO GET DATA FROM MOVEMENT");
        }
    } catch (MovementDuplicateException | MovementFaultException | ServiceException | MessageException | JMSException | ModelMapperException e) {
        log.error("Exception in communication with movements", e);
        throw new ServiceException(e.getMessage(), e);
    }
}
Also used : MovementQuery(eu.europa.ec.fisheries.schema.movement.search.v1.MovementQuery) MovementFaultException(eu.europa.ec.fisheries.uvms.movement.model.exception.MovementFaultException) MovementDuplicateException(eu.europa.ec.fisheries.uvms.movement.model.exception.MovementDuplicateException) ArrayList(java.util.ArrayList) MovementMapResponseType(eu.europa.ec.fisheries.schema.movement.search.v1.MovementMapResponseType) JMSException(javax.jms.JMSException) MovementType(eu.europa.ec.fisheries.schema.movement.v1.MovementType) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) MessageException(eu.europa.ec.fisheries.uvms.commons.message.api.MessageException) ModelMapperException(eu.europa.ec.fisheries.uvms.movement.model.exception.ModelMapperException) TextMessage(javax.jms.TextMessage) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 5 with TransactionAttribute

use of javax.ejb.TransactionAttribute in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityMessageConsumerBean method onMessage.

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void onMessage(Message message) {
    TextMessage textMessage = null;
    try {
        textMessage = (TextMessage) message;
        MappedDiagnosticContext.addMessagePropertiesToThreadMappedDiagnosticContext(textMessage);
        ActivityModuleRequest request;
        request = JAXBMarshaller.unmarshallTextMessage(textMessage, ActivityModuleRequest.class);
        LOG.debug("Message unmarshalled successfully in activity");
        if (request == null) {
            LOG.error("[ Request is null ]");
            return;
        }
        ActivityModuleMethod method = request.getMethod();
        if (method == null) {
            LOG.error("[ Request method is null ]");
            return;
        }
        switch(method) {
            case GET_FLUX_FA_REPORT:
            case GET_FLUX_FA_QUERY:
                receiveFishingActivityEvent.fire(new EventMessage(textMessage, method));
                break;
            case MAP_TO_SUBSCRIPTION_REQUEST:
                mapToSubscriptionRequest.fire(new EventMessage(textMessage));
                break;
            case GET_FISHING_TRIPS:
                getFishingTripListEvent.fire(new EventMessage(textMessage));
                break;
            case GET_FA_CATCH_SUMMARY_REPORT:
                getFACatchSummaryReportEvent.fire(new EventMessage(textMessage));
                break;
            case GET_NON_UNIQUE_IDS:
                getNonUniqueIdsRequest.fire(new EventMessage(textMessage));
                break;
            case GET_FISHING_ACTIVITY_FOR_TRIPS:
                getFishingActivityForTrips.fire(new EventMessage(textMessage));
                break;
            default:
                LOG.error("[ Request method {} is not implemented ]", method.name());
                errorEvent.fire(new EventMessage(textMessage, ActivityModuleResponseMapper.createFaultMessage(FaultCode.ACTIVITY_MESSAGE, "[ Request method " + method.name() + "  is not implemented ]")));
        }
    } catch (ActivityModelMarshallException | ClassCastException e) {
        LOG.error("[ Error when receiving message in activity: ] {}", e);
        errorEvent.fire(new EventMessage(textMessage, ActivityModuleResponseMapper.createFaultMessage(FaultCode.ACTIVITY_MESSAGE, "Error when receiving message")));
    }
}
Also used : ActivityModelMarshallException(eu.europa.ec.fisheries.uvms.activity.model.exception.ActivityModelMarshallException) ActivityModuleMethod(eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityModuleMethod) EventMessage(eu.europa.ec.fisheries.uvms.activity.message.event.carrier.EventMessage) TextMessage(javax.jms.TextMessage) ActivityModuleRequest(eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityModuleRequest) TransactionAttribute(javax.ejb.TransactionAttribute)

Aggregations

TransactionAttribute (javax.ejb.TransactionAttribute)50 IOException (java.io.IOException)7 JMSException (javax.jms.JMSException)6 Query (javax.persistence.Query)5 Dataset (edu.harvard.iq.dataverse.Dataset)4 Date (java.util.Date)4 EJBException (javax.ejb.EJBException)4 Connection (javax.jms.Connection)4 Message (javax.jms.Message)4 MessageProducer (javax.jms.MessageProducer)4 Session (javax.jms.Session)4 TextMessage (javax.jms.TextMessage)4 Configuration (org.hibernate.cfg.Configuration)4 DataFile (edu.harvard.iq.dataverse.DataFile)3 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)3 EntityManager (javax.persistence.EntityManager)3 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)2 Dataverse (edu.harvard.iq.dataverse.Dataverse)2 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)2 RestApiClient (fi.otavanopisto.muikku.openfire.rest.client.RestApiClient)2