List of usage examples for org.springframework.beans.factory.config BeanDefinition ROLE_SUPPORT
int ROLE_SUPPORT
To view the source code for org.springframework.beans.factory.config BeanDefinition ROLE_SUPPORT.
Click Source Link
From source file:org.springframework.data.jdbc.config.oracle.AqJmsConnectionFactoryBeanDefinitionParser.java
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { //attributes//from www. j av a 2 s .c o m String dataSourceRef = element.getAttribute(DATA_SOURCE_ATTRIBUTE); if (logger.isDebugEnabled()) { logger.debug("Using provided " + NATIVE_JDBC_EXTRACTOR_ATTRIBUTE + ": " + dataSourceRef); } String useLocalDataSourceTx = element.getAttribute(USE_LOCAL_DATA_SOURCE_TX_ATTRIBUTE); String connectionFactoryTypeRef = element.getAttribute(CONNECTION_FACTORY_TYPE_ATTRIBUTE); String nativeJdbcExtractorRef = element.getAttribute(NATIVE_JDBC_EXTRACTOR_ATTRIBUTE); builder.getRawBeanDefinition().setBeanClassName(FACTORY_BEAN_CLASS); RuntimeBeanReference ds = new RuntimeBeanReference(dataSourceRef); builder.addPropertyValue("dataSource", ds); if (StringUtils.hasText(useLocalDataSourceTx)) { if ("true".equals(useLocalDataSourceTx.toLowerCase()) || "false".equals(useLocalDataSourceTx.toLowerCase())) { builder.addPropertyValue("coordinateWithDataSourceTransactions", useLocalDataSourceTx); } else { parserContext.getReaderContext().error( "The 'use-local-data-source-transaction' attribute should be \"true\" or \"false\"; \"" + useLocalDataSourceTx + "\" is an invalid value", element); } } if (StringUtils.hasText(connectionFactoryTypeRef)) { builder.addPropertyValue("connectionFactoryType", connectionFactoryTypeRef); } if (StringUtils.hasText(nativeJdbcExtractorRef)) { RuntimeBeanReference nje = new RuntimeBeanReference(nativeJdbcExtractorRef); builder.addPropertyValue("nativeJdbcExtractor", nje); } builder.setRole(BeanDefinition.ROLE_SUPPORT); }
From source file:org.springframework.data.jdbc.config.oracle.PoolingDataSourceBeanDefinitionParser.java
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { ResourceLoader rl = parserContext.getReaderContext().getResourceLoader(); //attributes//from ww w. ja v a 2s . c o m String propertyFileLocation = element.getAttribute(PROPERTIES_LOCATION_ATTRIBUTE); String connectionPropertyFileLocation = element.getAttribute(PROPERTIES_LOCATION_ATTRIBUTE); String connectionPropertyPrefix = element.getAttribute(CONNECTION_PROPERTIES_PREFIX_ATTRIBUTE); String cachingPropertyPrefix = element.getAttribute(CONNECTON_CACHE_PROPERTIS_PREFIX_ATTRIBUTE); String url = element.getAttribute(URL_ATTRIBUTE); String username = element.getAttribute(USERNAME_ATTRIBUTE); String password = element.getAttribute(PASSWORD_ATTRIBUTE); String onsConfiguration = element.getAttribute(ONS_CONFIGURATION_ATTRIBUTE); String fastConnectionFailoverEnabled = element.getAttribute(FAST_CONNECTION_FAILOVER_ENABLED_ATTRIBUTE); String connectionCachingEnabled = element.getAttribute(CONNECTION_CACHING_ENABLED_ATTRIBUTE); boolean propertyFileProvided = false; Map<String, Object> providedProperties = new HashMap<String, Object>(); // defaults if (!StringUtils.hasText(propertyFileLocation) && !StringUtils.hasText(connectionPropertyFileLocation)) { propertyFileLocation = DEFAULT_PROPERTY_FILE_LOCATION; } if (!StringUtils.hasText(connectionPropertyPrefix)) { connectionPropertyPrefix = DEFAULT_PROPERTY_PREFIX; } // look for property files if (StringUtils.hasText(propertyFileLocation)) { logger.debug("Using properties location: " + propertyFileLocation); String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(propertyFileLocation); Resource r = rl.getResource(resolvedLocation); logger.debug("Loading properties from resource: " + r); PropertiesFactoryBean factoryBean = new PropertiesFactoryBean(); factoryBean.setLocation(r); try { factoryBean.afterPropertiesSet(); Properties resource = factoryBean.getObject(); for (Map.Entry<Object, Object> entry : resource.entrySet()) { providedProperties.put((String) entry.getKey(), entry.getValue()); } propertyFileProvided = true; } catch (FileNotFoundException e) { propertyFileProvided = false; if (propertyFileLocation.equals(DEFAULT_PROPERTY_FILE_LOCATION)) { logger.debug("Unable to find " + propertyFileLocation); } else { parserContext.getReaderContext() .error("pooling-datasource defined with attribute '" + PROPERTIES_LOCATION_ATTRIBUTE + "' but the property file was not found at location \"" + propertyFileLocation + "\"", element); } } catch (IOException e) { logger.warn("Error loading " + propertyFileLocation + ": " + e.getMessage()); } } else { propertyFileProvided = false; } if (logger.isDebugEnabled()) { logger.debug("Using provided properties: " + providedProperties); } if (connectionPropertyPrefix == null) { connectionPropertyPrefix = ""; } if (connectionPropertyPrefix.length() > 0 && !connectionPropertyPrefix.endsWith(".")) { connectionPropertyPrefix = connectionPropertyPrefix + "."; } logger.debug("Using connection properties prefix: " + connectionPropertyPrefix); if (cachingPropertyPrefix == null) { cachingPropertyPrefix = ""; } if (cachingPropertyPrefix.length() > 0 && !cachingPropertyPrefix.endsWith(".")) { cachingPropertyPrefix = cachingPropertyPrefix + "."; } logger.debug("Using caching properties prefix: " + cachingPropertyPrefix); if (!(StringUtils.hasText(connectionCachingEnabled) || providedProperties .containsKey(attributeToPropertyMap.get(CONNECTION_CACHING_ENABLED_ATTRIBUTE)))) { connectionCachingEnabled = DEFAULT_CONNECTION_CACHING_ENABLED; } setRequiredAttribute(builder, parserContext, element, providedProperties, connectionPropertyPrefix, propertyFileProvided, url, URL_ATTRIBUTE, "URL"); setOptionalAttribute(builder, providedProperties, connectionPropertyPrefix, username, USERNAME_ATTRIBUTE); setOptionalAttribute(builder, providedProperties, connectionPropertyPrefix, password, PASSWORD_ATTRIBUTE); setOptionalAttribute(builder, providedProperties, connectionPropertyPrefix, connectionCachingEnabled, CONNECTION_CACHING_ENABLED_ATTRIBUTE); setOptionalAttribute(builder, providedProperties, connectionPropertyPrefix, fastConnectionFailoverEnabled, FAST_CONNECTION_FAILOVER_ENABLED_ATTRIBUTE); setOptionalAttribute(builder, providedProperties, connectionPropertyPrefix, onsConfiguration, ONS_CONFIGURATION_ATTRIBUTE); Properties providedConnectionProperties = new Properties(); Properties providedCachingProperties = new Properties(); for (String key : providedProperties.keySet()) { if (StringUtils.hasText(connectionPropertyPrefix) && key.startsWith(connectionPropertyPrefix)) { String newKey = key.substring(connectionPropertyPrefix.length()); providedConnectionProperties.put(newKey, providedProperties.get(key)); } else { if (StringUtils.hasText(cachingPropertyPrefix) && key.startsWith(cachingPropertyPrefix)) { String newKey = key.substring(cachingPropertyPrefix.length()); providedCachingProperties.put(newKey, providedProperties.get(key)); } else { providedConnectionProperties.put(key, providedProperties.get(key)); } } } // look for connectionProperties Object connProperties = DomUtils.getChildElementValueByTagName(element, CONNECTION_PROPERTIES_CHILD_ELEMENT); if (connProperties != null) { if (logger.isDebugEnabled()) { logger.debug("Using connection-properties"); } builder.addPropertyValue("connectionProperties", connProperties); } else { if (providedConnectionProperties.size() > 0) { if (logger.isDebugEnabled()) { logger.debug("Using provided connection properties: " + providedConnectionProperties); } builder.addPropertyValue("connectionProperties", providedConnectionProperties); } } // look for connectionCacheProperties Object cacheProperties = DomUtils.getChildElementValueByTagName(element, CONNECTION_CACHE_PROPERTIES_CHILD_ELEMENT); if (cacheProperties != null) { if (logger.isDebugEnabled()) { logger.debug("Using connection-cache-properties: [" + cacheProperties + "]"); } builder.addPropertyValue("connectionCacheProperties", cacheProperties); } else { if (providedCachingProperties.size() > 0) { if (logger.isDebugEnabled()) { logger.debug("Using provided caching properties: " + providedCachingProperties); } builder.addPropertyValue("connectionCacheProperties", providedCachingProperties); } } builder.setRole(BeanDefinition.ROLE_SUPPORT); }
From source file:org.springframework.data.jdbc.config.oracle.RacFailoverInterceptorBeanDefinitionParser.java
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { //attributes/*from ww w . ja v a2s. com*/ List<Integer> recoverableErrorCodesList = new ArrayList<Integer>(); String recoverableErrorCodes = element.getAttribute(RECOVERABLE_ERROR_CODES_ATTRIBUTE); if (StringUtils.hasText(recoverableErrorCodes)) { String[] parsedRecoverableErrorCodes = StringUtils.tokenizeToStringArray(recoverableErrorCodes, ",", true, true); for (int i = 0; i < parsedRecoverableErrorCodes.length; i++) { try { recoverableErrorCodesList.add(new Integer(parsedRecoverableErrorCodes[i])); } catch (NumberFormatException e) { parserContext.getReaderContext().error("Error parsing recoverable error code list: \"" + recoverableErrorCodes + "\"; " + e.getClass().getName() + " - " + e.getMessage(), element); } } if (logger.isDebugEnabled()) { logger.debug( "Using provided " + RECOVERABLE_ERROR_CODES_ATTRIBUTE + ": " + recoverableErrorCodesList); } } String maxNumberOfRetries = element.getAttribute(MAX_NUMBER_OF_RETRIES_ATTRIBUTE); if (logger.isDebugEnabled()) { if (StringUtils.hasText(maxNumberOfRetries)) { logger.debug("Using provided " + MAX_NUMBER_OF_RETRIES_ATTRIBUTE + ": " + maxNumberOfRetries); } } String backOffPolicyRef = null; if (element.hasAttribute(BACK_OFF_POLICY_ATTRIBUTE)) { backOffPolicyRef = element.getAttribute(BACK_OFF_POLICY_ATTRIBUTE); if (logger.isDebugEnabled()) { logger.debug("Using provided " + BACK_OFF_POLICY_ATTRIBUTE + ": " + backOffPolicyRef); } } BeanDefinitionBuilder retryTemplateBuilder = BeanDefinitionBuilder.genericBeanDefinition(); retryTemplateBuilder.getRawBeanDefinition().setBeanClassName(RETRY_TEMPLATE_CLASS); BeanDefinitionBuilder racFailoverRetryPolicyBuilder = BeanDefinitionBuilder.genericBeanDefinition(); racFailoverRetryPolicyBuilder.getRawBeanDefinition().setBeanClassName(RAC_FAILOVER_RETRY_POLICY_CLASS); if (recoverableErrorCodesList.size() > 0) { racFailoverRetryPolicyBuilder.addPropertyValue(RECOVERABLE_ERROR_CODES_PROPERTY, recoverableErrorCodesList); } if (StringUtils.hasText(maxNumberOfRetries)) { racFailoverRetryPolicyBuilder.addPropertyValue(MAX_NUMBER_OF_RETRIES_PROPERTY, maxNumberOfRetries); } retryTemplateBuilder.addPropertyValue(RETRY_POLICY_PROPERTY, racFailoverRetryPolicyBuilder.getRawBeanDefinition()); if (StringUtils.hasText(backOffPolicyRef)) { retryTemplateBuilder.addPropertyReference(BACK_OFF_POLICY_PROPERTY, backOffPolicyRef); } builder.addPropertyValue(RETRY_OPERATIONS_PROPERTY, retryTemplateBuilder.getRawBeanDefinition()); if (logger.isDebugEnabled()) { logger.debug("Using retry policy: " + racFailoverRetryPolicyBuilder.getRawBeanDefinition().getBeanClassName()); } builder.setRole(BeanDefinition.ROLE_SUPPORT); }