package com.fp.hbm.bgenerator.ann;

import java.io.PrintWriter;
import java.io.StringWriter;

import com.fp.hbm.bgenerator.AbstractColumn;
import com.fp.common.exception.APPException;

public class MapperColumn extends AbstractColumn {

	public MapperColumn() {
		super();
	}

	public String formatProperty() {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		pw.println("@Column(name=\"" + this.name.toUpperCase() + "\", nullable=" + nullable +(this.pk ?",updatable=false" : "") + ")");
		String data = sw.toString();
		pw.close();
		return data;
	}

	public String formatJava() throws APPException {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		pw.println("/**");
		pw.println("* " + this.getComments());
		pw.println("*/");
		name = name.toLowerCase();
		pw.println("private " + getJavaSimple() + " " + this.name + ";");

		String data = sw.toString();
		pw.close();
		return data;
	}

	@Override
	public void formatSinglePK(PrintWriter pw) {
		pw.println("@Id");

	}

	@Override
	public String formatComposeKey() {

		return null;
	}
}
