Java tutorial
/* * 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.Date; import java.util.GregorianCalendar; import java.util.List; import java.util.Map; import javax.activation.DataSource; import konditer.client.bean.OrdereStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; /** * * @author */ @Repository("ordereStatusDao") public class OrdereStatusDao implements OrdereStatusDaoInterface { 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; } @Override public void addOrdereStatus(int orderStatusId, String orderStatusName) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } //ordereStatusDao.getOrdereStatus(1); @Override public OrdereStatus getOrdereStatus(int orderStatusId) { String SQL_QUERY = "SELECT ORDER_STATUS_ID, ORDER_STATUS_NAME, TIMESTAMP " + "FROM order_statuses " + "WHERE ORDER_STATUS_ID = ?"; OrdereStatus ordereStatus = (OrdereStatus) jdbcTemplate.queryForObject(SQL_QUERY, new Object[] { orderStatusId }, new BeanPropertyRowMapper(OrdereStatus.class)); return ordereStatus; } @Override public ArrayList<OrdereStatus> getAllOrdereStatuses() { String SQL_QUERY = "SELECT ORDER_STATUS_ID, ORDER_STATUS_NAME, TIMESTAMP " + " FROM order_statuses "; List<Map<String, Object>> rows = jdbcTemplate.queryForList(SQL_QUERY); ArrayList<OrdereStatus> ordereStatusList = new ArrayList<>(); for (Map row : rows) { OrdereStatus ordereStatus = new OrdereStatus(); ordereStatus.setOrderStatusId(Integer.parseInt(String.valueOf(row.get("ORDER_STATUS_ID")))); ordereStatus.setOrderStatusName(String.valueOf(row.get("ORDER_STATUS_NAME"))); //// 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])); ordereStatus.setTimestamp(new GregorianCalendar(year, month, day, hour, minut, (int) second).getTime()); /// ordereStatusList.add(ordereStatus); } return ordereStatusList; } @Override public ArrayList<OrdereStatus> getAllOrdereStatuses(String searchValue) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public ArrayList<OrdereStatus> searchAllOrdereStatuses(String sqlQuery) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public int updateOrdereStatus(int orderStatusId, String newOrderStatusName) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public int deleteOrdereStatus(int orderStatusId) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public ArrayList<OrdereStatus> getTimestamp() { String SQL_QUERY = "SELECT ORDER_STATUS_ID, TIMESTAMP " + "FROM order_statuses "; List<Map<String, Object>> rows = jdbcTemplate.queryForList(SQL_QUERY); ArrayList<OrdereStatus> ordereStatusList = new ArrayList<>(); for (Map row : rows) { OrdereStatus ordereStatus = new OrdereStatus(); ordereStatus.setOrderStatusId(Integer.parseInt(String.valueOf(row.get("ORDER_STATUS_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])); ordereStatus.setTimestamp(new GregorianCalendar(year, month, day, hour, minut, (int) second).getTime()); /// ordereStatusList.add(ordereStatus); } return ordereStatusList; } }