public <T> T requireNewTransaction(T target) { final TransactionProxyFactoryBean proxy = new TransactionProxyFactoryBean(); // Inject transaction manager here proxy.setTransactionManager(transactionManager); // Define which object instance is to be proxied (your bean) proxy.setTarget(target); // Programmatically setup transaction attributes proxy.setTransactionAttributes(transactionAttributes); // Is needed since Spring 4.3.1 proxy.setProxyTargetClass(true); // Finish FactoryBean setup proxy.afterPropertiesSet(); return (T) proxy.getObject(); }
/** * <p>create</p> * * @param ifaceId a {@link java.lang.Integer} object. * @param ifaceDao a {@link org.opennms.netmgt.dao.IpInterfaceDao} object. * @param transMgr a {@link org.springframework.transaction.PlatformTransactionManager} object. * @return a {@link org.opennms.netmgt.collectd.CollectionAgentService} object. */ public static CollectionAgentService create(Integer ifaceId, final IpInterfaceDao ifaceDao, final PlatformTransactionManager transMgr) { CollectionAgentService agent = new DefaultCollectionAgentService(ifaceId, ifaceDao); TransactionProxyFactoryBean bean = new TransactionProxyFactoryBean(); bean.setTransactionManager(transMgr); bean.setTarget(agent); Properties props = new Properties(); props.put("*", "PROPAGATION_REQUIRED,readOnly"); bean.setTransactionAttributes(props); bean.afterPropertiesSet(); return (CollectionAgentService) bean.getObject(); }