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:edu.harvard.iq.dvn.core.study.StudyServiceBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Study importHarvestStudy(File xmlFile, Long vdcId, Long userId, String harvestIdentifier) {
    VDC vdc = em.find(VDC.class, vdcId);
    em.refresh(vdc); // workaround to get correct value for harvesting dataverse (to be investigated)

    if (vdc.getHarvestingDataverse() == null) {
        throw new EJBException("importHarvestStudy(...) should only be called for a harvesting dataverse.");
    }//from  w  w w . j ava  2 s  .  c o m

    Study study = doImportStudy(xmlFile, vdc.getHarvestingDataverse().getHarvestFormatType().getId(), vdcId,
            userId, harvestIdentifier, null);

    // new create exports files for these studies

    studyService.exportStudy(study);

    logger.info("completed importHarvestStudy() returning study" + study.getGlobalId());
    return study;
}

From source file:org.rhq.enterprise.server.content.ContentManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Package persistPackage(Package pkg) {
    // EM.persist requires related entities to be attached, let's attach them now
    pkg.setPackageType(entityManager.find(PackageType.class, pkg.getPackageType().getId()));

    // our object's relations are now full attached, we can persist it
    entityManager.persist(pkg);/*from   w  ww  .  j  a v  a  2s.c o m*/
    return pkg;
}

From source file:org.rhq.enterprise.server.content.ContentSourceManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public RepoSyncResults _mergeAdvisorySyncReportREMOVE(ContentSource contentSource, AdvisorySyncReport report,
        RepoSyncResults syncResults, StringBuilder progress) {

    progress.append(new Date()).append(": ").append("Removing");
    syncResults.setResults(progress.toString());
    syncResults = repoManager.mergeRepoSyncResults(syncResults);

    AdvisoryManagerLocal advManager = LookupUtil.getAdvisoryManagerLocal();
    Subject overlord = LookupUtil.getSubjectManager().getOverlord();

    // remove all advisories that are no longer available on the remote repository
    for (AdvisoryDetails advDetails : report.getDeletedAdvisorys()) {
        Advisory nukeAdv = advManager.getAdvisoryByName(advDetails.getAdvisory());
        advManager.deleteAdvisoryCVE(overlord, nukeAdv.getId());
        advManager.deleteAdvisoryPackage(overlord, nukeAdv.getId());
        advManager.deleteAdvisoryBugList(overlord, nukeAdv.getId());
        advManager.deleteAdvisoryByAdvId(overlord, nukeAdv.getId());

        progress.append("Removed advisory & advisory cves for: " + advDetails.getAdvisory());
        syncResults.setResults(progress.toString());
        syncResults = repoManager.mergeRepoSyncResults(syncResults);
    }/*  w w  w  .ja v  a 2  s  .  c  o  m*/

    progress.append("Finished Advisory removal...").append('\n');
    syncResults.setResults(progress.toString());
    syncResults = repoManager.mergeRepoSyncResults(syncResults);

    return syncResults;
}

From source file:edu.harvard.iq.dvn.core.study.StudyServiceBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Study importStudy(File xmlFile, Long harvestFormatTypeId, Long vdcId, Long userId) {
    return doImportStudy(xmlFile, harvestFormatTypeId, vdcId, userId, null, null);
}

From source file:edu.harvard.iq.dvn.core.study.StudyServiceBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Study importStudy(File xmlFile, Long harvestFormatTypeId, Long vdcId, Long userId,
        List<StudyFileEditBean> filesToUpload) {
    return doImportStudy(xmlFile, harvestFormatTypeId, vdcId, userId, null, filesToUpload);
}

From source file:edu.harvard.iq.dvn.core.study.StudyServiceBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Study importStudy(File xmlFile, Long harvestFormatTypeId, Long vdcId, Long userId,
        String harvestIdentifier, List<StudyFileEditBean> filesToUpload) {
    return doImportStudy(xmlFile, harvestFormatTypeId, vdcId, userId, harvestIdentifier, filesToUpload);
}

From source file:org.nightlabs.jfire.store.StoreManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@RolesAllowed("_Guest_")
@Override//from   ww w.jav  a  2 s .co m
public DeliveryResult _deliverEnd(DeliveryID deliveryID, DeliveryResult deliverEndClientResult,
        boolean forceRollback) {
    if (deliveryID == null)
        throw new NullPointerException("deliveryID");

    if (deliverEndClientResult == null)
        throw new NullPointerException("deliverEndClientResult");

    // Store deliverEndClientResult into the database within a NEW TRANSACTION to
    // prevent it from being lost (if this method fails later and causes a rollback).
    try {
        deliveryHelperLocal.deliverEnd_storeDeliverEndClientResult(deliveryID, deliverEndClientResult,
                forceRollback);
    } catch (RuntimeException x) {
        throw x;
    } catch (Exception x) {
        throw new RuntimeException(x);
    }

    String[] fetchGroups = new String[] { FetchPlan.DEFAULT };

    try {

        DeliveryResult res = deliveryHelperLocal.deliverEnd_internal(deliveryID, fetchGroups,
                NLJDOHelper.MAX_FETCH_DEPTH_NO_LIMIT);
        if (!res.isFailed())
            AsyncInvoke.exec(new CrossTradeDeliverInvocation(deliveryID), false); // no xa necessary, because deliveryHelperLocal.deliverEnd_internal(...) used a new transaction before

        return res;

    } catch (Throwable t) {
        DeliveryResult deliverEndServerResult = new DeliveryResult(t);

        try {
            DeliveryResult deliverEndServerResult_detached = deliveryHelperLocal
                    .deliverEnd_storeDeliverEndServerResult(deliveryID, deliverEndServerResult, true,
                            fetchGroups, NLJDOHelper.MAX_FETCH_DEPTH_NO_LIMIT);

            deliveryHelperLocal.deliverRollback(deliveryID);

            return deliverEndServerResult_detached;
        } catch (RuntimeException x) {
            throw x;
        } catch (Exception x) {
            throw new RuntimeException(x);
        }
    }
}

