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

File AbstractStatsStoreItem.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

0
11
2
1
106
38
2
0.18
5.5
2
1

Classes

Class Line # Actions
AbstractStatsStoreItem 39 11 0% 2 13
0.00%
 

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.stats.impl.xwiki;
21   
22    import java.util.Date;
23    import java.util.List;
24   
25    import org.xwiki.context.Execution;
26    import org.xwiki.context.ExecutionContext;
27   
28    import com.xpn.xwiki.XWikiContext;
29    import com.xpn.xwiki.stats.impl.StatsUtil;
30    import com.xpn.xwiki.stats.impl.StatsUtil.PeriodType;
31    import com.xpn.xwiki.web.Utils;
32   
33    /**
34    * Base class of interface {@link XWikiStatsStoreItem}.
35    *
36    * @version $Id: 991459ffbf01170dba09a3bcb34cbacd70296798 $
37    * @since 1.4M2
38    */
 
39    public abstract class AbstractStatsStoreItem implements XWikiStatsStoreItem
40    {
41    /**
42    * The XWiki context clone made when this statistics event occurred.
43    */
44    protected XWikiContext context;
45   
46    /**
47    * The statistic name.
48    */
49    protected String name;
50   
51    /**
52    * The period date.
53    */
54    protected Date periodDate;
55   
56    /**
57    * The period type.
58    */
59    protected PeriodType periodType;
60   
61    /**
62    * The period.
63    */
64    protected int period;
65   
66    /**
67    * @param name the statistic name.
68    * @param periodDate the period date.
69    * @param periodType the period type.
70    * @param context the XWiki context.
71    */
 
72  0 toggle public AbstractStatsStoreItem(String name, Date periodDate, PeriodType periodType, XWikiContext context)
73    {
74  0 this.name = name;
75   
76  0 this.periodDate = periodDate;
77  0 this.periodType = periodType;
78  0 this.period = StatsUtil.getPeriodAsInt(this.periodDate, this.periodType);
79   
80  0 this.context = context.clone();
81    }
82   
 
83  0 toggle @Override
84    public void store(List<XWikiStatsStoreItem> statsList)
85    {
86  0 ExecutionContext econtext = Utils.getComponent(Execution.class).getContext();
87   
88  0 XWikiContext currentContext = (XWikiContext) econtext.getProperty(XWikiContext.EXECUTIONCONTEXT_KEY);
89   
90  0 try {
91  0 econtext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, this.context);
92   
93  0 storeInternal(statsList);
94    } finally {
95  0 econtext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, currentContext);
96    }
97    }
98   
99    /**
100    * Store provided statistics into the database.
101    *
102    * @param statsList the list of statistics item to store.
103    * @since 2.2.4
104    */
105    protected abstract void storeInternal(List<XWikiStatsStoreItem> statsList);
106    }