Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright (C) 2022-2023 WaveMaker, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.wavemaker.runtime.data.dao.callbacks;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.orm.hibernate5.HibernateOperations;
import com.wavemaker.commons.MessageResource;
import com.wavemaker.commons.WMRuntimeException;
import com.wavemaker.runtime.data.dao.procedure.parameters.ResolvableParam;
import com.wavemaker.runtime.data.model.JavaType;
import com.wavemaker.runtime.data.model.procedures.ProcedureParameter;
import com.wavemaker.runtime.data.transform.Transformers;
import com.wavemaker.runtime.data.transform.WMResultTransformer;
import com.wavemaker.runtime.data.util.JDBCUtils;
/**
* @author Dilip Kumar
* @since 16/11/16
*/
public class NativeProcedureExecutor {
private NativeProcedureExecutor() {
}
public static final String CONTENT_FIELD = "content";
public static T execute(HibernateOperations hibernateOperations, String jdbcQuery, List params, Class type) {
return hibernateOperations.execute(session -> session.doReturningWork(connection -> {
CallableStatement statement = prepareStatement(connection, jdbcQuery, params);
boolean resultSetType = statement.execute();
Map result = getResultMap(statement, params, resultSetType, 0);
return convert(result, type);
}));
}
public static CallableStatement prepareStatement(
Connection connection, String jdbcQuery, List params) throws SQLException {
final CallableStatement statement = connection.prepareCall(jdbcQuery);
configureParameters(statement, params);
return statement;
}
public static Map getResultMap(
final CallableStatement statement, final List params,
final boolean resultSetType, final int limit) throws SQLException {
Map result = new LinkedHashMap<>();
if (resultSetType) {
result.put(CONTENT_FIELD, readResultSet(statement.getResultSet(), limit));
}
result.putAll(readResponse(statement, params, limit));
return result;
}
public static List