📄 atomicqueryitem.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: AtomicQueryItem.java,v 1.14 2005/05/17 16:41:06 jmettraux Exp $ *///// AtomicQueryItem.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;/** * A base class for AttributeQueryItem and ElementQueryItem * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Id: AtomicQueryItem.java,v 1.14 2005/05/17 16:41:06 jmettraux Exp $ </font> * * @author john.mettraux@openwfe.org */public abstract class AtomicQueryItem implements QueryItem{ static org.apache.log4j.Logger log = org.apache.log4j.Logger .getLogger(AtomicQueryItem.class.getName()); // // CONSTANTS & co public final static int LIKE = 0; public final static int GREATER = 1; public final static int GREATER_OR_EQUALS = 2; public final static int LESSER = -1; public final static int LESSER_OR_EQUALS = -2; public final static int NOT_LIKE = -99; public final static String ELTNAME = "eTagName"; public final static String ELTVALUE = "eText"; public final static String XML_ATT_VALUE_OPERATOR = "value-operator"; // // FIELDS protected int valueOperator = LIKE; // // CONSTRUCTORS // // METHODS protected boolean childrenMatches (org.jdom.Element elt) { java.util.Iterator it = elt.getChildren().iterator(); while (it.hasNext()) if (matches((org.jdom.Element)it.next())) return true; return false; } /** * A value operator is either LIKE, GREATER, GREATER_OR_EQUALS, NOT_LIKE... */ public QueryItem setValueOperator (int valueOperator) { this.valueOperator = valueOperator; return this; } protected String encodeValueOperator () { if (this.valueOperator == GREATER) return "greater"; if (this.valueOperator == GREATER_OR_EQUALS) return "greater-or-equals"; if (this.valueOperator == LESSER) return "lesser"; if (this.valueOperator == LESSER_OR_EQUALS) return "lesser-or-equals"; if (this.valueOperator == NOT_LIKE) return "not-like"; return "like"; } protected String getValueOperator () { if (this.valueOperator == GREATER) return " > "; if (this.valueOperator == GREATER_OR_EQUALS) return " >= "; if (this.valueOperator == LESSER) return " < "; if (this.valueOperator == LESSER_OR_EQUALS) return " <= "; if (this.valueOperator == NOT_LIKE) return " NOT LIKE "; return " LIKE "; } protected boolean compare (String a, String b) { int result = openwfe.org.Utils.compareValues(a, b); if (this.valueOperator == GREATER) return (result > 0); if (this.valueOperator == GREATER_OR_EQUALS) return (result >= 0); if (this.valueOperator == LESSER) return (result < 0); if (this.valueOperator == LESSER_OR_EQUALS) return (result <= 0); if (this.valueOperator == NOT_LIKE) return (result != 0); return (result == 0); } protected IdSet query (String tableName, String clientIdLike, java.sql.Connection con) throws XdbcException { // // prepare query StringBuffer sb = new StringBuffer(); sb.append("SELECT "); sb.append(DOCUMENT_ID); sb.append(", "); sb.append(CLIENT_ID); sb.append(" FROM "); sb.append(tableName); sb.append(", "); sb.append(DOCUMENTS); sb.append(" WHERE "); sb.append(tableName); sb.append("."); sb.append(DOCUMENT_ID); sb.append(" = "); sb.append(DOCUMENTS); sb.append("."); sb.append("id"); sb.append(" AND "); if (clientIdLike != null) { 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 executeQuery(con, query); } // // STATIC METHODS protected static int decodeValueOperator (String sop) { if (sop == null) return LIKE; if (sop.equals("greater")) return GREATER; if (sop.equals("greater-or-equals")) return GREATER_OR_EQUALS; if (sop.equals("lesser")) return LESSER; if (sop.equals("lesser-or-equals")) return LESSER_OR_EQUALS; if (sop.equals("not-like")) return NOT_LIKE; return LIKE; } public static IdSet executeQuery (java.sql.Connection con, String query) throws XdbcException { java.sql.Statement st = null; java.sql.ResultSet rs = null; try { st = con.createStatement(); rs = st.executeQuery(query); return IdSet.extractDocumentIds(rs); } catch (java.sql.SQLException se) { throw new XdbcException ("Failed to query db", se); } finally { try { rs.close(); st.close(); } catch (Exception e) { // don't care about it } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -