📄 eqlinterpretergenericimpl.java
字号:
/* * 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.jxb.entity.ChainTable;import com.queplix.core.jxb.entity.Chainref;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.Ref;import com.queplix.core.jxb.entity.types.RefSType;import com.queplix.core.modules.config.utils.EntityHelper;import com.queplix.core.modules.eql.EQLReq;import com.queplix.core.modules.eql.EQLReqEntity;import com.queplix.core.modules.eql.EQLReqField;import com.queplix.core.modules.eql.EQLReqJoin;import com.queplix.core.modules.eql.EQLReqSubWhere;import com.queplix.core.modules.eql.EQLReqSubWhereCond;import com.queplix.core.modules.eql.error.EQLException;import com.queplix.core.modules.eql.error.EQLSystemException;import java.util.ArrayList;import java.util.List;/** * <p>EQL interpreter generic implementation</p> * @author Baranov Andrey [ALB] * @version $Revision: 1.2 $ $Date: 2006/06/05 12:50:42 $ */public class EQLInterpreterGenericImpl extends AbstractEQLInterpreter { // ------------------------------------------------------- Variables // indicates whether current interpreter clone or not private boolean isClonned; // reference on parent mediator for clone private EQLIntMediator parentMediator; // ------------------------------------------------------- Cloneable methods /* (non-Javadoc) * @see AbstractEQLInterpreter */ public Object clone() { EQLInterpreterGenericImpl _new = new EQLInterpreterGenericImpl(); _new.setSession( getSession() ); _new.isClonned = true; _new.parentMediator = getMainMediator(); if( getPreparedStatement() != null ) { _new.setPreparedStatement( getPreparedStatement() ); } return _new; } /* (non-Javadoc) * @see AbstractEQLInterpreter */ public boolean isCloned() { return isClonned; } // ------------------------------------------------------- EQLRequestBuilder methods /* (non-Javadoc) * @see EQLRequestBuilder */ public void addEntity( EQLReqEntity reqEntity ) throws EQLException { // fast checking: if entity alredy added - skip procedure if( getMainMediator().getEQLReq().getFrom().contains( reqEntity ) ) { return; } if( getLogger().isDebugEnabled() ) { DEBUG( "[#] Add entity: " + reqEntity ); } // chain current entity with others addChainTab( reqEntity, null ); // add current entity in FROM list addEntityInFromList( reqEntity, true ); } /* (non-Javadoc) * @see EQLRequestBuilder */ public EQLReqField addField( EQLReqField reqField ) throws EQLException { return addField( reqField, true ); } /* (non-Javadoc) * @see EQLRequestBuilder */ public EQLReqField addField( EQLReqField reqField, boolean withRef ) throws EQLException { if( getLogger().isDebugEnabled() ) { DEBUG( "[#] Add field: " + reqField + ", withRef?=" + withRef ); } EQLReqEntity reqEntity = reqField.getReqEntity(); Efield field = reqField.getField(); // add entity addEntity( reqEntity ); Ref ref = field.getRef(); if( withRef && ref != null ) { Entity refEntity = session.findEntity( ref.getEntity() ); Efield refField = EntityHelper.getEfield( ref.getEfield(), refEntity ); EQLReqEntity refReqEntity = new EQLReqEntity( refEntity, reqField ); EQLReqField refReqField = new EQLReqField( refReqEntity, refField ); // chain Ref entity - use original field addChainTab( refReqEntity, reqField ); // [!!!] return reference, not original field return refReqField; } else { return reqField; } } /* (non-Javadoc) * @see EQLRequestBuilder */ public EQLReqField addListField( EQLReqField reqField ) throws EQLException { if( getLogger().isDebugEnabled() ) { DEBUG( "[#] Add list field: " + reqField ); } Listref listRef = reqField.getField().getListref(); if( listRef == null ) { throw new EQLSystemException( "Field '" + reqField.getField().getId() + "' does not have list reference" ); } // first - add reqField itself // [!!!] it can be added as Ref, so remember it EQLReqField newReqField = addField( reqField ); boolean join = reqField.getField().getJoin().booleanValue(); if(join) { // get listref entity and field Entity lrefEntity = session.findEntity( listRef.getEntity() ); Efield lrefField = EntityHelper.getEfield( listRef.getEfield(), lrefEntity ); // construct list ref EQLReqEntity and EQLReqField objects EQLReqEntity lrefReqEntity = new EQLReqEntity( lrefEntity, newReqField ); EQLReqField listReqField = new EQLReqField( lrefReqEntity, lrefField ); // add dataschema - use original field addDataschema( newReqField.getReqEntity(), lrefReqEntity, listRef.getDataschema(), reqField ); return listReqField; } else { return newReqField; } } /* (non-Javadoc) * @see EQLRequestBuilder */ public boolean addJoin( List reqFields1, List reqFields2, EQLReqField leftReqField ) throws EQLException { EQLReq req = getMainMediator().getEQLReq(); // try to set join type using 'required' attribute from left field(s) int joinType; boolean required = true; if( leftReqField != null ) { // .. left field is present - take 'required attribute from there required = leftReqField.getField().getRequired().booleanValue(); } else { // .. try to check all left fields and find out not required field int size = reqFields1.size(); for( int i = 0; i < size; i++ ) { EQLReqField reqField1 = ( EQLReqField ) reqFields1.get( i ); if( !reqField1.getField().getRequired().booleanValue() ) { required = false; break; } } } if( required ) { joinType = EQLReqJoin.INNER_JOIN; } else { joinType = EQLReqJoin.OUTER_JOIN; } // create new EQLReqJoin EQLReqJoin reqJoin = new EQLReqJoin( reqFields1, reqFields2, joinType ); EQLReqEntity leftReqEntity = reqJoin.getLeftEntity(); EQLReqEntity rightReqEntity = reqJoin.getRightEntity(); if( getLogger().isDebugEnabled() ) { DEBUG( "Try to add JOIN" ); DEBUG( " right entity: " + leftReqEntity ); DEBUG( " left entity: " + rightReqEntity ); DEBUG( " join type: " + joinType ); } if( req.getFrom().contains( reqJoin ) ) { return false; } // add right entity in FROM list // NOTE: [ALB] Quick fix - add right entity CONSTRAINT. String eqlConstraintQuery = rightReqEntity.getEntity().getEqlConstraint(); if( eqlConstraintQuery != null ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -