package com.vci.server.workflow.server.service; import java.util.List; import org.hibernate.HibernateException; import com.vci.corba.common.VCIError; 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.workflow.dao.PlwfinstancetemplateDaoImpl; import com.vci.server.workflow.dao.PlwfpersonsetDaoImpl; import com.vci.server.workflow.objects.Plwfinstancetemplate; import com.vci.server.workflow.objects.Plwfpersonset; public class PlwfinstancetemplateService extends BaseService{ private static PlwfinstancetemplateService instance = null; private PlwfinstancetemplateService(){ } public static PlwfinstancetemplateService getInstance(){ if(instance == null){ instance = new PlwfinstancetemplateService(); } return instance; } //add public boolean savePlwfinstancetemplate(Plwfinstancetemplate obj) throws VCIError { try { PlwfinstancetemplateDaoImpl daoImpl = new PlwfinstancetemplateDaoImpl(); daoImpl.saveOrUpdate(obj); return true; } catch(Exception e){ e.printStackTrace(); throw new VCIError("411116", new String[] {}); } } //query public Plwfinstancetemplate getPlwfinstancetemplateById(String plOId) throws Throwable { try { PlwfinstancetemplateDaoImpl daoImpl = new PlwfinstancetemplateDaoImpl(); return daoImpl.getById(plOId); } catch(Throwable e){ throw e; } } //query by plclass and plisdefault @SuppressWarnings("unchecked") public List getPlwfinstancetemplateByClassAndDefault(String plclass, String plisdefault) throws VCIError { try { PlwfinstancetemplateDaoImpl daoImpl = new PlwfinstancetemplateDaoImpl(); String hql = "from Plwfinstancetemplate where plclass= ?"; Object[] obj = new Object[]{plclass}; if (!"".equals(plisdefault)) { hql = "from Plwfinstancetemplate where plclass= ? and plisdefault= ?"; obj = new Object[]{plclass, plisdefault}; } return daoImpl.createQueryList(hql, obj); } catch(Exception e){ e.printStackTrace(); throw new VCIError("411117", new String[] {}); } } public List getPlwfinstancetemplate() throws VCIError { try { PlwfinstancetemplateDaoImpl daoImpl = new PlwfinstancetemplateDaoImpl(); return daoImpl.loadAll(); } catch(Exception e){ e.printStackTrace(); throw new VCIError("411117", new String[] {}); } } @SuppressWarnings("unchecked") public List getPlwfpersonset(final String name) { return (List)new HibernateTemplate().run(new HibernateCallback(){ public Object execute() throws HibernateException { PlwfpersonsetDaoImpl daoImpl = new PlwfpersonsetDaoImpl(); String hql = "from Plwfpersonset where pltempid= ?"; return daoImpl.createQueryList(hql, new Object[]{name}); } }); } //del public boolean deletePlwfinstancetemplate(Plwfinstancetemplate obj) throws VCIError{ try { PlwfinstancetemplateDaoImpl daoImpl = new PlwfinstancetemplateDaoImpl(); // String hql ="from Plwfpersonset where pltempid='"+obj.getPloid()+"' "; List list = getPlwfpersonset(obj.getPloid()); PlwfpersonsetDaoImpl pdaoImpl = new PlwfpersonsetDaoImpl(); for (Plwfpersonset plwfpersonset : list) { String sql = "delete from Plwfpersonset t where t.ploid = '" + plwfpersonset.getPloid() + "'"; pdaoImpl.createSQLQuery(sql); } daoImpl.delete(obj); return true; } catch(Exception e){ e.printStackTrace(); throw new VCIError("411118", new String[] {}); } } //del by id // public boolean deletePlwfinstancetemplateById(String id) throws Throwable{ // try { // PlwfinstancetemplateDaoImpl daoImpl = new PlwfinstancetemplateDaoImpl(); // Plwfinstancetemplate obj = daoImpl.getById(id); // if (obj != null) { // daoImpl.delete(obj); // } // return true; // } catch(Throwable e){ // throw e; // } // // } }