001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Florent Guillaume 011 */ 012 013package org.nuxeo.ecm.core.storage.sql.jdbc; 014 015import java.io.Serializable; 016import java.util.LinkedList; 017import java.util.List; 018 019import org.nuxeo.ecm.core.query.QueryFilter; 020import org.nuxeo.ecm.core.storage.sql.Model; 021import org.nuxeo.ecm.core.storage.sql.Session.PathResolver; 022import org.nuxeo.ecm.core.storage.sql.jdbc.SQLInfo.SQLInfoSelect; 023 024/** 025 * A Query Maker, that can transform a query string into a SQL statement. 026 * <p> 027 * Must have a zero-arg constructor. 028 * 029 * @author Florent Guillaume 030 */ 031public interface QueryMaker { 032 033 /** 034 * Gets the name for this query maker. 035 */ 036 String getName(); 037 038 /** 039 * Checks if this query maker accepts a given query. 040 * <p> 041 * Called first. 042 * 043 * @param query the query 044 * @return {@code true} if the query is accepted 045 */ 046 boolean accepts(String query); 047 048 /** 049 * Builds the query. 050 * 051 * @param sqlInfo the sql info 052 * @param model the model 053 * @param pathResolver the path resolver 054 * @param query the query 055 * @param queryFilter the query filter 056 * @param params additional parameters, maker-specific 057 */ 058 Query buildQuery(SQLInfo sqlInfo, Model model, PathResolver pathResolver, String query, QueryFilter queryFilter, 059 Object... params); 060 061 /** 062 * A SQL query that can be executed by the backend. 063 */ 064 public static class Query { 065 066 public SQLInfoSelect selectInfo; 067 068 public List<Serializable> selectParams = new LinkedList<Serializable>(); 069 070 } 071 072 public static class QueryCannotMatchException extends RuntimeException { 073 private static final long serialVersionUID = 1L; 074 } 075 076}