001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.platform.query.core; 021 022import org.nuxeo.common.xmap.annotation.XNode; 023import org.nuxeo.common.xmap.annotation.XNodeList; 024import org.nuxeo.common.xmap.annotation.XObject; 025import org.nuxeo.ecm.core.search.api.client.querymodel.Escaper; 026import org.nuxeo.ecm.platform.query.api.PredicateDefinition; 027import org.nuxeo.ecm.platform.query.api.WhereClauseDefinition; 028 029/** 030 * Generic descriptor for query where clause, accepting predicates and a fixed part. A custom escaper can also be set. 031 * 032 * @author Anahide Tchertchian 033 * @since 5.4 034 */ 035@XObject(value = "whereClause") 036public class WhereClauseDescriptor implements WhereClauseDefinition { 037 038 /** 039 * @deprecated since 6.0: doc type moved up to the page provider descriptor. 040 */ 041 @Deprecated 042 @XNode("@docType") 043 protected String docType; 044 045 @XNode("@escaper") 046 protected Class<? extends Escaper> escaperClass; 047 048 @XNodeList(value = "predicate", componentType = PredicateDescriptor.class, type = PredicateDefinition[].class) 049 protected PredicateDefinition[] predicates; 050 051 protected String fixedPart; 052 053 /** 054 * This parameter allows to override the default select statement used by the fixed part ("select * from Document" 055 * for NXQL queries, for instance). 056 * 057 * @since 5.9.2 058 */ 059 @XNode("fixedPart@statement") 060 protected String selectStatement; 061 062 @XNode("fixedPart@quoteParameters") 063 protected boolean quoteFixedPartParameters = true; 064 065 @XNode("fixedPart@escape") 066 protected boolean escapeFixedPartParameters = true; 067 068 /** 069 * @deprecated since 6.0: use {@link BasePageProviderDescriptor#getSearchDocumentType()} 070 */ 071 @Override 072 @Deprecated 073 public String getDocType() { 074 return docType; 075 } 076 077 @Override 078 @XNode("fixedPart") 079 public void setFixedPath(String fixedPart) { 080 // remove new lines and following spaces 081 this.fixedPart = fixedPart.replaceAll("\r?\n\\s*", " "); 082 } 083 084 @Override 085 public boolean getQuoteFixedPartParameters() { 086 return quoteFixedPartParameters; 087 } 088 089 @Override 090 public boolean getEscapeFixedPartParameters() { 091 return escapeFixedPartParameters; 092 } 093 094 @Override 095 public PredicateDefinition[] getPredicates() { 096 return predicates; 097 } 098 099 @Override 100 public void setPredicates(PredicateDefinition[] predicates) { 101 this.predicates = predicates; 102 } 103 104 @Override 105 public String getFixedPart() { 106 return fixedPart; 107 } 108 109 @Override 110 public void setFixedPart(String fixedPart) { 111 this.fixedPart = fixedPart; 112 } 113 114 @Override 115 public Class<? extends Escaper> getEscaperClass() { 116 return escaperClass; 117 } 118 119 @Override 120 public String getSelectStatement() { 121 return selectStatement; 122 } 123 124 /** 125 * @since 5.6 126 */ 127 @Override 128 public WhereClauseDescriptor clone() { 129 WhereClauseDescriptor clone = new WhereClauseDescriptor(); 130 clone.docType = getDocType(); 131 clone.escaperClass = getEscaperClass(); 132 if (predicates != null) { 133 clone.predicates = new PredicateDefinition[predicates.length]; 134 for (int i = 0; i < predicates.length; i++) { 135 clone.predicates[i] = predicates[i].clone(); 136 } 137 } 138 clone.fixedPart = fixedPart; 139 clone.quoteFixedPartParameters = quoteFixedPartParameters; 140 clone.escapeFixedPartParameters = escapeFixedPartParameters; 141 clone.selectStatement = selectStatement; 142 return clone; 143 } 144}