001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.beanquery.sql;
018
019import org.apache.juneau.commons.beanquery.*;
020
021/**
022 * Maps a logical column name to its dialect-quoted SQL reference, for {@link SqlSearchCompiler}.
023 *
024 * <p>
025 * Only columns that passed validation reach it: column types and operator sets travel in the {@link ResolvedQuery},
026 * so a resolver never has to guess about an unknown name.  {@link SqlBeanQueryContext} is the usual implementation.
027 * The interface is small so the compiler can be tested without a context or a database.
028 *
029 * <h5 class='section'>Example:</h5>
030 * <p class='bjava'>
031 *    <jc>// Logical names map one-to-one to quoted SQL names.</jc>
032 *    ColumnResolver <jv>columns</jv> = <jv>c</jv> -&gt; <jv>dialect</jv>.quote(<jv>c</jv>);
033 *    SqlFragment <jv>where</jv> = SqlSearchCompiler.<jsm>create</jsm>(<jv>dialect</jv>, <jv>columns</jv>).compile(<jv>context</jv>.resolve(<jv>query</jv>).filter());
034 * </p>
035 *
036 * @since 10.0.0
037 */
038@FunctionalInterface
039public interface ColumnResolver {
040
041   /**
042    * Returns the dialect-quoted SQL reference for a column (for example {@code "age"} for column {@code age}).
043    *
044    * @param column A validated logical column name.  Never <jk>null</jk>.
045    * @return The quoted SQL reference.
046    */
047   String columnSql(String column);
048}