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

📄 historyejb.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2006-2007 Queplix Corp. * * Licensed under the Queplix Public License, Version 1.1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package com.queplix.core.modules.eql.ejb;import com.queplix.core.error.ErrorHelper;import com.queplix.core.jxb.entity.Efield;import com.queplix.core.jxb.entity.Entity;import com.queplix.core.modules.config.utils.EntityHelper;import com.queplix.core.modules.eql.EQLERes;import com.queplix.core.modules.eql.EQLFactory;import com.queplix.core.modules.eql.EQLReqField;import com.queplix.core.modules.eql.EQLResCell;import com.queplix.core.modules.eql.EQLResRecord;import com.queplix.core.modules.eql.EQLSession;import com.queplix.core.modules.eql.error.EQLException;import com.queplix.core.modules.eql.history.HistoryConstants;import com.queplix.core.modules.eql.jxb.history.HistoryTopic;import com.queplix.core.modules.eql.jxb.history.HistoryUnparsedTopic;import com.queplix.core.modules.jeo.JEObjectHandler;import com.queplix.core.modules.jeo.ejb.JEOManagerLocal;import com.queplix.core.modules.jeo.ejb.JEOManagerLocalHome;import com.queplix.core.modules.jeo.gen.HistoryObject;import com.queplix.core.modules.jeo.gen.HistoryObjectHandler;import com.queplix.core.integrator.security.LogonSession;import com.queplix.core.utils.JNDINames;import com.queplix.core.utils.StringHelper;import com.queplix.core.utils.DateHelper;import com.queplix.core.utils.xml.TransletWrapper;import com.queplix.core.utils.xml.XMLFactory;import com.queplix.core.utils.xml.XMLHelper;import javax.xml.transform.stream.StreamResult;import javax.xml.transform.stream.StreamSource;import java.io.CharArrayReader;import java.io.CharArrayWriter;import java.util.List;/** * History logger EJB. * * @author [ALB] Baranov Andrey * @author [ONZ] Oleg N. Zhovtanyuk * @version $Revision: 1.2 $ $Date: 2006/07/05 12:04:51 $ */public class HistoryEJB    extends AbstractEQLSupportedEJB {    // ================================================================== Fields    // XSL translet implementation.    private TransletWrapper transletWrapper = XMLFactory.getTransletWrapper();    // ========================================================= EJB API methods    /** Initialize bean. */    public void ejbCreate() {        INFO( "HistoryEJB created - " + hashCode() );    }    // ========================================================== Public methods    /**     * Writes the changes history.     *     * @param session EQL session     * @param res EQLERes response     * @param resRecord given EQL response record     * @return new EQLResRecord object     * @throws EQLException     */    public EQLResRecord logHistory( EQLSession session, EQLERes res, EQLResRecord resRecord )        throws EQLException {        // Initialization.        long time = System.currentTimeMillis();        EQLResCell historyResCell = null;        EQLResCell pkeyResCell = null;        // Get the base entity.        Entity baseEntity = res.getEntity();        if( baseEntity == null ) {            throw new IllegalStateException( "Base entity is not found." );        }        String dbObject = baseEntity.getDbobject();        String entityName = baseEntity.getName();        try {                        // Check if the record was changed.            if( !resRecord.isChanged() ) {                DEBUG( "Entity '" + entityName + "' was not changed." );                return resRecord;            }            // Get the names of fields that might be logged.            List fieldNames = getLogFieldNames( session, dbObject );            if( fieldNames == null ) {                if( getLogger().isDebugEnabled() ) {                    DEBUG( "Entity '" + entityName + "' (table '" + dbObject +                           "') doesn't have the fields to log history for." );                }                return resRecord;            }            // Find the 'pkey' field.            Efield pkeyField = EntityHelper.getEfield( baseEntity.getPkeyfield(), baseEntity );            if( pkeyField == null ) {                WARN( "Can't find the pkey field for entity '" + entityName + "'." );                return resRecord;            }            pkeyResCell = resRecord.getResCell( new EQLReqField( baseEntity, pkeyField ) );            Long pkeyId = pkeyResCell.getLong();            if( baseEntity.getHasHistoryFields().booleanValue() ) {                // Find the 'history' field.                Efield historyField = EntityHelper.getEfield( baseEntity.getHistoryfield(), baseEntity );                if( historyField == null ) {                    WARN( "Can't find the history field for entity '" + entityName + "'." );                    return resRecord;                }                               historyResCell = resRecord.getResCell( new EQLReqField( baseEntity, historyField ) );                               Long historyId = historyResCell.getLong();                Long newHistoryId = storeHistoryById(session, resRecord, historyId, fieldNames, dbObject, pkeyId);                                // Store the updated history.                historyResCell.setNumber( newHistoryId );            } else {                storeHistoryByObj(session, resRecord, fieldNames, dbObject, pkeyId);                            }        } catch( Throwable tr ) {            ErrorHelper.throwSystemException( tr, this );        }        // Ok.        if( getLogger().isInfoEnabled() ) {            time = System.currentTimeMillis() - time;            INFO( "History topic created for entity '" + entityName + "'. Time (ms) = " + time );        }        return resRecord;    }    /**     * Writes the changes history.     *     * @param session EQL session     * @param resRecord given EQL response record     * @param historyId link to the current history     * @param fieldNames names of fields that might be logged     * @param dbObject table name     * @param pkeyId value of the pkey field     * @return ID of a new History object     * @throws EQLException     */    public Long storeHistoryById( EQLSession session, EQLResRecord resRecord, Long historyId, List fieldNames, String dbObject, Long pkeyId )        throws EQLException {        try {            // Make a new history topic.            HistoryTopic historyTopic = createHistoryTopic( session, resRecord, fieldNames );            /* Escape history saving, if all histories are empty*/            if((historyTopic.getHistoryData() == null || historyTopic.getHistoryData().getHistoryFieldCount() == 0) &&                    (historyTopic.getIfgData() == null || historyTopic.getIfgData().getIfgCount() == 0)) {                return null;            }            // History topic -> string            String history = toString( historyTopic );            DEBUG(history);            // Initialization.            LogonSession ls = session.getLogonSession();            JEOManagerLocal jeoManager = ( JEOManagerLocal ) session.getCOM().                getLocalObject( JNDINames.JEOManager, JEOManagerLocalHome.class );                        // Add the topic to an existing history.            if( historyId != null ) {                HistoryObjectHandler hisHnd = ( HistoryObjectHandler )                    HistoryObjectHandler.selectById( jeoManager, ls, historyId.longValue() );                      HistoryObject hisObj = ( HistoryObject ) hisHnd.getJEObject();                char[] memo = hisObj.getQx_history();                String existingHistory = String.valueOf( memo );                // If the existing history is invalid, leave it unparsed.                if( !isHistoryValid( existingHistory ) ) {                    HistoryUnparsedTopic unparsedTopic = new HistoryUnparsedTopic();                    unparsedTopic.setHistoryUnparsedData( StringHelper.escape( existingHistory ) );                    existingHistory = toString( unparsedTopic );                }

⌨️ 快捷键说明

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