Java Code Examples for javax.ejb.TransactionAttributeType#REQUIRED

The following examples show how to use javax.ejb.TransactionAttributeType#REQUIRED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XAProducerSB.java    From solace-integration-guides with Apache License 2.0 6 votes vote down vote up
@TransactionAttribute(value = TransactionAttributeType.REQUIRED)
@Override
public void sendMessage() throws JMSException {

    Connection conn = null;
    Session session = null;
    MessageProducer prod = null;

    try {
        conn = myCF.createConnection();
        session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        prod = session.createProducer(myReplyQueue);

        ObjectMessage msg = session.createObjectMessage();
        msg.setObject("Hello world!");
        prod.send(msg, DeliveryMode.PERSISTENT, 0, 0);
    } finally {
        if (prod != null)
            prod.close();
        if (session != null)
            session.close();
        if (conn != null)
            conn.close();
    }
}
 
Example 2
Source File: Accounting.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void transfer(int amount) {
    Account accountA = em.getReference(Account.class, 1);
    Account accountB = em.getReference(Account.class, 2);

    // update the from balance
    accountA.setBalance(accountA.getBalance() - amount);

    // update the mirror balance
    em.createQuery("update Account set balance = " + accountA.getBalance() + " where id = 3").executeUpdate();

    // rollback if from balance is < 0
    if (accountA.getBalance() < 0) {
        context.setRollbackOnly();
        return;
    }

    // update the to balance
    accountB.setBalance(accountB.getBalance() + amount);
}
 
Example 3
Source File: BuildConfigurationRepositoryImpl.java    From pnc with Apache License 2.0 6 votes vote down vote up
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public BuildConfiguration save(BuildConfiguration buildConfiguration) {
    Integer id = buildConfiguration.getId();
    BuildConfiguration persisted = queryById(id);
    if (persisted != null) {
        if (!areParametersEqual(persisted, buildConfiguration)
                || !equalAuditedValues(persisted, buildConfiguration)) {
            // always increment the revision of main entity when the child collection is updated
            // the @PreUpdate method in BuildConfiguration was removed, the calculation of whether the
            // lastModificationTime needs to be changed is done here
            buildConfiguration.setLastModificationTime(new Date());
        } else {
            // No changes to audit, reset the lastModificationUser to previous existing
            buildConfiguration.setLastModificationUser(persisted.getLastModificationUser());
        }
    }
    return springRepository.save(buildConfiguration);
}
 
Example 4
Source File: APPConfigurationServiceBean.java    From development with Apache License 2.0 6 votes vote down vote up
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public HashMap<String, String> getControllerOrganizations() {

    LOGGER.debug("Retrieving configured controllers");
    HashMap<String, String> result = new HashMap<>();
    Query query = em
            .createNamedQuery("ConfigurationSetting.getControllersForKey");
    query.setParameter("key",
            ControllerConfigurationKey.BSS_ORGANIZATION_ID.name());
    List<?> resultList = query.getResultList();
    for (Object entry : resultList) {
        ConfigurationSetting currentCs = (ConfigurationSetting) entry;
        result.put(currentCs.getControllerId(),
                currentCs.getSettingValue());
    }
    return result;
}
 
Example 5
Source File: APPTimerServiceBean.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * If BES is available process failed serviceInstances and reset
 * APP_SUSPEND.
 * 
 * @param isRestartAPP
 *            if true the method invoked by restartAPP else invoked by
 *            ControllerUI
 * @return If true restart successfully else restart unsuccessfully
 */
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public boolean restart(boolean isRestartAPP) {
    final String messageKey = "mail_bes_notification_connection_success";
    boolean isSuspendedByApp = false;
    if (!besDAO.isBESAvalible()) {
        if (isRestartAPP) {
            sendMailToAppAdmin("mail_bes_notification_error_app_admin");
        }
        return false;
    }
    List<ServiceInstance> serviceInstances = instanceDAO
            .getInstancesSuspendedbyApp();
    for (ServiceInstance instance : serviceInstances) {
        String actionLink = getResumeLinkForInstance(instance);
        if (actionLink == null || actionLink.isEmpty()) {
            isSuspendedByApp = true;
            continue;
        }
        sendActionMail(true, instance, messageKey, null, actionLink, false);
        instance.setSuspendedByApp(false);
    }
    configService
            .setAPPSuspend(Boolean.valueOf(isSuspendedByApp).toString());
    return true;
}
 
Example 6
Source File: DefaultDatastore.java    From pnc with Apache License 2.0 5 votes vote down vote up
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public BuildRecord storeCompletedBuild(
        BuildRecord.Builder buildRecordBuilder,
        List<Artifact> builtArtifacts,
        List<Artifact> dependencies) {
    BuildRecord buildRecord = buildRecordBuilder.build(true);
    logger.debug("Storing completed build {}.", buildRecord);
    if (logger.isTraceEnabled()) {
        logger.trace("Build Log: {}.", buildRecord.getBuildLog());
    }

    Map<TargetRepository.IdentifierPath, TargetRepository> repositoriesCache = new HashMap<>();
    Map<Artifact.IdentifierSha256, Artifact> artifactCache = new HashMap<>();

    /**
     * Built artifacts must be saved before the dependencies. In case an artifact is built and the dependency
     * (re-downloaded), it must be linked to built artifacts repository.
     */
    logger.debug("Saving built artifacts ...");
    final Set<Artifact> savedBuiltArtifacts = saveArtifacts(builtArtifacts, repositoriesCache, artifactCache);

    logger.debug("Saving dependencies ...");
    buildRecord.setDependencies(saveArtifacts(dependencies, repositoriesCache, artifactCache));

    logger.debug("Done saving artifacts.");
    logger.trace("Saving build record {}.", buildRecord);
    buildRecord = buildRecordRepository.save(buildRecord);
    logger.debug("Build record {} saved.", buildRecord.getId());

    logger.trace("Setting artifacts as built.");
    for (Artifact builtArtifact : savedBuiltArtifacts) {
        builtArtifact.setBuildRecord(buildRecord);
    }

    return buildRecord;
}
 
