portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r330702 - in /portals/jetspeed-2/trunk/components/statistics/src: java/org/apache/jetspeed/statistics/impl/ test/org/apache/jetspeed/statistics/
Date Fri, 04 Nov 2005 04:13:02 GMT
Author: taylor
Date: Thu Nov  3 20:12:56 2005
New Revision: 330702

URL: http://svn.apache.org/viewcvs?rev=330702&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-362
statistics portlet query support

Added:
    portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/AggregateStatisticsImpl.java
    portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/StatisticsQueryCriteriaImpl.java
Modified:
    portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
    portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java

Added: portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/AggregateStatisticsImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/AggregateStatisticsImpl.java?rev=330702&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/AggregateStatisticsImpl.java
(added)
+++ portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/AggregateStatisticsImpl.java
Thu Nov  3 20:12:56 2005
@@ -0,0 +1,121 @@
+/* Copyright 2005 Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.jetspeed.statistics.impl;
+
+import javax.sql.DataSource;
+
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.statistics.AggregateStatistics;
+import org.apache.jetspeed.statistics.StatisticsQueryCriteria;
+
+
+
+/**
+ * AggregateStatisticsImpl
+ * 
+ * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer</a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class AggregateStatisticsImpl implements AggregateStatistics
+{
+
+    float avgProcessingTime;
+    float maxProcessingTime;
+    float minProcessingTime;
+    float stddevProcessingTime;
+    int hitcount;
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.AggregateStatistics#getAvgProcessingTime()
+     */
+    public float getAvgProcessingTime()
+    {
+        return this.avgProcessingTime;
+    }
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.AggregateStatistics#getHitCount()
+     */
+    public int getHitCount()
+    {
+         return this.hitcount;
+    }
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.AggregateStatistics#getMaxProcessingTime()
+     */
+    public float getMaxProcessingTime()
+    {
+        return this.maxProcessingTime;
+    }
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.AggregateStatistics#getMinProcessingTime()
+     */
+    public float getMinProcessingTime()
+    {
+        return this.minProcessingTime;
+    }
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.AggregateStatistics#getStdDevProcessingTime()
+     */
+    public float getStdDevProcessingTime()
+    {
+        return this.stddevProcessingTime;
+    }
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.AggregateStatistics#setAvgProcessingTime(float)
+     */
+    public void setAvgProcessingTime(float time)
+    {
+        this.avgProcessingTime = time;
+    }
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.AggregateStatistics#setHitCount(int)
+     */
+    public void setHitCount(int hitCount)
+    {
+        this.hitcount = hitCount;
+    }
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.AggregateStatistics#setMaxProcessingTime(float)
+     */
+    public void setMaxProcessingTime(float time)
+    {
+        this.maxProcessingTime = time;
+    }
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.AggregateStatistics#setMinProcessingTime(float)
+     */
+    public void setMinProcessingTime(float time)
+    {
+        this.minProcessingTime = time;
+    }
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.AggregateStatistics#setStdDevProcessingTime(float)
+     */
+    public void setStdDevProcessingTime(float time)
+    {
+        this.stddevProcessingTime = time;
+    }
+    
+    
+    public String toString() {
+        String s = "hit count = "+this.hitcount+"\n";
+        s = s + "max time = "+this.maxProcessingTime+"\n";
+        s = s + "min time = "+this.minProcessingTime+"\n";
+        s = s + "avg time = "+this.avgProcessingTime+"\n";
+        s = s + "stddev   = "+this.stddevProcessingTime+"\n";
+        return s;
+    }
+}

Modified: portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java?rev=330702&r1=330701&r2=330702&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
Thu Nov  3 20:12:56 2005
@@ -17,6 +17,10 @@
 package org.apache.jetspeed.statistics.impl;
 
 import java.security.Principal;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Timestamp;
 import java.text.MessageFormat;
 import java.text.SimpleDateFormat;
@@ -32,7 +36,10 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.components.rdbms.ojb.ConnectionRepositoryEntry;
 import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.statistics.AggregateStatistics;
+import org.apache.jetspeed.statistics.InvalidCriteriaException;
 import org.apache.jetspeed.statistics.PortalStatistics;
