/**
* Determine the specific transaction manager to use for the given transaction.
*/
protected PlatformTransactionManager determineTransactionManager(TransactionAttribute txAttr) {
if (this.transactionManager != null || this.beanFactory == null || txAttr == null) {
return this.transactionManager;
}
String qualifier = txAttr.getQualifier();
if (StringUtils.hasLength(qualifier)) {
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this.beanFactory, PlatformTransactionManager.class, qualifier);
}
else if (this.transactionManagerBeanName != null) {
return this.beanFactory.getBean(this.transactionManagerBeanName, PlatformTransactionManager.class);
}
else {
return this.beanFactory.getBean(PlatformTransactionManager.class);
}
}
java类org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils的实例源码
TransactionAspectSupport.java 文件源码
项目:lams
阅读 31
收藏 0
点赞 0
评论 0
AsyncExecutionAspectSupport.java 文件源码
项目:lams
阅读 31
收藏 0
点赞 0
评论 0
/**
* Determine the specific executor to use when executing the given method.
* @return the executor to use (or {@code null}, but just if no default executor has been set)
*/
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
AsyncTaskExecutor executor = this.executors.get(method);
if (executor == null) {
Executor executorToUse = this.defaultExecutor;
String qualifier = getExecutorQualifier(method);
if (StringUtils.hasLength(qualifier)) {
Assert.notNull(this.beanFactory, "BeanFactory must be set on " + getClass().getSimpleName() +
" to access qualified executor '" + qualifier + "'");
executorToUse = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
this.beanFactory, Executor.class, qualifier);
}
else if (executorToUse == null) {
return null;
}
executor = (executorToUse instanceof AsyncTaskExecutor ?
(AsyncTaskExecutor) executorToUse : new TaskExecutorAdapter(executorToUse));
this.executors.put(method, executor);
}
return executor;
}
AsyncExecutionAspectSupport.java 文件源码
项目:spring4-understanding
阅读 27
收藏 0
点赞 0
评论 0
/**
* Determine the specific executor to use when executing the given method.
* Should preferably return an {@link AsyncListenableTaskExecutor} implementation.
* @return the executor to use (or {@code null}, but just if no default executor has been set)
*/
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
AsyncTaskExecutor executor = this.executors.get(method);
if (executor == null) {
Executor executorToUse = this.defaultExecutor;
String qualifier = getExecutorQualifier(method);
if (StringUtils.hasLength(qualifier)) {
if (this.beanFactory == null) {
throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() +
" to access qualified executor '" + qualifier + "'");
}
executorToUse = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
this.beanFactory, Executor.class, qualifier);
}
else if (executorToUse == null) {
return null;
}
executor = (executorToUse instanceof AsyncListenableTaskExecutor ?
(AsyncListenableTaskExecutor) executorToUse : new TaskExecutorAdapter(executorToUse));
this.executors.put(method, executor);
}
return executor;
}
TransactionalTestExecutionListener.java 文件源码
项目:spring4-understanding
阅读 27
收藏 0
点赞 0
评论 0
/**
* Get the {@linkplain PlatformTransactionManager transaction manager} to use
* for the supplied {@linkplain TestContext test context} and {@code qualifier}.
* <p>Delegates to {@link #getTransactionManager(TestContext)} if the
* supplied {@code qualifier} is {@code null} or empty.
* @param testContext the test context for which the transaction manager
* should be retrieved
* @param qualifier the qualifier for selecting between multiple bean matches;
* may be {@code null} or empty
* @return the transaction manager to use, or {@code null} if not found
* @throws BeansException if an error occurs while retrieving the transaction manager
* @see #getTransactionManager(TestContext)
*/
protected PlatformTransactionManager getTransactionManager(TestContext testContext, String qualifier) {
// look up by type and qualifier from @Transactional
if (StringUtils.hasText(qualifier)) {
try {
// Use autowire-capable factory in order to support extended qualifier
// matching (only exposed on the internal BeanFactory, not on the
// ApplicationContext).
BeanFactory bf = testContext.getApplicationContext().getAutowireCapableBeanFactory();
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(bf, PlatformTransactionManager.class, qualifier);
}
catch (RuntimeException ex) {
if (logger.isWarnEnabled()) {
logger.warn(
String.format(
"Caught exception while retrieving transaction manager with qualifier '%s' for test context %s",
qualifier, testContext), ex);
}
throw ex;
}
}
// else
return getTransactionManager(testContext);
}
DeviceEventProcessor.java 文件源码
项目:konker-platform
阅读 22
收藏 0
点赞 0
评论 0
private String getJsonPayload(Device device, byte[] payloadBytes) throws BusinessException {
DeviceModel.ContentType contentType = device.getDeviceModel().getContentType();
if (contentType == null) {
contentType = DeviceModel.ContentType.APPLICATION_JSON;
}
JsonConverter jsonConverter = BeanFactoryAnnotationUtils.qualifiedBeanOfType(beans, JsonConverter.class, contentType.getValue());
ServiceResponse<String> jsonConverterResponse = jsonConverter.toJson(payloadBytes);
if (jsonConverterResponse.isOk()) {
return jsonConverterResponse.getResult();
} else {
throw new BusinessException(Messages.INVALID_PAYLOAD.getCode());
}
}
AsyncExecutionAspectSupport.java 文件源码
项目:class-guard
阅读 31
收藏 0
点赞 0
评论 0
/**
* Determine the specific executor to use when executing the given method.
* @return the executor to use (or {@code null}, but just if no default executor has been set)
*/
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
AsyncTaskExecutor executor = this.executors.get(method);
if (executor == null) {
Executor executorToUse = this.defaultExecutor;
String qualifier = getExecutorQualifier(method);
if (StringUtils.hasLength(qualifier)) {
Assert.notNull(this.beanFactory, "BeanFactory must be set on " + getClass().getSimpleName() +
" to access qualified executor '" + qualifier + "'");
executorToUse = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
this.beanFactory, Executor.class, qualifier);
}
else if (executorToUse == null) {
return null;
}
executor = (executorToUse instanceof AsyncTaskExecutor ?
(AsyncTaskExecutor) executorToUse : new TaskExecutorAdapter(executorToUse));
this.executors.put(method, executor);
}
return executor;
}
TransactionAspectSupport.java 文件源码
项目:class-guard
阅读 26
收藏 0
点赞 0
评论 0
/**
* Determine the specific transaction manager to use for the given transaction.
*/
protected PlatformTransactionManager determineTransactionManager(TransactionAttribute txAttr) {
if (this.transactionManager != null || this.beanFactory == null || txAttr == null) {
return this.transactionManager;
}
String qualifier = txAttr.getQualifier();
if (StringUtils.hasLength(qualifier)) {
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this.beanFactory, PlatformTransactionManager.class, qualifier);
}
else if (this.transactionManagerBeanName != null) {
return this.beanFactory.getBean(this.transactionManagerBeanName, PlatformTransactionManager.class);
}
else {
return this.beanFactory.getBean(PlatformTransactionManager.class);
}
}
TransactionalTestExecutionListener.java 文件源码
项目:class-guard
阅读 31
收藏 0
点赞 0
评论 0
/**
* Get the {@link PlatformTransactionManager transaction manager} to use
* for the supplied {@link TestContext test context} and {@code qualifier}.
* <p>Delegates to {@link #getTransactionManager(TestContext)} if the
* supplied {@code qualifier} is {@code null} or empty.
* @param testContext the test context for which the transaction manager
* should be retrieved
* @param qualifier the qualifier for selecting between multiple bean matches;
* may be {@code null} or empty
* @return the transaction manager to use, or {@code null} if not found
* @throws BeansException if an error occurs while retrieving the transaction manager
* @see #getTransactionManager(TestContext)
*/
protected final PlatformTransactionManager getTransactionManager(TestContext testContext, String qualifier) {
// look up by type and qualifier from @Transactional
if (StringUtils.hasText(qualifier)) {
try {
// Use autowire-capable factory in order to support extended qualifier
// matching (only exposed on the internal BeanFactory, not on the
// ApplicationContext).
BeanFactory bf = testContext.getApplicationContext().getAutowireCapableBeanFactory();
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(bf, PlatformTransactionManager.class, qualifier);
} catch (RuntimeException ex) {
if (logger.isWarnEnabled()) {
logger.warn("Caught exception while retrieving transaction manager for test context " + testContext
+ " and qualifier [" + qualifier + "]", ex);
}
throw ex;
}
}
// else
return getTransactionManager(testContext);
}
TransactionAspectSupport.java 文件源码
项目:spring4-understanding
阅读 29
收藏 0
点赞 0
评论 0
private PlatformTransactionManager determineQualifiedTransactionManager(String qualifier) {
PlatformTransactionManager txManager = this.transactionManagerCache.get(qualifier);
if (txManager == null) {
txManager = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
this.beanFactory, PlatformTransactionManager.class, qualifier);
this.transactionManagerCache.putIfAbsent(qualifier, txManager);
}
return txManager;
}
EventPublisherDevice.java 文件源码
项目:konker-platform
阅读 22
收藏 0
点赞 0
评论 0
private ServiceResponse<byte[]> getJsonPayload(Device device, String payloadJson) {
DeviceModel.ContentType contentType = DeviceModel.ContentType.APPLICATION_JSON;
if (device.getDeviceModel() != null &&
device.getDeviceModel().getContentType() != null) {
contentType = device.getDeviceModel().getContentType();
}
JsonConverter jsonConverter = BeanFactoryAnnotationUtils.qualifiedBeanOfType(beans, JsonConverter.class, contentType.getValue());
ServiceResponse<byte[]> jsonConverterResponse = jsonConverter.fromJson(payloadJson);
return jsonConverterResponse;
}
HystrixFallbackBeanFactory.java 文件源码
项目:java-restify
阅读 22
收藏 0
点赞 0
评论 0
private Object doSearch(Class<?> classType) {
try {
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, classType, QUALIFIER_NAME);
} catch (NoSuchBeanDefinitionException e) {
return null;
}
}
AsyncExecutionAspectSupport.java 文件源码
项目:spring
阅读 31
收藏 0
点赞 0
评论 0
/**
* Retrieve a target executor for the given qualifier.
* @param qualifier the qualifier to resolve
* @return the target executor, or {@code null} if none available
* @since 4.2.6
* @see #getExecutorQualifier(Method)
*/
protected Executor findQualifiedExecutor(BeanFactory beanFactory, String qualifier) {
if (beanFactory == null) {
throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() +
" to access qualified executor '" + qualifier + "'");
}
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, Executor.class, qualifier);
}
AnnotationLdtmAttributeSource.java 文件源码
项目:ldtm
阅读 28
收藏 0
点赞 0
评论 0
private PlatformTransactionManager determineQualifiedTransactionManager(String qualifier) {
PlatformTransactionManager txManager = this.transactionManagerCache.get(qualifier);
if (txManager == null) {
txManager = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
this.beanFactory, PlatformTransactionManager.class, qualifier);
this.transactionManagerCache.putIfAbsent(qualifier, txManager);
}
return txManager;
}
CacheAspectSupport.java 文件源码
项目:Qihua
阅读 24
收藏 0
点赞 0
评论 0
/**
* Return a bean with the specified name and type. Used to resolve services that are referenced by name in a
* {@link CacheOperation}.
*
* @param beanName the name of the bean, as defined by the operation
* @param expectedType type type for the bean
* @return the bean matching that name
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException if such bean does not exist
* @see CacheOperation#keyGenerator
* @see CacheOperation#cacheManager
* @see CacheOperation#cacheResolver
*/
protected <T> T getBean(String beanName, Class<T> expectedType) {
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(applicationContext, expectedType, beanName);
}
CacheAspectSupport.java 文件源码
项目:spring4-understanding
阅读 26
收藏 0
点赞 0
评论 0
/**
* Return a bean with the specified name and type. Used to resolve services that
* are referenced by name in a {@link CacheOperation}.
* @param beanName the name of the bean, as defined by the operation
* @param expectedType type type for the bean
* @return the bean matching that name
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException if such bean does not exist
* @see CacheOperation#keyGenerator
* @see CacheOperation#cacheManager
* @see CacheOperation#cacheResolver
*/
protected <T> T getBean(String beanName, Class<T> expectedType) {
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this.applicationContext, expectedType, beanName);
}
CacheAspectSupport.java 文件源码
项目:spring
阅读 27
收藏 0
点赞 0
评论 0
/**
* Return a bean with the specified name and type. Used to resolve services that
* are referenced by name in a {@link CacheOperation}.
* @param beanName the name of the bean, as defined by the operation
* @param expectedType type for the bean
* @return the bean matching that name
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException if such bean does not exist
* @see CacheOperation#keyGenerator
* @see CacheOperation#cacheManager
* @see CacheOperation#cacheResolver
*/
protected <T> T getBean(String beanName, Class<T> expectedType) {
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this.beanFactory, expectedType, beanName);
}
TransactionAspectUtils.java 文件源码
项目:class-guard
阅读 29
收藏 0
点赞 0
评论 0
/**
* Obtain a PlatformTransactionManager from the given BeanFactory, matching the given qualifier.
* @param beanFactory the BeanFactory to get the {@code PlatformTransactionManager} bean from
* @param qualifier the qualifier for selecting between multiple {@code PlatformTransactionManager} matches
* @return the chosen {@code PlatformTransactionManager} (never {@code null})
* @throws IllegalStateException if no matching {@code PlatformTransactionManager} bean found
* @deprecated as of Spring 3.1.2 in favor of
* {@link BeanFactoryAnnotationUtils#qualifiedBeanOfType(BeanFactory, Class, String)}
*/
@Deprecated
public static PlatformTransactionManager getTransactionManager(BeanFactory beanFactory, String qualifier) {
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, PlatformTransactionManager.class, qualifier);
}
TransactionAspectUtils.java 文件源码
项目:class-guard
阅读 26
收藏 0
点赞 0
评论 0
/**
* Obtain a PlatformTransactionManager from the given BeanFactory, matching the given qualifier.
* @param bf the BeanFactory to get the {@code PlatformTransactionManager} bean from
* @param qualifier the qualifier for selecting between multiple {@code PlatformTransactionManager} matches
* @return the chosen {@code PlatformTransactionManager} (never {@code null})
* @throws IllegalStateException if no matching {@code PlatformTransactionManager} bean found
* @deprecated as of Spring 3.1.2 in favor of
* {@link BeanFactoryAnnotationUtils#qualifiedBeanOfType(BeanFactory, Class, String)}
*/
@Deprecated
public static PlatformTransactionManager getTransactionManager(ConfigurableListableBeanFactory bf, String qualifier) {
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(bf, PlatformTransactionManager.class, qualifier);
}