Example 7
Source File: BookingServiceTestDataGenerator.java    From CargoTracker-J12015 with MIT License 5 votes vote down vote up
@PostConstruct
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void loadSampleData() {
	logger.info("Loading sample data.");
	unLoadAll(); // Fail-safe in case of application restart that does not
					// trigger a JPA schema drop.
	loadSampleLocations();
	loadSampleVoyages();
	// loadSampleCargos();
}
 
Example 8
Source File: SampleDataGenerator.java    From pragmatic-microservices-lab with MIT License 5 votes vote down vote up
@PostConstruct
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void loadSampleData() {
    logger.info("Loading sample data.");
    unLoadAll(); //  Fail-safe in case of application restart that does not trigger a JPA schema drop.
    loadSampleLocations();
    loadSampleVoyages();
    loadSampleCargos();
}
 
Example 9
Source File: Accounting.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void transferCamel(int amount) throws Exception {
    Account accountA = em.getReference(Account.class, 1);
    Account accountB = em.getReference(Account.class, 2);

    // update the from balance
    accountA.setBalance(accountA.getBalance() - amount);

    // do something in camel that is transactional
    CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository());
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .wireTap("log:org.wildfly.camel.test.jpa?level=WARN")
            .to("sql:update Account set balance = :#${body} where id = 3?dataSource=java:jboss/datasources/ExampleDS");
        }
    });

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        producer.requestBody("direct:start", accountA.getBalance());
    } finally {
        camelctx.close();
    }

    // rollback if from balance is < 0
    if (accountA.getBalance() < 0) {
        context.setRollbackOnly();
        return;
    }

    // update the to balance
    accountB.setBalance(accountB.getBalance() + amount);
}
 
Example 10
Source File: IdentityServiceBean.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
@Asynchronous
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void notifySubscriptionsAboutUserUpdate(PlatformUser existingUser) {

    // 2. notify all products the user is subscribed to
    List<Subscription> subscriptions = sm
            .getSubscriptionsForUserInt(existingUser);
    List<TaskMessage> messages = new ArrayList<>();
    for (Subscription subscription : subscriptions) {
        SubscriptionStatus status = subscription.getStatus();
        // in these states the product instance is not existing
        if (status != SubscriptionStatus.PENDING
                && status != SubscriptionStatus.INVALID) {
            UsageLicense license = getUsgeLicenseForUserAndSubscription(
                    existingUser, subscription);
            if (license != null) {
                UpdateUserPayload payload = new UpdateUserPayload(
                        subscription.getKey(), license.getKey());
                TaskMessage message = new TaskMessage(
                        UpdateUserHandler.class, payload);
                messages.add(message);
            }
        }
    }
    tqs.sendAllMessages(messages);

}
 
Example 11
Source File: WoWBusinessBean.java    From wow-auctions with GNU General Public License v3.0 5 votes vote down vote up
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void deleteAuctionDataByFile(Long fileId) {
    Query deleteQuery = em.createNamedQuery("Auction.deleteByAuctionFile");
    deleteQuery.setParameter("fileId", fileId);
    deleteQuery.executeUpdate();
}
 
Example 12
Source File: TimerServiceBean.java    From development with Apache License 2.0 4 votes vote down vote up
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void reInitTimers() throws ValidationException {
    cancelAllObsoleteTimer();
    initAllTimers();
}
 
Example 13
Source File: Movies.java    From tomee with Apache License 2.0 4 votes vote down vote up
@RolesAllowed({"Employee", "Manager"})
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Interceptors(AddInterceptor.class)
public void addMovie(Movie movie) throws Exception {
    entityManager.persist(movie);
}
 
Example 14
Source File: CheckInvalidTransactionAttributeTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void sayCheesePlease() {
}
 
Example 15
Source File: RequiredEjbTxTestEntityDao.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Override
public int incrementCount(String name) {
	return super.incrementCountInternal(name);
}
 
Example 16
Source File: TransactionRuleTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Test
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void yes() throws NamingException, SystemException {
    assertNotNull(OpenEJB.getTransactionManager().getTransaction());
}
 
Example 17
Source File: WoWBusinessBean.java    From wow-auctions with GNU General Public License v3.0 4 votes vote down vote up
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public AuctionFile updateAuctionFile(AuctionFile auctionFile) {
    return em.merge(auctionFile);
}
 
Example 18
Source File: WoWBusinessBean.java    From wow-auctions with GNU General Public License v3.0 4 votes vote down vote up
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void createRealm(Realm realm) {
    em.persist(realm);
}
 
Example 19
Source File: WoWBusinessBean.java    From wow-auctions with GNU General Public License v3.0 4 votes vote down vote up
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void createRealmFolder(RealmFolder realmFolder) {
    em.persist(realmFolder);
}
 
Example 20
Source File: RequiredEjbTxTestEntityDao.java    From java-technology-stack with MIT License 4 votes vote down vote up
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Override
public int incrementCount(String name) {
	return super.incrementCountInternal(name);
}