Package com.vst.dao.hibernate

Source Code of com.vst.dao.hibernate.PipeLineElementDaoImpl

package com.vst.dao.hibernate;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;
import com.vst.dao.DetailDao;
import com.vst.dao.PipeLineElementDao;
import com.vst.model.PipeLineElement;


/**
* Created by IntelliJ IDEA.
* User: And Lilia
* Date: 25.05.2009
* Time: 14:06:42
* To change this template use File | Settings | File Templates.
*/
public class PipeLineElementDaoImpl extends HibernateDaoSupport implements PipeLineElementDao {

    DetailDao detailDao;
    VisualInspectionDaoHibernate visualInspectionDaoHibernate;


    public void setVisualInspectionDaoHibernate(VisualInspectionDaoHibernate visualInspectionDaoHibernate) {
        this.visualInspectionDaoHibernate = visualInspectionDaoHibernate;
    }

    public void setDetailDao(DetailDao detailDao) {
        this.detailDao = detailDao;
    }

    public List getPipeLineListByObjectInspectionId(Integer id, Properties props) throws SQLException {

        Connection dbConn = getConnection(props);
        Statement st = (Statement) dbConn.createStatement();
        ResultSet rs = (ResultSet) st.executeQuery("select * from pipeLineElement where objectId=" + id);
        List plList = setValues(rs);
        rs.close();
        return plList;


    }

    public List getPipeLineListByObjectInspectionAndDetailType(Integer typeId, Integer objectId, Properties props) throws SQLException {


        Connection dbConn = getConnection(props);
        Statement st = (Statement) dbConn.createStatement();
        ResultSet rs = (ResultSet) st.executeQuery("select * from pipeLineElement where objectId=" + objectId + " and detailTypeId=" + typeId);
        List plList = setValues(rs);
        rs.close();

        return plList;
    }

    public void delete(PipeLineElement pipeLineElement) {
        getHibernateTemplate().delete(pipeLineElement);
    }

    public void insert(PipeLineElement pipeLineElement) {
        getHibernateTemplate().clear();
        getHibernateTemplate().save(pipeLineElement);
    }

    public void update(PipeLineElement pipeLineElement) {
        getHibernateTemplate().evict(pipeLineElement);
        getHibernateTemplate().evict(pipeLineElement.getPipeLineElementDefectList());
        for (int i=0; i<pipeLineElement.getPipeLineElementDefectList().size(); i++){
             getHibernateTemplate().evict(pipeLineElement.getPipeLineElementDefectList().get(i));
        }
        getHibernateTemplate().clear();
        getHibernateTemplate().update(pipeLineElement);
        getHibernateTemplate().flush();
    }

    public PipeLineElement getPipeLineElementById(Integer id) {
        return (PipeLineElement) getHibernateTemplate().get(PipeLineElement.class, id);
    }

    public List getAllPipeLineElement() {
        return getHibernateTemplate().find("from PipeLineElement");
    }

