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:gov.medicaid.screening.dao.impl.NurseAnesthetistsLicenseDAOBean.java

/**
 * Searches for Nurse Anesthetists license.
 *
 * @param criteria the search criteria//  ww w.  j a  v a  2  s . com
 * @return the matched profile
 * @throws IllegalArgumentException if the criteria is null
 * @throws IllegalArgumentException if the last 4 digits of the SSN is not provided
 * @throws IllegalArgumentException if the AANA number is not provided
 * @throws ServiceException for any other exceptions encountered
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public ProviderProfile search(NurseAnesthetistsSearchCriteria criteria) throws ServiceException {
    String signature = "NurseAnesthetistsLicenseDAOBean#search";
    LogUtil.traceEntry(getLog(), signature, new String[] { "criteria" }, new Object[] { criteria });

    if (criteria == null) {
        throw new IllegalArgumentException(ErrorCode.MITA10005.getDesc());
    }

    if (criteria.getSsn() == null || !criteria.getSsn().matches(".*[0-9]{4}$")) {
        throw new IllegalArgumentException(ErrorCode.MITA10025.getDesc());
    }

    if (criteria.getAanaNumber() <= 0) {
        throw new IllegalArgumentException(ErrorCode.MITA10026.getDesc());
    }

    try {
        ProviderProfile result = getProviderProfile(criteria);
        logSearchEntry(criteria);
        return LogUtil.traceExit(getLog(), signature, result);
    } catch (ServiceException e) {
        LogUtil.traceError(getLog(), signature, e);
        throw e;
    } catch (Throwable e) {
        LogUtil.traceError(getLog(), signature, e);
        throw new ServiceException(ErrorCode.MITA99999.getDesc(), e);
    }
}

From source file:com.flexive.ejb.beans.search.ResultPreferencesEngineBean.java

/** {@inheritDoc} */
@Override/*from   w  w w.j  a va 2 s.com*/
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public ResultPreferences load(long typeId, ResultViewType viewType, ResultLocation location)
        throws FxApplicationException {
    return loadWithType(typeId, viewType, location).getPreferences();
}

From source file:fr.ortolang.diffusion.notification.NotificationServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void throwEvent(String fromObject, String throwedBy, String objectType, String eventType,
        Map<String, String> arguments) throws NotificationServiceException {
    try {/*  ww  w.j  a va2s.c  om*/
        Message message = context.createMessage();
        message.setStringProperty(OrtolangEvent.DATE, OrtolangEvent.getEventDateFormatter().format(new Date()));
        message.setStringProperty(OrtolangEvent.THROWED_BY, throwedBy);
        message.setStringProperty(OrtolangEvent.FROM_OBJECT, fromObject);
        message.setStringProperty(OrtolangEvent.OBJECT_TYPE, objectType);
        message.setStringProperty(OrtolangEvent.TYPE, eventType);
        if (arguments != null && arguments instanceof Serializable) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(arguments);
            oos.close();
            message.setStringProperty(OrtolangEvent.ARGUMENTS, Base64.encodeBase64String(baos.toByteArray()));
        }
        context.createProducer().send(notificationTopic, message);

    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "unable to throw event", e);
        throw new NotificationServiceException("unable to throw event", e);
    }
}

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

/**
 * This method gets the applicable providers that meet the search criteria. If none available, the search result
 * will be empty./*from   w  w w  . j  ava 2  s  .co m*/
 *
 * @param criteria the search criteria
 * @return the search result with the matched providers
 * @throws IllegalArgumentException if the criteria is null, if criteria.pageNumber < 0; if criteria.pageSize < 1
 *             unless criteria.pageNumber <= 0
 * @throws ParsingException - if the parsing of the responses caused an error
 * @throws ServiceException for any other exceptions encountered
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public SearchResult<ProviderProfile> search(MedicaidCertifiedProviderSearchCriteria criteria)
        throws ParsingException, ServiceException {
    String signature = "MedicaidCertifiedProvidersDAOBean#search";
    LogUtil.traceEntry(getLog(), signature, new String[] { "criteria" }, new Object[] { criteria });

    // make sure we have enough parameters to perform the external search
    validateCriteria(criteria);

    // make sure that the sort column is one of the properties we support
    validateSortOptions(criteria, SORT_COLUMNS);

    try {
        SearchResult<ProviderProfile> allResults = getAllResults(criteria);
        SearchResult<ProviderProfile> results = trimResults(allResults, criteria.getPageSize(),
                criteria.getPageNumber(), SORT_COLUMNS.get(criteria.getSortColumn()), criteria.getSortOrder());
        logSearchEntry(criteria);
        return LogUtil.traceExit(getLog(), signature, results);
    } catch (ServiceException e) {
        LogUtil.traceError(getLog(), signature, e);
        throw e;
    } catch (Throwable e) {
        LogUtil.traceError(getLog(), signature, e);
        throw new ServiceException(ErrorCode.MITA99999.getDesc(), e);
    }
}

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

