001/*
002 * Copyright 2012-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.jta.atomikos;
018
019import org.springframework.beans.factory.BeanNameAware;
020import org.springframework.beans.factory.DisposableBean;
021import org.springframework.beans.factory.InitializingBean;
022import org.springframework.boot.context.properties.ConfigurationProperties;
023import org.springframework.util.StringUtils;
024
025/**
026 * Spring friendly version of {@link com.atomikos.jdbc.AtomikosDataSourceBean}.
027 *
028 * @author Phillip Webb
029 * @author Andy Wilkinson
030 * @since 1.2.0
031 */
032@SuppressWarnings("serial")
033@ConfigurationProperties(prefix = "spring.jta.atomikos.datasource")
034public class AtomikosDataSourceBean extends com.atomikos.jdbc.AtomikosDataSourceBean
035                implements BeanNameAware, InitializingBean, DisposableBean {
036
037        private String beanName;
038
039        @Override
040        public void setBeanName(String name) {
041                this.beanName = name;
042        }
043
044        @Override
045        public void afterPropertiesSet() throws Exception {
046                if (!StringUtils.hasLength(getUniqueResourceName())) {
047                        setUniqueResourceName(this.beanName);
048                }
049                init();
050        }
051
052        @Override
053        public void destroy() throws Exception {
054                close();
055        }
056
057}