//
// https://www.ramecera.it/myscrewdriver.html
// e-mail: screwdriver@ramecera.it
//
/* This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License v1.0 which accompanies this
 * distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html */
package it.ramecera.screwdriver.component;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import it.ramecera.salad.everyday.Candies;
import it.ramecera.salad.everyday.ExactException;
import it.ramecera.screwdriver.CandyScrew;
import it.ramecera.screwdriver.Cst;
import it.ramecera.screwdriver.Markup;
import it.ramecera.screwdriver.Skill;
import it.ramecera.screwdriver.Train;
import it.ramecera.screwdriver.outfits.TableOutfit;

/** @author M. Maglioni */
final public class ImplementTableDao_java extends FileComponent {

	/** @param skill application descriptive data set
	 * @param snippetG path and snippet file name (fragment)
	 * @param candies external properties of the application */
	public ImplementTableDao_java(Skill skill, String snippetG,
			CandyScrew candies) {
		super();
		this.skill = skill;
		this.snippetG = snippetG;
		this.candies = candies;
	}

	/** @throws ExactException exception specified by a numeric code */
	@Override
	public void synthesis(HashMap<String, Markup> markupE,
			List<Train> trainE, CandyScrew candyScrew)

			throws FileNotFoundException, IOException, ExactException {

		String[] tipo = locateKey(skill.tableDBE.get(skill.tK));
		TableOutfit ct = skill.tableDBE.get(skill.tK);
		producedMaterial += "package " + skill.pckg + "."
				+ ct.railLowercase + ".dao.impl;" + Candies.LF
				+ Candies.LF;
		producedMaterial += "import org.hibernate.Criteria;"
				+ Candies.LF;
		producedMaterial += "import org.hibernate.criterion.Projections;"
				+ Candies.LF;
		producedMaterial += "import org.springframework.dao.DataAccessException;"
				+ Candies.LF;
		producedMaterial += "import org.springframework.stereotype.Repository;"
				+ Candies.LF + Candies.LF;
		producedMaterial += "import " + skill.pckg + "."
				+ ct.railLowercase + ".dao.I" + ct.railUppercase
				+ ct.entityName + "Dao;" + Candies.LF;
		producedMaterial += "import " + ct.pathDots + "."
				+ ct.entityName + ";" + Candies.LF;
		if (tipo[0].equals("EmbeddedId")) {
			producedMaterial += "import " + ct.pathDots + "." + tipo[1]
					+ ";" + Candies.LF;
		}
		producedMaterial += "import " + skill.pckg + "."
				+ ct.railLowercase + ".Generic" + ct.railUppercase
				+ "DaoImpl;" + Candies.LF + Candies.LF;
		if (skill.log4jVers != null) {
			producedMaterial += "import org.apache.log4j.Logger;"
					+ Candies.LF + Candies.LF;
		}
		producedMaterial += "@Repository" + Candies.LF;
		if (skill.jpaVersion == 1) {
			producedMaterial += "public class " + ct.railUppercase
					+ ct.entityName + "Dao extends" + Candies.LF
					+ Candies.LF;
			producedMaterial += Candies.TABS + Candies.TABS + "Generic"
					+ ct.railUppercase + "DaoImpl<" + ct.entityName
					+ ", " + tipo[1] + ">" + Candies.LF + Candies.LF;
			producedMaterial += Candies.TABS + "implements I"
					+ ct.railUppercase + ct.entityName + "Dao {"
					+ Candies.LF + Candies.LF;
		} else {
			producedMaterial += "public class " + ct.railUppercase
					+ ct.entityName + "Dao<T> extends" + Candies.LF
					+ Candies.LF;
			producedMaterial += Candies.TABS + Candies.TABS + "Generic"
					+ ct.railUppercase + "DaoImpl<T>" + Candies.LF
					+ Candies.LF;
			producedMaterial += Candies.TABS + "implements I"
					+ ct.railUppercase + ct.entityName + "Dao<T> {"
					+ Candies.LF + Candies.LF;
		}
		if (skill.log4jVers != null) {
			producedMaterial += Candies.TABS + "/** ordinary logger */"
					+ Candies.LF;
			producedMaterial += Candies.TABS
					+ "@SuppressWarnings(\"unused\")" + Candies.LF;
			producedMaterial += Candies.TABS
					+ "private static Logger logger = Logger.getLogger("
					+ Candies.LF + Candies.TABS + Candies.TABS
					+ Candies.TABS + ct.railUppercase + ct.entityName
					+ "Dao" + ".class);" + Candies.LF + Candies.LF;
		}
		producedMaterial += Candies.TABS + "/* " + Cst.KNIFE + " */"
				+ Candies.LF;
		producedMaterial += "}";
	}

	/* written only to comply with the abstract class FileComponent */
	@SuppressWarnings("javadoc")
	@Override
	/** @param markupE the list of markups
	 * @param skill together with the descriptive data of the
	 *        application
	 * @param file basket where the deleted files are moved
	 * @throws ExactException exception specified by a numerical code */
	public void directory(HashMap<String, Markup> markupE)

			throws ExactException {

	}
}
