@Service
public class DepartmentServiceBean extends DaoSupport<Department> implements DepartmentService {
@Override
public void save(Object entity) {
Department department = (Department) entity;
department.setDepartmentid(UUID.randomUUID().toString());
super.save(entity);
}
@Override
public void delete(Serializable... entityids) {
for(Serializable id : entityids){
Department department = this.find(id);
for(Employee employee : department.getEmployees()){
employee.setDepartment(null);
}
em.remove(department);
}
}
}
----------------------------------------------------------------------------
@Service
public class EmployeeServiceBean extends DaoSupport<Employee> implements EmployeeService {
public boolean validate(String username, String password){
long count = (Long)em.createQuery("select count(o) from Employee o where o.username=?1 and o.password=?2")
.setParameter(1, username).setParameter(2, password).getSingleResult();
return count>0;
}
@Override
public void delete(Serializable... entityids) {
if(entityids!=null && entityids.length>0){
StringBuilder sb = new StringBuilder();
for(int i=0; i<entityids.length;i++){
sb.append('?').append(i+2).append(',');
}
sb.deleteCharAt(sb.length()-1);
Query query = em.createQuery("update Employee o set o.visible=?1 where o.username in("+ sb.toString() +")");
query.setParameter(1, false);
for(int i=0; i<entityids.length;i++){
query.setParameter(i+2, entityids[i]);
}
query.executeUpdate();
}
}
public boolean exsit(String username){
long count = (Long)em.createQuery("select count(o) from Employee o where o.username=?1")
.setParameter(1, username).getSingleResult();
return count>0;
}
}
-=-----------------------------------------------------------------
@Service
public class PrivilegeGroupServiceBean extends DaoSupport<PrivilegeGroup> implements PrivilegeGroupService {
@Override
public void save(Object entity) {
PrivilegeGroup group = (PrivilegeGroup) entity;
group.setGroupid(UUID.randomUUID().toString());
super.save(entity);
}
}
-------------------------------------------------------------------
@Service
public class SystemPrivilegeServiceBean extends DaoSupport<SystemPrivilege> implements SystemPrivilegeService {
public void saves(List<SystemPrivilege> privileges){
for(SystemPrivilege p : privileges){
this.save(p);
}
}
}