List of usage examples for org.springframework.transaction.support DefaultTransactionDefinition DefaultTransactionDefinition
public DefaultTransactionDefinition(int propagationBehavior)
From source file:nl.nn.adapterframework.unmanaged.SpringJmsConnector.java
public void configureEndpointConnection(final IPortConnectedListener jmsListener, ConnectionFactory connectionFactory, Destination destination, IbisExceptionListener exceptionListener, String cacheMode, int acknowledgeMode, boolean sessionTransacted, String messageSelector) throws ConfigurationException { super.configureEndpointConnection(jmsListener, connectionFactory, destination, exceptionListener); // Create the Message Listener Container manually. // This is needed, because otherwise the Spring Factory will // call afterPropertiesSet() on the object which will validate // that all required properties are set before we get a chance // to insert our dynamic values from the config. file. this.jmsContainer = createMessageListenerContainer(); if (getReceiver().isTransacted()) { log.debug(getLogPrefix() + "setting transction manager to [" + txManager + "]"); jmsContainer.setTransactionManager(txManager); if (getReceiver().getTransactionTimeout() > 0) { jmsContainer.setTransactionTimeout(getReceiver().getTransactionTimeout()); }/*www . j a v a2 s .co m*/ TX = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED); } else { log.debug(getLogPrefix() + "setting no transction manager"); } if (sessionTransacted) { jmsContainer.setSessionTransacted(sessionTransacted); } if (StringUtils.isNotEmpty(messageSelector)) { jmsContainer.setMessageSelector(messageSelector); } // Initialize with a number of dynamic properties which come from the configuration file jmsContainer.setConnectionFactory(getConnectionFactory()); jmsContainer.setDestination(getDestination()); jmsContainer.setExceptionListener(this); // the following is not required, the timeout set is the time waited to start a new poll attempt. //this.jmsContainer.setReceiveTimeout(getJmsListener().getTimeOut()); if (getReceiver().getNumThreads() > 0) { jmsContainer.setMaxConcurrentConsumers(getReceiver().getNumThreads()); } else { jmsContainer.setMaxConcurrentConsumers(1); } jmsContainer.setIdleTaskExecutionLimit(IDLE_TASK_EXECUTION_LIMIT); if (StringUtils.isNotEmpty(cacheMode)) { jmsContainer.setCacheLevelName(cacheMode); } else { if (getReceiver().isTransacted()) { jmsContainer.setCacheLevel(DEFAULT_CACHE_LEVEL_TRANSACTED); } else { jmsContainer.setCacheLevel(DEFAULT_CACHE_LEVEL_NON_TRANSACTED); } } if (acknowledgeMode >= 0) { jmsContainer.setSessionAcknowledgeMode(acknowledgeMode); } jmsContainer.setMessageListener(this); // Use Spring BeanFactory to complete the auto-wiring of the JMS Listener Container, // and run the bean lifecycle methods. try { ((AutowireCapableBeanFactory) this.beanFactory).configureBean(this.jmsContainer, "proto-jmsContainer"); } catch (BeansException e) { throw new ConfigurationException(getLogPrefix() + "Out of luck wiring up and configuring Default JMS Message Listener Container for JMS Listener [" + (getListener().getName() + "]"), e); } // Finally, set bean name to something we can make sense of if (getListener().getName() != null) { jmsContainer.setBeanName(getListener().getName()); } else { jmsContainer.setBeanName(getReceiver().getName()); } }
From source file:org.alfresco.repo.transfer.RepoTransferReceiverImplTest.java
/** * Called during the transaction setup//w ww .j a v a2s .co m */ protected void onSetUp() throws Exception { super.onSetUp(); System.out.println("java.io.tmpdir == " + System.getProperty("java.io.tmpdir")); // Get the required services this.nodeService = (NodeService) this.applicationContext.getBean("nodeService"); this.contentService = (ContentService) this.applicationContext.getBean("contentService"); this.authenticationService = (MutableAuthenticationService) this.applicationContext .getBean("authenticationService"); this.actionService = (ActionService) this.applicationContext.getBean("actionService"); this.transactionService = (TransactionService) this.applicationContext.getBean("transactionComponent"); this.authenticationComponent = (AuthenticationComponent) this.applicationContext .getBean("authenticationComponent"); this.receiver = (RepoTransferReceiverImpl) this.getApplicationContext().getBean("transferReceiver"); this.policyComponent = (PolicyComponent) this.getApplicationContext().getBean("policyComponent"); this.searchService = (SearchService) this.getApplicationContext().getBean("searchService"); this.dummyContent = "This is some dummy content."; this.dummyContentBytes = dummyContent.getBytes("UTF-8"); setTransactionDefinition(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW)); authenticationComponent.setSystemUserAsCurrentUser(); startNewTransaction(); String guestHomeQuery = "/app:company_home/app:guest_home"; ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); assertEquals("", 1, guestHomeResult.length()); guestHome = guestHomeResult.getNodeRef(0); endTransaction(); }
From source file:org.apache.ctakes.ytex.uima.mapper.DocumentMapperServiceImpl.java
public Integer saveDocument(final JCas jcas, final String analysisBatch, final boolean bStoreDocText, final boolean bStoreCAS, final boolean bInsertAnnotationContainmentLinks, final Set<String> setTypesToIgnore) { if (log.isTraceEnabled()) log.trace("begin saveDocument"); // communicate options to mappers using thread local variable final DefaultTransactionDefinition txDef = new DefaultTransactionDefinition( TransactionDefinition.PROPAGATION_REQUIRES_NEW); txDef.setIsolationLevel("orcl".equals(this.dbType) ? TransactionDefinition.ISOLATION_READ_COMMITTED : TransactionDefinition.ISOLATION_READ_UNCOMMITTED); final TransactionTemplate txTemplate = new TransactionTemplate(this.getTransactionManager(), txDef); final int documentId = txTemplate.execute(new TransactionCallback<Integer>() { @Override//w w w . j a v a2 s. c o m public Integer doInTransaction(TransactionStatus arg0) { Document doc = createDocument(jcas, analysisBatch, bStoreDocText, bStoreCAS); sessionFactory.getCurrentSession().save(doc); // make sure the document has been saved getSessionFactory().getCurrentSession().flush(); saveAnnotationsHib(jcas, bInsertAnnotationContainmentLinks, setTypesToIgnore, doc); extractAndSaveDocKey(jcas, doc); return doc.getDocumentID(); } }); if (log.isTraceEnabled()) log.trace("end saveDocument"); return documentId; }
From source file:org.sakaiproject.tool.assessment.facade.ItemHashUtil.java
private TransactionDefinition requireNewTransaction() { return new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW); }
From source file:org.unitils.database.core.TransactionManager.java
/** * Returns a @{link TransactionDefinition} to use when starting a transaction. * Defaults to a transaction definition with propagation required. * * @return The transaction definition, not null *//*from w w w . j a v a 2 s . c o m*/ protected TransactionDefinition createTransactionDefinition() { return new DefaultTransactionDefinition(PROPAGATION_REQUIRED); }
From source file:org.unitils.database.dbmaintain.DbMaintainSQLHandler.java
public void startTransaction(DataSource dataSource) { PlatformTransactionManager platformTransactionManager = defaultTransactionProvider .getPlatformTransactionManager(null, dataSource); TransactionDefinition transactionDefinition = new DefaultTransactionDefinition(PROPAGATION_REQUIRED); TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition); transactionStatuses.put(dataSource, transactionStatus); }
From source file:org.unitils.database.transaction.impl.DefaultUnitilsTransactionManager.java
/** * Returns a <code>TransactionDefinition</code> object containing the * necessary transaction parameters. Simply returns a default * <code>DefaultTransactionDefinition</code> object with the 'propagation * required' attribute/* w w w . j av a2 s .c o m*/ * * @param testObject The test object, not null * @return The default TransactionDefinition */ protected TransactionDefinition createTransactionDefinition(Object testObject) { return new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED); }