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.OIGDAOBean.java

/**
 * Retrieves all available exclusion types.
 *
 * @return the exclusion types.//from  ww  w .  j  a  v  a  2 s.  com
 * @throws ParsingException if any parsing errors are encountered
 * @throws ServiceException for any other exceptions encountered
 *
 * @deprecated not updated in new site layout.
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Deprecated
public List<ExclusionType> getExclusionTypeList() throws ParsingException, ServiceException {
    String signature = "OIGDataAccessImpl#verifySSN";
    LogUtil.traceEntry(getLog(), signature, new String[] {}, new Object[] {});

    try {
        return LogUtil.traceExit(getLog(), signature, getAllExclusions());
    } catch (ClientProtocolException e) {
        LogUtil.traceError(getLog(), signature, e);
        throw new ServiceException(ErrorCode.MITA50001.getDesc(), e);
    } 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:com.flexive.ejb.beans.search.ResultPreferencesEngineBean.java

/** {@inheritDoc} */
@Override//from   ww w .  ja va  2  s .c o m
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void save(ResultPreferences preferences, long typeId, ResultViewType viewType, ResultLocation location)
        throws FxApplicationException {
    if (preferences.getSelectedColumns().isEmpty()) {
        throw new FxInvalidParameterException("preferences", "ex.ResultPreferences.save.empty");
    }
    configuration.put(SystemParameters.USER_RESULT_PREFERENCES, getKey(typeId, viewType, location),
            preferences);
}

From source file:gov.nih.nci.caarray.application.project.ProjectManagementServiceBean.java

