org.specrunner.hibernate4.ObjectSelector Maven / Gradle / Ivy
package org.specrunner.hibernate4;
import java.util.List;
import org.apache.commons.beanutils.PropertyUtils;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.specrunner.context.IContext;
import org.specrunner.plugins.core.objects.AbstractPluginObject;
import org.specrunner.plugins.core.objects.IObjectSelector;
import org.specrunner.result.IResultSet;
import org.specrunner.util.xom.node.RowAdapter;
/**
* Hibernate object selector.
*
* @author Thiago Santos
*
*/
public class ObjectSelector implements IObjectSelector {
/**
* Thread safe instance of ObjectSelector
.
*/
protected static ThreadLocal instance = new ThreadLocal() {
@Override
protected ObjectSelector initialValue() {
return new ObjectSelector();
};
};
/**
* The object session factory.
*/
protected Session session;
/**
* Gets the thread safe instance of finder.
*
* @return The finder instance.
*/
public static ObjectSelector get() {
return instance.get();
}
@Override
public Session getSource(AbstractPluginObject caller, IContext context) throws Exception {
// recover the plugin session factory.
if (session == null) {
SessionFactory sf = PluginSessionFactory.getSessionFactory(context, caller.getName());
session = sf.openSession();
}
return session;
}
@SuppressWarnings("unchecked")
@Override
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy