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;
014
015import org.nuxeo.ecm.core.query.QueryFilter;
016import org.nuxeo.ecm.core.storage.sql.Session.PathResolver;
017import org.nuxeo.ecm.core.storage.sql.jdbc.QueryMaker;
018import org.nuxeo.ecm.core.storage.sql.jdbc.SQLInfo;
019
020/**
021 * A dummy QueryMaker usable to capture the low level sqlInfo, model and session from a high-level session, in order to
022 * further test QueryMakers.
023 *
024 * @author Florent Guillaume
025 */
026public class CapturingQueryMaker implements QueryMaker {
027
028    public static final String TYPE = "test-capturing";
029
030    public static class Captured {
031        public SQLInfo sqlInfo;
032
033        public Model model;
034
035        public PathResolver pathResolver;
036    }
037
038    @Override
039    public String getName() {
040        return TYPE;
041    }
042
043    @Override
044    public boolean accepts(String queryType) {
045        return TYPE.equals(queryType);
046    }
047
048    @Override
049    public Query buildQuery(SQLInfo sqlInfo, Model model, PathResolver pathResolver, String query,
050            QueryFilter queryFilter, Object... params) {
051        Captured captured = (Captured) params[0];
052        captured.sqlInfo = sqlInfo;
053        captured.model = model;
054        captured.pathResolver = pathResolver;
055        return null;
056    }
057}