templates.repository.sp.SqlQueryImpl.ftl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of autoplsp Show documentation
Show all versions of autoplsp Show documentation
Maven plugin to generate Java classes from StoredProcedure and Functions in Database
<#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}.repository.sp;
<#list proc.parameters as parameter>
<#if parameter.inputOutput>
<#assign fillInOut = 1>
<#elseif parameter.output>
<#assign fillOut = 1>
<#elseif parameter.input>
<#assign fillIn = 1>
<#elseif parameter.returnResultSet>
<#assign fillResultSet = 1>
<#if parameter.resultSet || parameter.returnResultSet>
<#assign fillSpace = 1>
import ${javaPackage}.repository.mapper.${parameter.javaTypeName}RowMapper;
<#if fillSpace??>
import java.util.Map;
import org.springframework.jdbc.core.JdbcTemplate;
<#if fillInOut??>
import org.springframework.jdbc.core.SqlInOutParameter;
<#if fillOut??>
import org.springframework.jdbc.core.SqlOutParameter;
<#if fillIn??>
import org.springframework.jdbc.core.SqlParameter;
<#if fillResultSet??>
import org.springframework.jdbc.core.SqlReturnResultSet;
import org.springframework.jdbc.object.GenericSqlQuery;
/**
* DAO for <#if proc.function>function<#else>stored procedure.
*
* ${proc.fullName}
*
* @author @GENERATOR.NAME@
* @version @GENERATOR.VERSION@
*/
public final class ${proc.className}SqlQueryImpl
extends GenericSqlQuery
implements ${proc.className}SqlQuery {
/**
* Full <#if proc.function>function<#else>stored procedure name.
*/
public static final String SPROC_NAME
= "${proc.fullName}";
/**
* Class constructor from jdbcTemplate.
*
* @param jdbcTemplate jdbcTemplate
*/
public ${proc.className}SqlQueryImpl(final JdbcTemplate jdbcTemplate) {
super();
setDataSource(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};
<#list proc.parameters as parameter>
<#if !parameter.returnResultSet>
sql${parameter.propertyName} = 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});
<#else>
try {
setRowMapperClass(new ${parameter.javaTypeName}RowMapper().getClass());
} catch (Exception ex) {
}
compile();
}
/**
* 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;
}
}