📄 contactdao.java
字号:
hql.append(" AND e.contactTimestamp >= :contactTimestampStart ");
if (contactTimestampEnd != null)
hql.append(" AND e.contactTimestamp <= :contactTimestampEnd ");
if (name != null)
{
hql.append(" AND (lower(p.firstName) like :name ");
hql.append(" OR lower(p.lastName) like :name ");
hql.append(" OR lower(c.companyName) like :name ");
hql.append(" ) ");
}
if(user != null) {
hql.append(" AND (e.accessGlobal != '"+EntityAccess.Access.NONE+"' ");
hql.append(" OR (e.accessGroup != '"+EntityAccess.Access.NONE+"' ");
hql.append(" AND exists (from ").append(UserVO.class.getName()).append(" as u where u.id = :userId and u.profile.usergroups.id = e.ownerGroup)) ");
hql.append(" OR (e.accessUser != '"+EntityAccess.Access.NONE+"' ");
hql.append(" AND e.ownerUser = :userId)) ");
}
Query query = HibernateContext.getSession().createQuery(hql.toString());
if (personId != null)
query.setInteger("personId", personId);
if (subject != null)
query.setString("subject", _subject);
if (contactType != null)
query.setString("contactType", contactType);
if (boundType != null)
query.setString("boundType", boundType);
if (contactTimestampStart != null)
query.setTimestamp("contactTimestampStart", contactTimestampStart);
if (contactTimestampEnd != null)
query.setTimestamp("contactTimestampEnd", contactTimestampEnd);
if (name != null)
query.setString("name", _name);
if (user != null)
query.setInteger("userId", user.getId());
count = (Long) query.uniqueResult();
if (log.isDebugEnabled())
log.debug("count " + count + " contacts");
}
catch (HibernateException e)
{
log.error("Could not find contacts", e);
throw e;
}
return count;
}
public List<ContactVO> getListForCompany(Integer companyId, String subject, String contactType, String boundType, Date contactTimestampStart, Date contactTimestampEnd, String name, Sort sort, Page page, UserVO user)
{
String _subject = toLower(adjustWildcards(subject));
String _name = toLower(adjustWildcards(name));
List<ContactVO> list = new ArrayList<ContactVO>();
try
{
StringBuilder hql = new StringBuilder();
hql.append(" select distinct e ");
hql.append(" FROM ").append(getEntityClass().getName()).append(" e ");
hql.append(" left join e.personContacts pc ");
hql.append(" left join pc.person p ");
hql.append(" left join e.company c ");
hql.append(" WHERE (c.id = :companyId ");
hql.append(" OR pc.company.id = :companyId) ");
if (subject != null)
hql.append(" AND lower(e.subject) like :subject ");
if (contactType != null)
hql.append(" AND lower(e.contactType) like :contactType ");
if (boundType != null)
hql.append(" AND lower(e.boundType) like :boundType ");
if (contactTimestampStart != null)
hql.append(" AND e.contactTimestamp >= :contactTimestampStart ");
if (contactTimestampEnd != null)
hql.append(" AND e.contactTimestamp <= :contactTimestampEnd ");
if (name != null)
{
hql.append(" AND (lower(p.firstName) like :name ");
hql.append(" OR lower(p.lastName) like :name ");
hql.append(" OR lower(c.companyName) like :name ");
hql.append(" ) ");
}
if(user != null) {
hql.append(" AND (e.accessGlobal != '"+EntityAccess.Access.NONE+"' ");
hql.append(" OR (e.accessGroup != '"+EntityAccess.Access.NONE+"' ");
hql.append(" AND exists (from ").append(UserVO.class.getName()).append(" as u where u.id = :userId and u.profile.usergroups.id = e.ownerGroup)) ");
hql.append(" OR (e.accessUser != '"+EntityAccess.Access.NONE+"' ");
hql.append(" AND e.ownerUser = :userId)) ");
}
if (sort != null)
hql.append(" order by " + getSortString(sort));
Query query = HibernateContext.getSession().createQuery(hql.toString());
if (companyId != null)
query.setInteger("companyId", companyId);
if (subject != null)
query.setString("subject", _subject);
if (contactType != null)
query.setString("contactType", contactType);
if (boundType != null)
query.setString("boundType", boundType);
if (contactTimestampStart != null)
query.setTimestamp("contactTimestampStart", contactTimestampStart);
if (contactTimestampEnd != null)
query.setTimestamp("contactTimestampEnd", contactTimestampEnd);
if (name != null)
query.setString("name", _name);
if (user != null)
query.setInteger("userId", user.getId());
if (page != null)
{
query.setFirstResult(getFirstResult(page));
query.setMaxResults(getMaxResults(page));
}
list = toTypeSafeList(query.list());
if (log.isDebugEnabled())
log.debug("found " + list.size() + " contacts");
}
catch (HibernateException e)
{
log.error("Could not find contacts", e);
throw e;
}
return list;
}
public long countListForCompany(Integer companyId, String subject, String contactType, String boundType, Date contactTimestampStart, Date contactTimestampEnd, String name, UserVO user)
{
String _subject = toLower(adjustWildcards(subject));
String _name = toLower(adjustWildcards(name));
long count = 0;
try
{
StringBuilder hql = new StringBuilder();
hql.append(" select count(distinct e.id) ");
hql.append(" FROM ").append(getEntityClass().getName()).append(" e ");
hql.append(" left join e.personContacts pc ");
hql.append(" left join pc.person p ");
hql.append(" left join e.company c ");
hql.append(" WHERE (c.id = :companyId ");
hql.append(" OR pc.company.id = :companyId) ");
if (subject != null)
hql.append(" AND lower(e.subject) like :subject ");
if (contactType != null)
hql.append(" AND lower(e.contactType) like :contactType ");
if (boundType != null)
hql.append(" AND lower(e.boundType) like :boundType ");
if (contactTimestampStart != null)
hql.append(" AND e.contactTimestamp >= :contactTimestampStart ");
if (contactTimestampEnd != null)
hql.append(" AND e.contactTimestamp <= :contactTimestampEnd ");
if (name != null)
{
hql.append(" AND (lower(p.firstName) like :name ");
hql.append(" OR lower(p.lastName) like :name ");
hql.append(" OR lower(c.companyName) like :name ");
hql.append(" ) ");
}
if(user != null) {
hql.append(" AND (e.accessGlobal != '"+EntityAccess.Access.NONE+"' ");
hql.append(" OR (e.accessGroup != '"+EntityAccess.Access.NONE+"' ");
hql.append(" AND exists (from ").append(UserVO.class.getName()).append(" as u where u.id = :userId and u.profile.usergroups.id = e.ownerGroup)) ");
hql.append(" OR (e.accessUser != '"+EntityAccess.Access.NONE+"' ");
hql.append(" AND e.ownerUser = :userId)) ");
}
Query query = HibernateContext.getSession().createQuery(hql.toString());
if (companyId != null)
query.setInteger("companyId", companyId);
if (subject != null)
query.setString("subject", _subject);
if (contactType != null)
query.setString("contactType", contactType);
if (boundType != null)
query.setString("boundType", boundType);
if (contactTimestampStart != null)
query.setTimestamp("contactTimestampStart", contactTimestampStart);
if (contactTimestampEnd != null)
query.setTimestamp("contactTimestampEnd", contactTimestampEnd);
if (name != null)
query.setString("name", _name);
if (user != null)
query.setInteger("userId", user.getId());
count = (Long) query.uniqueResult();
if (log.isDebugEnabled())
log.debug("count " + count + " contacts");
}
catch (HibernateException e)
{
log.error("Could not find contacts", e);
throw e;
}
return count;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -