Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* 
   * Copyright (C) 2010---2013 星星(wuweixing)<349446658@qq.com>
   * 
   * This file is part of Wabacus 
   * 
   * Wabacus 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 3 of the License, or
   * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 package com.wabacus.system.inputbox.autocomplete;
 
 import java.util.List;
 import java.util.Map;
 
 
 public class AutoCompleteBean implements Cloneable
 {
     public final static String MULTIPLE_FIRST="first";
 
     public final static String MULTIPLE_LAST="last";
 
     public final static String MULTIPLE_NONE="none";
 
     private AbsInputBox owner;
 
     private IAutoCompleteDataSet datasetObj;
 
     private List<StringlstAutoCompleteColumns;
 
     private List<ColBeanlstAutoCompleteColBeans;
     
     private String colvalueCondition;
 
     
     private List<ConditionBeanlstConditionBeans;
 
     private String multiple;//如果匹配了多条记录的处理办法,可取值为first/last/none,分别表示取第一条、最后一条、不取任何记录
 
     public AutoCompleteBean(AbsInputBox owner)
     {
         this.=owner;
     }
 
     public AbsInputBox getOwner()
     {
         return ;
     }
 
     public void setOwner(AbsInputBox owner)
     {
         this.=owner;
     }
 
     {
         return ;
     }
 
     {
         return ;
     }
 
    {
        return ;
    }
    {
        return ;
    }
    public String getMultiple()
    {
        return ;
    }
    public void loadConfig(XmlElementBean eleAutocompleteBean)
    {
        ReportBean rbean=this..getOwner().getReportBean();
        String columns=eleAutocompleteBean.attributeValue("columns");
        if(columns==null||columns.trim().equals(""))
        {
            throw new WabacusConfigLoadingException("加载报表"+rbean.getPath()+"上的输入框"+this..getOwner().getInputBoxId()
                    +"的自动填充配置失败,没有指定要填充的列columns属性");
        }
        this.=Tools.parseStringToList(columns,";",false);
        String dataset=eleAutocompleteBean.attributeValue("dataset");
        if(dataset==null||dataset.trim().equals(""))
        {
            throw new WabacusConfigLoadingException("加载报表"+rbean.getPath()+"上的输入框"+this..getOwner().getInputBoxId()
                    +"的自动填充配置失败,没有配置dataset属性指定数据集");
        }
        dataset=dataset.trim();
        if(dataset.startsWith("{")&&dataset.endsWith("}")) dataset=dataset.substring(1,dataset.length()-1).trim();
        if(Tools.isDefineKey("class",dataset))
        {
            Object obj;
            try
            {
                obj=..loadClassByCurrentLoader(Tools.getRealKeyByDefine("class",dataset)).newInstance();
            }catch(Exception e)
            {
                throw new WabacusConfigLoadingException("加载报表"+rbean.getPath()+"上的输入框"+this..getOwner().getInputBoxId()+"的自动填充配置失败,配置的数据集"
                        +dataset+"类无法实例化",e);
            }
            if(!(obj instanceof IAutoCompleteDataSet))
            {
                throw new WabacusConfigLoadingException("加载报表"+rbean.getPath()+"上的输入框"+this..getOwner().getInputBoxId()+"的自动填充配置失败,配置的数据集"
                        +dataset+"类没有实现接口"+IAutoCompleteDataSet.class.getName());
            }
            this.=(IAutoCompleteDataSet)obj;
        }else if(dataset.toLowerCase().startsWith("call "))
        {
            this.=new SPDataSet();
            String spname=dataset.substring("call ".length()).trim();
            if(spname.equals(""))
            {
                throw new WabacusConfigLoadingException("加载报表"+rbean.getPath()+"上的输入框"+this..getOwner().getInputBoxId()+"的自动填充配置失败,配置的数据集"
                        +dataset+"是存储过程,但没有指定存储过程名");
            }
            if(spname.indexOf("(")>0) spname=spname.substring(0,spname.indexOf("("));
            spname="{call "+spname+"(?)}";
            ((SPDataSet)this.).setSp(spname);
        }else
        {
            this.=new SqlDataSet();
            if(dataset.indexOf("{#condition#}")<0)
            {
                throw new WabacusConfigLoadingException("加载报表"+rbean.getPath()+"上的输入框"+this..getOwner().getInputBoxId()+"的自动填充配置失败,配置的数据集"
                        +dataset+"是SQL语句,必须指定{#condition#}占位符");
            }
            ((SqlDataSet)this.).setSql(dataset.trim());
        }
        String colvaluecondition=eleAutocompleteBean.attributeValue("colvaluecondition");
        if(colvaluecondition!=nullthis.=colvaluecondition.trim();
        String multiple=eleAutocompleteBean.attributeValue("multiple");
        if(multiple==null||multiple.trim().equals("")) multiple=;
        multiple=multiple.toLowerCase().trim();
        if(!multiple.equals()&&!multiple.equals()&&!multiple.equals())
        {
            throw new WabacusConfigLoadingException("加载报表"+rbean.getPath()+"上的输入框"+this..getOwner().getInputBoxId()+"的自动填充配置失败,配置的multiple属性值"
                    +multiple+"无效,只能配置为first/last/none");
        }
        this.=multiple;
        this.=ComponentConfigLoadManager.loadConditionsInOtherPlace(eleAutocompleteBean,rbean);
    }
    public void doPostLoad()
    {
        if(this. instanceof SqlDataSet&&this.!=null)
        {
            ReportBean rbean=this..getOwner().getReportBean();
            boolean isPreparedStmt=false;
            if(rbean.getSbean().getStatementType()==.)
            {
                isPreparedStmt=true;
            }
            ((SqlDataSet)this.).setPreparedStmt(isPreparedStmt);
            for(ConditionBean cbTmp:this.)
            {
                if(isPreparedStmtcbTmp.getConditionExpression().parseConditionExpression();
                if(cbTmp.isConditionValueFromUrl())
                {
                    rbean.addParamNameFromURL(cbTmp.getName());
                }
            }
        }
        processAutoCompleteCols();
        if(this. instanceof SqlDataSet)
        {
            processColvalueConditionForSqlDataset();
        }else
        {
        }
        ColBean cbUpdatecolDest=cbOwner.getUpdateColBeanDest(false);
        if(!this..contains(cbOwner.getProperty()))
        {
            if(cbUpdatecolDest==null||!this..contains(cbUpdatecolDest.getProperty()))
            {
                throw new WabacusConfigLoadingException("加载报表"+cbOwner.getReportBean().getPath()+"的列"+cbOwner.getColumn()
                        +"失败,没有在colvaluecondition属性中指定本列输入框的值做为动态条件");
            }
        }
        if(cbUpdatecolDest!=null&&!this..contains(cbUpdatecolDest.getProperty()))
        {
            this..add(cbUpdatecolDest.getProperty());
        }
    }
    
    private void processAutoCompleteCols()
    {
        DisplayBean dbean=.getOwner().getReportBean().getDbean();
        this.=new ArrayList<ColBean>();
        if(!this..contains(cbOwner.getColumn())) this..add(cbOwner.getColumn());
        ColBean cbTmpcbUpdatecolDestcbUpdatecolSrc;
        List<StringlstRealAutoCompleteColumns=new ArrayList<String>();
        for(String columnTmp:this.)
        {
            if(lstRealAutoCompleteColumns.contains(columnTmp)) continue;
            lstRealAutoCompleteColumns.add(columnTmp);
            cbTmp=dbean.getColBeanByColColumn(columnTmp);
            if(cbTmp==null||cbTmp.isControlCol()||cbTmp.getProperty()==null||cbTmp.getProperty().trim().equals(""))
            {
                throw new WabacusConfigLoadingException("加载报表"+dbean.getReportBean().getPath()+"的列"+cbOwner.getColumn()+"失败,为它配置的自动填充列"+columnTmp
                        +"不存在或不是有效填充列");
            }
            this..add(cbTmp);
            cbUpdatecolDest=cbTmp.getUpdateColBeanDest(false);
            if(cbUpdatecolDest!=null&&!lstRealAutoCompleteColumns.contains(cbUpdatecolDest.getColumn()))
            {
                this..add(cbUpdatecolDest);
                lstRealAutoCompleteColumns.add(cbUpdatecolDest.getColumn());
            }
            cbUpdatecolSrc=cbTmp.getUpdateColBeanSrc(false);
            if(cbUpdatecolSrc!=null&&!lstRealAutoCompleteColumns.contains(cbUpdatecolSrc.getColumn()))
            {
                this..add(cbUpdatecolSrc);
                lstRealAutoCompleteColumns.add(cbUpdatecolSrc.getColumn());
            }
        }
        this.=null;
    }
    
    {
        DisplayBean dbean=.getOwner().getReportBean().getDbean();
        if(this.==null||this..trim().equals(""))
        {
            boolean isVarcharType=cbOwner.getDatatypeObj() instanceof VarcharType;
            this.=cbOwner.getColumn()+"=";
            if(isVarcharTypethis.+="'";
            this.+="#"+cbOwner.getProperty()+"#";
            if(isVarcharTypethis.+="'";
            this..add(cbOwner.getProperty());
        }else
        {
            ColBean cbTmp;
            String expressTmp=this.;
            String propertyTmp;
            while(true)
            {
                int idx=expressTmp.indexOf("#");
                if(idx<0) break;
                expressTmp=expressTmp.substring(idx+1);
                idx=expressTmp.indexOf("#");
                if(idx<=0) break;
                propertyTmp=expressTmp.substring(0,idx);
                cbTmp=dbean.getColBeanByColProperty(propertyTmp.trim());
                if(cbTmp!=null)
                {
                    if(cbTmp.isControlCol()||cbTmp.getProperty()==null||cbTmp.getProperty().trim().equals(""))
                    {
                        throw new WabacusConfigLoadingException("加载报表"+dbean.getReportBean().getPath()+"的列"+cbOwner.getColumn()
                                +"失败,为它配置的自动填充列所用做为条件的列"+propertyTmp+"不存在或不是有效数据列");
                    }
                    if(!.contains(cbTmp.getProperty()))
                    {
                        .add(cbTmp.getProperty());
                    }
                    expressTmp=expressTmp.substring(idx+1);
                }
            }
        }
    }
    
    {
        DisplayBean dbean=.getOwner().getReportBean().getDbean();
        if(this.==null||this..trim().equals(""))
        {
            this..add(cbOwner.getProperty());
        }else
        {
            ColBean cbTmp;
            List<StringlstColProperties=Tools.parseStringToList(this.,";",false);
            for(String propTmp:lstColProperties)
            {
                if(propTmp==null||propTmp.trim().equals("")) continue;
                cbTmp=dbean.getColBeanByColProperty(propTmp.trim());
                if(cbTmp==null||cbTmp.isControlCol())
                {
                    throw new WabacusConfigLoadingException("加载报表"+dbean.getReportBean().getPath()+"的列"+cbOwner.getColumn()+"失败,为它配置的自动填充列所用做为条件的列"
                            +propTmp+"不存在或不是有效数据列");
                }
                if(!.contains(cbTmp.getProperty()))
                {
                    .add(cbTmp.getProperty());
                }
            }
        }
    }
    
    private class SqlDataSet implements IAutoCompleteDataSet
    {
        private String sql;
        
        private boolean isPreparedStmt=false;
        public String getSql()
        {
            return ;
        }
        public void setSql(String sql)
        {
            this.=sql;
        }
        public void setPreparedStmt(boolean isPreparedStmt)
        {
            this.=isPreparedStmt;
        }
        public Map<String,StringgetAutoCompleteColumnsData(ReportRequest rrequest,AutoCompleteBean autoCompleteBean,Map<String,StringmParams)
        {
            if(mParams==null||mParams.size()==0) return null;
            String realColConditionExpression=;
            String colValTmp;
            for(String colpropertyTmp:)
            {
                colValTmp=mParams.get(colpropertyTmp);
                if(colValTmp==nullcolValTmp="";
                realColConditionExpression=Tools.replaceAll(realColConditionExpression,"#"+colpropertyTmp+"#",colValTmp);
            }
            if(realColConditionExpression==null||realColConditionExpression.trim().equals("")) return null;
            ISqlDataSet sqlDataSet=null;
            if(this.)
            {
                sqlDataSet=new GetAllDataSetByPreparedSQL();
            }else
            {
                sqlDataSet=new GetAllDataSetBySQL();
            }
            String sqlTmp=Tools.replaceAll(,"{#condition#}","{@condition@} and "+realColConditionExpression);//保留{#condition#},因为后面还有可能拼凑<condition/>中配置的条件
            sqlTmp=Tools.replaceAll(sqlTmp,"{@condition@}","{#condition#}");
            Object objTmp=sqlDataSet.getDataSet(rrequest,.getOwner().getReportBean(),autoCompleteBean,sqlTmp,,null);
            if(objTmp==null||rrequest.getWResponse().getMessageCollector().hasErrors()||rrequest.getWResponse().getMessageCollector().hasWarnings())
            {
                return null;
            }
            if(objTmp instanceof Mapreturn (Map<String,String>)objTmp;//用户直接在拦截器加载数据前置动作中返回了自己构造的填充列的值
            return getMColDataValuesByResultSet((ResultSet)objTmp);
        }
    }
    private class SPDataSet implements IAutoCompleteDataSet
    {
        private String sp;
        public String getSp()
        {
            return ;
        }
        public void setSp(String sp)
        {
            this.=sp;
        }
        public Map<String,StringgetAutoCompleteColumnsData(ReportRequest rrequest,AutoCompleteBean autoCompleteBean,Map<String,StringmParams)
        {
            StringBuffer paramsBuf=new StringBuffer();
            String colValTmp;
            for(String colpropertyTmp:)
            {
                colValTmp=mParams.get(colpropertyTmp);
                if(colValTmp==nullcolValTmp="";
                paramsBuf.append("["+colpropertyTmp+"="+colValTmp+"]");
            }
            if(!=null)
            {
                String conValTmp;
                for(ConditionBean cbTmp:)
                {
                    conValTmp=cbTmp.getConditionValue(rrequest,-1);
                    if(conValTmp==nullconValTmp="";
                    paramsBuf.append("["+cbTmp.getName()+"="+conValTmp+"]");
                }
            }
            ConditionBean conbeanTmp=new ConditionBean(null);
            conbeanTmp.setConstant(true);
            conbeanTmp.setHidden(true);
            ConditionExpressionBean cebean=new ConditionExpressionBean();
            cebean.setValue(paramsBuf.toString());
            conbeanTmp.setConditionExpression(cebean);
            List<ConditionBeanlstConditionsTmp=new ArrayList<ConditionBean>();
            lstConditionsTmp.add(conbeanTmp);
            Object objTmp=new GetDataSetByStoreProcedure().getDataSet(rrequest,.getOwner().getReportBean(),autoCompleteBean,,lstConditionsTmp,null);
            if(objTmp==null||rrequest.getWResponse().getMessageCollector().hasErrors()||rrequest.getWResponse().getMessageCollector().hasWarnings())
            {
                return null;
            }
            if(objTmp instanceof Mapreturn (Map<String,String>)objTmp;
            return getMColDataValuesByResultSet((ResultSet)objTmp);
        }
    }
    {
        String colValTmp;
        Map<String,StringmResults=new HashMap<String,String>();
        try
        {
            while(rs.next())
            {
                if(mResults.size()>0)
                {
                    if(.equals(this.)) return mResults;
                    if(.equals(this.)) return null;
                }
                for(ColBean cbTmp:)
                {
                    colValTmp=rs.getString(cbTmp.getColumn());
                    if(colValTmp==nullcolValTmp="";
                    mResults.put(cbTmp.getProperty(),colValTmp);
                }
            }
        }catch(SQLException e)
        {
            throw new WabacusRuntimeException("获取报表"+this..getOwner().getReportBean().getPath()+"的自动填充数据失败",e);
        }finally
        {
            try
            {
                if(rs!=nullrs.close();
            }catch(SQLException e)
            {
                e.printStackTrace();
            }
        }
        return mResults;
    }
    
    protected Object clone() throws CloneNotSupportedException
    {
        return super.clone();
    }
    public AutoCompleteBean clone(AbsInputBox newowner)
    {
        AutoCompleteBean newBean=null;
        try
        {
            newBean=(AutoCompleteBean)clone();
            newBean.setOwner(newowner);
            if(!=nullnewBean.lstAutoCompleteColumns=(List<String>)((ArrayList<String>)).clone();
            if(!=null)
            {
                newBean.lstConditionBeans=ComponentConfigLoadAssistant.getInstance().cloneLstConditionBeans(null,);
            }
        }catch(CloneNotSupportedException e)
        {
            throw new WabacusConfigLoadingException("clone输入框对象失败",e);
        }
        return newBean;
    }
New to GrepCode? Check out our FAQ X