Project

General

Profile

« Previous | Next » 

Revision 23e98ce3

Added by Andreas Kohlbecker almost 8 years ago

#5536 centralized handling of NULL removal related to HHH-9751

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/hibernate/HHH_9751_Util.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.hibernate;
11

  
12
import java.util.Collection;
13

  
14
/**
15
 * Helper class to remove null values from collections which are left over artifacts due to
16
 * https://hibernate.atlassian.net/browse/HHH-9751
17
 *
18
 * @author a.kohlbecker
19
 * @date Jun 13, 2016
20
 *
21
 */
22
public class HHH_9751_Util {
23

  
24
    /**
25
     *
26
     * @param collection
27
     * @return the number of null values removed from the collection
28
     */
29
    static public int removeAllNull(Collection collection) {
30
        int cnt = 0;
31
        if (collection.contains(null)){
32
            while(collection.contains(null)){
33
                cnt++;
34
                collection.remove(null);
35
            }
36
        }
37
        return cnt;
38
    }
39

  
40
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonNode.java
42 42
import org.hibernate.search.annotations.ContainedIn;
43 43
import org.hibernate.search.annotations.IndexedEmbedded;
44 44

  
45
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util;
45 46
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
46 47
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
47 48
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
......
864 865

  
865 866
    public void removeNullValueFromChildren(){
866 867
        try {
867
            if (childNodes.contains(null)){
868
                while(childNodes.contains(null)){
869
                    childNodes.remove(null);
870
                }
871
            }
868
            HHH_9751_Util.removeAllNull(childNodes);
872 869
            this.updateSortIndex(0);
873 870
        } catch (LazyInitializationException e) {
874 871
            logger.info("Cannot clean up uninitialized children without a session, skipping.");

Also available in: Unified diff