Project

General

Profile

Download (1.3 KB) Statistics
| Branch: | Tag: | Revision:
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
import org.apache.log4j.Logger;
15
import org.hibernate.LazyInitializationException;
16

    
17

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

    
28
    private static final Logger logger = Logger.getLogger(HHH_9751_Util.class);
29

    
30
    /**
31
     *
32
     * @param collection
33
     * @return the number of null values removed from the collection
34
     */
35
    static public int removeAllNull(Collection collection) {
36

    
37
        int cnt = 0;
38
        try {
39
           if (collection.contains(null)){
40
                while(collection.contains(null)){
41
                    cnt++;
42
                    collection.remove(null);
43
                }
44
            }
45
        } catch (LazyInitializationException e) {
46
            logger.info("Cannot clean up uninitialized children without a session, skipping.");
47
        }
48
        return cnt;
49
    }
50

    
51
}
(4-4/11)