001/* 002 * Copyright 2010 Anyware Services 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 */ 016package org.ametys.plugins.externaldata.data; 017 018import java.util.Map; 019import java.util.regex.Pattern; 020 021import org.ametys.core.datasource.DataSourceClientInteraction.DataSourceType; 022 023/** 024 * <p>Data interrogation query class.</p> 025 * <p>Defines an interrogation query (SQL select, LDAP search, ...) on a specified 026 * data source, with optional parameters, which returns either a single result 027 * (i.e. name of a person in a LDAP directory), or a list of multiple structured 028 * results (i.e. list of products from a SQL database). 029 * </p> 030 */ 031public interface Query 032{ 033 /** Parameter pattern. */ 034 public static final String PARAMETER_PATTERN = "\\$\\{(\\w+)(\\[([^\\]]+)\\])?\\}"; 035 036 /** Parameter matcher. */ 037 public static final Pattern PARAMETER_MATCHER = Pattern.compile(PARAMETER_PATTERN); 038 039 /** Query result type. */ 040 public enum ResultType 041 { 042 /** Simple result : single (scalar) value. */ 043 SIMPLE, 044 /** Multiple result : table of structured values. */ 045 MULTIPLE; 046 } 047 048 /** 049 * Get the query ID. 050 * @return the query ID. 051 */ 052 String getId(); 053 054 /** 055 * Get the query name. 056 * @return the query name. 057 */ 058 String getName(); 059 060 /** 061 * Get the query description. 062 * @return the query description. 063 */ 064 String getDescription(); 065 066 /** 067 * Get the query type. 068 * @return the query type. 069 */ 070 DataSourceType getType(); 071 072 /** 073 * Get the id of source factory 074 * @return the id of source factory 075 */ 076 String getFactory(); 077 078 /** 079 * Get the query parameter names. 080 * @return the query parameter names as a Collection. 081 */ 082 Map<String, String> getParameters(); 083 084 /** 085 * Get the query result type. 086 * @return the query result type. 087 */ 088 ResultType getResultType(); 089 090 /** 091 * Get the additional query configuration information. 092 * @return the additional query configuration information as a Map of String -> String. 093 */ 094 Map<String, String> getAdditionalConfiguration(); 095 096 /** 097 * Get the id of datasource on which depends this query. 098 * @return the datasource on which depends this query. 099 */ 100 String getDataSourceId(); 101}