001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ 020 */ 021 022package org.nuxeo.ecm.platform.query.core; 023 024import org.nuxeo.common.xmap.annotation.XNode; 025import org.nuxeo.common.xmap.annotation.XNodeList; 026import org.nuxeo.common.xmap.annotation.XObject; 027import org.nuxeo.ecm.core.search.api.client.querymodel.Escaper; 028import org.nuxeo.ecm.platform.query.api.PredicateDefinition; 029import org.nuxeo.ecm.platform.query.api.WhereClauseDefinition; 030 031/** 032 * Generic descriptor for query where clause, accepting predicates and a fixed part. A custom escaper can also be set. 033 * 034 * @author Anahide Tchertchian 035 * @since 5.4 036 */ 037@XObject(value = "whereClause") 038public class WhereClauseDescriptor implements WhereClauseDefinition { 039 040 /** 041 * @deprecated since 6.0: doc type moved up to the page provider descriptor. 042 */ 043 @Deprecated 044 @XNode("@docType") 045 protected String docType; 046 047 @XNode("@escaper") 048 protected Class<? extends Escaper> escaperClass; 049 050 @XNodeList(value = "predicate", componentType = PredicateDescriptor.class, type = PredicateDefinition[].class) 051 protected PredicateDefinition[] predicates; 052 053 protected String fixedPart; 054 055 /** 056 * This parameter allows to override the default select statement used by the fixed part ("select * from Document" 057 * for NXQL queries, for instance). 058 * 059 * @since 5.9.2 060 */ 061 @XNode("fixedPart@statement") 062 protected String selectStatement; 063 064 @XNode("fixedPart@quoteParameters") 065 protected boolean quoteFixedPartParameters = true; 066 067 @XNode("fixedPart@escape") 068 protected boolean escapeFixedPartParameters = true; 069 070 /** 071 * @deprecated since 6.0: use {@link BasePageProviderDescriptor#getSearchDocumentType()} 072 */ 073 @Override 074 @Deprecated 075 public String getDocType() { 076 return docType; 077 } 078 079 @Override 080 @XNode("fixedPart") 081 public void setFixedPath(String fixedPart) { 082 // remove new lines and following spaces 083 this.fixedPart = fixedPart.replaceAll("\r?\n\\s*", " "); 084 } 085 086 @Override 087 public boolean getQuoteFixedPartParameters() { 088 return quoteFixedPartParameters; 089 } 090 091 @Override 092 public boolean getEscapeFixedPartParameters() { 093 return escapeFixedPartParameters; 094 } 095 096 @Override 097 public PredicateDefinition[] getPredicates() { 098 return predicates; 099 } 100 101 @Override 102 public void setPredicates(PredicateDefinition[] predicates) { 103 this.predicates = predicates; 104 } 105 106 @Override 107 public String getFixedPart() { 108 return fixedPart; 109 } 110 111 @Override 112 public void setFixedPart(String fixedPart) { 113 this.fixedPart = fixedPart; 114 } 115 116 @Override 117 public Class<? extends Escaper> getEscaperClass() { 118 return escaperClass; 119 } 120 121 @Override 122 public String getSelectStatement() { 123 return selectStatement; 124 } 125 126 /** 127 * @since 5.6 128 */ 129 @Override 130 public WhereClauseDescriptor clone() { 131 WhereClauseDescriptor clone = new WhereClauseDescriptor(); 132 clone.docType = getDocType(); 133 clone.escaperClass = getEscaperClass(); 134 if (predicates != null) { 135 clone.predicates = new PredicateDefinition[predicates.length]; 136 for (int i = 0; i < predicates.length; i++) { 137 clone.predicates[i] = predicates[i].clone(); 138 } 139 } 140 clone.fixedPart = fixedPart; 141 clone.quoteFixedPartParameters = quoteFixedPartParameters; 142 clone.escapeFixedPartParameters = escapeFixedPartParameters; 143 clone.selectStatement = selectStatement; 144 return clone; 145 } 146}