com.objectsql.spring.SpringUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of object-sql Show documentation
Show all versions of object-sql Show documentation
Lightweight Object SQL Relational Mapping (OSRM)
The newest version!
package com.objectsql.spring;
import org.springframework.beans.TypeMismatchException;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.validation.DataBinder;
import javax.sql.DataSource;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.sql.Connection;
public class SpringUtils {
public static A findAnnotation(Class> clazz, Class annotationType) {
return AnnotationUtils.findAnnotation(clazz, annotationType);
}
public static Connection getConnection(DataSource dataSource) {
return DataSourceUtils.getConnection(dataSource);
}
public static void releaseConnection(Connection con, DataSource dataSource) {
DataSourceUtils.releaseConnection(con, dataSource);
}
public static T convertIfNecessary(Field field, Object value) throws TypeMismatchException {
DataBinder binder = new DataBinder(field, field.getName());
return (T)binder.convertIfNecessary(value.toString(), field.getType());
}
}