001/* 
002 * JKNIV, whinstone one contract to access your database.
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.whinstone.params;
021
022import java.util.Calendar;
023import java.util.Date;
024
025import net.sf.jkniv.sqlegance.params.ParamMarkType;
026import net.sf.jkniv.whinstone.Queryable;
027import net.sf.jkniv.whinstone.statement.StatementAdapter;
028import net.sf.jkniv.whinstone.types.RegisterType;
029
030/**
031 * Factory to create new instances of {@link AutoBindParams}.
032 * 
033 * @author Alisson Gomes
034 * @since 0.6.0
035 */
036public class PrepareParamsFactory
037{
038    
039    public static <T,R> AutoBindParams newPrepareParams(StatementAdapter<T,R> adapter, Queryable queryable)
040    {
041        AutoBindParams prepareParams = null;
042        if (queryable.isTypeOfNull())
043            prepareParams = new NoParams(adapter);
044        else if (queryable.isTypeOfBasic() || queryable.getParams() instanceof Date || queryable.getParams() instanceof Calendar)
045            prepareParams = new BasicParam(adapter, queryable);
046        else if (queryable.isTypeOfArrayBasicTypes())
047            prepareParams = new PositionalArrayParams(adapter, queryable);
048        else if (queryable.isTypeOfCollectionBasicTypes())
049            prepareParams = new PositionalCollectionParams(adapter, queryable);
050        else if (queryable.getDynamicSql().getParamParser().getType() == ParamMarkType.QUESTION)
051            prepareParams = new PositionalParams(adapter, queryable);
052        else
053            prepareParams = new NamedParams(adapter, queryable);
054        
055        return prepareParams;
056    }
057    
058    public static <T,R> AutoBindParams newNoParams(StatementAdapter<T,R> adapter)
059    {
060        return new NoParams(adapter);
061    }
062
063    public static <T,R> AutoBindParams newBasicParam(StatementAdapter<T,R> adapter, Queryable queryable)
064    {
065        return new BasicParam(adapter, queryable);
066    }
067    
068    public static <T,R> AutoBindParams newPositionalArrayParams(StatementAdapter<T,R> adapter, Queryable queryable)
069    {
070        return new PositionalArrayParams(adapter,  queryable);
071    }
072    
073    public static <T,R> AutoBindParams newPositionalCollectionParams(StatementAdapter<T,R> adapter, Queryable queryable)
074    {
075        return new PositionalCollectionParams(adapter, queryable);
076    }
077
078    public static <T,R> AutoBindParams newPositionalCollectionMapParams(StatementAdapter<T,R> adapter, Queryable queryable)
079    {
080        return new PositionalCollectionMapParams(adapter, queryable);
081    }
082
083
084    public static <T,R> AutoBindParams newPositionalCollectionPojoParams(StatementAdapter<T,R> adapter, Queryable queryable, RegisterType registerType)
085    {
086        return new PositionalCollectionPojoParams(adapter, queryable);
087    }
088
089    public static <T,R> AutoBindParams newPositionalCollectionArrayParams(StatementAdapter<T,R> adapter, Queryable queryable)
090    {
091        return new PositionalCollectionArrayParams(adapter, queryable);
092    }
093
094    public static <T,R> AutoBindParams newPositionalParams(StatementAdapter<T,R> adapter, Queryable queryable)
095    {
096        return new PositionalParams(adapter, queryable);
097    }
098    
099    public static <T,R> AutoBindParams newNamedParams(StatementAdapter<T,R> adapter, Queryable queryable)
100    {
101        return new NamedParams(adapter, queryable);
102    }
103
104//    public static <T,R> AutoBindParams newPositionalArrayMapParams(StatementAdapter<T,R> adapter, Queryable queryable)
105//    {
106//        return new PositionalarCollectionMapParams(adapter, queryable);
107//    }
108}