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: package org.apache.jetspeed.statistics.impl;
18:
19: import java.sql.Connection;
20: import java.sql.PreparedStatement;
21: import java.sql.SQLException;
22:
23: import javax.sql.DataSource;
24:
25: /**
26: * <p>
27: * BatchedUserStatistics
28: * </p>
29: *
30: * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer </a>
31: * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
32: * @version $Id: TestPortletEntityDAO.java,v 1.3 2005/05/24 14:43:19 ate Exp $
33: */
34: public class BatchedUserStatistics extends BatchedStatistics {
35:
36: /*
37: * (non-Javadoc)
38: *
39: * @see org.apache.jetspeed.statistics.impl.BatchedStatistics#canDoRecordType(org.apache.jetspeed.statistics.impl.LogRecord)
40: */
41: public boolean canDoRecordType(LogRecord rec) {
42: return (rec instanceof UserLogRecord);
43: }
44:
45: public BatchedUserStatistics(DataSource ds, int batchSize,
46: long msElapsedTimeThreshold, String name) {
47: super (ds, batchSize, msElapsedTimeThreshold, name);
48: }
49:
50: /**
51: * @param stm
52: * @param recordIterator
53: * @throws SQLException
54: */
55: protected void loadOneRecordToStatement(PreparedStatement stm,
56: LogRecord rec) throws SQLException {
57: UserLogRecord record = (UserLogRecord) rec;
58:
59: stm.setString(1, record.getIpAddress());
60: stm.setString(2, record.getUserName());
61: stm.setTimestamp(3, record.getTimeStamp());
62: stm.setInt(4, record.getStatus());
63: stm.setLong(5, record.getMsElapsedTime());
64: }
65:
66: /**
67: * @param con
68: * @return
69: * @throws SQLException
70: */
71: protected PreparedStatement getPreparedStatement(Connection con)
72: throws SQLException {
73: PreparedStatement stm;
74: stm = con
75: .prepareStatement("INSERT INTO USER_STATISTICS VALUES(?,?,?,?,?)");
76: return stm;
77: }
78:
79: }
|