/**
 * Searches for Podiatric Medicine Licenses by name.
 *
 * @param criteria the search criteria//from w  w w.j  a  v a2s  .c om
 * @return the matched results
 * @throws ParsingException if any parsing errors are encountered
 * @throws IllegalArgumentException If criteria is null
 * @throws IllegalArgumentException If criteria.pageNumber < 0
 * @throws IllegalArgumentException If criteria.pageSize < 1 unless criteria.pageNumber <= 0
 * @throws IllegalArgumentException If no name criteria is provided
 * @throws ServiceException for any other exceptions encountered
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public SearchResult<License> searchByName(PodiatricMedicineLicenseSearchByNameCriteria criteria)
        throws ParsingException, ServiceException {
    String signature = "PodiatricMedicineLicenseDAOBean#searchByName";
    LogUtil.traceEntry(getLog(), signature, new String[] { "criteria" }, new Object[] { criteria });

    if (criteria == null) {
        throw new IllegalArgumentException(ErrorCode.MITA10005.getDesc());
    }

    if (criteria.getPageNumber() < 0 || (criteria.getPageNumber() > 0 && criteria.getPageSize() < 0)) {
        throw new IllegalArgumentException(ErrorCode.MITA10027.getDesc());
    }

    if (Util.isBlank(criteria.getLastName())) {
        throw new IllegalArgumentException(ErrorCode.MITA10001.getDesc());
    }

    return LogUtil.traceExit(getLog(), signature, doSearch(criteria, criteria.getLastName()));
}

From source file:be.fedict.eid.pkira.blm.model.usermgmt.RegistrationManagerBean.java

/**
 * {@inheritDoc}/*w ww .j a  v a  2  s  .  co m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void registerUser(String userRRN, String userLastName, String userFirstName, Integer domainId,
        String emailAddress, String locale) throws RegistrationException {
    // Check if there are already users in the database; if not this one
    // becomes admin
    boolean isAdmin = 0 == userRepository.getUserCount();

    // Lookup or create the user
    if (StringUtils.isBlank(userRRN)) {
        throw new RegistrationException("Empty user RRN.");
    }
    User user = userRepository.findByNationalRegisterNumber(userRRN);
    if (user == null) {
        user = new User();
        user.setFirstName(userFirstName);
        user.setLastName(userLastName);
        user.setNationalRegisterNumber(userRRN);
        user.setAdmin(isAdmin);
        user.setLocale(locale != null ? locale : "en");
        userRepository.persist(user);
    } else {
        userHome.setInstance(user);
        userHome.getInstance().setLocale(locale);
        userHome.update();
    }

    // Check if we have to add him to a certificate domain
    if (domainId != null) {
        // Lookup the domain
        certificateDomainHome.setId(domainId);
        CertificateDomain domain = certificateDomainHome.find();
        if (domain == null) {
            throw new RegistrationException("Unknown certificate domain.");
        }

        // Validate the e-mail address
        if (StringUtils.isBlank(emailAddress) || !createEmailValidator().isValid(emailAddress)) {
            throw new RegistrationException("Invalid e-mail address");
        }

        // Check if the registration is new
        if (registrationRepository.findRegistration(domain, user) != null) {
            throw new RegistrationException("User already has a registration for this domain.");
        }

        // Create the registration
        Registration registration = new Registration();
        registration.setCertificateDomain(domain);
        registration.setRequester(user);
        registration.setEmail(emailAddress);
        registration.setStatus(RegistrationStatus.NEW);

        registrationRepository.persist(registration);

        if (Events.exists()) {
            Events.instance().raiseEvent(RegistrationMailHandler.REGISTRATION_CREATED, registration);
        }
    }
}

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

/**
 * Searches for MN business and liens by name.
 *
 * @param criteria the search criteria//from   ww w  .  j  a  v a  2s  .  c om
 * @return the matched results
 * @throws ParsingException if any parsing errors are encountered
 * @throws ServiceException for any other exceptions encountered
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public SearchResult<ProviderProfile> searchByName(BusinessLienSearchCriteria criteria)
        throws ParsingException, ServiceException {
    String signature = "BusinessLienDataAccessImpl#searchByName";
    LogUtil.traceEntry(getLog(), signature, new String[] { "criteria" }, new Object[] { criteria });

    if (criteria == null) {
        throw new ServiceException(ErrorCode.MITA10005.getDesc());
    }

    if (Util.isBlank(criteria.getBusinessName())) {
        throw new ServiceException(ErrorCode.MITA10023.getDesc());
    }

    return LogUtil.traceExit(getLog(), signature, search(criteria));
}

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

/**
 * Searches for health occupations program credentials.
 *
 * @param criteria the search criteria//from w  w  w. j  ava 2  s . c o m
 * @return the matched results
 * @throws IllegalArgumentException if the criteria is null
 * @throws ServiceException for any other exceptions encountered
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public SearchResult<ProviderProfile> search(HealthOccupationsProgramCredentialSearchCriteria criteria)
        throws ServiceException {
    String signature = "HealthOccupationsProgramCredentialDAOBean#search";
    LogUtil.traceEntry(getLog(), signature, new String[] { "criteria" }, new Object[] { criteria });

    if (criteria == null) {
        throw new ServiceException(ErrorCode.MITA10005.getDesc());
    }

    validateSortOptions(criteria, SORT_COLUMNS);

    // site allows blank search so no other validations are performed
    try {
        SearchResult<ProviderProfile> allResults = getAllResults(criteria);
        SearchResult<ProviderProfile> results = trimResults(allResults, criteria.getPageSize(),
                criteria.getPageNumber(), SORT_COLUMNS.get(criteria.getSortColumn()), criteria.getSortOrder());
        logSearchEntry(criteria);
        return results;
    } catch (ClientProtocolException e) {
        throw new ServiceException(ErrorCode.MITA50001.getDesc(), e);
    } catch (URISyntaxException e) {
        throw new ServiceException(ErrorCode.MITA50001.getDesc(), e);
    } catch (IOException e) {
        throw new ServiceException(ErrorCode.MITA50001.getDesc(), e);
    } catch (ParseException e) {
        throw new ServiceException(ErrorCode.MITA50001.getDesc(), e);
    }
}

From source file:com.flexive.ejb.beans.MandatorEngineBean.java

/**
 * {@inheritDoc}/*from ww  w .  j  a  v a  2s .c  o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public int create(String name, boolean active) throws FxApplicationException {
    final UserTicket ticket = FxContext.getUserTicket();
    final FxEnvironment environment;
    // Security
    FxPermissionUtils.checkRole(ticket, Role.GlobalSupervisor);
    FxSharedUtils.checkParameterEmpty(name, "NAME");
    environment = CacheAdmin.getEnvironment();
    //exist check
    for (Mandator m : environment.getMandators(true, true))
        if (m.getName().equalsIgnoreCase(name))
            throw new FxEntryExistsException("ex.mandator.exists", name);

    Connection con = null;
    PreparedStatement ps = null;
    String sql;

    try {

        // Obtain a database connection
        con = Database.getDbConnection();

        // Obtain a new id
        int newId = (int) seq.getId(FxSystemSequencer.MANDATOR);

        sql = "INSERT INTO " + TBL_MANDATORS + "(" +
        //1 2    3        4         5          6          7           8
                "ID,NAME,METADATA,IS_ACTIVE,CREATED_BY,CREATED_AT,MODIFIED_BY,MODIFIED_AT)"
                + "VALUES (?,?,?,?,?,?,?,?)";
        final long NOW = System.currentTimeMillis();
        ps = con.prepareStatement(sql);
        ps.setInt(1, newId);
        ps.setString(2, name.trim());
        ps.setNull(3, java.sql.Types.INTEGER);
        ps.setBoolean(4, active);
        ps.setLong(5, ticket.getUserId());
        ps.setLong(6, NOW);
        ps.setLong(7, ticket.getUserId());
        ps.setLong(8, NOW);
        ps.executeUpdate();
        ps.close();
        sql = "INSERT INTO " + TBL_USERGROUPS + " "
                + "(ID,MANDATOR,AUTOMANDATOR,ISSYSTEM,NAME,COLOR,CREATED_BY,CREATED_AT,MODIFIED_BY,MODIFIED_AT) VALUES ("
                + "?,?,?,?,?,?,?,?,?,?)";
        ps = con.prepareStatement(sql);
        long gid = seq.getId(FxSystemSequencer.GROUP);
        ps.setLong(1, gid);
        ps.setLong(2, newId);
        ps.setLong(3, newId);
        ps.setBoolean(4, true);
        ps.setString(5, "Everyone (" + name.trim() + ")");
        ps.setString(6, "#00AA00");
        ps.setLong(7, 0);
        ps.setLong(8, NOW);
        ps.setLong(9, 0);
        ps.setLong(10, NOW);
        ps.executeUpdate();
        StructureLoader.addMandator(FxContext.get().getDivisionId(), new Mandator(newId, name.trim(), -1,
                active, new LifeCycleInfoImpl(ticket.getUserId(), NOW, ticket.getUserId(), NOW)));
        StructureLoader.updateUserGroups(FxContext.get().getDivisionId(), grp.loadAll(-1));
        return newId;
    } catch (SQLException exc) {
        final boolean uniqueConstraintViolation = StorageManager.isUniqueConstraintViolation(exc);
        EJBUtils.rollback(ctx);
        if (uniqueConstraintViolation) {
            throw new FxEntryExistsException(LOG, "ex.mandator.exists", name);
        } else {
            throw new FxCreateException(LOG, exc, "ex.mandator.createFailed", name, exc.getMessage());
        }
    } finally {
        Database.closeObjects(MandatorEngineBean.class, con, ps);
    }
}

From source file:gov.nih.nci.caarray.application.GenericDataServiceBean.java

/**
 * {@inheritDoc}/*from w ww  .  j a v a2s  .c om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void save(PersistentObject entity) {
    if (entity instanceof Protectable && !SecurityUtils.canWrite(entity, CaArrayUsernameHolder.getCsmUser())) {
        throw new IllegalArgumentException(
                "The current user does not have the rights to edit the given object.");
    }
    this.searchDao.save(entity);
}