KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MClickCount


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Smart Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.model;
15
16 import java.util.*;
17 import java.sql.*;
18 import java.text.*;
19
20 import org.compiere.util.*;
21
22 /**
23  * Click Count (header)
24  *
25  * @author Jorg Janke
26  * @version $Id: MClickCount.java,v 1.3 2003/08/31 06:48:59 jjanke Exp $
27  */

28 public class MClickCount extends X_W_ClickCount
29 {
30     /**
31      * Standard Constructor
32      * @param ctx context
33      * @param W_ClickCount_ID id
34      */

35     public MClickCount (Properties ctx, int W_ClickCount_ID)
36     {
37         super (ctx, W_ClickCount_ID);
38     } // MClickCount
39

40     private SimpleDateFormat m_dateFormat = DisplayType.getDateFormat(DisplayType.Date);
41     private DecimalFormat m_intFormat = DisplayType.getNumberFormat(DisplayType.Integer);
42
43     /*************************************************************************/
44
45     /**
46      * Get Clicks
47      * @return clicks
48      */

49     public MClick[] getMClicks()
50     {
51         ArrayList list = new ArrayList();
52         /** @todo Clicks */
53         //
54
MClick[] retValue = new MClick[list.size()];
55         list.toArray(retValue);
56         return retValue;
57     } // getMClicks
58

59     /**
60      * Get Count for date format
61      * @param DateFormat valid TRUNC date format
62      * @return count
63      */

64     public ValueNamePair[] getCount (String JavaDoc DateFormat)
65     {
66         ArrayList list = new ArrayList();
67         String JavaDoc sql = "SELECT TRUNC(Created, '" + DateFormat + "'), Count(*) "
68             + "FROM W_Click "
69             + "WHERE W_ClickCount_ID=? "
70             + "GROUP BY TRUNC(Created, '" + DateFormat + "')";
71         //
72
PreparedStatement pstmt = null;
73         try
74         {
75             pstmt = DB.prepareStatement(sql);
76             pstmt.setInt(1, getW_ClickCount_ID());
77             ResultSet rs = pstmt.executeQuery();
78             while (rs.next())
79             {
80                 String JavaDoc value = m_dateFormat.format(rs.getTimestamp(1));
81                 String JavaDoc name = m_intFormat.format(rs.getInt(2));
82                 ValueNamePair pp = new ValueNamePair (value, name);
83                 list.add(pp);
84             }
85             rs.close();
86             pstmt.close();
87             pstmt = null;
88         }
89         catch (SQLException ex)
90         {
91             log.error("getCount - " + sql, ex);
92         }
93         try
94         {
95             if (pstmt != null)
96                 pstmt.close();
97         }
98         catch (SQLException ex1)
99         {
100         }
101         pstmt = null;
102         //
103
ValueNamePair[] retValue = new ValueNamePair[list.size()];
104         list.toArray(retValue);
105         return retValue;
106     } // getCount
107

108     /**
109      * Get Monthly Count
110      * @return monthly count
111      */

112     public ValueNamePair[] getCountQuarter ()
113     {
114         return getCount("Q");
115     } // getCountQuarter
116

117     /**
118      * Get Monthly Count
119      * @return monthly count
120      */

121     public ValueNamePair[] getCountMonth ()
122     {
123         return getCount("MM");
124     } // getCountMonth
125

126     /**
127      * Get Weekly Count
128      * @return weekly count
129      */

130     public ValueNamePair[] getCountWeek ()
131     {
132         return getCount("DY");
133     } // getCountWeek
134

135     /**
136      * Get Daily Count
137      * @return dailt count
138      */

139     public ValueNamePair[] getCountDay ()
140     {
141         return getCount("J");
142     } // getCountDay
143

144 } // MClickCount
145
Popular Tags