# ReticleFamilyDAOImpl.java

    package com.mycim.server.reticle.dao.impl;

    import com.fa.sesa.threadlocal.LocalContext;
    import com.mycim.framework.jdbc.JdbcTemplate;
    import com.mycim.server.reticle.dao.ReticleFamilyDAO;
    import com.mycim.valueobject.ObjectList;
    import com.mycim.valueobject.bas.TransactionLog;
    import com.mycim.valueobject.consts.DataBaseNames;
    import com.mycim.valueobject.consts.LinkTypeList;
    import com.mycim.valueobject.ems.ReticleFamily;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Repository;

    @Repository
    public class ReticleFamilyDAOImpl implements ReticleFamilyDAO {

        @Autowired
        JdbcTemplate jdbcTemplate;

        @Override
        public String getReticleFamilyStatus(String id) {
            String sql = "SELECT instance_status FROM " + DataBaseNames.NAMEDOBJECT + " WHERE object = '" +
                    ObjectList.RETICLEFAMILY_KEY + "' and instance_id ='" + id + "'";
            return jdbcTemplate.queryForObjectWithNull(sql, String.class);
        }

        @Override
        public void deleteReticleFamily(long groupRrn) {
            String sql = "delete from relation where " + " link_type='" + LinkTypeList.RETICLE_TO_RETICLEFAMILY_KEY + "' " +
                    " and to_rrn=" + groupRrn;
            jdbcTemplate.update(sql);
        }

        @Override
        public void deleteReticleFamily(ReticleFamily reticleFamily) {
            String sql = "DELETE FROM " + DataBaseNames.RETICLE_FAMILY + " WHERE SYS_RRN=? ";
            jdbcTemplate.update(sql, reticleFamily.getInstanceRrn());
        }

        @Override
        public void updateReticleFamily(ReticleFamily reticleFamily) {
            String updateSql = "UPDATE " + DataBaseNames.RETICLE_FAMILY + " SET DESCRIPTION=?,OBJ_STATUS=?," +
                    "UPDATE_USER_RRN=?,UPDATE_TIME=? WHERE SYS_RRN=?";
            jdbcTemplate.update(updateSql, reticleFamily.getInstanceDesc(), reticleFamily.getInstanceStatus(),
                                reticleFamily.getLastUpdateUserRrn(), reticleFamily.getLastUpdateTimestamp(),
                                reticleFamily.getInstanceRrn());
        }

        @Override
        public long isProductLay4ReticleFamily(long reticleFamilyRrn) {
            String sql = "SELECT count(*) seq FROM " + DataBaseNames.PRODUCT_LAYER_MASK + " WHERE reticle_family_rrn =?";
            return jdbcTemplate.queryForObject(sql, new Object[]{reticleFamilyRrn}, long.class);
        }

        @Override
        public long isProductLay(long entityRrn) {
            String sql = "SELECT count(*) seq FROM " + DataBaseNames.PRODUCT_LAYER_MASK + " WHERE reticle_family_rrn in (" +
                    " " + " select r.to_rrn from relation r where r.link_type = '" +
                    LinkTypeList.RETICLE_TO_RETICLEFAMILY_KEY + "'" + " and r.from_rrn = ? )";
            return jdbcTemplate.queryForObject(sql, new Object[]{entityRrn}, long.class);
        }

        @Override
        public void insertReticleFamily(ReticleFamily rf) {
            String sql = "INSERT INTO " + DataBaseNames.RETICLE_FAMILY + " (" + "SYS_RRN,RETICLE_FAMILY_ID,FACILITY_RRN," +
                    "DESCRIPTION,OBJ_SPACE," + "OBJ_TYPE,OBJ_SUBTYPE,OBJ_STATUS,OBJ_CURRENT_VERSION,OBJ_ACTIVE_VERSION," +
                    "CREATE_TIME,UPDATE_TIME,CREATE_USER_RRN,UPDATE_USER_RRN,LOCK_VERSION) " +
                    "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            jdbcTemplate.update(sql, rf.getInstanceRrn(), rf.getInstanceId(), LocalContext.getFacilityRrn(),
                                rf.getInstanceDesc(), rf.getNamedSpace(), rf.getObjectType(), rf.getObjectSubtype(),
                                rf.getInstanceStatus(), rf.getCurrentVersion(), rf.getActiveVersion(),
                                rf.getCreatedTimestamp(), rf.getCreatedTimestamp(), rf.getCreatedUserRrn(),
                                rf.getLastUpdateUserRrn(), rf.getLockVersion());
        }

        @Override
        public void insertReticleFamilyHistory(ReticleFamily rf, TransactionLog tr) {
            String sql = "INSERT INTO " + DataBaseNames.RETICLE_FAMILY_H + " (" + "TRANS_RRN,TRANS_ID,SYS_RRN," +
                    "RETICLE_FAMILY_ID,FACILITY_RRN,DESCRIPTION,OBJ_SPACE," + "OBJ_TYPE,OBJ_SUBTYPE,OBJ_STATUS," +
                    "OBJ_CURRENT_VERSION,OBJ_ACTIVE_VERSION,TRANS_USER_RRN,TRANS_TIME) " + "SELECT ?,?,SYS_RRN," +
                    "RETICLE_FAMILY_ID,FACILITY_RRN,DESCRIPTION,OBJ_SPACE,OBJ_TYPE," + "OBJ_SUBTYPE,OBJ_STATUS," +
                    "OBJ_CURRENT_VERSION,OBJ_ACTIVE_VERSION,?,?" + " FROM " + DataBaseNames.RETICLE_FAMILY + " WHERE " +
                    "SYS_RRN = ?";
            jdbcTemplate
                    .update(sql, tr.getTransRrn(), tr.getTransId(), rf.getLastUpdateUserRrn(), tr.getTransStartTimestamp(),
                            rf.getInstanceRrn());
        }

    }