001/* 
002 * JKNIV, SQLegance keeping queries maintainable.
003 * 
004 * Copyright (C) 2017, the original author or authors.
005 *
006 * This library is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 2.1 of the License.
010 * 
011 * This library is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 * 
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with this library; if not, write to the Free Software Foundation, Inc., 
018 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
019 */
020package net.sf.jkniv.sqlegance;
021
022import java.util.List;
023import java.util.Map;
024
025import net.sf.jkniv.sqlegance.builder.RepositoryConfig;
026import net.sf.jkniv.sqlegance.dialect.SqlDialect;
027
028/**
029 * Main interface to load and access the set of queries defined at XML files for an application.
030 * 
031 * @author Alisson Gomes
032 * @since 0.6.0
033 */
034public interface SqlContext
035{
036    /**
037     * Return context name that belong the statements
038     * @return context name
039     */
040    String getName();
041    
042    /**
043     * Retrieve one query according your name.
044     * 
045     * @param name Name of the query.
046     * @return Return the query object with SQL.
047     * @exception IllegalArgumentException
048     *            if the parameter name does not refer names of query
049     *            configured this exception is thrower.
050     */
051    Sql getQuery(String name);
052    
053    Sql add(Sql sql);
054    
055    /**
056     * Retrieve all queries from package
057     * @param packageName name of package
058     * @return the list of queries that belong this package, if any one query ins't find
059     * a empty list is returned.
060     */
061    List<Sql> getPackage(String packageName);
062    
063    /**
064     * Retrieve all packages starting with {@code packagetName}.
065     * @param packageName name of package
066     * @return Map with found packages, where each key it is a package
067     */
068    Map<String, List<Sql>> getPackageStartWith(String packageName);
069    
070    boolean containsQuery(String name);
071    
072    RepositoryConfig getRepositoryConfig();
073    
074    SqlDialect getSqlDialect();
075
076    void setSqlDialect(SqlDialect sqlDialect);
077
078    /**
079     * Closes this SQL context.
080     * After close the SQL context the access to SQL is lost and 
081     * retrieve a SQL {@code QueryNotFoundException} is throw.  
082     */
083    void close();
084}