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

import it.softecspa.database.dbconnect.ConnectionManager;
import it.softecspa.database.dbconnect.DatabaseStatement;
import it.softecspa.database.dbconnect.NoRecordFoundException;
import it.softecspa.database.dbconnect.UpdatableRow;
import it.softecspa.fileproxy.db.criterias.ConfigPropertiesCriteria;
import it.softecspa.kahuna.sql.SqlWriter;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

/**
 * Abstract manager for table T001_CONFIG_PROPERTIES
 * 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 ConfigPropertiesSkin extends UpdatableRow implements Cloneable {


	// Table name: T001_CONFIG_PROPERTIES
	public static final String NAME = "t001_config_properties";

	public static final String ALIAS = "t001";


	protected Logger log = Logger.getLogger(ConfigPropertiesSkin.class);

	// V_KEY - VARCHAR(50) NOT NULL PK
	protected String key;

	// V_VALUE - VARCHAR(256) NOT NULL
	protected String value;

	// V_DESCRIPTION - VARCHAR(100) nullable
	protected String description;


	protected ConfigPropertiesSkin() {
		super();
	}

	/**
	 * Extract bean using key
	 */
	protected ConfigPropertiesSkin(ConnectionManager cm, String key) throws NoRecordFoundException, SQLException {
		this();
		// Setup key filter values
		ConfigPropertiesCriteria filter = new ConfigPropertiesCriteria(cm);
		filter.setKey(key);
		readRow(cm, filter.getSelect().costruisciSelect());
	}


	public String getKey() {
		return this.key;
	}

	public void setKey(String value) {
		this.key = value;
	}

	public String getValue() {
		return this.value;
	}

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

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

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


	@Override
	public ConfigPropertiesSkin clone() throws CloneNotSupportedException {
		ConfigPropertiesSkin c = (ConfigPropertiesSkin) super.clone();
		//
		// Not primitive or not immutable objects
		//
		return c;
	}


	/**
	 * Standard implementation of update method
	 * @param updateType operation to execute
	 * @param dbs DatabaseStatement that perform operation
	 * @return number of update rows or new autoincrement id
	 * @throws SQLException if there is an error in your query
	 */
	public int updateRecord(UpdateType updateType, DatabaseStatement dbs) throws SQLException {
		SqlWriter sql = new SqlWriter();
		sql.setTables(NAME);
		if (updateType == INSERT) {
			sql.addValue("v_key"			, sql.fStr(this.key));
			sql.addValue("v_value"			, sql.fStr(this.value));
			sql.addValue("v_description"			, sql.fStr(this.description));
			int _retval = dbs.execute(sql.costruisciInsert());
			return _retval;

		} else if (updateType == UPDATE) {
			sql.addColumnSET("v_value"			, sql.fStr(this.value));
			sql.addColumnSET("v_description"			, sql.fStr(this.description));
			sql.addWhere("v_key = " +sql.fStr(this.key));
			return dbs.execute(sql.costruisciUpdate());

		} else if (updateType == DELETE) {
			sql.addWhere("v_key = " +sql.fStr(this.key));
			return dbs.execute(sql.costruisciDelete());
		}
		return 0;
	}
	
	protected void readRow(ResultSet rs) throws SQLException {
		setKey(rs.getString("v_key"));
		// -------
		setValue(rs.getString("v_value"));
		setDescription(rs.getString("v_description"));
	}

}