All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.repository.sp.SqlQueryImpl.ftl Maven / Gradle / Ivy

<#if header>
/*
 * Copyright (C) 2019 Yadickson Soto
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */

package ${javaPackage}.${repositoryFolderName}.sp;
<#assign importList = ["java.util.Map", ""org.springframework.stereotype.Repository", "org.springframework.jdbc.object.GenericSqlQuery", "java.util.Objects", "org.springframework.beans.factory.annotation.Qualifier", "org.springframework.jdbc.core.JdbcTemplate"]>
<#list proc.parameters as parameter>
<#if parameter.inputOutput>
<#assign importList = importList + ["org.springframework.jdbc.core.SqlInOutParameter"]>
<#elseif parameter.output>
<#assign importList = importList + ["org.springframework.jdbc.core.SqlOutParameter"]>
<#elseif parameter.input>
<#assign importList = importList + ["org.springframework.jdbc.core.SqlParameter"]>
<#elseif parameter.returnResultSet>
<#assign importList = importList + ["org.springframework.jdbc.core.SqlReturnResultSet"]>

<#if parameter.resultSet || parameter.returnResultSet>
<#assign importList = importList + ["${javaPackage}.${repositoryFolderName}.mapper.${parameter.javaTypeName}RowMapper"]>



<#list importSort(importList) as import>
<#if previousImportMatch?? && !import?starts_with(previousImportMatch)>


import ${import};
<#assign previousImportMatch = import?keep_before_last(".") >

<#if importList?has_content>


<#if documentation>
/**
 * DAO for <#if proc.function>function<#else>stored procedure.
 *
 * ${proc.fullName}
 *
 * @author @GENERATOR.NAME@
 * @version @GENERATOR.VERSION@
 */

@Repository
final class ${proc.className}SqlQueryImpl${'\n'}        extends GenericSqlQuery${'\n'}        implements ${proc.className}SqlQuery {

<#if documentation>
    /**
     * Full <#if proc.function>function<#else>stored procedure name.
     */

    public static final String SPROC_NAME = "${proc.fullName}";

<#if documentation>
    /**
     * Class constructor from jdbcTemplate.
     *
     * @param jdbcTemplate jdbcTemplate
     */

    public ${proc.className}SqlQueryImpl(${'\n'}        @Qualifier("${jdbcTemplate}") final JdbcTemplate jdbcTemplate<#list proc.parameters as parameter><#if parameter.resultSet || parameter.returnResultSet>,${'\n'}        final ${parameter.javaTypeName}RowMapper ${parameter.fieldName}RowMapper${'\n'}    ) {
        super();

        setDataSource(Objects.requireNonNull(jdbcTemplate.getDataSource()));

        setSql("select * from ${proc.fullName}(<#list proc.inputParameters as parameter>?<#sep>, )");

<#list proc.parameters as parameter>
<#if !parameter.returnResultSet>
        Sql<#if parameter.inputOutput>InOut<#elseif parameter.output>OutParameter sql${parameter.propertyName}${proc.className};



<#list proc.parameters as parameter>
<#if !parameter.returnResultSet>
        sql${parameter.propertyName}${proc.className} = new Sql<#if parameter.inputOutput>InOut<#elseif parameter.output>OutParameter(
                "${parameter.prefix}${parameter.name}",
                ${parameter.sqlTypeName}
        );



<#list proc.parameters as parameter>
<#if !parameter.returnResultSet>
        declareParameter(sql${parameter.propertyName}${proc.className});
<#else>
        try {
            setRowMapperClass(${parameter.javaTypeName}RowMapper.getClass());
        } catch (Exception ex) {
            // do nothing
        }



        compile();
    }

<#if documentation>
    /**
     * Execute the <#if proc.function>function<#else>stored procedure.
     *
     * @return response.
     * @param params input parameters.
     */

    public Map execute(final Map params) {
        Map map = new HashMap<<#if !diamond>String, Object>();
<#list proc.parameters as parameter>
<#if parameter.returnResultSet>
        map.put("${parameter.prefix}${parameter.name}", super.execute(params.values().toArray()));


        return map;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy