package twitter;

import java.util.Collections;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jerrymouse.database.DaoAdapter;
import org.jerrymouse.database.DaoSupport;
import org.jerrymouse.database.jpa.JPAPMF;

public class TwitterDao {
	private static Log log = LogFactory.getLog(TwitterDao.class);

	DaoSupport<Twitter> daoSupport;

	public TwitterDao() {
		daoSupport = new DaoAdapter<Twitter>().getDaoSupport();
	}

	@SuppressWarnings("unchecked")
	public List<Twitter> list() {
		EntityManager pm = JPAPMF.getEntityManager();
		Query query = pm.createQuery("SELECT e FROM " + Twitter.class.getName()
				+ " e");
		List<Twitter> list = query.getResultList();
		list.size();
		pm.close();
		if (list != null)
			Collections.sort(list);
		return list;
	}

	public void put(Twitter twitter) {
		daoSupport.put(twitter);
	}
}
