com.wavemaker.runtime.data.service.AbstractDesignService Maven / Gradle / Ivy
/*******************************************************************************
* 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.service;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import com.wavemaker.commons.util.StringTemplate;
import com.wavemaker.runtime.commons.WMAppContext;
import com.wavemaker.runtime.data.model.ReferenceType;
import com.wavemaker.runtime.data.model.returns.FieldType;
import com.wavemaker.runtime.data.model.returns.ReturnProperty;
/**
* @author Dilip Kumar
* @since 17/11/16
*/
public abstract class AbstractDesignService {
private static final StringTemplate TRANSACTION_MANAGER_BEAN_ST = new StringTemplate(
"${serviceId}TransactionManager");
protected T executeInTransaction(String serviceId, TransactionCallback callback) {
final String transactionManagerBeanName = TRANSACTION_MANAGER_BEAN_ST
.substitute(getStringTemplateMap(serviceId));
PlatformTransactionManager transactionManager = WMAppContext.getInstance()
.getSpringBean(transactionManagerBeanName);
TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
return txTemplate.execute(callback);
}
@SuppressWarnings("unchecked")
protected List extractMetaFromResults(Collection