/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kr.co.kihyun.beans.ecross;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.jdo.Query;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import kr.co.kihyun.beans.entity.AcceptanceLimitStrategy;
import kr.co.kihyun.beans.entity.Board;
import kr.co.kihyun.beans.entity.MDept;
import kr.co.kihyun.beans.entity.TotDoc;
import kr.co.kihyun.beans.entity.TotItem;
import kr.co.kihyun.beans.entity.TotReport;
import kr.co.kihyun.beans.entity.TotTable;
import kr.co.kihyun.beans.entity.ecross.CRUD;
import kr.co.kihyun.beans.entity.ecross.ECross;
import kr.co.kihyun.beans.entity.ecross.IRemotePersistable;
import kr.co.kihyun.beans.entity.ecross.ReceiverTotReport;
import kr.co.kihyun.beans.entity.util.MPersistenceManager;
import kr.co.kihyun.beans.totsys.report.ReportsView;
import kr.co.kihyun.moumi.MoumiConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author bhs
 */
public final class VCMCCMC2016 extends ECrossInterface {

	private static final Logger LOG = LoggerFactory.getLogger(VCMCCMC2016.class);

	private TotReport totReport;

	public VCMCCMC2016(TotReport totReport) {
		super(AcceptanceLimitStrategy.class, TotDoc.class, TotReport.class);
		this.totReport = totReport;
	}

	public void saveAll(MPersistenceManager moumiPm, MPersistenceManager eCrossPm) {
		List<MDept> parties = new ArrayList<MDept>();
		parties.add(eCrossPm.getObjectById(MDept.class, totReport.getTotDoc().getDept()));
		for (MDept party : parties) {
			LOG.debug("send to {}, {}, {}, {}", new Object[] {totReport, totReport.getTotDoc(), totReport.getTotDoc().getDept(), party});
		}

		saveAll(moumiPm, eCrossPm, parties);
	}

	public void saveAll(MPersistenceManager moumiPm, MPersistenceManager eCrossPm, MDept party) {
		List<MDept> parties = new ArrayList<MDept>();
		parties.add(party);

		saveAll(moumiPm, eCrossPm, parties);
	}

	@Override
	public void saveAll(MPersistenceManager moumiPm, MPersistenceManager eCrossPm, Collection<MDept> parties) {
		this.save(moumiPm, eCrossPm, totReport, CRUD.U, parties);
		TotDoc slaveTotDoc = totReport.getSlaveTotDoc();
		if (slaveTotDoc != null) {
			this.save(moumiPm, eCrossPm, slaveTotDoc.getAcceptanceLimitStrategy(), CRUD.C, parties);
			this.save(moumiPm, eCrossPm, slaveTotDoc, CRUD.C, parties);
			this.saveAll(moumiPm, eCrossPm, slaveTotDoc.getTotReports(), CRUD.C, parties);
		}
	}
}
