⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auditlogbean.java

📁 Sun公司Dream项目
💻 JAVA
字号:
/*
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the "License").  You may not use this file except
 * in compliance with the License.
 *
 * You can obtain a copy of the license at
 * http://www.opensource.org/licenses/cddl1.php
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL
 * HEADER in each file and include the License file at
 * http://www.opensource.org/licenses/cddl1.php.  If 
 * applicable, add the following below this CDDL HEADER, 
 * with the fields enclosed by brackets "[]" replaced 
 * with your own identifying information: 
 * Portions Copyright [yyyy]
 * [name of copyright owner]
 */ 

/*
 * $(@)AuditLogBean.java $Revision: 1.1.1.1 $ $Date: 2006/03/15 13:12:10 $
 * 
 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
 */
/**

 *

 * @version: 1.0

 * @date: Sept 19, 2002

 *

 */

package com.sun.sjc.idtv.vod.server.auditing;



import java.sql.*;

import java.util.*;

import javax.sql.*;

import javax.ejb.*;

import javax.naming.*;

import com.sun.sjc.idtv.vod.shared.data.*;



/**

 * Implementation bean for the <code>AuditLog</code> interface, <code>AuditLogBean</code>

 * defines all possible business methods for the bean.

 *

 * @see AuditLog

 * @see AuditLogHome

 */

public class AuditLogBean implements SessionBean {



    private  javax.ejb.SessionContext m_ctx = null; 

    public static final int QUERYTIMEOUT = 60;

    private DataSource dataSource;



    /**

     * Sets the session context. Required by EJB spec.

     * @param ctx A SessionContext object.

     */

    public void setSessionContext(javax.ejb.SessionContext ctx) { 

        m_ctx = ctx; 

	try {

	    InitialContext ic = new InitialContext();

	    //dataSource = (DataSource) ic.lookup("java:comp/env/jdbc/vod");

	    dataSource = (DataSource) ic.lookup("jdbc/sample");

	} catch (Exception ex) {

	    throw new EJBException("Unable to connect to database. " +

				   ex.getMessage());

	}

    } 



    /**

     * Creates a bean. Required by EJB spec.

     * @exception throws CreateException.

     */

    public void ejbCreate() throws java.rmi.RemoteException, javax.ejb.CreateException { 

    } 



    /**

     * Removes the bean. Required by EJB spec.

     */

    public void ejbRemove() { 

    } 



    /**

     * Loads the state of the bean from secondary storage. Required by EJB spec.

     */

    public void ejbActivate() { 

    } 



    /**

     * Serializes the state of the bean to secondary storage. Required by EJB spec.

     */

    public void ejbPassivate() { 

    } 



    /**

     * Required by EJB spec.

     */

    public void AuditLog() { 

    } 





    /**

     * Fetch the list of subscribers for a given STB IP address.

     * Logs a timestamped record in the audit log for a particular action.

     * @param subscriber the subscriber who caused the action

     * @param event name of the action

     * @param params parameters given to the action

     * @param status status of the action (OK or error message)

     * @exception RemoteException

     */

    public void log(Subscriber subscriber, String event, String params, String status) throws java.rmi.RemoteException, SQLException {



       // get db connection from pool

       Connection conn = dataSource.getConnection();



       // insert a record in the log table

       PreparedStatement stmt = conn.prepareStatement("INSERT INTO auditlog VALUES (?, ?, ?, ?, ?)");



       stmt.setQueryTimeout(QUERYTIMEOUT);

       Timestamp now = new Timestamp(System.currentTimeMillis());

       stmt.setTimestamp(1, now);

       stmt.setLong(2, subscriber.masterid);

       stmt.setString(3, event);

       stmt.setString(4, params);

       stmt.setString(5, status);

       stmt.executeUpdate();

       stmt.close();

       conn.close();

       return;

    } 

} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -