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

📄 eqlintmediator.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.parser.generic;import com.queplix.core.error.GenericSystemException;import com.queplix.core.jxb.entity.Dataschema;import com.queplix.core.jxb.entity.Efield;import com.queplix.core.jxb.entity.Entity;import com.queplix.core.jxb.entity.Listref;import com.queplix.core.jxb.entity.types.JoinSType;import com.queplix.core.jxb.entity.types.SqlSType;import com.queplix.core.modules.config.utils.EntityHelper;import com.queplix.core.modules.eql.EQLEReq;import com.queplix.core.modules.eql.EQLNullObject;import com.queplix.core.modules.eql.EQLNumberObject;import com.queplix.core.modules.eql.EQLObject;import com.queplix.core.modules.eql.EQLReq;import com.queplix.core.modules.eql.EQLReqAggFunc;import com.queplix.core.modules.eql.EQLReqEntity;import com.queplix.core.modules.eql.EQLReqField;import com.queplix.core.modules.eql.EQLReqFuncExecutable;import com.queplix.core.modules.eql.EQLReqOp;import com.queplix.core.modules.eql.EQLReqSelectAttr;import com.queplix.core.modules.eql.EQLReqSubOp;import com.queplix.core.modules.eql.EQLReqSubOpMember;import com.queplix.core.modules.eql.EQLReqSubOpMemberEnum;import com.queplix.core.modules.eql.EQLReqSubOpMemberField;import com.queplix.core.modules.eql.EQLReqSubOpMemberFunc;import com.queplix.core.modules.eql.EQLReqSubOpMemberUnknown;import com.queplix.core.modules.eql.EQLReqSubOrder;import com.queplix.core.modules.eql.EQLReqSubWhere;import com.queplix.core.modules.eql.EQLReqSubWhereCond;import com.queplix.core.modules.eql.EQLReqWhere;import com.queplix.core.modules.eql.EQLSession;import com.queplix.core.modules.eql.EQLStringObject;import com.queplix.core.modules.eql.conds.EqCond;import com.queplix.core.modules.eql.error.EQLException;import com.queplix.core.modules.eql.error.EQLFunctionParseException;import com.queplix.core.modules.eql.error.EQLSystemException;import com.queplix.core.modules.eql.ops.NoneOp;import com.queplix.core.modules.eql.parser.EQLFuncManager;import com.queplix.core.modules.eql.utils.EQLUtils;import com.queplix.core.utils.log.AbstractLogger;/** * <p>Special class mediator for EQL interpreter and EQL parser. * Stores EQLReq object.</p> * <p>Schema:</p> * <p>EQL interpreter <-> EQL mediator <-> EQL parser</p> * @author [ALB] Baranov Andrey */public class EQLIntMediator    extends AbstractLogger {    // ------------------------------------------------------- variables    private AbstractEQLInterpreter interpreter;    private EQLReq req;    // ------------------------------------------------------- constructor    /**     * Constructor     * @param interpreter EQL generic interpreter     */    protected EQLIntMediator( AbstractEQLInterpreter interpreter ) {        this.interpreter = interpreter;        this.req = new EQLReq();    }    // ------------------------------------------------------- public methods    //    // SERVICE METHODS    //    /**     * Return current EQL session     * @return EQLSession object     */    public EQLSession getSession() {        return interpreter.getSession();    }    /**     * Get EQL request object     * @return EQLReq object     */    public EQLReq getEQLReq() {        return req;    }    /**     * Clone EQL mediator     * @return new mediator     */    public Object clone() {        DEBUG( "Clone mediator..." );        return( ( AbstractEQLInterpreter ) interpreter.clone() ).getMainMediator();    }    //    // Wrappers for EQLParserGenericImpl parser methods    //    public void parse( String eql )        throws EQLException {        AbstractEQLParser.getParser( this, eql ).parse();    }    public void parseWhere( String eql )        throws EQLException {        AbstractEQLParser.getParser( this, eql ).parseWhere();    }    public EQLReqOp parseSrc( String eql )        throws EQLException {        return AbstractEQLParser.getParser( this, eql ).parseSrc();    }    public void parseOrder( String eql )        throws EQLException {        AbstractEQLParser.getParser( this, eql ).parseOrder();    }    /**     * Get EQL function by the <code>name</code>     * @param name function name     * @return EQLReqSubOpMemberFunc object     * @throws EQLException     */    public EQLReqSubOpMemberFunc getFunction( String name )        throws EQLException {        return EQLFuncManager.getFunction( name, interpreter );    }    //    // BUILDER METHODS    //    /**     * Add EQL request meta information     * @param name parameter name     * @param value parameter value     */    public void addMetaInfoAsNumber( String name, String value ) {        try {            getEQLReq().getMetaData().setParam( name, EQLUtils.parseEQLNumber( value ) );        } catch( Exception ex ) {            throw new EQLSystemException( ex );        }    }    /**     * Add EQL request meta information     * @param name parameter name     * @param value parameter value     * @throws EQLException     */    public void addMetaInfoAsBoolean( String name, Boolean value )        throws EQLException {        getEQLReq().getMetaData().setParam( name, value );    }    /**     * Add EQL request meta information     * @param name parameter name     * @param value parameter value     */    public void addMetaInfoAsList( String name, String value ) {        try {            getEQLReq().getMetaData().setParam( name, EQLUtils.parseEQLList( value ) );        } catch( Exception ex ) {            throw new EQLSystemException( ex );        }    }    /**     * Add all field from entity <code>entity</code> in select list     * @param entity toplevel entity     * @throws EQLException     */    public void addSelectAllColumns( Entity entity )        throws EQLException {        if( getLogger().isDebugEnabled() ) {            DEBUG( " addSelectAllColumns(): " + entity.getName() );        }        EQLReq __req = req;        req = new EQLEReq( entity );        req.copyOf( __req );        __req = null;        // add entity        EQLReqEntity reqEntity = new EQLReqEntity( entity );        interpreter.addEntity( reqEntity );        // checking        int size = entity.getEfieldCount();        if( size == 0 ) {            throw new GenericSystemException( "Entity '" + entity.getName() +                                              "' doesn't contain any fields" );        }        // add ALL in SELECT list        for( int i = 0; i < size; i++ ) {            Efield field = entity.getEfield( i );            boolean isLazy = req.isLazy( field );            addSelectColumn( new EQLReqField( reqEntity, field ), isLazy );        }        // add entity WHERE conditions        addEntityWhereCondition( reqEntity );        // add entity ORDER BY condition as default        String eqlOrderQuery = entity.getEqlOrder();        if( eqlOrderQuery != null ) {            parseOrder( eqlOrderQuery );        }        if( getLogger().isDebugEnabled() ) {            DEBUG( "Added all fields from entity: " + reqEntity );        }    }    /**     * Add field <code>reqField</code> in select list     * @param reqField EQLReqField object     * @throws EQLException     */    public void addSelectColumn( EQLReqField reqField )        throws EQLException {        addSelectColumn( reqField, false );        // add entity WHERE conditions        addEntityWhereCondition( reqField.getReqEntity() );    }    /**     * Add field <code>reqField</code> in select list     * @param reqField EQLReqField object     * @param lazyField is field for lazy loading     * @throws EQLException     */    public void addSelectColumn( EQLReqField reqField, boolean lazyField )        throws EQLException {        if( getLogger().isDebugEnabled() ) {            DEBUG( " addSelectColumn(): " + reqField + " lazyField?=" + lazyField );        }        if( !reqField.getField().getSelectable().booleanValue() ) {            // field isn't selectable            return;        }        // add field        /** @todo re-implement it */        // NOTE: [ALB] Quick fix for lazy loading (add reference only for MEMO lazy fields).        Efield field = reqField.getField();        int sql_type = field.getSqltype().getType();        boolean withRef;        if( sql_type == SqlSType.MEMO_TYPE ) {            withRef = true;        } else if( lazyField ) {            withRef = false;        } else {            withRef = true;        }        // <---        EQLReqOp reqOp = buildSelectEQLReqOp( interpreter.addField( reqField, withRef ) );        EQLReqSelectAttr reqSelectAttr = new EQLReqSelectAttr( reqField, reqOp );        if( !lazyField && !interpreter.isCloned() ) {            // top level select query --            // try to add list reference            Listref listref = reqField.getField().getListref();            if( listref != null ) {                // check list field JOIN type                JoinSType joinType = listref.getJointype();                switch( joinType.getType() ) {                case JoinSType.USE_CACHE_TYPE: {                    // don't add in query - take from cache later                    break;                }                default: {                    // join entities                    EQLReqField listReqField = interpreter.addListField( reqField );                    reqSelectAttr.setListFieldSelectAttr( new EQLReqSelectAttr( listReqField, buildSelectEQLReqOp( listReqField ) ) );                }                }            }        }        if( getLogger().isDebugEnabled() ) {            DEBUG( "Add field in select list: " + reqField );        }        // add in SELECT list        req.getSelect().addAttr( reqSelectAttr );    }    /**     * Add field <code>reqField</code> default value in select list     * @param reqField EQLReqField object     * @throws EQLException     */    public void addSelectColumnAsDefault( EQLReqField reqField )        throws EQLException {        if( getLogger().isDebugEnabled() ) {            DEBUG( " addSelectColumnAsDefault(): " + reqField );        }        if( !reqField.getField().getSelectable().booleanValue() ) {            // field isn't selectable            return;        }        EQLReqOp reqOp = buildDefaultSelectEQLReqOp( reqField );        EQLReqSelectAttr reqSelectAttr = new EQLReqSelectAttr( reqField, reqOp );        // try to add list reference        addListFieldAsDefault( reqSelectAttr, reqField );        // add in SELECT list        req.getSelect().addAttr( reqSelectAttr );    }    /**     * Add function <code>memberFunc</code> in select list     * @param memberFunc EQLReqSubOpMemberFunc object     * @throws EQLException     */    public void addSelectColumnAsFunc( EQLReqSubOpMemberFunc memberFunc )        throws EQLException {        if( getLogger().isDebugEnabled() ) {            DEBUG( " addSelectColumnAsFunc(): " + memberFunc );        }        if( ! ( memberFunc instanceof EQLReqAggFunc ) ) {            throw new EQLFunctionParseException( memberFunc );        }        EQLReqAggFunc aggFunc = ( EQLReqAggFunc ) memberFunc;        // build new EQLReqOp object        EQLReqOp reqOp = new EQLReqOp();        reqOp.addSubOp( new NoneOp( aggFunc ) );        // build new EQLReqSelectAttr object        EQLReqSelectAttr reqSelectAttr =            new EQLReqSelectAttr( aggFunc.getParameter().getReqField(), reqOp );        // add in SELECT list        req.getSelect().addAttr( reqSelectAttr );    }    /**     * Add entity WHERE condition     * @param reqEntity EQLReqEntity object     * @throws EQLException     */    public void addEntityWhereCondition( EQLReqEntity reqEntity )        throws EQLException {        String eqlWhereQuery = reqEntity.getEntity().getEqlWhere();        if( eqlWhereQuery != null ) {            parseWhere( eqlWhereQuery );        }    }    /**     * Create and add new where condition as subwhere object

⌨️ 快捷键说明

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