/**
 * {@inheritDoc}//from  w ww .  ja  va2  s.  com
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@TransactionTimeout(UPLOAD_TIMEOUT)
public CaArrayFile addFile(Project project, InputStream data, String filename)
        throws ProposalWorkflowException, InconsistentProjectStateException {
    LogUtil.logSubsystemEntry(LOG, project);
    checkIfProjectSaveAllowed(project);
    final CaArrayFile caArrayFile = doAddStream(project, data, filename);

    LogUtil.logSubsystemExit(LOG);
    return caArrayFile;
}

From source file:org.cesecore.certificates.certificate.CertificateStoreSessionBean.java

License:asdf

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void storeCertificate(AuthenticationToken admin, Certificate incert, String username, String cafp,
        int status, int type, int certificateProfileId, String tag, long updateTime)
        throws AuthorizationDeniedException {
    // Check that user is authorized to the CA that issued this certificate
    int caid = CertTools.getIssuerDN(incert).hashCode();
    authorizedToCA(admin, caid);// w  ww .  j a  v  a 2  s  . c om
    storeCertificateNoAuth(admin, incert, username, cafp, status, type, certificateProfileId, tag, updateTime);
}

From source file:com.sfs.ucm.controller.UseCaseFlowAction.java

/**
 * Action: remove basic flow step//from w ww  . j a v a  2s.co m
 * 
 * @throws UCMException
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void removeFlowStep() throws UCMException {
    try {
        this.basicFlow.removeFlowStep(this.basicFlowStep);
        em.remove(this.basicFlowStep);
        logger.info("Deleted Step {}", this.basicFlowStep.getStepNumber());
        this.facesContextMessage.infoMessage("Step {0} deleted successfully",
                this.basicFlowStep.getStepNumber());

        // renumber steps
        renumberAllFlowSteps();

        // persist renumbering changes

        // force testcase update
        Timestamp now = new Timestamp(System.currentTimeMillis());
        this.useCase.setModifiedDate(now);

        em.persist(this.useCase);

        this.basicStepSelected = false;
    } catch (Exception e) {
        throw new UCMException(e);
    }
}

From source file:com.flexive.ejb.beans.structure.AssignmentEngineBean.java

/**
 * {@inheritDoc}//from  w w w  . j a v  a2 s. c  om
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public long createProperty(long typeId, FxPropertyEdit property, String parentXPath, String assignmentAlias)
        throws FxApplicationException {
    FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.StructureManagement);
    Connection con = null;
    PreparedStatement ps = null;
    StringBuilder sql = new StringBuilder(2000);
    long newPropertyId;
    long newAssignmentId;
    try {
        parentXPath = parentXPath.toUpperCase();
        assignmentAlias = assignmentAlias.toUpperCase();
        FxType type = CacheAdmin.getEnvironment().getType(typeId);
        FxAssignment tmp = type.getAssignment(parentXPath);
        if (tmp != null && tmp instanceof FxPropertyAssignment)
            throw new FxInvalidParameterException("ex.structure.assignment.noGroup", parentXPath);
        property.checkConsistency();
        //parentXPath is valid, create the property, then assign it to root
        newPropertyId = seq.getId(FxSystemSequencer.TYPEPROP);
        FxValue defValue = property.getDefaultValue();
        ContentStorage storage = StorageManager.getContentStorage(type.getStorageMode());
        con = Database.getDbConnection();
        if (defValue instanceof FxBinary) {
            storage.prepareBinary(con, (FxBinary) defValue);
        }
        final String _def = defValue == null || defValue.isEmpty() ? null
                : ConversionEngine.getXStream().toXML(defValue);

        if (_def != null && (property.getDefaultValue() instanceof FxReference)) {
            //check if the type matches the instance
            checkReferencedType(con, (FxReference) property.getDefaultValue(), property.getReferencedType());
        }

        // do not allow to add mandatory properties (i.e. min multiplicity > 0) to types for which content exists
        if (storage.getTypeInstanceCount(con, typeId) > 0 && property.getMultiplicity().getMin() > 0) {
            throw new FxCreateException("ex.structure.property.creation.existingContentMultiplicityError",
                    property.getName(), property.getMultiplicity().getMin());
        }

        //create property, no checks for existing names are performed as this is handled with unique keys
        sql.append("INSERT INTO ").append(TBL_STRUCT_PROPERTIES).
        //               1  2    3          4          5               6        7
                append("(ID,NAME,DEFMINMULT,DEFMAXMULT,MAYOVERRIDEMULT,DATATYPE,REFTYPE," +
        //8                9   10             11      12
                        "ISFULLTEXTINDEXED,ACL,MAYOVERRIDEACL,REFLIST,UNIQUEMODE," +
                        //13         14
                        "SYSINTERNAL,DEFAULT_VALUE)VALUES(" + "?,?,?,?,?," + "?,?,?,?,?,?,?,?,?)");
        ps = con.prepareStatement(sql.toString());
        ps.setLong(1, newPropertyId);
        ps.setString(2, property.getName());
        ps.setInt(3, property.getMultiplicity().getMin());
        ps.setInt(4, property.getMultiplicity().getMax());
        ps.setBoolean(5, property.mayOverrideBaseMultiplicity());
        ps.setLong(6, property.getDataType().getId());
        if (property.hasReferencedType())
            ps.setLong(7, property.getReferencedType().getId());
        else
            ps.setNull(7, java.sql.Types.NUMERIC);
        ps.setBoolean(8, property.isFulltextIndexed());
        ps.setLong(9, property.getACL().getId());
        ps.setBoolean(10, property.mayOverrideACL());
        if (property.hasReferencedList())
            ps.setLong(11, property.getReferencedList().getId());
        else
            ps.setNull(11, java.sql.Types.NUMERIC);
        ps.setInt(12, property.getUniqueMode().getId());
        ps.setBoolean(13, false);
        if (_def == null)
            ps.setNull(14, java.sql.Types.VARCHAR);
        else
            ps.setString(14, _def);
        if (!property.isAutoUniquePropertyName())
            ps.executeUpdate();
        else {
            //fetch used property names
            PreparedStatement ps2 = null;
            try {
                ps2 = con.prepareStatement(
                        "SELECT NAME FROM " + TBL_STRUCT_PROPERTIES + " WHERE NAME LIKE ? OR NAME=?");
                ps2.setString(1, property.getName() + "_%");
                ps2.setString(2, property.getName());
                ResultSet rs = ps2.executeQuery();
                int max = -1;
                while (rs.next()) {
                    String last = rs.getString(1);
                    if (last.equals(property.getName()) || last.startsWith(property.getName() + "_")) {
                        if (last.equals(property.getName())) {
                            max = Math.max(0, max);
                        } else if (last.startsWith(property.getName() + "_")) {
                            final String suffix = last.substring(last.lastIndexOf("_") + 1);
                            if (StringUtils.isNumeric(suffix)) {
                                max = Math.max(Integer.parseInt(suffix), max);
                            }
                        }
                    }
                    if (max != -1) {
                        final String autoName = property.getName() + "_" + (max + 1);
                        ps.setString(2, autoName);
                        LOG.info("Assigning unique property name [" + autoName + "] to [" + type.getName() + "."
                                + property.getName() + "]");
                    }
                }
            } finally {
                Database.closeObjects(AssignmentEngineBean.class, ps2);
            }
            ps.executeUpdate();
        }
        Database.storeFxString(new FxString[] { property.getLabel(), property.getHint() }, con,
                TBL_STRUCT_PROPERTIES, new String[] { "DESCRIPTION", "HINT" }, "ID", newPropertyId);
        ps.close();
        sql.setLength(0);
        //calc new position
        sql.append("SELECT COALESCE(MAX(POS)+1,0) FROM ").append(TBL_STRUCT_ASSIGNMENTS)
                .append(" WHERE PARENTGROUP=? AND TYPEDEF=?");
        ps = con.prepareStatement(sql.toString());
        ps.setLong(1, (tmp == null ? FxAssignment.NO_PARENT : tmp.getId()));
        ps.setLong(2, typeId);
        ResultSet rs = ps.executeQuery();
        long pos = 0;
        if (rs != null && rs.next())
            pos = rs.getLong(1);
        ps.close();
        storeOptions(con, TBL_STRUCT_PROPERTY_OPTIONS, "ID", newPropertyId, null, property.getOptions());
        sql.setLength(0);
        //create root assignment
        sql.append("INSERT INTO ").append(TBL_STRUCT_ASSIGNMENTS).
        //               1  2     3       4       5       6       7       8   9     10    11    12          13
                append("(ID,ATYPE,ENABLED,TYPEDEF,MINMULT,MAXMULT,DEFMULT,POS,XPATH,XALIAS,BASE,PARENTGROUP,APROPERTY,"
                        +
                        //14 15
                        "ACL,DEFAULT_VALUE)" + "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
        ps = con.prepareStatement(sql.toString());
        newAssignmentId = seq.getId(FxSystemSequencer.ASSIGNMENT);
        ps.setLong(1, newAssignmentId);
        ps.setInt(2, FxAssignment.TYPE_PROPERTY);
        ps.setBoolean(3, true);
        ps.setLong(4, typeId);
        ps.setInt(5, property.getMultiplicity().getMin());
        ps.setInt(6, property.getMultiplicity().getMax());
        if (property.getMultiplicity().isValid(property.getAssignmentDefaultMultiplicity())) {
            ps.setInt(7, property.getAssignmentDefaultMultiplicity());
        } else {
            //default is min(min,1).
            ps.setInt(7, property.getMultiplicity().getMin() > 1 ? property.getMultiplicity().getMin() : 1);
        }
        ps.setLong(8, pos);
        if (parentXPath == null || "/".equals(parentXPath))
            parentXPath = "";
        ps.setString(9, type.getName() + XPathElement.stripType(parentXPath) + "/" + assignmentAlias);
        ps.setString(10, assignmentAlias);
        ps.setNull(11, Types.NUMERIC);
        if (tmp == null)
            ps.setLong(12, FxAssignment.NO_PARENT);
        else
            ps.setLong(12, tmp.getId());
        ps.setLong(13, newPropertyId);
        ps.setLong(14, property.getACL().getId());
        ps.setString(15, _def);
        ps.executeUpdate();
        Database.storeFxString(new FxString[] { property.getLabel(), property.getHint() }, con,
                TBL_STRUCT_ASSIGNMENTS, new String[] { "DESCRIPTION", "HINT" }, "ID", newAssignmentId);
        StructureLoader.reloadAssignments(FxContext.get().getDivisionId());
        if (divisionConfig.isFlatStorageEnabled() && divisionConfig.get(SystemParameters.FLATSTORAGE_AUTO)) {
            final FxFlatStorage fs = FxFlatStorageManager.getInstance();
            FxPropertyAssignment pa = (FxPropertyAssignment) CacheAdmin.getEnvironment()
                    .getAssignment(newAssignmentId);
            if (fs.isFlattenable(pa)) {
                fs.flatten(con, fs.getDefaultStorage(), pa);
                StructureLoader.reloadAssignments(FxContext.get().getDivisionId());
            }
        }
        htracker.track(type, "history.assignment.createProperty", property.getName(), type.getId(),
                type.getName());
        if (type.getId() != FxType.ROOT_ID)
            createInheritedAssignments(CacheAdmin.getEnvironment().getAssignment(newAssignmentId), con, sql,
                    type.getDerivedTypes());
    } catch (FxNotFoundException e) {
        EJBUtils.rollback(ctx);
        throw new FxCreateException(e);
    } catch (FxLoadException e) {
        EJBUtils.rollback(ctx);
        throw new FxCreateException(e);
    } catch (SQLException e) {
        final boolean uniqueConstraintViolation = StorageManager.isUniqueConstraintViolation(e);
        EJBUtils.rollback(ctx);
        if (uniqueConstraintViolation)
            throw new FxEntryExistsException("ex.structure.property.exists", property.getName(),
                    (parentXPath.length() == 0 ? "/" : parentXPath));
        throw new FxCreateException(LOG, e, "ex.db.sqlError", e.getMessage());
    } finally {
        Database.closeObjects(AssignmentEngineBean.class, con, ps);
    }
    return newAssignmentId;
}

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

/**
 * Performs verification of the given license.
 *
 * @param license the license to verify//from   w  w w  .  j  av a  2 s  .com
 * @return true if the license has been verified, false otherwise
 *
 * @throws ParsingException if any parsing errors are encountered
 * @throws ServiceException for any other exceptions encountered
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public boolean verifyLicense(License license) throws ParsingException, ServiceException {
    String signature = "BBHTLicenseDataAccessImpl#verifyLicense";
    LogUtil.traceEntry(getLog(), signature, new String[] { "license" }, new Object[] { license });

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

    BBHTLicenseSearchCriteria criteria = new BBHTLicenseSearchCriteria();
    criteria.setLicenseType(license.getType());
    criteria.setIdentifier(license.getLicenseNumber());
    SearchResult<License> result = search(criteria);
    // single result expected
    return result != null && !result.getItems().isEmpty()
            && "Active".equals(result.getItems().get(0).getStatus().getName());
}

From source file:be.fedict.trust.service.bean.TrustServiceBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
@SNMP(oid = SnmpConstants.VALIDATE)//from  w  w  w .ja  va 2 s.c  o  m
public ValidationResult validate(String trustDomainName, List<X509Certificate> certificateChain,
        Date validationDate, List<byte[]> ocspResponses, List<byte[]> crls) throws TrustDomainNotFoundException,
        CertificateException, NoSuchProviderException, CRLException, IOException {

    LOG.debug("isValid CRLs: " + certificateChain.get(0).getSubjectX500Principal());

    TrustLinkerResult lastResult = null;
    RevocationData lastRevocationData = null;
    for (TrustDomainEntity trustDomain : getTrustDomains(trustDomainName)) {

        TrustValidator trustValidator = getTrustValidator(trustDomain, ocspResponses, crls);

        try {
            trustValidator.isTrusted(certificateChain, validationDate);
        } catch (CertPathValidatorException ignored) {
        }

        if (trustValidator.getResult().isValid()) {
            LOG.debug("valid for trust domain: " + trustDomain.getName());
            return new ValidationResult(trustValidator.getResult(), trustValidator.getRevocationData());
        }

        lastResult = trustValidator.getResult();
        lastRevocationData = trustValidator.getRevocationData();
    }

    return new ValidationResult(lastResult, lastRevocationData);
}

From source file:ch.puzzle.itc.mobiliar.business.template.boundary.TemplateEditor.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
boolean hasTemplateWithSameName(TemplateDescriptorEntity template, HasContexts<?> hasContext) {
    for (ContextDependency<?> c : hasContext
            .getContextsByLowestContext(contextService.getGlobalResourceContextEntity())) {
        for (TemplateDescriptorEntity t : c.getTemplates()) {
            // If the template doesn't exist but has the same name, we return true
            if (!t.getId().equals(template.getId()) && t.getName().equals(template.getName())) {
                return true;
            }//ww  w  .  j  a  va  2  s  . co  m
        }
    }
    return false;
}

From source file:com.sfs.ucm.controller.SpecificationAction.java

/**
 * save action/*from w w w .  ja v a 2  s.  co  m*/
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void save() throws UCMException {
    try {
        if (validate()) {
            this.specification.setModifiedBy(authUser.getUsername());
            if (this.specification.getId() == null) {
                this.project.addSpecification(this.specification);
            }

            em.persist(this.project);

            logger.info("saved {}", this.specification.getArtifact());
            this.facesContextMessage.infoMessage("{0} saved successfully", this.specification.getArtifact());

            // refresh list
            loadList();
            this.selected = true;
        }
    } catch (Exception e) {
        throw new UCMException(e);
    }
}