ChangeLogCSkin.java 3.21 KB
/*
 * @(#)ChangeLogCSkin.java	1.7.1,126 custom	2014-06-22T22:00:00Z UTC
 * Built automatically by REVERSER
 */
package it.softecspa.fileproxy.db.skins.criterias;


import it.softecspa.database.dbconnect.ConnectionManager;
import it.softecspa.database.dbconnect.Query;
import it.softecspa.fileproxy.db.ChangeLog;
import it.softecspa.kahuna.sql.SqlWriter;
import it.softecspa.kahuna.util.calendar.EnterpriseCalendar;

import org.apache.log4j.Logger;


/**
 * Abstract criteria filter for table A001_CHANGE_LOG
 * Class auto generated by REVERSER, version 1.7.1,126 custom
 * 
 * Warning: this class will be rewrited from REVERSER
 * 
 * @author il Vera
 */
public abstract class ChangeLogCSkin {


	protected Logger log = Logger.getLogger(getClass());

	protected ConnectionManager cm;

	// V_CODE - VARCHAR(30) NOT NULL PK
	protected String code;

	// V_DESCRIPTION - VARCHAR(100) NOT NULL
	protected String description;

	// D_CHANGE - DATETIME NOT NULL
	// protected EnterpriseCalendar change;

	protected String custom_order_by;
	protected String custom_add_where;
	protected String custom_add_options;


	protected ChangeLogCSkin(ConnectionManager cm) {
		super();
		this.cm = cm;
	}


	public String getCode() {
		return this.code;
	}

	public void setCode(String value) {
		this.code = value;
	}


	public String getDescription() {
		return this.description;
	}

	public void setDescription(String value) {
		this.description = value;
	}


	/**
	 * ORDER BY condition
	 */
	public void orderBy(String value) {
		this.custom_order_by = value;
	}

	/**
	 * Custom WHERE condition to add in query composition
	 */
	public void addCustomWhere(String value) {
		this.custom_add_where = value;
	}

	/**
	 * Custom option to add in query composition
	 */
	public void addCustomOptions(String value) {
		this.custom_add_options = value;
	}



	public ConnectionManager getConnectionManager() {
		return this.cm;
	}

	/**
	 * Columns used in select with alias
	 */
	protected String getColumns(String alias) {
		return alias+".v_code" +
		  ", "+alias+".v_description" +
		  ", "+alias+".d_change";
	}

	/**
	 * Build select * using alias
	 */
	protected SqlWriter getSelectAll(String alias) {
		SqlWriter sql = new SqlWriter();
		sql.setColumns(getColumns(alias));
		sql.setTables(ChangeLog.NAME +" "+ alias);
		return sql;
	}

	/**
	 * Build select * with filter with standard alias 't'
	 */
	protected SqlWriter getSelect() {
		return getSelect("t");
	}

	/**
	 * Build select * with filter using custom alias
	 */
	protected SqlWriter getSelect(String alias) {
		SqlWriter sql = getSelectAll(alias);
		if (this.code != null)			 sql.addWhere(alias+".v_code = "+ sql.fStr(this.code));
		if (this.description != null)			 sql.addWhere(alias+".v_description = "+ sql.fStr(this.description));
		// No query condition set for column D_CHANGE

		// Custom WHERE
		if (this.custom_add_where!=null) sql.addWhere(this.custom_add_where);
		// Custom OPTIONS
		if (this.custom_add_options!=null) sql.addOption(this.custom_add_options);
		// Custom ORDER_BY
		if (this.custom_order_by!=null) sql.addOption("ORDER BY "+this.custom_order_by);

		return sql;
	}


}