From source file:org.rhq.enterprise.server.content.ContentSourceManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void _mergePackageSyncReportUpdateRepo(int contentSourceId) {
    // this method should be called only after a merge of a content source
    // added/updated/removed one or more packages.  When this happens, we need to change
    // the last modified time for all repos that get content from the changed content source
    long now = System.currentTimeMillis();
    ContentSource contentSource = entityManager.find(ContentSource.class, contentSourceId);
    Set<RepoContentSource> ccss = contentSource.getRepoContentSources();
    for (RepoContentSource ccs : ccss) {
        ccs.getRepoContentSourcePK().getRepo().setLastModifiedDate(now);
    }/*from   www  .j av  a  2s . c  o m*/

    return;
}

From source file:org.rhq.enterprise.server.content.ContentSourceManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public RepoSyncResults _mergePackageSyncReportREMOVE(ContentSource contentSource, Repo repo,
        PackageSyncReport report, Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous,
        RepoSyncResults syncResults, StringBuilder progress) {

    progress.append(new Date()).append(": ").append("Removing");
    syncResults.setResults(progress.toString());
    syncResults = repoManager.mergeRepoSyncResults(syncResults);

    Query q;//  ww w . ja  v a2  s . c o m
    int flushCount = 0; // used to know when we should flush the entity manager - for performance purposes
    int removeCount = 0;

    // remove all packages that are no longer available on the remote repository
    // for each removed package, we need to purge the PVCS mapping and the PV itself

    for (ContentProviderPackageDetails doomedDetails : report.getDeletedPackages()) {

        // Delete the mapping between package version and content source
        ContentProviderPackageDetailsKey doomedDetailsKey = doomedDetails.getContentProviderPackageDetailsKey();
        PackageVersionContentSource doomedPvcs = previous.get(doomedDetailsKey);
        doomedPvcs = entityManager.find(PackageVersionContentSource.class,
                doomedPvcs.getPackageVersionContentSourcePK());
        if (doomedPvcs != null) {
            entityManager.remove(doomedPvcs);
        }

        // Delete the relationship between package and repo IF no other providers provide the
        // package
        q = entityManager.createNamedQuery(RepoPackageVersion.DELETE_WHEN_NO_PROVIDER);
        q.setParameter("repoId", repo.getId());
        q.executeUpdate();

        // Delete the package version if it is sufficiently orphaned:
        // - No repos
        // - No content sources
        // - No installed packages
        PackageVersion doomedPv = doomedPvcs.getPackageVersionContentSourcePK().getPackageVersion();
        q = entityManager.createNamedQuery(PackageVersion.DELETE_SINGLE_IF_NO_CONTENT_SOURCES_OR_REPOS);
        q.setParameter("packageVersionId", doomedPv.getId());
        q.executeUpdate();

        if ((++flushCount % 200) == 0) {
            entityManager.flush();
            entityManager.clear();
        }

        if ((++removeCount % 200) == 0) {
            progress.append("...").append(removeCount);
            syncResults.setResults(progress.toString());
            syncResults = repoManager.mergeRepoSyncResults(syncResults);
        }
    }

    progress.append("...").append(removeCount).append('\n');
    syncResults.setResults(progress.toString());
    syncResults = repoManager.mergeRepoSyncResults(syncResults);

    return syncResults;
}

From source file:org.nightlabs.jfire.accounting.AccountingManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@RolesAllowed("_Guest_")
@Override/* w  w w.j ava  2s  .c o m*/
public PaymentResult _payDoWork(final PaymentID paymentID, final PaymentResult payDoWorkClientResult,
        final boolean forceRollback) {
    if (paymentID == null)
        throw new NullPointerException("paymentID");

    if (payDoWorkClientResult == null)
        throw new NullPointerException("payDoWorkClientResult");

    // Store payDoWorkClientResult into the database within a NEW TRANSACTION to
    // prevent it from being lost (if this method fails later and causes a rollback).
    try {
        paymentHelperLocal.payDoWork_storePayDoWorkClientResult(paymentID, payDoWorkClientResult,
                forceRollback);
    } catch (final RuntimeException x) {
        throw x;
    } catch (final Exception x) {
        throw new RuntimeException(x);
    }

    final String[] fetchGroups = new String[] { FetchPlan.DEFAULT };

    try {

        return paymentHelperLocal.payDoWork_internal(paymentID, fetchGroups,
                NLJDOHelper.MAX_FETCH_DEPTH_NO_LIMIT);

    } catch (final Throwable t) {
        logger.error("payDoWork_internal(...) failed: " + paymentID, t);
        final PaymentResult payDoWorkServerResult = new PaymentResult(getOrganisationID(), t);

        try {
            final PaymentResult payDoWorkServerResult_detached = paymentHelperLocal
                    .payDoWork_storePayDoWorkServerResult(paymentID, payDoWorkServerResult, true, fetchGroups,
                            NLJDOHelper.MAX_FETCH_DEPTH_NO_LIMIT);

            return payDoWorkServerResult_detached;
        } catch (final RuntimeException x) {
            throw x;
        } catch (final Exception x) {
            throw new RuntimeException(x);
        }
    }
}