/*
 * Copyright (c) 2015 by Rafael Angel Aznar Aparici (rafaaznar at gmail dot com)
 * 
 * openAUSIAS: The stunning micro-library that helps you to develop easily 
 *             AJAX web applications by using Java and jQuery
 * openAUSIAS is distributed under the MIT License (MIT)
 * Sources at https://github.com/rafaelaznar/
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 */
package net.daw.dao.implementation;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import net.daw.bean.implementation.UsuarioBean;
import net.daw.bean.implementation.UsuarioxcursoBean;
import net.daw.dao.publicinterface.TableDaoInterface;
import net.daw.dao.publicinterface.ViewDaoInterface;
import net.daw.data.implementation.MysqlDataSpImpl;
import net.daw.helper.statics.ExceptionBooster;
import net.daw.helper.statics.FilterBeanHelper;
import net.daw.helper.statics.SqlBuilder;

public class UsuarioxcursoDao implements ViewDaoInterface<UsuarioxcursoBean>, TableDaoInterface<UsuarioxcursoBean> {

//    private String strTable = "usuariocurso";
    private String strSQLusuariocurso = "select * from usuariocurso where 1=1 ";
    private String strSQLcurso = "select * from curso where 1=1 ";
    private MysqlDataSpImpl oMysql = null;
    private Connection oConnection = null;

    public UsuarioxcursoDao(Connection oPooledConnection) throws Exception {
        try {
            oConnection = oPooledConnection;
            oMysql = new MysqlDataSpImpl(oConnection);
        } catch (Exception ex) {
            ExceptionBooster.boost(new Exception(this.getClass().getName() + ":constructor ERROR: " + ex.getMessage()));
        }
    }

    public int getPagesUsuarioXCurso(int intCurso, int intRegsPerPag, ArrayList<FilterBeanHelper> hmFilter) throws Exception {
        strSQLusuariocurso += SqlBuilder.buildSqlUsuarioCursoXCurso(intCurso);
        strSQLusuariocurso += SqlBuilder.buildSqlWhere(hmFilter);
        int pages = 0;
        try {
            pages = oMysql.getPages(strSQLusuariocurso, intRegsPerPag);
        } catch (Exception ex) {
            ExceptionBooster.boost(new Exception(this.getClass().getName() + ":getPages ERROR: " + ex.getMessage()));
        }
        return pages;
    }

    public int getCountUsuarioXCurso(int intCurso, ArrayList<FilterBeanHelper> hmFilter) throws Exception {
        strSQLusuariocurso += SqlBuilder.buildSqlUsuarioCursoXCurso(intCurso);
        strSQLusuariocurso += SqlBuilder.buildSqlWhere(hmFilter);
        int pages = 0;
        try {
            pages = oMysql.getCount(strSQLusuariocurso);
        } catch (Exception ex) {
            ExceptionBooster.boost(new Exception(this.getClass().getName() + ":getCount ERROR: " + ex.getMessage()));
        }
        return pages;
    }

    public UsuarioxcursoBean getPageUsuarioXCurso(int intCurso, int intRegsPerPag, int intPage, ArrayList<FilterBeanHelper> hmFilter, HashMap<String, String> hmOrder, Integer expand) throws Exception {
        strSQLusuariocurso += SqlBuilder.buildSqlUsuarioCursoXCurso(intCurso);
        strSQLusuariocurso += SqlBuilder.buildSqlWhere(hmFilter);
        strSQLusuariocurso += SqlBuilder.buildSqlOrder(hmOrder);
        strSQLusuariocurso += SqlBuilder.buildSqlLimit(oMysql.getCount(strSQLusuariocurso), intRegsPerPag, intPage);
        strSQLcurso += SqlBuilder.buildSqlCurso(intCurso);
        strSQLcurso += SqlBuilder.buildSqlWhere(hmFilter);
        strSQLcurso += SqlBuilder.buildSqlOrder(hmOrder);
        strSQLcurso += SqlBuilder.buildSqlLimit(oMysql.getCount(strSQLcurso), intRegsPerPag, intPage);

        UsuarioxcursoBean oUsuarioxcursoBean = new UsuarioxcursoBean();
        try {
            ResultSet oResultSetUsuarioCurso = oMysql.getAllSql(strSQLusuariocurso);
            ResultSet oResultSetCurso = oMysql.getAllSql(strSQLcurso);
            if (oResultSetCurso != null) {
                while (oResultSetCurso.next()) {
                    oUsuarioxcursoBean = (oUsuarioxcursoBean.fills(oResultSetCurso, oResultSetUsuarioCurso, oConnection, expand));
                }
            }
        } catch (Exception ex) {
            ExceptionBooster.boost(new Exception(this.getClass().getName() + ":getPage ERROR: " + ex.getMessage()));
        }
        return oUsuarioxcursoBean;
    }

    @Override
    public int getPages(int intRegsPerPag, ArrayList<FilterBeanHelper> alFilter) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

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

    @Override
    public ArrayList<UsuarioxcursoBean> getPage(int intRegsPerPag, int intPage, ArrayList<FilterBeanHelper> alFilter, HashMap<String, String> hmOrder, Integer expand) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ArrayList<UsuarioxcursoBean> getAll(ArrayList<FilterBeanHelper> alFilter, HashMap<String, String> hmOrder, Integer expand) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public UsuarioxcursoBean get(UsuarioxcursoBean oBean, Integer expand) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Integer set(UsuarioxcursoBean oBean) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Integer remove(Integer id) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}
