org.sql2o.reflection.ReflectionObjectConstructorFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of anima Show documentation
Show all versions of anima Show documentation
Operate the database like a stream
package org.sql2o.reflection;
import org.sql2o.Sql2oException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
public class ReflectionObjectConstructorFactory implements ObjectConstructorFactory {
public ObjectConstructor newConstructor(final Class> clazz) {
try {
final Constructor> ctor = clazz.getDeclaredConstructor();
ctor.setAccessible(true);
return new ObjectConstructor() {
public Object newInstance() {
try {
return ctor.newInstance((Object[])null);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new Sql2oException("Could not create a new instance of class " + clazz, e);
}
}
};
} catch (Throwable e) {
throw new Sql2oException("Could not find parameter-less constructor of class " + clazz, e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy