23 |
23 |
|
24 |
24 |
import my.com.upass.ConfigBean;
|
25 |
25 |
import my.com.upass.MinimalConstants;
|
|
26 |
import my.com.upass.UPassException;
|
26 |
27 |
import my.com.upass.dao.UserDAO;
|
27 |
28 |
import my.com.upass.generic.hibernate.GenericDAOHibernate;
|
28 |
29 |
import my.com.upass.maybank.entities.Im2uUser;
|
... | ... | |
43 |
44 |
import org.hibernate.Hibernate;
|
44 |
45 |
import org.hibernate.Query;
|
45 |
46 |
import org.hibernate.Session;
|
|
47 |
import org.hibernate.criterion.CriteriaSpecification;
|
46 |
48 |
import org.hibernate.criterion.Criterion;
|
47 |
49 |
import org.hibernate.criterion.Example;
|
|
50 |
import org.hibernate.criterion.Projections;
|
48 |
51 |
import org.hibernate.criterion.Restrictions;
|
49 |
52 |
|
50 |
53 |
/**
|
... | ... | |
57 |
60 |
extends GenericDAOHibernate
|
58 |
61 |
implements UserDAO {
|
59 |
62 |
|
|
63 |
private static final int MAX_QUERY_RESULT_SIZE = 1000;
|
60 |
64 |
private static Logger logger = Logger.getLogger(UserDAOHibernate.class);
|
61 |
65 |
|
62 |
66 |
//
|
... | ... | |
570 |
574 |
Session session = null;
|
571 |
575 |
try {
|
572 |
576 |
session = txSession != null ? txSession : getSession();
|
|
577 |
long totalRows = 0;
|
573 |
578 |
|
574 |
579 |
for (Iterator iter = exampleProfiles.iterator(); iter.hasNext();) {
|
575 |
580 |
UserProfile example = (UserProfile) iter.next();
|
... | ... | |
588 |
593 |
c.createAlias("minUser", MU);
|
589 |
594 |
}
|
590 |
595 |
c.add(Restrictions.ilike(MU + ".userAlias", username));
|
|
596 |
|
|
597 |
checkQueryResultSize(c);
|
591 |
598 |
}
|
592 |
599 |
profiles.addAll(c.list());
|
593 |
600 |
if (txSession == null)
|
... | ... | |
610 |
617 |
try {
|
611 |
618 |
session = txSession != null ? txSession : getSession();
|
612 |
619 |
|
|
620 |
long totalRows = 0;
|
613 |
621 |
perProfileLoop: for (Iterator iter = exampleProfiles.iterator(); iter.hasNext();) {
|
614 |
622 |
UserProfile example = (UserProfile) iter.next();
|
615 |
623 |
|
... | ... | |
662 |
670 |
if (toDate != null)
|
663 |
671 |
c.add(Restrictions.le(MU + ".udateCreated", toDate));
|
664 |
672 |
|
|
673 |
checkQueryResultSize(c);
|
|
674 |
|
665 |
675 |
profiles.addAll(c.list());
|
666 |
676 |
|
667 |
677 |
if (txSession == null)
|
... | ... | |
674 |
684 |
return profiles;
|
675 |
685 |
}
|
676 |
686 |
|
|
687 |
private Object checkQueryResultSize(Criteria c) throws UPassException {
|
|
688 |
long totalRows;
|
|
689 |
Object rowCount = c.setProjection(Projections.rowCount()).uniqueResult();
|
|
690 |
if (rowCount instanceof Number) {
|
|
691 |
totalRows = ((Number) rowCount).longValue();
|
|
692 |
if (totalRows > MAX_QUERY_RESULT_SIZE )
|
|
693 |
throw new UPassException(MinimalConstants.ERR_TOO_MANY_MATCHES);
|
|
694 |
}
|
|
695 |
c.setProjection(null);
|
|
696 |
c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
|
|
697 |
return rowCount;
|
|
698 |
}
|
|
699 |
|
677 |
700 |
public boolean deleteProfile(String username, Class profileClass, Session txSession) throws Exception {
|
678 |
701 |
|
679 |
702 |
boolean isSuccessful = false;
|