📄 abstractgraction.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.eqlext.actions;import com.queplix.core.error.GenericSystemException;import com.queplix.core.jxb.entity.Dataset;import com.queplix.core.jxb.entity.Efield;import com.queplix.core.jxb.entity.Entity;import com.queplix.core.modules.config.jxb.CustomField;import com.queplix.core.modules.config.jxb.Form;import com.queplix.core.modules.config.jxb.LinkedDataset;import com.queplix.core.modules.config.utils.EntityHelper;import com.queplix.core.modules.eql.EQLDRes;import com.queplix.core.modules.eql.EQLDateObject;import com.queplix.core.modules.eql.EQLObject;import com.queplix.core.modules.eql.EQLReqField;import com.queplix.core.modules.eql.EQLRes;import com.queplix.core.modules.eql.EQLResCell;import com.queplix.core.modules.eql.EQLResRecord;import com.queplix.core.modules.eql.error.EQLException;import com.queplix.core.modules.eql.error.UserQueryParseException;import com.queplix.core.modules.eql.parser.EQLIntPreparedStatement;import com.queplix.core.modules.eqlext.actions.filters.EntityGRFilterFactory;import com.queplix.core.modules.eqlext.jxb.gr.ReqEntity;import com.queplix.core.modules.eqlext.jxb.gr.ReqFilter;import com.queplix.core.modules.eqlext.jxb.gr.ReqFilters;import com.queplix.core.modules.eqlext.jxb.gr.ReqFiltersTypeItem;import com.queplix.core.modules.eqlext.jxb.gr.Reqs;import com.queplix.core.modules.eqlext.jxb.gr.ResDataset;import com.queplix.core.modules.eqlext.jxb.gr.ResField;import com.queplix.core.modules.eqlext.jxb.gr.ResHeader;import com.queplix.core.modules.eqlext.jxb.gr.ResHeaderDataset;import com.queplix.core.modules.eqlext.jxb.gr.ResHeaderField;import com.queplix.core.modules.eqlext.jxb.gr.ResLinkedDataset;import com.queplix.core.modules.eqlext.jxb.gr.ResRecord;import com.queplix.core.modules.eqlext.jxb.gr.types.DataSType;import com.queplix.core.modules.eqlext.jxb.gr.types.SqlSType;import com.queplix.core.modules.eqlext.utils.ExtDateParser;import com.queplix.core.utils.StringHelper;import com.queplix.core.utils.xml.XMLBinding;import com.queplix.core.utils.xml.XMLFactory;import com.queplix.core.utils.xml.XMLHelper;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.Writer;import java.util.ArrayList;import java.util.List;/** * <p>Abstract Get Records Action</p> * @author [ALB] Baranov Andrey * @version $Revision: 1.3 $ $Date: 2006/06/02 13:42:14 $ */public abstract class AbstractGRAction extends AbstractAction implements GRAction { // ----------------------------------------------------- constants // Ignore words detector protected static final GRIgnoreWordsDetector iwDetector = new GRIgnoreWordsDetector(); // Mapper a user operation to EQL private static final String[] DEFAULT_EQL_OP_MAPPINGS = {"=", "=", "!=", ">", "<", ">=", "<="}; // ----------------------------------------------------- variables // IN (request) parameters: protected ReqFilters reqFilters; protected String eqlFilters; protected int page; protected int pageSize; protected boolean doCount; protected boolean ignoreSendOnRequest; protected Writer writer; // OUT (response) parameters: private ResRecord[] resRecords; private EQLRes eqlRes; private int count = UNDEFINED_COUNT; private int rows = 0; private boolean hasMore = false; // SPECIAL parameters: // eql query protected String eqlQuery; // eql prepared statement protected EQLIntPreparedStatement eqlPS = new EQLIntPreparedStatement(); // prepared satetement parameter counter private int psCount = 1; protected boolean ignoreLower = false; // ----------------------------------------------------- public static method /** * Call process method * @param ctx action context * @param reqs Reqs object * @param writer Writer object * @return GRAction object * @throws EQLException */ public static final GRAction process( ActionContext ctx, Reqs reqs, Writer writer ) throws EQLException { // Init GR action. AbstractGRAction action; ReqEntity reqEntity = reqs.getReq().getReqEntity(); if( reqEntity == null ) { // .. get fields action = new FieldsGRAction(); } else if( reqEntity.getNew().booleanValue() ) { // .. get new entity action = new NewGRAction(); } else { // .. get entity filter action = EntityGRFilterFactory.getEntityGRFilter( reqs ); if( action == null ) { // .. select entity action = new EntityGRAction(); } } // Set context. action.setActionContext( ctx ); // Set writer. if( writer != null ) { action.setWriter( writer ); } // Init action. action.init( reqs ); // Call process. action.process(); // Ok. return action; } // ----------------------------------------------------- setters // Set writer for records writing. public final void setWriter( Writer writer ) { this.writer = writer; } // ----------------------------------------------------- getters // Get count records in database public final int getCount() { return count; } // Get count rows retrived from database public final int getRows() { return rows; } // Has more records in database flag public final boolean hasMore() { return hasMore; } // EQL response getter public final EQLRes getEQLRes() { return eqlRes; } // ResRecord array getter public final ResRecord[] getResRecords() { if( writer != null ) { throw new IllegalStateException( "Output stream is set" ); } return resRecords; } // Writer getter public final Writer getWriter() { if( writer == null ) { throw new IllegalStateException( "Output stream is not set" ); } return writer; } // ----------------------------------------------------- process method /* * No javadoc * @see Action#process */ public final void process() throws EQLException {// [MVT] do not uncomment line below - otherwise charts data will be broken// if( pageSize != UNDEFINED_PAGESIZE ) { // build EQL query buildEQL(); DEBUG( "Build EQL query - ok" ); // execute EQL query eqlRes = callEQLManager(); DEBUG( "Call EQL manager - ok" ); // get count doCount(); DEBUG( "Do count - ok" );// } // initialize response OUT attributes { // 1. rows - rows in package rows = ( eqlRes == null ) ? 0 : eqlRes.size(); } { // 2. hasMore - is there any available records... Object o = null; if( eqlRes != null ) { o = eqlRes.getMetaData().getParam( HAS_MORE_PARAM ); if( o != null ) { hasMore = ( ( Boolean ) o ).booleanValue(); } } } { // 3. count - count records in database... if( count == UNDEFINED_COUNT && rows > 0 ) { // Calculate count by the hands: // count = page * pageSize + rows + ((hasMore) ? 1 : 0) if( page != UNDEFINED_PAGE && pageSize != UNDEFINED_PAGESIZE ) { count = page * pageSize + rows + ( hasMore ? 1 : 0 ); } else { count = rows; } } } DEBUG( "Start read records..." ); // get Res records if( writer != null ) { // write records /*if( rows == 0 ) { resRecords = createFakeResRecord( getFields() ); XMLHelper.writeObject( resRecords[0], writer, true ); } else { createResRecords( eqlRes, writer ); }*///todo remove if need empty record in empty response if( rows == 0 ) { resRecords = new ResRecord[0]; XMLHelper.writeObject( resRecords[0], writer, true ); } else { createResRecords( eqlRes, writer ); } } else { // collect records /*if( rows == 0 ) { resRecords = createFakeResRecord( getFields() ); } else { resRecords = createResRecords( eqlRes ); }*///todo remove if need empty record in empty response if( rows == 0 ) { resRecords = new ResRecord[0]; } else { resRecords = createResRecords( eqlRes ); } } if( getLogger().isDebugEnabled() ) { DEBUG( " # page=" + page ); DEBUG( " # pageSize=" + pageSize ); DEBUG( " # count (in database)=" + count ); DEBUG( " # rows (package size)=" + rows ); DEBUG( " # has more=" + hasMore ); } } // ----------------------------------------------------- protected methods // // Initialization. // protected void init( Reqs reqs ) { page = reqs.getPage().intValue(); pageSize = reqs.getPagesize().intValue(); doCount = reqs.getDocount().booleanValue(); ignoreSendOnRequest = reqs.getIgnoreSendOnRequest().booleanValue(); reqFilters = reqs.getReqFilters(); eqlFilters = reqs.getEqlFilters(); } // ----------------------------------------------------- abstract methods /** * Call EQL manager * @return EQL response * @throws EQLException */ protected abstract EQLRes callEQLManager() throws EQLException; /** * Call EQL manager for counting * @return int * @throws EQLException */ protected abstract int callEQLManagerForCount() throws EQLException; /** * Create ResRecord objects using EQLRes * @param eqlRes EQLRes object * @return array of ResRecord objects or null * @throws EQLException */ protected abstract ResRecord[] createResRecords( EQLRes eqlRes ) throws EQLException; /** * Write ResRecord objects in <code>writer</code> * @param eqlRes EQLRes object * @param writer given writer * @throws EQLException */ protected abstract void createResRecords( EQLRes eqlRes, Writer writer ) throws EQLException; // ----------------------------------------------------- protected methods /** * Do counting. * Initialize "count" attribute. * @throws EQLException */ protected void doCount() throws EQLException { if( doCount ) { if( page == UNDEFINED_PAGE ) { // we got all records. don't count } else if( pageSize > eqlRes.size() ) { // we got less than expected. don't count } else { count = callEQLManagerForCount(); } } } /** * Build EQL query * @throws UserQueryParseException */ protected void buildEQL() throws UserQueryParseException { StringBuffer mainEql = new StringBuffer( "SELECT " ); // build EQL meta information
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -