1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * 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 and15 * limitations under the License.16 */1718packageorg.apache.jetspeed.statistics.impl;
1920import java.sql.Connection;
21import java.sql.PreparedStatement;
22import java.sql.SQLException;
2324import javax.sql.DataSource;
2526/***27 * Batches up LogRecord statistics, and flushes them periodically to the28 * appropriate table in the database.29 * <P>30 * IMPORTANT: It is the caller's responsibility to insure that the LogRecord31 * instances added to a BatchedStatistics instance are all of the same type32 * (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 */38publicclassBatchedPortletStatisticsextendsBatchedStatistics39 {
4041publicBatchedPortletStatistics(DataSource ds, int batchSize,
42long msElapsedTimeThreshold, String name)
43 {
44super(ds, batchSize, msElapsedTimeThreshold, name);
45 }
4647/*48 * (non-Javadoc)49 * 50 * @see org.apache.jetspeed.statistics.impl.BatchedStatistics#canDoRecordType(org.apache.jetspeed.statistics.impl.LogRecord)51 */52publicboolean canDoRecordType(LogRecord rec)
53 {
54return (rec instanceof PortletLogRecord);
55 }
5657/***58 * @param stm59 * @param recordIterator60 * @throws SQLException61 */62protectedvoid loadOneRecordToStatement(PreparedStatement stm, LogRecord rec)
63 throws SQLException
64 {
65PortletLogRecord record = (PortletLogRecord) rec;
6667 stm.setString(1, record.getIpAddress());
68 stm.setString(2, record.getUserName());
69 stm.setTimestamp(3, record.getTimeStamp());
70 stm.setString(4, record.getPagePath());
71 stm.setString(5, record.getPortletName());
72 stm.setInt(6, record.getStatus());
73 stm.setLong(7, record.getMsElapsedTime());
7475 }
7677/***78 * @param con79 * @return80 * @throws SQLException81 */82protected PreparedStatement getPreparedStatement(Connection con)
83 throws SQLException
84 {
85 PreparedStatement stm;
86 stm = con
87 .prepareStatement("INSERT INTO PORTLET_STATISTICS VALUES(?,?,?,?,?,?,?)");
88return stm;
89 }
9091 }