templates.util.ObjectUtilImpl.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}.util;
import java.sql.Connection;
import java.sql.SQLException;
<#if logger>
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
<#if driverName == 'oracle'>
import oracle.jdbc.OracleConnection;
<#if driverVersionName == 'ojdbc6' >
import oracle.sql.StructDescriptor;
import oracle.sql.STRUCT;
import org.springframework.stereotype.Component;
/**
* Class to process object element.
*
* @author @GENERATOR.NAME@
* @version @GENERATOR.VERSION@
*/
@Component
<#if driverVersionName == 'ojdbc6' >
@SuppressWarnings({"deprecation"})
public final class ObjectUtilImpl
implements ObjectUtil {
<#if logger>
/**
* Logger.
*/
private static final Logger LOGGER
= LoggerFactory.getLogger(ObjectUtilImpl.class);
/**
* {@inheritDoc}
*/
@Override
public Object process(
final Connection connection,
final String name,
final Object[] objects
) throws SQLException {
<#if driverName != 'oracle' >
throw new SQLException(
"Driver ${driverName} not supported",
"${successCode}"
);
<#else>
try {
OracleConnection oConn = connection.unwrap(OracleConnection.class);
<#if driverVersionName == 'ojdbc6' >
StructDescriptor descriptor;
descriptor = StructDescriptor.createDescriptor(
name,
oConn
);
return new STRUCT(descriptor, oConn, objects);
<#else>
return oConn.createStruct(name, objects);
} catch (Exception ex) {
<#if logger>
LOGGER.error(ex.getMessage(), ex);
throw new SQLException(ex.getMessage(), "${successCode}", ex);
}
}
}