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

📄 upgradesessionbean.java

📁 一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/************************************************************************* *                                                                       * *  EJBCA: The OpenSource Certificate Authority                          * *                                                                       * *  This software is free software; you can redistribute it and/or       * *  modify it under the terms of the GNU Lesser General Public           * *  License as published by the Free Software Foundation; either         * *  version 2.1 of the License, or any later version.                    * *                                                                       * *  See terms of license at gnu.org.                                     * *                                                                       * *************************************************************************/package org.ejbca.core.ejb.upgrade;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.Collection;import java.util.Iterator;import javax.ejb.CreateException;import javax.ejb.EJBException;import org.apache.commons.lang.StringUtils;import org.ejbca.core.ejb.BaseSessionBean;import org.ejbca.core.ejb.JNDINames;import org.ejbca.core.ejb.ServiceLocator;import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocal;import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocalHome;import org.ejbca.core.ejb.log.LogConfigurationDataLocal;import org.ejbca.core.ejb.log.LogConfigurationDataLocalHome;import org.ejbca.core.model.log.Admin;import org.ejbca.util.JDBCUtil;import org.ejbca.util.SqlExecutor;import se.anatom.ejbca.log.OldLogConfigurationDataLocal;import se.anatom.ejbca.log.OldLogConfigurationDataLocalHome;/** The upgrade session bean is used to upgrade the database between ejbca releases. * * @version $Id: UpgradeSessionBean.java,v 1.12 2007/01/12 09:43:27 anatom Exp $ * @ejb.bean *   display-name="UpgradeSB" *   name="UpgradeSession" *   jndi-name="UpgradeSession" *   view-type="both" *   type="Stateless" *   transaction-type="Container" *   generate="true" * * @ejb.transaction type="RequiresNew" *  * @weblogic.enable-call-by-reference True * * @ejb.home *   extends="javax.ejb.EJBHome" *   local-extends="javax.ejb.EJBLocalHome" *   local-class="org.ejbca.core.ejb.upgrade.IUpgradeSessionLocalHome" *   remote-class="org.ejbca.core.ejb.upgrade.IUpgradeSessionHome" * * @ejb.env-entry * name="DataSource" * type="java.lang.String" * value="${datasource.jndi-name-prefix}${datasource.jndi-name}" * * @ejb.interface *   extends="javax.ejb.EJBObject" *   local-extends="javax.ejb.EJBLocalObject" *   local-class="org.ejbca.core.ejb.upgrade.IUpgradeSessionLocal" *   remote-class="org.ejbca.core.ejb.upgrade.IUpgradeSessionRemote" *  * @ejb.ejb-external-ref *   description="The Log Configuration Data Entity bean" *   view-type="local" *   ref-name="ejb/LogConfigurationDataLocal" *   type="Entity" *   home="org.ejbca.core.ejb.log.LogConfigurationDataLocalHome" *   business="org.ejbca.core.ejb.log.LogConfigurationDataLocal" *   link="LogConfigurationData" *    * @ejb.ejb-external-ref *   description="The Old Log Configuration Data Entity bean" *   view-type="local" *   ref-name="ejb/OldLogConfigurationDataLocal" *   type="Entity" *   home="se.anatom.ejbca.log.OldLogConfigurationDataLocalHome" *   business="se.anatom.ejbca.log.OldLogConfigurationDataLocal" *   link="OldLogConfigurationData" *  * @ejb.ejb-external-ref *   description="The CA Admin Session" *   view-type="local" *   ref-name="ejb/CAAdminSessionLocal" *   type="Session" *   home="org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocalHome" *   business="org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocal" *   link="CAAdminSession" */public class UpgradeSessionBean extends BaseSessionBean {    /** Var holding JNDI name of datasource */    private String dataSource = "";    private  OldLogConfigurationDataLocalHome oldLogHome = null;    private  LogConfigurationDataLocalHome logHome = null;    /** The local interface of the ca admin session bean */    private ICAAdminSessionLocal caadminsession = null;    private Admin administrator = null;        /**     * Default create for SessionBean without any creation Arguments.     *     * @throws CreateException if bean instance can't be created     */    public void ejbCreate() throws CreateException {        dataSource = getLocator().getString(JNDINames.DATASOURCE);        logHome = (LogConfigurationDataLocalHome)ServiceLocator.getInstance().getLocalHome(LogConfigurationDataLocalHome.COMP_NAME);        oldLogHome = (OldLogConfigurationDataLocalHome)ServiceLocator.getInstance().getLocalHome(OldLogConfigurationDataLocalHome.COMP_NAME);            }    /**      * Gets connection to ca admin session bean     */    private ICAAdminSessionLocal getCaAdminSession() {        if(caadminsession == null){          try{              ICAAdminSessionLocalHome caadminsessionhome = (ICAAdminSessionLocalHome)getLocator().getLocalHome(ICAAdminSessionLocalHome.COMP_NAME);              caadminsession = caadminsessionhome.create();          }catch(Exception e){             throw new EJBException(e);          }        }        return caadminsession;    } //getCaAdminSession    /** Runs a preCheck to see if an upgrade is possible     *     * @return true if ok to upgrade or false if not     */    private boolean preCheck() {        debug(">preCheck");        boolean ret = false;        Connection con = null;        PreparedStatement ps = null;        try {            error("Getting connection for: "+dataSource);            con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE);            ps = con.prepareStatement("select userDataVO from CertReqHistoryData");            ResultSet rs = ps.executeQuery();            if (rs.next()) {                try {                    String ud = rs.getString(1);                    java.beans.XMLDecoder decoder = null;                    try {                      decoder = new java.beans.XMLDecoder(                                new java.io.ByteArrayInputStream(ud.getBytes("UTF8")));                    } catch (UnsupportedEncodingException e) {                        error("Can not decode old UserDataVO: ", e);                    }                    se.anatom.ejbca.common.UserDataVO oldud  = (se.anatom.ejbca.common.UserDataVO)decoder.readObject();                                              decoder.close();                    // If we came this far, we have an old UserDataVO.                    ret = true;                    error("(this is not an error) during pre-check successfully decoded old UserDataVO with username="+oldud.getUsername());                } catch (Exception e) {                    error("Can not decode old UserDataVO: ", e);                }                            }        } catch (Exception e) {        	error("Database error during preCheck: ", e);        } finally {            JDBCUtil.close(ps);            JDBCUtil.close(con);        }        debug("<preCheck("+ret+")");        return ret;    }    /** Upgrades the database     * @ejb.interface-method     * @jboss.method-attributes transaction-timeout="3600"     *      * @param admin     * @return true or false if upgrade was done or not     */    public boolean upgrade(Admin admin, String[] args) {        debug(">upgrade("+admin.toString()+")");        this.administrator = admin;                String dbtype = null;        if (args.length > 0) {            dbtype = args[0];            debug("Database type="+dbtype);        }        boolean upgradefrom31 = false;        if (args.length > 1) {        	String u = args[1];        	if (StringUtils.equalsIgnoreCase(u, "yes")) {        		upgradefrom31 = true;        	}        }        // Upgrade small database change between ejbca 3.3.x and 3.4.x        if (!migradeDatabase33(dbtype)) {        	// Ignore errors and continue, perhaps we have already done this manually        	// return false;        }        // If we are not upgrading from EJBCA 3.1.x we can stop here        if (!upgradefrom31) {        	return true;        }                if (!preCheck()) {        	info("preCheck failed, no upgrade performed.");            return false;        }        if (!migradeDatabase31(dbtype)) {        	return false;        }        if (!upgradeHardTokenClassPath()) {        	return false;        }        if (!upgradeUserDataVO()) {            return false;        }        ArrayList datas = logConfStep1();        // If we got some datas, we have something to upgrade, otherwise we don't        if (datas != null) {            if (!logConfStep2(datas)) {                return false;            }            if (!logConfStep3(datas)) {                return false;

⌨️ 快捷键说明

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