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

templates.util.CheckResultImpl.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}.${utilFolderName};
<#assign importList = ["java.sql.SQLException", "java.util.Map", "org.springframework.stereotype.Component"]>
<#if logger>
<#assign importList = importList + ["org.slf4j.Logger", "org.slf4j.LoggerFactory", "org.slf4j.Marker"]>


<#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>
/**
 * Check result from store procedure or function.
 *
 * @author @GENERATOR.NAME@
 * @version @GENERATOR.VERSION@
 */

@Component
public final class ${prefixUtilityName}CheckResultImpl
        implements ${prefixUtilityName}CheckResult {
<#if logger>

<#if documentation>
    /**
     * Logger.
     */

    private static final Logger LOGGER
            = LoggerFactory.getLogger(${prefixUtilityName}CheckResultImpl.class);


<#if documentation>
    /**
     * Success constant value.
     */

    private static final String <#if prefixUtilityName??>${prefixUtilityName?upper_case}_SUCCESS_CODE = "${successCode}";

<#if documentation>
    /**
     * Code to check.
     */

    private static final String <#if prefixUtilityName??>${prefixUtilityName?upper_case}_CODE = "${outParameterCode}";

<#if documentation>
    /**
     * Message to check.
     */

    private static final String <#if prefixUtilityName??>${prefixUtilityName?upper_case}_MESSAGE = "${outParameterMessage}";

<#if documentation>
    /**
     * {@inheritDoc}
     */

    @Override
    public void check(final Map map) throws SQLException {

        if (map == null) {
            return;
        }

        Number <#if prefixUtilityName??>${prefixUtilityName?uncap_first}Code<#else>code = (Number) map.get(<#if prefixUtilityName??>${prefixUtilityName?upper_case}_CODE);

        if (<#if prefixUtilityName??>${prefixUtilityName?uncap_first}Code<#else>code == null) {
            return;
        }

        if (!<#if prefixUtilityName??>${prefixUtilityName?upper_case}_SUCCESS_CODE.equals(<#if prefixUtilityName??>${prefixUtilityName?uncap_first}Code<#else>code.toString())) {
            String description = (String) map.get(<#if prefixUtilityName??>${prefixUtilityName?upper_case}_MESSAGE);
<#if logger>
            LOGGER.error(Marker.ANY_MARKER, "${outParameterCode}: {}", <#if prefixUtilityName??>${prefixUtilityName?uncap_first}Code<#else>code);
            LOGGER.error(Marker.ANY_MARKER, "${outParameterMessage}: {}", description);

            throw new SQLException(description, <#if prefixUtilityName??>${prefixUtilityName?uncap_first}Code<#else>code.toString());
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy