konditer.client.dao.SitePageDao.java Source code

Java tutorial

Introduction

Here is the source code for konditer.client.dao.SitePageDao.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package konditer.client.dao;

import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import javax.activation.DataSource;
import konditer.client.bean.SitePage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 *
 * @author 
 */
@Repository("sitePageDao")
public class SitePageDao implements SitePageDaoInterface {

    private DataSource dataSource = null;
    private JdbcTemplate jdbcTemplate = null;

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    @Autowired
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public SitePageDao() {
    }

    @Override
    public void addSitePage(int pageId, int metaId, String pageName, String pageTitle, String pageContent) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public SitePage getSitePage(int pageId) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ArrayList<SitePage> getAllSitePages() {
        String SQL_QUERY = "SELECT PAGE_ID, META_ID, PAGE_NAME, PAGE_TITLE, PAGE_CONTENT, TIMESTAMP "
                + "  FROM site_pages ";
        List<Map<String, Object>> rows = jdbcTemplate.queryForList(SQL_QUERY);
        ArrayList<SitePage> sitePageList = new ArrayList<>();
        for (Map row : rows) {
            SitePage sitePage = new SitePage();
            sitePage.setPageId(Integer.parseInt(String.valueOf(row.get("PAGE_ID"))));
            sitePage.setPageId(Integer.parseInt(String.valueOf(row.get("META_ID"))));
            sitePage.setPageName(String.valueOf(row.get("PAGE_NAME")));
            sitePage.setPageTitle(String.valueOf(row.get("PAGE_TITLE")));
            sitePage.setPageContent(String.valueOf(row.get("PAGE_CONTENT")));
            ////
            String[] dateArrFull = (String.valueOf(row.get("TIMESTAMP"))).split(" ");
            String[] dateArrDate = dateArrFull[0].split("-");
            int year = Integer.parseInt(String.valueOf(dateArrDate[0]))/* -1900 */;
            int month = Integer.parseInt(String.valueOf(dateArrDate[1])) - 1;
            int day = Integer.parseInt(String.valueOf(dateArrDate[2]));
            String[] dateArrTime = dateArrFull[1].split(":");
            int hour = Integer.parseInt(String.valueOf(dateArrTime[0]));
            int minut = Integer.parseInt(String.valueOf(dateArrTime[1]));
            double second = Double.parseDouble(String.valueOf(dateArrTime[2]));
            sitePage.setTimestamp(new GregorianCalendar(year, month, day, hour, minut, (int) second).getTime());
            ///
            sitePageList.add(sitePage);
        }
        return sitePageList;
    }

    @Override
    public ArrayList<SitePage> getAllSitePages(String searchValues) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ArrayList<SitePage> getAllSitePagesByMetaId(int metaId) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int updateSitePage(int pageId, int newMetaId, String newPageName, String newPageTitle,
            String newPageContent) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int deleteSitePage(int pageId) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ArrayList<SitePage> getTimestamp() {
        String SQL_QUERY = "SELECT PAGE_ID, TIMESTAMP " + "FROM site_pages ";
        List<Map<String, Object>> rows = jdbcTemplate.queryForList(SQL_QUERY);
        ArrayList<SitePage> sitePageList = new ArrayList<>();
        for (Map row : rows) {
            SitePage sitePage = new SitePage();
            sitePage.setPageId(Integer.parseInt(String.valueOf(row.get("PAGE_ID"))));
            ////
            String[] dateArrFull = (String.valueOf(row.get("TIMESTAMP"))).split(" ");
            String[] dateArrDate = dateArrFull[0].split("-");
            int year = Integer.parseInt(String.valueOf(dateArrDate[0]))/* -1900 */;
            int month = Integer.parseInt(String.valueOf(dateArrDate[1])) - 1;
            int day = Integer.parseInt(String.valueOf(dateArrDate[2]));
            String[] dateArrTime = dateArrFull[1].split(":");
            int hour = Integer.parseInt(String.valueOf(dateArrTime[0]));
            int minut = Integer.parseInt(String.valueOf(dateArrTime[1]));
            double second = Double.parseDouble(String.valueOf(dateArrTime[2]));
            sitePage.setTimestamp(new GregorianCalendar(year, month, day, hour, minut, (int) second).getTime());
            ///
            sitePageList.add(sitePage);
        }
        return sitePageList;
    }

}