Commits

Daniel Zoller committed 74102bf

added ConversionServiceFactoryBeanPostProcessor
removed SqlSessionFactoryBean

Comments (0)

Files changed (4)

 		<dependency>
 			<groupId>org.mybatis</groupId>
 			<artifactId>mybatis</artifactId>
-			<version>3.0.1</version>
+			<version>3.0.5</version>
 			<type>jar</type>
-			<scope>provided</scope>
+			<optional>true</optional>
 		</dependency>
 		<dependency>
 			<groupId>org.springframework</groupId>
 			<artifactId>spring-beans</artifactId>
 			<version>3.0.5.RELEASE</version>
 			<type>jar</type>
-			<scope>provided</scope>
+			<optional>true</optional>
 		</dependency>
 	</dependencies>
 	<build>

src/main/java/de/nosebrain/spring/beans/factory/ConversionServiceFactoryBeanPostProcessor.java

+package de.nosebrain.spring.beans.factory;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.core.Ordered;
+import org.springframework.core.convert.ConversionService;
+
+/**
+ * 
+ * @author nosebrain
+ */
+public class ConversionServiceFactoryBeanPostProcessor implements BeanFactoryPostProcessor, Ordered {
+
+	private int order = Ordered.HIGHEST_PRECEDENCE;
+	private ConversionService conversionService;
+	
+	@Override
+	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
+		beanFactory.setConversionService(this.conversionService);
+	}
+	
+	/**
+	 * @param conversionService the conversion service to set
+	 */
+	public void setConversionService(ConversionService conversionService) {
+		this.conversionService = conversionService;
+	}
+	
+	/**
+	 * @param order the order to set
+	 */
+	public void setOrder(int order) {
+		this.order = order;
+	}
+
+	@Override
+	public int getOrder() {
+		return this.order;
+	}
+
+}

src/main/java/de/nosebrain/spring/beans/factory/SqlSessionFactoryBean.java

-package de.nosebrain.spring.beans.factory;
-
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.util.Properties;
-
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.apache.ibatis.session.SqlSessionFactoryBuilder;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.core.io.Resource;
-
-/**
- * 
- * @author nosebrain
- */
-public class SqlSessionFactoryBean implements FactoryBean<SqlSessionFactory> {
-
-	private SqlSessionFactory factory;
-	private String environment;
-	private Properties props;
-	private Resource configLocation;
-	
-	/**
-	 * @param configLocation the configLocation to set
-	 */
-	public void setConfigLocation(Resource configLocation) {
-		this.configLocation = configLocation;
-	}
-
-	/**
-	 * @param props the props to set
-	 */
-	public void setProps(Properties props) {
-		this.props = props;
-	}
-
-	/**
-	 * @param environment the environment to set
-	 */
-	public void setEnvironment(String environment) {
-		this.environment = environment;
-	}
-
-	@Override
-	public SqlSessionFactory getObject() throws Exception {
-		if (this.factory == null) {
-			this.factory = this.buildFactoryBean();
-		}
-		
-		return this.factory;
-	}
-
-	private SqlSessionFactory buildFactoryBean() throws IOException {
-		final Reader reader = new InputStreamReader(this.configLocation.getInputStream());
-		final SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
-		return builder.build(reader, this.environment, this.props);
-	}
-
-	@Override
-	public Class<?> getObjectType() {
-		return SqlSessionFactory.class;
-	}
-
-	@Override
-	public boolean isSingleton() {
-		return true;
-	}
-
-}

src/main/java/de/nosebrain/util/StringUtils.java

  */
 public abstract class StringUtils {
 	
+	private static final String DEFAULT_CHARSET = "UTF-8";
+
 	/**
 	 * md5 of the string
 	 * @param str the string to hash
 	public static String md5(final String str) {
 		try {
 			final MessageDigest md = MessageDigest.getInstance("MD5");
-			return toHexString(md.digest(str.getBytes("UTF-8")));
+			return toHexString(md.digest(str.getBytes(DEFAULT_CHARSET)));
 		} catch (final NoSuchAlgorithmException e) {
 			throw new RuntimeException(e);
 		} catch (final UnsupportedEncodingException e) {