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

templates.repository.sp.ProcedureImpl.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 = ["org.springframework.stereotype.Repository", "org.springframework.jdbc.object.StoredProcedure", "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}SPImpl${'\n'}        extends StoredProcedure${'\n'}        implements ${proc.className}SP {

<#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}SPImpl(${'\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(Objects.requireNonNull(jdbcTemplate.getDataSource()), SPROC_NAME);

        setFunction(<#if proc.function>true<#else>false);

<#if proc.parameters?size <= 10 >
<#assign noFullChunk = 1>
<#list proc.parameters as parameter>
        <#if parameter.returnResultSet>SqlReturnResultSet<#else>Sql<#if parameter.inputOutput>InOut<#elseif parameter.output>OutParameter ${parameter.fieldName}${proc.className};


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


<#list proc.parameters as parameter>
        declareParameter(${parameter.fieldName}${proc.className});

<#else>
<#assign step = 0 >
<#list proc.parameters?chunk(10) as childs>
<#assign step++ >
        fillStep${step}(<#assign jump = false><#list childs?filter(x -> x.resultSet || x.returnResultSet) as parameter><#assign jump = true>${'\n'}            ${parameter.fieldName}RowMapper<#sep>,<#if jump>${'\n'}    );



        compile();
    }
<#if ! noFullChunk?? >
<#assign step = 0 >
<#list proc.parameters?chunk(10) as childs>
<#assign step++ >

<#if documentation>
    /**
     * Fill parameters declaration for step ${step}.
     */

    private void fillStep${step}(<#assign jump = false><#list childs?filter(x -> x.resultSet || x.returnResultSet) as parameter><#assign jump = true>${'\n'}            final ${parameter.javaTypeName}RowMapper ${parameter.fieldName}RowMapper<#sep>,<#if jump>${'\n'}        ) {

<#list childs as paramrs>
        <#if paramrs.returnResultSet>SqlReturnResultSet<#else>Sql<#if paramrs.inputOutput>InOut<#elseif paramrs.output>OutParameter ${paramrs.fieldName}${proc.className};


<#list childs as paramrs>
        ${paramrs.fieldName}${proc.className} = new <#if paramrs.returnResultSet>SqlReturnResultSet<#else>Sql<#if paramrs.inputOutput>InOut<#elseif paramrs.output>OutParameter(
                "${paramrs.prefix}${paramrs.name}"<#if ! paramrs.returnResultSet >,
                ${paramrs.sqlTypeName}<#if paramrs.resultSet || paramrs.returnResultSet >,
                ${paramrs.fieldName}RowMapper
        );


<#list childs as paramrs>
        declareParameter(${paramrs.fieldName}${proc.className});

    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy