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

com.jk.db.dynamic.dataaccess.DynamicFacade Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2002-2016 Jalal Kiswani.
 *
 * 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.jk.db.dynamic.dataaccess;

import java.util.ArrayList;
import java.util.List;

import com.jk.db.datasource.JKDataSourceFactory;
import com.jk.db.datasource.JKSession;
import com.jk.metadata.db.meta.EntityRecord;

/**
 * The Class DynamicFacade.
 *
 * @author Jalal Kiswani
 */
public class DynamicFacade {

	/**
	 * Adds the master detail record.
	 *
	 * @param master
	 *            the master
	 * @param detailRecords
	 *            the detail records
	 * @return the string
	 */
	public String addMasterDetailRecord(final EntityRecord master, final List detailRecords) {
		final JKSession session = JKDataSourceFactory.getDefaultDataSource().createSession();
		boolean commit = false;
		try {
			final DynamicDataAccess dao = new DynamicDataAccess(master.getTableMeta());
			final String id = dao.insertRecord(master);
			for (final EntityRecord record : detailRecords) {
				record.setFieldValue(master.getIdField().getFieldName(), id);
				final DynamicDataAccess detailDao = DynamicDataAccessFactory.createDynamicDao(record.getTableMeta());
				detailDao.insertRecord(record);
			}
			commit = true;
			return id;
		} finally {
			session.close(commit);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy