konditer.client.dao.IngredientDao.java Source code

Java tutorial

Introduction

Here is the source code for konditer.client.dao.IngredientDao.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.Ingredient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 *
 * @author 
 */
@Repository("ingredientDao")
public class IngredientDao implements IngredientDaoInterface {

    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 IngredientDao() {
    }

    @Override
    public void addIngredient(int ingredientId, String ingredientName, double ingredientPrice,
            double ingredientVolume) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

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

    @Override
    public ArrayList<Ingredient> getAllIngredients() {
        String SQL_QUERY = "SELECT INGREDIENT_ID, INGREDIENT_NAME, INGREDIENT_PRICE, INGREDIENT_VOLUME, TIMESTAMP "
                + "FROM ingredients ";
        List<Map<String, Object>> rows = jdbcTemplate.queryForList(SQL_QUERY);
        ArrayList<Ingredient> ingredientList = new ArrayList<>();
        for (Map row : rows) {
            Ingredient ingredient = new Ingredient();
            ingredient.setIngredientId(Integer.parseInt(String.valueOf(row.get("INGREDIENT_ID"))));
            ingredient.setIngredientName(String.valueOf(row.get("INGREDIENT_NAME")));
            ingredient.setIngredientPrice(Double.parseDouble(String.valueOf(row.get("INGREDIENT_PRICE"))));
            ingredient.setIngredientVolume(Double.parseDouble(String.valueOf(row.get("INGREDIENT_VOLUME"))));
            ////
            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]));
            ingredient.setTimestamp(new GregorianCalendar(year, month, day, hour, minut, (int) second).getTime());
            ///
            ingredientList.add(ingredient);
        }
        return ingredientList;
    }

    @Override
    public ArrayList<Ingredient> getAllIngredients(String searchValue) {
        String SQL_QUERY = searchValue;
        List<Map<String, Object>> rows = jdbcTemplate.queryForList(SQL_QUERY);
        ArrayList<Ingredient> ingredientList = new ArrayList<>();
        for (Map row : rows) {
            Ingredient ingredient = new Ingredient();
            ingredient.setIngredientId(Integer.parseInt(String.valueOf(row.get("INGREDIENT_ID"))));
            ingredient.setIngredientName(String.valueOf(row.get("INGREDIENT_NAME")));
            ingredient.setIngredientPrice(Double.parseDouble(String.valueOf(row.get("INGREDIENT_PRICE"))));
            ingredient.setIngredientVolume(Double.parseDouble(String.valueOf(row.get("INGREDIENT_VOLUME"))));
            ////
            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]));
            ingredient.setTimestamp(new GregorianCalendar(year, month, day, hour, minut, (int) second).getTime());
            ///
            ingredientList.add(ingredient);
        }
        return ingredientList;
    }

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

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

    @Override
    public int updateIngredient(int ingredientId, String newIngredientName, double newIngredientPrice,
            double newIngredientVolume) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

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

    @Override
    public ArrayList<Ingredient> getTimestamp() {
        String SQL_QUERY = "SELECT INGREDIENT_ID, TIMESTAMP " + "FROM ingredients ";
        List<Map<String, Object>> rows = jdbcTemplate.queryForList(SQL_QUERY);
        ArrayList<Ingredient> ingredientList = new ArrayList<>();
        for (Map row : rows) {
            Ingredient ingredient = new Ingredient();
            ingredient.setIngredientId(Integer.parseInt(String.valueOf(row.get("INGREDIENT_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]));
            ingredient.setTimestamp(new GregorianCalendar(year, month, day, hour, minut, (int) second).getTime());
            ///
            ingredientList.add(ingredient);
        }
        return ingredientList;
    }
}