Revision a5a5ec1b
Added by Katja Luther over 1 year ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/term/DefinedTermDaoImpl.java | ||
---|---|---|
644 | 644 |
@Override |
645 | 645 |
public <S extends DefinedTermBase> List<S> list(Class<S> clazz, List<TermVocabulary> vocs, Integer pageNumber, Integer limit, String pattern, MatchMode matchmode){ |
646 | 646 |
Session session = getSession(); |
647 |
// Query query = null; |
|
648 |
// if (pattern != null){ |
|
649 |
// if (vocs != null && !vocs.isEmpty()){ |
|
650 |
// query = session.createQuery("from NamedArea where titleCache like :pattern and vocabulary in :vocs ORDER BY titleCache"); |
|
651 |
// query.setParameterList("vocs", vocs); |
|
652 |
// }else{ |
|
653 |
// query = session.createQuery("from NamedArea where titleCache like :pattern ORDER BY titleCache"); |
|
654 |
// } |
|
655 |
// pattern = pattern.replace("*", "%"); |
|
656 |
// pattern = pattern.replace("?", "_"); |
|
657 |
// pattern = pattern + "%"; |
|
658 |
// query.setParameter("pattern", pattern); |
|
659 |
// |
|
660 |
// } else { |
|
661 |
// query = session.createQuery("FROM NamedArea WHERE vocabulary IN :vocs ORDER BY titleCache"); |
|
662 |
// query.setParameterList("vocs", vocs); |
|
663 |
// } |
|
664 |
// if (limit != null && limit > 0){ |
|
665 |
// query.setMaxResults(limit); |
|
666 |
// } |
|
667 |
|
|
668 | 647 |
if (clazz == null){ |
669 | 648 |
clazz = (Class)type; |
670 | 649 |
} |
... | ... | |
700 | 679 |
if (limit == null){ |
701 | 680 |
limit = 1; |
702 | 681 |
} |
703 |
// int firstItem = (pageNumber - 1) * limit; |
|
704 |
|
|
705 | 682 |
crit.setFirstResult(0); |
706 | 683 |
@SuppressWarnings("unchecked") |
707 | 684 |
List<S> results = deduplicateResult(crit.list()); |
... | ... | |
753 | 730 |
return results; |
754 | 731 |
} |
755 | 732 |
|
756 |
//FIXME AM: this returns only NamedArea counts though not mentioned in method name, fortunately it is currently not in use |
|
757 |
@Override |
|
758 |
public long count(List<TermVocabulary> vocs, String pattern){ |
|
759 |
Session session = getSession(); |
|
760 |
Query query = null; |
|
761 |
if (pattern != null){ |
|
762 |
if (vocs != null && !vocs.isEmpty()){ |
|
763 |
query = session.createQuery("SELECT COUNT(*) FROM NamedArea WHERE titleCache LIKE :pattern AND vocabulary IN :vocs"); |
|
764 |
query.setParameterList("vocs", vocs); |
|
765 |
}else{ |
|
766 |
query = session.createQuery("SELECT COUNT(*) FROM NamedArea WHERE titleCache LIKE :pattern "); |
|
767 |
} |
|
768 |
pattern = pattern.replace("*", "%"); |
|
769 |
pattern = pattern.replace("?", "_"); |
|
770 |
pattern = pattern + "%"; |
|
771 |
query.setParameter("pattern", pattern); |
|
772 |
|
|
773 |
} else { |
|
774 |
query = session.createQuery("SELECT COUNT(*) FROM NamedArea WHERE vocabulary IN :vocs"); |
|
775 |
query.setParameterList("vocs", vocs); |
|
776 |
} |
|
777 |
|
|
778 |
Long result = (Long) query.uniqueResult(); |
|
779 |
return result; |
|
780 |
} |
|
781 | 733 |
|
782 | 734 |
@Override |
783 | 735 |
public Collection<TermDto> getIncludesAsDto( |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/PostMergeEntityListener.java | ||
---|---|---|
13 | 13 |
import java.util.Set; |
14 | 14 |
import java.util.concurrent.ConcurrentHashMap; |
15 | 15 |
|
16 |
import org.apache.log4j.Logger; |
|
16 | 17 |
import org.hibernate.Hibernate; |
17 | 18 |
import org.hibernate.HibernateException; |
19 |
import org.hibernate.LazyInitializationException; |
|
18 | 20 |
import org.hibernate.Session; |
19 | 21 |
import org.hibernate.event.spi.MergeEvent; |
20 | 22 |
import org.hibernate.event.spi.MergeEventListener; |
... | ... | |
34 | 36 |
private static final long serialVersionUID = 1565797119368313987L; |
35 | 37 |
|
36 | 38 |
private static Map<Session, Set<CdmBase>> newEntitiesMap = new ConcurrentHashMap<>(); |
37 |
|
|
39 |
private static final Logger logger = Logger.getLogger(PostMergeEntityListener.class); |
|
38 | 40 |
|
39 | 41 |
public static void addSession(Session session) { |
40 | 42 |
newEntitiesMap.put(session, new HashSet<>()); |
... | ... | |
101 | 103 |
|
102 | 104 |
TermTree<?> tree = (TermTree<?>)entity; |
103 | 105 |
tree.removeNullValueFromChildren(); |
104 |
for (TermNode<?> node:tree.getRootChildren()){ |
|
105 |
node.removeNullValueFromChildren(); |
|
106 |
if (node.getChildNodes() != null){ |
|
107 |
for (TermNode<?> childNode: node.getChildNodes()){ |
|
108 |
removeNullFromCollections(childNode); |
|
106 |
try{ |
|
107 |
for (TermNode<?> node:tree.getRootChildren()){ |
|
108 |
node.removeNullValueFromChildren(); |
|
109 |
if (node.getChildNodes() != null){ |
|
110 |
for (TermNode<?> childNode: node.getChildNodes()){ |
|
111 |
removeNullFromCollections(childNode); |
|
112 |
} |
|
109 | 113 |
} |
110 | 114 |
} |
115 |
} catch (LazyInitializationException e) { |
|
116 |
logger.warn("Cannot clean up uninitialized children without a session, skipping."); |
|
111 | 117 |
} |
112 | 118 |
} else if (TermNode.class.isAssignableFrom(entityClazz)){ |
113 | 119 |
TermNode<?> node = (TermNode<?>)entity; |
Also available in: Unified diff
only log lazy initialisation exception while remove null from collection