Skip to content

Instantly share code, notes, and snippets.

@sasajib
Created September 14, 2014 18:27
Show Gist options
  • Save sasajib/97f80c20be665b4905f6 to your computer and use it in GitHub Desktop.
Save sasajib/97f80c20be665b4905f6 to your computer and use it in GitHub Desktop.
package com.webdev.pavilion.news;
import com.webdev.common.orm.ORMFactory;
import com.webdev.common.service.ApiService;
import com.webdev.common.service.request.ServiceRequest;
import com.webdev.common.service.response.ServiceResponse;
import com.webdev.pavilion.news.mapper.NewsMapper;
import org.apache.ibatis.session.SqlSessionManager;
import java.util.Map;
public class NewsService implements ApiService
{
private Class<NewsMapper> newsMapperClass = NewsMapper.class;
private SqlSessionManager sqlSessionManager;
private NewsMapper newsMapper;
public NewsService()
{
ORMFactory.addConfigMapper(newsMapperClass);
sqlSessionManager = ORMFactory.getSqlManager();
newsMapper = sqlSessionManager.getMapper(newsMapperClass);
}
private void startSqlSession()
{
sqlSessionManager.startManagedSession();
}
private void closeSqlSession()
{
sqlSessionManager.close();
}
public ServiceResponse run(ServiceRequest request)
{
return null;
}
public Map<String, String> findsinglenews(int id)
{
try{
startSqlSession();
return newsMapper.findNewsById(id);
}finally {
closeSqlSession();
}
}
public Map<String, String> findtopnews(int limit)
{
try{
startSqlSession();
return newsMapper.findNewsCollection(NewsType.TOP_NEWS, limit);
}finally {
closeSqlSession();
}
}
public Map<String, String> findtopnews(int from, int to)
{
try{
startSqlSession();
return newsMapper.findNewsCollection(NewsType.TOP_NEWS, from, to);
}finally {
closeSqlSession();
}
}
public Map<String, String> findsidetopnews(int limit)
{
try{
startSqlSession();
return newsMapper.findNewsCollection(NewsType.SIDE_TOP_NEWS, limit);
}finally {
closeSqlSession();
}
}
public Map<String, String> findsidetopnews(int from, int to)
{
try{
startSqlSession();
return newsMapper.findNewsCollection(NewsType.SIDE_TOP_NEWS, from, to);
}finally {
closeSqlSession();
}
}
public Map<String, String> findfeaturednews(int limit)
{
try{
startSqlSession();
return newsMapper.findNewsCollection(NewsType.FEATURED_NEWS, limit);
}finally {
closeSqlSession();
}
}
public Map<String, String> findfeaturednews(int from, int to)
{
try{
startSqlSession();
return newsMapper.findNewsCollection(NewsType.FEATURED_NEWS, from, to);
}finally {
closeSqlSession();
}
}
public Map<String, String> findinterviewnews(int limit)
{
try{
startSqlSession();
return newsMapper.findNewsCollection(NewsType.INTERVIEW_NEWS, limit);
}finally {
closeSqlSession();
}
}
public Map<String, String> findinterviewnews(int from, int to)
{
try{
startSqlSession();
return newsMapper.findNewsCollection(NewsType.INTERVIEW_NEWS, from, to);
}finally {
closeSqlSession();
}
}
public Map<String, String> findmostviewednews(int limit)
{
return null;
}
public Map<String, String> findmostviewednews(int from, int to)
{
return null;
}
public Map<String, String> findnormalnews(int limit)
{
try{
startSqlSession();
return newsMapper.findNewsCollection(NewsType.NORMAL_NEWS, limit);
}finally {
closeSqlSession();
}
}
public Map<String, String> findnormalnews(int from, int to)
{
try{
startSqlSession();
return newsMapper.findNewsCollection(NewsType.NORMAL_NEWS, from, to);
}finally {
closeSqlSession();
}
}
public Map<String, String> findworldcupnews(int limit)
{
return null;
}
public Map<String, String> findworldcupnews(int from, int to)
{
return null;
}
public Map<String, String> findgeneralnews(int limit)
{
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment