1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.objects

File ListPropertyCollectionType.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart3.png
80% of files have more coverage

Code metrics

4
15
7
1
111
73
9
0.6
2.14
7
1.29

Classes

Class Line # Actions
ListPropertyCollectionType 42 15 0% 9 18
0.3076923230.8%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.internal.objects;
21   
22    import java.util.ArrayList;
23    import java.util.Collection;
24    import java.util.Iterator;
25    import java.util.List;
26    import java.util.Map;
27   
28    import org.hibernate.HibernateException;
29    import org.hibernate.collection.PersistentCollection;
30    import org.hibernate.engine.SessionImplementor;
31    import org.hibernate.persister.collection.CollectionPersister;
32    import org.hibernate.usertype.UserCollectionType;
33   
34    import com.xpn.xwiki.objects.ListProperty.NotifyList;
35   
36    /**
37    * Helper class for hibernate to wrap a persistent collection around a NotifyList.
38    *
39    * @since 4.3
40    * @version $Id: 763290a2282aa83475d21944131f1747481e1ad8 $
41    */
 
42    public class ListPropertyCollectionType implements UserCollectionType
43    {
44   
 
45  358 toggle @Override
46    public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister)
47    throws HibernateException
48    {
49  358 return new ListPropertyPersistentList(session);
50    }
51   
 
52  249 toggle @Override
53    @SuppressWarnings("unchecked")
54    public PersistentCollection wrap(SessionImplementor session, Object collection)
55    {
56  249 if (collection instanceof NotifyList) {
57  249 return new ListPropertyPersistentList(session, (NotifyList) collection);
58  0 } else if (collection instanceof NotifyList) {
59  0 return new ListPropertyPersistentList(session, new NotifyList((List<String>) collection));
60    } else {
61  0 throw new IllegalArgumentException("Can only wrap ListProperty.NotifyList.");
62    }
63    }
64   
 
65  0 toggle @Override
66    @SuppressWarnings("unchecked")
67    public Iterator getElementsIterator(Object collection)
68    {
69  0 return ((Collection<?>) collection).iterator();
70    }
71   
 
72  0 toggle @Override
73    @SuppressWarnings("unchecked")
74    public boolean contains(Object collection, Object entity)
75    {
76  0 return ((Collection<?>) collection).contains(entity);
77    }
78   
 
79  0 toggle @Override
80    @SuppressWarnings("unchecked")
81    public Object indexOf(Object collection, Object entity)
82    {
83  0 return ((List) collection).indexOf(entity);
84    }
85   
 
86  0 toggle @Override
87    @SuppressWarnings("unchecked")
88    public Object replaceElements(
89    Object original,
90    Object target,
91    CollectionPersister persister,
92    Object owner,
93    Map copyCache,
94    SessionImplementor session)
95    throws HibernateException
96    {
97  0 Collection cTarget = (Collection) target;
98  0 Collection cOriginal = (Collection) original;
99   
100  0 cTarget.clear();
101  0 cTarget.addAll(cOriginal);
102   
103  0 return cTarget;
104    }
105   
 
106  358 toggle @Override
107    public Object instantiate(int anticipatedSize)
108    {
109  358 return new NotifyList(new ArrayList<String>());
110    }
111    }