+import org.apache.jetspeed.statistics.StatisticsQueryCriteria;
 import org.springframework.orm.ojb.support.PersistenceBrokerDaoSupport;
 
 /**
@@ -493,4 +500,55 @@
     }
 
     
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.PortalStatistics#queryStatistics(org.apache.jetspeed.statistics.StatisticsQueryCriteria)
+     */
+    public AggregateStatistics queryStatistics(StatisticsQueryCriteria criteria) throws InvalidCriteriaException
+    {
+        AggregateStatistics as = new AggregateStatisticsImpl();
+        String query;
+        query= "select count(*) as count ,STDDEV(ELAPSED_TIME),MIN(ELAPSED_TIME),AVG(ELAPSED_TIME),MAX(ELAPSED_TIME)
from ? ";
+        //String query = "select count(*) as count ,STDDEV(ELAPSED_TIME),MIN(ELAPSED_TIME),AVG(ELAPSED_TIME),MAX(ELAPSED_TIME),?
from ? group by ?";
+        String tableName;
+        String groupColumn;
+        
+        String queryType = criteria.getQueryType();
+        if ("user".equals(queryType))
+        {
+            tableName = "USER_STATISTICS";
+            groupColumn = "USER_NAME";
+        } else if ("portlet".equals(queryType))
+        {
+            tableName = "PORTLET_STATISTICS";
+            groupColumn = "PORTLET";
+        } else if ("page".equals(queryType))
+        {
+            tableName = "PAGE_STATISTICS";
+            groupColumn = "PAGE";
+        } else {
+            throw new InvalidCriteriaException(" invalid queryType passed to queryStatistics");
+        }
+        query= "select count(*) as count ,STDDEV(ELAPSED_TIME),MIN(ELAPSED_TIME),AVG(ELAPSED_TIME),MAX(ELAPSED_TIME)
from "+tableName;
+        
+        try
+        {
+            Connection con = ds.getConnection();
+            PreparedStatement pstmt = con.prepareStatement(query);
+            //pstmt.setString(1,groupColumn);
+            //pstmt.setString(2,groupColumn);
+            ResultSet rs = pstmt.executeQuery();
+            while(rs.next()) {
+                as.setHitCount(rs.getInt("count"));
+                as.setStdDevProcessingTime(rs.getFloat("STDDEV(ELAPSED_TIME)"));
+                as.setMinProcessingTime(rs.getFloat("MIN(ELAPSED_TIME)"));
+                as.setAvgProcessingTime(rs.getFloat("AVG(ELAPSED_TIME)"));
+                as.setMaxProcessingTime(rs.getFloat("MAX(ELAPSED_TIME)"));
+            }
+        } catch (SQLException e)
+        {
+            throw new InvalidCriteriaException(e.toString());
+        }
+        
+        return as;
+    }
 }

Added: portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/StatisticsQueryCriteriaImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/StatisticsQueryCriteriaImpl.java?rev=330702&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/StatisticsQueryCriteriaImpl.java
(added)
+++ portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/StatisticsQueryCriteriaImpl.java
Thu Nov  3 20:12:56 2005
@@ -0,0 +1,59 @@
+
+package org.apache.jetspeed.statistics.impl;
+
+import org.apache.jetspeed.statistics.StatisticsQueryCriteria;
+
+
+public class StatisticsQueryCriteriaImpl implements StatisticsQueryCriteria
+{
+
+    String user;
+    String ipAddress;
+    String queryType;
+    
+    /**
+     * @return Returns the ipAddress.
+     */
+    public String getIpAddress()
+    {
+        return ipAddress;
+    }
+    /**
+     * @param ipAddress The ipAddress to set.
+     */
+    public void setIpAddress(String ipAddress)
+    {
+        this.ipAddress = ipAddress;
+    }
+    /**
+     * @return Returns the user.
+     */
+    public String getUser()
+    {
+        return user;
+    }
+    /**
+     * @param user The user to set.
+     */
+    public void setUser(String user)
+    {
+        this.user = user;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.StatisticsQueryCriteria#getQueryType()
+     */
+    public String getQueryType()
+    {
+        
+        return queryType;
+    }
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.StatisticsQueryCriteria#setQueryType(java.lang.String)
+     */
+    public void setQueryType(String queryType)
+    {
+        this.queryType = queryType;
+    }
+}

Modified: portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java?rev=330702&r1=330701&r2=330702&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java
(original)
+++ portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java
Thu Nov  3 20:12:56 2005
@@ -28,6 +28,7 @@
 import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl;
 import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
 import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.statistics.impl.StatisticsQueryCriteriaImpl;
 
 import com.mockrunner.mock.web.MockHttpServletRequest;
 import com.mockrunner.mock.web.MockHttpServletResponse;
@@ -138,9 +139,11 @@
         return new TestSuite(TestStatistics.class);
     }
     
+    
     public void testPortletStatistics() 
     throws Exception
     {
+        System.out.println("testing one of each ");
         statistics.forceFlush();
         clearDBs();
         
@@ -173,6 +176,7 @@
     public void testLotsOfPortletStatistics() 
     throws Exception
     {
+        System.out.println("testing Multiple portlet stats");
         statistics.forceFlush();
         clearDBs();
         
@@ -206,6 +210,24 @@
         
     }
 
+    
+    public void testQuerySystem() 
+    throws Exception
+    {
+        System.out.println("testing Query System");
+        StatisticsQueryCriteria sqc = new StatisticsQueryCriteriaImpl();
+        sqc.setQueryType("user");
+        AggregateStatistics as = statistics.queryStatistics( sqc    );
+        System.out.println("user = "+as);
+        sqc.setQueryType("portlet");
+        as = statistics.queryStatistics( sqc );
+        System.out.println("user = "+as);
+        sqc.setQueryType("page");
+        as = statistics.queryStatistics( sqc );
+        System.out.println("user = "+as);
+        
+    }
+    
     private RequestContext initRequestContext()
     {
         MockHttpServletRequest request = new MockHttpServletRequest();



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message