<?php


abstract class BaseVioletprokey extends BaseObject  implements Persistent {


	
	protected static $peer;

	
	protected $vp_prokey;

	
	protected $vp_type;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function __construct()
	{
		parent::__construct();
		$this->applyDefaultValues();
	}

	
	public function applyDefaultValues()
	{
		$this->vp_type = 0;
	}

	
	public function getVpProkey()
	{
		return $this->vp_prokey;
	}

	
	public function getVpType()
	{
		return $this->vp_type;
	}

	
	public function setVpProkey($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->vp_prokey !== $v) {
			$this->vp_prokey = $v;
			$this->modifiedColumns[] = VioletprokeyPeer::VP_PROKEY;
		}

		return $this;
	} 
	
	public function setVpType($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->vp_type !== $v || $v === 0) {
			$this->vp_type = $v;
			$this->modifiedColumns[] = VioletprokeyPeer::VP_TYPE;
		}

		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array(VioletprokeyPeer::VP_TYPE))) {
				return false;
			}

			if ($this->vp_type !== 0) {
				return false;
			}

				return true;
	} 
	
	public function hydrate($row, $startcol = 0, $rehydrate = false)
	{
		try {

			$this->vp_prokey = ($row[$startcol + 0] !== null) ? (string) $row[$startcol + 0] : null;
			$this->vp_type = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
			$this->resetModified();

			$this->setNew(false);

			if ($rehydrate) {
				$this->ensureConsistency();
			}

						return $startcol + 2; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Violetprokey object", $e);
		}
	}

	
	public function ensureConsistency()
	{

	} 
	
	public function reload($deep = false, PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("Cannot reload a deleted object.");
		}

		if ($this->isNew()) {
			throw new PropelException("Cannot reload an unsaved object.");
		}

		if ($con === null) {
			$con = Propel::getConnection(VioletprokeyPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = VioletprokeyPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
		$row = $stmt->fetch(PDO::FETCH_NUM);
		$stmt->closeCursor();
		if (!$row) {
			throw new PropelException('Cannot find matching row in the database to reload object values.');
		}
		$this->hydrate($row, 0, true); 
		if ($deep) {  
		} 	}

	
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(VioletprokeyPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			VioletprokeyPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	public function save(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(VioletprokeyPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			VioletprokeyPeer::addInstanceToPool($this);
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	protected function doSave(PropelPDO $con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = VioletprokeyPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += VioletprokeyPeer::doUpdate($this, $con);
				}

				$this->resetModified(); 			}

			$this->alreadyInSave = false;

		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = VioletprokeyPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = VioletprokeyPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		$field = $this->getByPosition($pos);
		return $field;
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getVpProkey();
				break;
			case 1:
				return $this->getVpType();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = VioletprokeyPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getVpProkey(),
			$keys[1] => $this->getVpType(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = VioletprokeyPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setVpProkey($value);
				break;
			case 1:
				$this->setVpType($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = VioletprokeyPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setVpProkey($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setVpType($arr[$keys[1]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(VioletprokeyPeer::DATABASE_NAME);

		if ($this->isColumnModified(VioletprokeyPeer::VP_PROKEY)) $criteria->add(VioletprokeyPeer::VP_PROKEY, $this->vp_prokey);
		if ($this->isColumnModified(VioletprokeyPeer::VP_TYPE)) $criteria->add(VioletprokeyPeer::VP_TYPE, $this->vp_type);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(VioletprokeyPeer::DATABASE_NAME);

		$criteria->add(VioletprokeyPeer::VP_PROKEY, $this->vp_prokey);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getVpProkey();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setVpProkey($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setVpProkey($this->vp_prokey);

		$copyObj->setVpType($this->vp_type);


		$copyObj->setNew(true);

	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new VioletprokeyPeer();
		}
		return self::$peer;
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
		} 
	}

} 