1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.vci.server.framework.systemConfig.stafforgmanage.combination;
 
import java.util.List;
 
import org.hibernate.HibernateException;
 
import com.vci.server.base.persistence.dao.BaseService;
import com.vci.server.base.persistence.dao.HibernateCallback;
import com.vci.server.base.persistence.dao.HibernateTemplate;
import com.vci.server.framework.systemConfig.stafforgmanage.passwordStrategy.PasswordStrategyDaoImpl;
 
public class CombinationValueService extends BaseService {
    /**
     * 根据父Id获取密码组合方式取值范围
     * <p>Description: </p>
     * 
     * @author wangxl
     * @time 2013-1-3
     * @param parentId
     * @return
     */
    public List getCombinationValuesByParentId(final String parentId) {
        return (List)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                CombinationValueDAOImpl impl = new CombinationValueDAOImpl();
                String hsql = "from CombinationValue cv where PLPARENTID = '" + parentId + "' order by cv.value";
                if(parentId.equals("")){
                    hsql = "from CombinationValue cv order by cv.value";
                }
                return impl.findEntities(hsql);
            }
        });
    }
    
    @SuppressWarnings("unchecked")
    public List<CombinationValue> getCombValByClsfIdAndVal(final String parentId, final String value) {
        return (List<CombinationValue>)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                CombinationValueDAOImpl impl = new CombinationValueDAOImpl();
                String hsql = "from CombinationValue cv where cv.parentId = ? and cv.value = ? order by cv.value";
                String[] values = new String[2];
                values[0] = parentId;
                values[1] = value;
                return impl.findEntites(hsql, values);
            }
        });
    }
    public List getCombinationValueObjById(final String id) {
        return (List)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                PasswordStrategyDaoImpl impl = new PasswordStrategyDaoImpl();
                String hsql = "from CombinationValue cv where id = '" + id + "'";
                return impl.findEntities(hsql);
            }
        });
    }
    /**
     * 添加密码组合方式
     * <p>Description: </p>
     * 
     * @author wangxl
     * @time 2013-1-3
     * @param comb
     */
    public void saveCombinationValue(final CombinationValue[] combValue){
        new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                CombinationValueDAOImpl impl = new CombinationValueDAOImpl();
                for (CombinationValue val : combValue){
                    val.setUserEntity(userEntity);
                    impl.save(val);
                }
                return combValue;
            }
        });
    }
 
    public boolean updateCombinationValue(final CombinationValue combVal){
        return (Boolean)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                CombinationValueDAOImpl impl = new CombinationValueDAOImpl();
                CombinationValue cCombVal = impl.getById(combVal.getId());
                if (cCombVal == null) {
                    combVal.setUserEntity(userEntity);
                    impl.saveOrUpdate(combVal);
                } else {
                    cCombVal.setId(combVal.getId());
                    cCombVal.setParentId(combVal.getParentId());
                    cCombVal.setValue(combVal.getValue());
                    cCombVal.setUserEntity(userEntity);
                    impl.saveOrUpdate(cCombVal);
                }
                return true;
            }
        });
    }
    public boolean deleteCombinationValueByMQL(final String[] ids) {
        return (Boolean)new HibernateTemplate().run(new HibernateCallback() {
            public Object execute() throws HibernateException {
                int len = ids.length;
                String inStr = "";
                for (int i = 0; i < len; i++) {
                    inStr += "?";
                    if (i != len - 1) {
                        inStr += ",";
                    }
                }
                CombinationValueDAOImpl impl = new CombinationValueDAOImpl();
                String hql = "delete CombinationValue cv where cv.id in (" + inStr + ")";
                impl.deleteQueryObject(hql, ids, userEntity);
                return true;
            }
        });
    }
    
}