001/*
002 * (C) Copyright 2006-2011 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 *     Florent Guillaume
018 */
019
020package org.nuxeo.ecm.core.storage.sql.jdbc;
021
022import java.io.Serializable;
023import java.util.LinkedList;
024import java.util.List;
025
026import org.nuxeo.ecm.core.query.QueryFilter;
027import org.nuxeo.ecm.core.storage.sql.Model;
028import org.nuxeo.ecm.core.storage.sql.Session.PathResolver;
029import org.nuxeo.ecm.core.storage.sql.jdbc.SQLInfo.SQLInfoSelect;
030
031/**
032 * A Query Maker, that can transform a query string into a SQL statement.
033 * <p>
034 * Must have a zero-arg constructor.
035 *
036 * @author Florent Guillaume
037 */
038public interface QueryMaker {
039
040    /**
041     * Gets the name for this query maker.
042     */
043    String getName();
044
045    /**
046     * Checks if this query maker accepts a given query.
047     * <p>
048     * Called first.
049     *
050     * @param query the query
051     * @return {@code true} if the query is accepted
052     */
053    boolean accepts(String query);
054
055    /**
056     * Builds the query.
057     *
058     * @param sqlInfo the sql info
059     * @param model the model
060     * @param pathResolver the path resolver
061     * @param query the query
062     * @param queryFilter the query filter
063     * @param params additional parameters, maker-specific
064     */
065    Query buildQuery(SQLInfo sqlInfo, Model model, PathResolver pathResolver, String query, QueryFilter queryFilter,
066            Object... params);
067
068    /**
069     * A SQL query that can be executed by the backend.
070     */
071    public static class Query {
072
073        public SQLInfoSelect selectInfo;
074
075        public List<Serializable> selectParams = new LinkedList<Serializable>();
076
077    }
078
079    public static class QueryCannotMatchException extends RuntimeException {
080        private static final long serialVersionUID = 1L;
081    }
082
083}