ref #8162 move OriginalSourceXXX to reference package
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / hibernate / HHH_9751_Util.java
1 /**
2 * Copyright (C) 2016 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.hibernate;
10
11 import java.util.Collection;
12
13 import org.apache.log4j.Logger;
14 import org.hibernate.LazyInitializationException;
15
16
17 /**
18 * Helper class to remove null values from collections which are left over artifacts due to
19 * https://hibernate.atlassian.net/browse/HHH-9751
20 *
21 * @author a.kohlbecker
22 * @since Jun 13, 2016
23 *
24 */
25 public class HHH_9751_Util {
26
27 private static final Logger logger = Logger.getLogger(HHH_9751_Util.class);
28
29 /**
30 *
31 * @param collection
32 * @return the number of null values removed from the collection
33 */
34 static public int removeAllNull(Collection collection) {
35
36 int cnt = 0;
37 try {
38
39 if (collection.contains(null)){
40 while(collection.contains(null)){
41 cnt++;
42 collection.remove(null);
43 }
44 }
45
46 } catch (LazyInitializationException e) {
47 logger.info("Cannot clean up uninitialized children without a session, skipping.");
48 }
49 return cnt ;
50 }
51
52 }