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

📄 compositequeryitem.java

📁 一个工作流设计及定义的系统,可以直接与数据库结合进行系统工作流程的定义及应用.
💻 JAVA
字号:
/* * Copyright (c) 2005, John Mettraux, OpenWFE.org * All rights reserved. *  * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions are met: *  * . Redistributions of source code must retain the above copyright notice, this *   list of conditions and the following disclaimer.   *  * . Redistributions in binary form must reproduce the above copyright notice,  *   this list of conditions and the following disclaimer in the documentation  *   and/or other materials provided with the distribution. *  * . Neither the name of the "OpenWFE" nor the names of its contributors may be *   used to endorse or promote products derived from this software without *   specific prior written permission. *  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  * POSSIBILITY OF SUCH DAMAGE. * * $Id: CompositeQueryItem.java,v 1.13 2005/05/17 16:41:06 jmettraux Exp $ *///// CompositeQueryItem.java//// john.mettraux@openwfe.org//// generated with // jtmpl 1.1.00 16.08.2003 John Mettraux (jmettraux@openwfe.org)//package openwfe.org.xdbc.query;import openwfe.org.sql.SqlUtils;import openwfe.org.xdbc.XdbcException;/** * no comment * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Id: CompositeQueryItem.java,v 1.13 2005/05/17 16:41:06 jmettraux Exp $ </font> * * @author john.mettraux@openwfe.org */public abstract class CompositeQueryItem    implements QueryItem{    static org.apache.log4j.Logger log = org.apache.log4j.Logger        .getLogger(CompositeQueryItem.class.getName());    //    // CONSTANTS & co    public static String XML_ELT_NAME = "composite";        // this is not a real constant... It's not final    //    // FIELDS    protected java.util.List items = new java.util.ArrayList();    //    // CONSTRUCTORS    //    // METHODS from QueryItem    public IdSet query (String clientIdLike, java.sql.Connection con)        throws XdbcException    {        //        // is it an homogeneous composite ?                Class firstClass = getFirstClass();        boolean isHomogeneous = false;        if (firstClass != null) isHomogeneous = isHomogeneous(firstClass);        //        // it's an homogeneous composite                if (isHomogeneous)        {            StringBuffer sb = new StringBuffer();            sb.append("SELECT ");            sb.append(DOCUMENT_ID);            sb.append(", ");            sb.append(CLIENT_ID);            sb.append(" FROM ");            if (firstClass.equals(AttributeQueryItem.class))                sb.append(ATTRIBUTES);            else                sb.append(ELEMENTS);            sb.append(", ");            sb.append(DOCUMENTS);            sb.append(" WHERE ");            if (firstClass.equals(AttributeQueryItem.class))                sb.append(ATTRIBUTES);            else                sb.append(ELEMENTS);            sb.append("."); sb.append(DOCUMENT_ID);            sb.append(" = ");            sb.append(DOCUMENTS); sb.append("."); sb.append("id");            sb.append(" AND ");            sb.append(CLIENT_ID);            sb.append(" LIKE ");            sb.append(SqlUtils.prepareString(clientIdLike));            sb.append(" AND ");            sb.append(getQueryString());            //sb.append(";");            String query = sb.toString();            log.debug("query() >\n"+query+"\n<");            //            // execute query            return AtomicQueryItem.executeQuery(con, query);        }        //        // it's an heterogeneous composite                /*         * this is NOT optimized...          * to optimized, homogeneous groups should be detected,         * because there is one select per homongeneous group...         */                IdSet result = new IdSet();        java.util.Iterator it = this.items.iterator();        while (it.hasNext())        {            QueryItem next = (QueryItem)it.next();            if (it.hasNext())                result = combineResults(result, next.query(clientIdLike, con));        }        return result;    }    public org.jdom.Element encode ()    {        org.jdom.Element result = new org.jdom.Element(XML_ELT_NAME);        java.util.Iterator it = this.items.iterator();        while (it.hasNext())            result.addContent(((QueryItem)it.next()).encode());        return result;    }    //    // METHODS    public CompositeQueryItem add (QueryItem qi)    {        this.items.add(qi);        return this;    }    public boolean isHomogeneous ()    {        if (this.items.size() < 1) return true;        Class queryItemClass = getFirstClass();        return isHomogeneous(queryItemClass);    }    public Class getFirstClass ()    {        if (this.items.size() < 1) return null;        java.util.Iterator it = this.items.iterator();        while (it.hasNext())        {            Object next = it.next();            if (next instanceof AttributeQueryItem ||                next instanceof ElementQueryItem)            {                return next.getClass();            }            //            // deep first...            if (next instanceof CompositeQueryItem)            {                Class clazz = ((CompositeQueryItem)next).getFirstClass();                if (clazz != null) return clazz;            }        }        return null;    }    public boolean isHomogeneous (Class queryItemClass)    {        java.util.Iterator it = this.items.iterator();        while (it.hasNext())        {            Object next = it.next();            if (next instanceof OwfeQueryItem)            {                //                // an OwfeQueryItem is never part of an homogeneous                // query : it is complex itself and cannot mix                // with other QueryItem in a simple SQL query string.                //                return false;            }            if (next instanceof CompositeQueryItem)            {                if ( ! ((CompositeQueryItem)next).isHomogeneous(queryItemClass))                    return false;            }            Class nextClass = next.getClass();            if ( ! nextClass.equals(queryItemClass)) return false;        }        return true;    }    //    // METHODS that have to be implemented (or overriden if static)    public static CompositeQueryItem buildNew ()    {        return null;    }    protected abstract IdSet combineResults (IdSet set1, IdSet set2);    //    // non public methods    protected String combineQueryStrings (String combinationOperator)    {        StringBuffer sb = new StringBuffer();        sb.append("(");        java.util.Iterator it = this.items.iterator();        while (it.hasNext())        {            QueryItem qi = (QueryItem)it.next();            sb.append(qi.getQueryString());            if (it.hasNext())            {                sb.append(" ");                sb.append(combinationOperator);                sb.append(" ");            }        }        sb.append(")");        return sb.toString();    }}

⌨️ 快捷键说明

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