    public Integer getPipesObjectId(Integer pipeId, Properties properties) {
        String driverURL = "jdbc:mysql://localhost/vstbase";
        java.sql.Connection dbConn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            dbConn = DriverManager.getConnection(driverURL, properties);
            java.sql.Statement st = dbConn.createStatement();
            java.sql.ResultSet rs = st.executeQuery("select objectId from pipelineelement where idElement=" + pipeId);
            Integer result = new Integer(1);
            while (rs.next()) {
                result = Integer.valueOf(rs.getInt(1));
            }
            rs.close();
            return result;
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;

        }

    }

    private List setValues(ResultSet rs) throws SQLException {
        List list = new ArrayList();

        while (rs.next()) {
            PipeLineElement pl = new PipeLineElement();
            pl.setIdElement((Integer) rs.getInt(1));
            pl.setDetailType(detailDao.getDetailTypesById((Integer) rs.getInt(4)));
            pl.setVisualInspection(visualInspectionDaoHibernate.getById((Integer) rs.getInt(2)));

            if (pl.getDetailType() != null) {
                if (pl.getDetailType().getTypeId().equals(new Integer(1))) {
                    pl.setDetail(detailDao.getPipeById((Integer) rs.getInt(3)));
                }
                if (pl.getDetailType().getTypeId().equals(new Integer(2))) {
                    pl.setDetail(detailDao.getTapById((Integer) rs.getInt(3)));
                }
                if (pl.getDetailType().getTypeId().equals(new Integer(3))) {
                    pl.setDetail(detailDao.getTransitionById((Integer) rs.getInt(3)));
                }
                if (pl.getDetailType().getTypeId().equals(new Integer(4))) {
                    pl.setDetail(detailDao.getTeeById((Integer) rs.getInt(3)));
                }
                if (pl.getDetailType().getTypeId().equals(new Integer(5))) {
                    pl.setDetail(detailDao.getZaglushkaById((Integer) rs.getInt(3)));
                }
                if (pl.getDetailType().getTypeId().equals(new Integer(6))) {
                    pl.setDetail(detailDao.getFlangeById((Integer) rs.getInt(3)));
                }
                if (pl.getDetailType().getTypeId().equals(new Integer(7))) {
                    pl.setDetail(detailDao.getArmatureById((Integer) rs.getInt(3)));
                }
                if (pl.getDetailType().getTypeId().equals(new Integer(8))) {
                    pl.setDetail(detailDao.getOborudovanieById((Integer) rs.getInt(3)));
                }
            }


            pl.setDiametr((Double) rs.getDouble(5));
            pl.setThickness((Double) rs.getDouble(6));
            pl.setFirstDiametr((Double) rs.getDouble(7));
            pl.setSecondDiametr((Double) rs.getDouble(8));
            pl.setFirstThickness((Double) rs.getDouble(9));
            pl.setSecondThickness((Double) rs.getDouble(10));
            pl.setPressure((Integer) rs.getInt(11));
            pl.setCorner((Integer) rs.getInt(12));
            pl.setNumberElement(rs.getString(13));
            pl.setMarkElement(rs.getString(14));
            pl.setPassportExist(rs.getBoolean(15));

            list.add(pl);
        }

        return list;
    }

    private Connection getConnection(Properties props) {

        String driverURL = "jdbc:mysql://localhost/vstbase?useUnicode=true&amp;characterEncoding=UTF-8";
        Connection dbConn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            dbConn = (Connection) DriverManager.getConnection(driverURL, props);
            return dbConn;
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

    /*  public List getThListByDiameter(Integer id, String currentPath,Properties props) throws SQLException {


            String driverURL = "jdbc:mysql://localhost/vstbase";

            java.sql.Connection dbConn = null;
                try {
                    Class.forName("com.mysql.jdbc.Driver");
                    dbConn = DriverManager.getConnection(driverURL, props);
                    java.sql.Statement st =  dbConn.createStatement();
                    java.sql.ResultSet rs= st.executeQuery("select thickness.* from thickness, thicknessRealtions where thickness.thicknessId=thicknessRealtions.thicknessId and thicknessRealtions.diametrId="+id);

                    List thList = new ArrayList();
                    while (rs.next()){
                       Thickness th= new Thickness();
                       th.setThicknessCount((Double)rs.getDouble(2));
                       th.setThicknessId((Integer)rs.getInt(1));
                       thList.add(th);
                   }
                   rs.close();
                   System.out.println("IT IS OK!!! size="+thList.size());
                   return thList;
                }
                catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("ERRORRRRRR") ;
                    return null;

                }

    }*/

    /* public List getThListByDiameter(Integer id,String currentPath) throws SQLException, IOException {
            BasicDataSource basicDataSource= (BasicDataSource) BeanUtils.getBean("dataSource",currentPath);
            Properties props = new Properties();
            props.setProperty("driver.url", "jdbc:mysql://localhost/vstbase");
            props.setProperty("driver.class",basicDataSource.getDriverClassName());
            props.setProperty("user",basicDataSource.getUsername());
            props.setProperty("password",basicDataSource.getPassword());
        return diameterDao.getThListByDiameter(id,currentPath, props);
    }*/

}
 
TOP

Related Classes of com.vst.dao.hibernate.PipeLineElementDaoImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.