01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.jetspeed.statistics.impl;
19:
20: import java.sql.Connection;
21: import java.sql.PreparedStatement;
22: import java.sql.SQLException;
23:
24: import javax.sql.DataSource;
25:
26: /**
27: * Batches up LogRecord statistics, and flushes them periodically to the
28: * appropriate table in the database.
29: * <P>
30: * IMPORTANT: It is the caller's responsibility to insure that the LogRecord
31: * instances added to a BatchedStatistics instance are all of the same type
32: * (Portlet Access, Page Access, or User Logout).
33: *
34: * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer </a>
35: * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
36: * @version $Id: TestPortletEntityDAO.java,v 1.3 2005/05/24 14:43:19 ate Exp $
37: */
38: public class BatchedPortletStatistics extends BatchedStatistics {
39:
40: public BatchedPortletStatistics(DataSource ds, int batchSize,
41: long msElapsedTimeThreshold, String name) {
42: super (ds, batchSize, msElapsedTimeThreshold, name);
43: }
44:
45: /*
46: * (non-Javadoc)
47: *
48: * @see org.apache.jetspeed.statistics.impl.BatchedStatistics#canDoRecordType(org.apache.jetspeed.statistics.impl.LogRecord)
49: */
50: public boolean canDoRecordType(LogRecord rec) {
51: return (rec instanceof PortletLogRecord);
52: }
53:
54: /**
55: * @param stm
56: * @param recordIterator
57: * @throws SQLException
58: */
59: protected void loadOneRecordToStatement(PreparedStatement stm,
60: LogRecord rec) throws SQLException {
61: PortletLogRecord record = (PortletLogRecord) rec;
62:
63: stm.setString(1, record.getIpAddress());
64: stm.setString(2, record.getUserName());
65: stm.setTimestamp(3, record.getTimeStamp());
66: stm.setString(4, record.getPagePath());
67: stm.setString(5, record.getPortletName());
68: stm.setInt(6, record.getStatus());
69: stm.setLong(7, record.getMsElapsedTime());
70:
71: }
72:
73: /**
74: * @param con
75: * @return
76: * @throws SQLException
77: */
78: protected PreparedStatement getPreparedStatement(Connection con)
79: throws SQLException {
80: PreparedStatement stm;
81: stm = con
82: .prepareStatement("INSERT INTO PORTLET_STATISTICS VALUES(?,?,?,?,?,?,?)");
83: return stm;
84: }
85:
86: }
|