BaseCcCountryPeer.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. <?php
  2. /**
  3. * Base static class for performing query and update operations on the 'cc_country' table.
  4. *
  5. *
  6. *
  7. * @package propel.generator.airtime.om
  8. */
  9. abstract class BaseCcCountryPeer {
  10. /** the default database name for this class */
  11. const DATABASE_NAME = 'airtime';
  12. /** the table name for this class */
  13. const TABLE_NAME = 'cc_country';
  14. /** the related Propel class for this table */
  15. const OM_CLASS = 'CcCountry';
  16. /** A class that can be returned by this peer. */
  17. const CLASS_DEFAULT = 'airtime.CcCountry';
  18. /** the related TableMap class for this table */
  19. const TM_CLASS = 'CcCountryTableMap';
  20. /** The total number of columns. */
  21. const NUM_COLUMNS = 2;
  22. /** The number of lazy-loaded columns. */
  23. const NUM_LAZY_LOAD_COLUMNS = 0;
  24. /** the column name for the ISOCODE field */
  25. const ISOCODE = 'cc_country.ISOCODE';
  26. /** the column name for the NAME field */
  27. const NAME = 'cc_country.NAME';
  28. /**
  29. * An identiy map to hold any loaded instances of CcCountry objects.
  30. * This must be public so that other peer classes can access this when hydrating from JOIN
  31. * queries.
  32. * @var array CcCountry[]
  33. */
  34. public static $instances = array();
  35. /**
  36. * holds an array of fieldnames
  37. *
  38. * first dimension keys are the type constants
  39. * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
  40. */
  41. private static $fieldNames = array (
  42. BasePeer::TYPE_PHPNAME => array ('DbIsoCode', 'DbName', ),
  43. BasePeer::TYPE_STUDLYPHPNAME => array ('dbIsoCode', 'dbName', ),
  44. BasePeer::TYPE_COLNAME => array (self::ISOCODE, self::NAME, ),
  45. BasePeer::TYPE_RAW_COLNAME => array ('ISOCODE', 'NAME', ),
  46. BasePeer::TYPE_FIELDNAME => array ('isocode', 'name', ),
  47. BasePeer::TYPE_NUM => array (0, 1, )
  48. );
  49. /**
  50. * holds an array of keys for quick access to the fieldnames array
  51. *
  52. * first dimension keys are the type constants
  53. * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
  54. */
  55. private static $fieldKeys = array (
  56. BasePeer::TYPE_PHPNAME => array ('DbIsoCode' => 0, 'DbName' => 1, ),
  57. BasePeer::TYPE_STUDLYPHPNAME => array ('dbIsoCode' => 0, 'dbName' => 1, ),
  58. BasePeer::TYPE_COLNAME => array (self::ISOCODE => 0, self::NAME => 1, ),
  59. BasePeer::TYPE_RAW_COLNAME => array ('ISOCODE' => 0, 'NAME' => 1, ),
  60. BasePeer::TYPE_FIELDNAME => array ('isocode' => 0, 'name' => 1, ),
  61. BasePeer::TYPE_NUM => array (0, 1, )
  62. );
  63. /**
  64. * Translates a fieldname to another type
  65. *
  66. * @param string $name field name
  67. * @param string $fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  68. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
  69. * @param string $toType One of the class type constants
  70. * @return string translated name of the field.
  71. * @throws PropelException - if the specified name could not be found in the fieldname mappings.
  72. */
  73. static public function translateFieldName($name, $fromType, $toType)
  74. {
  75. $toNames = self::getFieldNames($toType);
  76. $key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
  77. if ($key === null) {
  78. throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
  79. }
  80. return $toNames[$key];
  81. }
  82. /**
  83. * Returns an array of field names.
  84. *
  85. * @param string $type The type of fieldnames to return:
  86. * One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  87. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
  88. * @return array A list of field names
  89. */
  90. static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
  91. {
  92. if (!array_key_exists($type, self::$fieldNames)) {
  93. throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.');
  94. }
  95. return self::$fieldNames[$type];
  96. }
  97. /**
  98. * Convenience method which changes table.column to alias.column.
  99. *
  100. * Using this method you can maintain SQL abstraction while using column aliases.
  101. * <code>
  102. * $c->addAlias("alias1", TablePeer::TABLE_NAME);
  103. * $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
  104. * </code>
  105. * @param string $alias The alias for the current table.
  106. * @param string $column The column name for current table. (i.e. CcCountryPeer::COLUMN_NAME).
  107. * @return string
  108. */
  109. public static function alias($alias, $column)
  110. {
  111. return str_replace(CcCountryPeer::TABLE_NAME.'.', $alias.'.', $column);
  112. }
  113. /**
  114. * Add all the columns needed to create a new object.
  115. *
  116. * Note: any columns that were marked with lazyLoad="true" in the
  117. * XML schema will not be added to the select list and only loaded
  118. * on demand.
  119. *
  120. * @param Criteria $criteria object containing the columns to add.
  121. * @param string $alias optional table alias
  122. * @throws PropelException Any exceptions caught during processing will be
  123. * rethrown wrapped into a PropelException.
  124. */
  125. public static function addSelectColumns(Criteria $criteria, $alias = null)
  126. {
  127. if (null === $alias) {
  128. $criteria->addSelectColumn(CcCountryPeer::ISOCODE);
  129. $criteria->addSelectColumn(CcCountryPeer::NAME);
  130. } else {
  131. $criteria->addSelectColumn($alias . '.ISOCODE');
  132. $criteria->addSelectColumn($alias . '.NAME');
  133. }
  134. }
  135. /**
  136. * Returns the number of rows matching criteria.
  137. *
  138. * @param Criteria $criteria
  139. * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
  140. * @param PropelPDO $con
  141. * @return int Number of matching rows.
  142. */
  143. public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
  144. {
  145. // we may modify criteria, so copy it first
  146. $criteria = clone $criteria;
  147. // We need to set the primary table name, since in the case that there are no WHERE columns
  148. // it will be impossible for the BasePeer::createSelectSql() method to determine which
  149. // tables go into the FROM clause.
  150. $criteria->setPrimaryTableName(CcCountryPeer::TABLE_NAME);
  151. if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
  152. $criteria->setDistinct();
  153. }
  154. if (!$criteria->hasSelectClause()) {
  155. CcCountryPeer::addSelectColumns($criteria);
  156. }
  157. $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
  158. $criteria->setDbName(self::DATABASE_NAME); // Set the correct dbName
  159. if ($con === null) {
  160. $con = Propel::getConnection(CcCountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  161. }
  162. // BasePeer returns a PDOStatement
  163. $stmt = BasePeer::doCount($criteria, $con);
  164. if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
  165. $count = (int) $row[0];
  166. } else {
  167. $count = 0; // no rows returned; we infer that means 0 matches.
  168. }
  169. $stmt->closeCursor();
  170. return $count;
  171. }
  172. /**
  173. * Method to select one object from the DB.
  174. *
  175. * @param Criteria $criteria object used to create the SELECT statement.
  176. * @param PropelPDO $con
  177. * @return CcCountry
  178. * @throws PropelException Any exceptions caught during processing will be
  179. * rethrown wrapped into a PropelException.
  180. */
  181. public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
  182. {
  183. $critcopy = clone $criteria;
  184. $critcopy->setLimit(1);
  185. $objects = CcCountryPeer::doSelect($critcopy, $con);
  186. if ($objects) {
  187. return $objects[0];
  188. }
  189. return null;
  190. }
  191. /**
  192. * Method to do selects.
  193. *
  194. * @param Criteria $criteria The Criteria object used to build the SELECT statement.
  195. * @param PropelPDO $con
  196. * @return array Array of selected Objects
  197. * @throws PropelException Any exceptions caught during processing will be
  198. * rethrown wrapped into a PropelException.
  199. */
  200. public static function doSelect(Criteria $criteria, PropelPDO $con = null)
  201. {
  202. return CcCountryPeer::populateObjects(CcCountryPeer::doSelectStmt($criteria, $con));
  203. }
  204. /**
  205. * Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
  206. *
  207. * Use this method directly if you want to work with an executed statement durirectly (for example
  208. * to perform your own object hydration).
  209. *
  210. * @param Criteria $criteria The Criteria object used to build the SELECT statement.
  211. * @param PropelPDO $con The connection to use
  212. * @throws PropelException Any exceptions caught during processing will be
  213. * rethrown wrapped into a PropelException.
  214. * @return PDOStatement The executed PDOStatement object.
  215. * @see BasePeer::doSelect()
  216. */
  217. public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
  218. {
  219. if ($con === null) {
  220. $con = Propel::getConnection(CcCountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  221. }
  222. if (!$criteria->hasSelectClause()) {
  223. $criteria = clone $criteria;
  224. CcCountryPeer::addSelectColumns($criteria);
  225. }
  226. // Set the correct dbName
  227. $criteria->setDbName(self::DATABASE_NAME);
  228. // BasePeer returns a PDOStatement
  229. return BasePeer::doSelect($criteria, $con);
  230. }
  231. /**
  232. * Adds an object to the instance pool.
  233. *
  234. * Propel keeps cached copies of objects in an instance pool when they are retrieved
  235. * from the database. In some cases -- especially when you override doSelect*()
  236. * methods in your stub classes -- you may need to explicitly add objects
  237. * to the cache in order to ensure that the same objects are always returned by doSelect*()
  238. * and retrieveByPK*() calls.
  239. *
  240. * @param CcCountry $value A CcCountry object.
  241. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  242. */
  243. public static function addInstanceToPool(CcCountry $obj, $key = null)
  244. {
  245. if (Propel::isInstancePoolingEnabled()) {
  246. if ($key === null) {
  247. $key = (string) $obj->getDbIsoCode();
  248. } // if key === null
  249. self::$instances[$key] = $obj;
  250. }
  251. }
  252. /**
  253. * Removes an object from the instance pool.
  254. *
  255. * Propel keeps cached copies of objects in an instance pool when they are retrieved
  256. * from the database. In some cases -- especially when you override doDelete
  257. * methods in your stub classes -- you may need to explicitly remove objects
  258. * from the cache in order to prevent returning objects that no longer exist.
  259. *
  260. * @param mixed $value A CcCountry object or a primary key value.
  261. */
  262. public static function removeInstanceFromPool($value)
  263. {
  264. if (Propel::isInstancePoolingEnabled() && $value !== null) {
  265. if (is_object($value) && $value instanceof CcCountry) {
  266. $key = (string) $value->getDbIsoCode();
  267. } elseif (is_scalar($value)) {
  268. // assume we've been passed a primary key
  269. $key = (string) $value;
  270. } else {
  271. $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or CcCountry object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
  272. throw $e;
  273. }
  274. unset(self::$instances[$key]);
  275. }
  276. } // removeInstanceFromPool()
  277. /**
  278. * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
  279. *
  280. * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
  281. * a multi-column primary key, a serialize()d version of the primary key will be returned.
  282. *
  283. * @param string $key The key (@see getPrimaryKeyHash()) for this instance.
  284. * @return CcCountry Found object or NULL if 1) no instance exists for specified key or 2) instance pooling has been disabled.
  285. * @see getPrimaryKeyHash()
  286. */
  287. public static function getInstanceFromPool($key)
  288. {
  289. if (Propel::isInstancePoolingEnabled()) {
  290. if (isset(self::$instances[$key])) {
  291. return self::$instances[$key];
  292. }
  293. }
  294. return null; // just to be explicit
  295. }
  296. /**
  297. * Clear the instance pool.
  298. *
  299. * @return void
  300. */
  301. public static function clearInstancePool()
  302. {
  303. self::$instances = array();
  304. }
  305. /**
  306. * Method to invalidate the instance pool of all tables related to cc_country
  307. * by a foreign key with ON DELETE CASCADE
  308. */
  309. public static function clearRelatedInstancePool()
  310. {
  311. }
  312. /**
  313. * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
  314. *
  315. * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
  316. * a multi-column primary key, a serialize()d version of the primary key will be returned.
  317. *
  318. * @param array $row PropelPDO resultset row.
  319. * @param int $startcol The 0-based offset for reading from the resultset row.
  320. * @return string A string version of PK or NULL if the components of primary key in result array are all null.
  321. */
  322. public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
  323. {
  324. // If the PK cannot be derived from the row, return NULL.
  325. if ($row[$startcol] === null) {
  326. return null;
  327. }
  328. return (string) $row[$startcol];
  329. }
  330. /**
  331. * Retrieves the primary key from the DB resultset row
  332. * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
  333. * a multi-column primary key, an array of the primary key columns will be returned.
  334. *
  335. * @param array $row PropelPDO resultset row.
  336. * @param int $startcol The 0-based offset for reading from the resultset row.
  337. * @return mixed The primary key of the row
  338. */
  339. public static function getPrimaryKeyFromRow($row, $startcol = 0)
  340. {
  341. return (string) $row[$startcol];
  342. }
  343. /**
  344. * The returned array will contain objects of the default type or
  345. * objects that inherit from the default.
  346. *
  347. * @throws PropelException Any exceptions caught during processing will be
  348. * rethrown wrapped into a PropelException.
  349. */
  350. public static function populateObjects(PDOStatement $stmt)
  351. {
  352. $results = array();
  353. // set the class once to avoid overhead in the loop
  354. $cls = CcCountryPeer::getOMClass(false);
  355. // populate the object(s)
  356. while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
  357. $key = CcCountryPeer::getPrimaryKeyHashFromRow($row, 0);
  358. if (null !== ($obj = CcCountryPeer::getInstanceFromPool($key))) {
  359. // We no longer rehydrate the object, since this can cause data loss.
  360. // See http://www.propelorm.org/ticket/509
  361. // $obj->hydrate($row, 0, true); // rehydrate
  362. $results[] = $obj;
  363. } else {
  364. $obj = new $cls();
  365. $obj->hydrate($row);
  366. $results[] = $obj;
  367. CcCountryPeer::addInstanceToPool($obj, $key);
  368. } // if key exists
  369. }
  370. $stmt->closeCursor();
  371. return $results;
  372. }
  373. /**
  374. * Populates an object of the default type or an object that inherit from the default.
  375. *
  376. * @param array $row PropelPDO resultset row.
  377. * @param int $startcol The 0-based offset for reading from the resultset row.
  378. * @throws PropelException Any exceptions caught during processing will be
  379. * rethrown wrapped into a PropelException.
  380. * @return array (CcCountry object, last column rank)
  381. */
  382. public static function populateObject($row, $startcol = 0)
  383. {
  384. $key = CcCountryPeer::getPrimaryKeyHashFromRow($row, $startcol);
  385. if (null !== ($obj = CcCountryPeer::getInstanceFromPool($key))) {
  386. // We no longer rehydrate the object, since this can cause data loss.
  387. // See http://www.propelorm.org/ticket/509
  388. // $obj->hydrate($row, $startcol, true); // rehydrate
  389. $col = $startcol + CcCountryPeer::NUM_COLUMNS;
  390. } else {
  391. $cls = CcCountryPeer::OM_CLASS;
  392. $obj = new $cls();
  393. $col = $obj->hydrate($row, $startcol);
  394. CcCountryPeer::addInstanceToPool($obj, $key);
  395. }
  396. return array($obj, $col);
  397. }
  398. /**
  399. * Returns the TableMap related to this peer.
  400. * This method is not needed for general use but a specific application could have a need.
  401. * @return TableMap
  402. * @throws PropelException Any exceptions caught during processing will be
  403. * rethrown wrapped into a PropelException.
  404. */
  405. public static function getTableMap()
  406. {
  407. return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
  408. }
  409. /**
  410. * Add a TableMap instance to the database for this peer class.
  411. */
  412. public static function buildTableMap()
  413. {
  414. $dbMap = Propel::getDatabaseMap(BaseCcCountryPeer::DATABASE_NAME);
  415. if (!$dbMap->hasTable(BaseCcCountryPeer::TABLE_NAME))
  416. {
  417. $dbMap->addTableObject(new CcCountryTableMap());
  418. }
  419. }
  420. /**
  421. * The class that the Peer will make instances of.
  422. *
  423. * If $withPrefix is true, the returned path
  424. * uses a dot-path notation which is tranalted into a path
  425. * relative to a location on the PHP include_path.
  426. * (e.g. path.to.MyClass -> 'path/to/MyClass.php')
  427. *
  428. * @param boolean $withPrefix Whether or not to return the path with the class name
  429. * @return string path.to.ClassName
  430. */
  431. public static function getOMClass($withPrefix = true)
  432. {
  433. return $withPrefix ? CcCountryPeer::CLASS_DEFAULT : CcCountryPeer::OM_CLASS;
  434. }
  435. /**
  436. * Method perform an INSERT on the database, given a CcCountry or Criteria object.
  437. *
  438. * @param mixed $values Criteria or CcCountry object containing data that is used to create the INSERT statement.
  439. * @param PropelPDO $con the PropelPDO connection to use
  440. * @return mixed The new primary key.
  441. * @throws PropelException Any exceptions caught during processing will be
  442. * rethrown wrapped into a PropelException.
  443. */
  444. public static function doInsert($values, PropelPDO $con = null)
  445. {
  446. if ($con === null) {
  447. $con = Propel::getConnection(CcCountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  448. }
  449. if ($values instanceof Criteria) {
  450. $criteria = clone $values; // rename for clarity
  451. } else {
  452. $criteria = $values->buildCriteria(); // build Criteria from CcCountry object
  453. }
  454. // Set the correct dbName
  455. $criteria->setDbName(self::DATABASE_NAME);
  456. try {
  457. // use transaction because $criteria could contain info
  458. // for more than one table (I guess, conceivably)
  459. $con->beginTransaction();
  460. $pk = BasePeer::doInsert($criteria, $con);
  461. $con->commit();
  462. } catch(PropelException $e) {
  463. $con->rollBack();
  464. throw $e;
  465. }
  466. return $pk;
  467. }
  468. /**
  469. * Method perform an UPDATE on the database, given a CcCountry or Criteria object.
  470. *
  471. * @param mixed $values Criteria or CcCountry object containing data that is used to create the UPDATE statement.
  472. * @param PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
  473. * @return int The number of affected rows (if supported by underlying database driver).
  474. * @throws PropelException Any exceptions caught during processing will be
  475. * rethrown wrapped into a PropelException.
  476. */
  477. public static function doUpdate($values, PropelPDO $con = null)
  478. {
  479. if ($con === null) {
  480. $con = Propel::getConnection(CcCountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  481. }
  482. $selectCriteria = new Criteria(self::DATABASE_NAME);
  483. if ($values instanceof Criteria) {
  484. $criteria = clone $values; // rename for clarity
  485. $comparison = $criteria->getComparison(CcCountryPeer::ISOCODE);
  486. $value = $criteria->remove(CcCountryPeer::ISOCODE);
  487. if ($value) {
  488. $selectCriteria->add(CcCountryPeer::ISOCODE, $value, $comparison);
  489. } else {
  490. $selectCriteria->setPrimaryTableName(CcCountryPeer::TABLE_NAME);
  491. }
  492. } else { // $values is CcCountry object
  493. $criteria = $values->buildCriteria(); // gets full criteria
  494. $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
  495. }
  496. // set the correct dbName
  497. $criteria->setDbName(self::DATABASE_NAME);
  498. return BasePeer::doUpdate($selectCriteria, $criteria, $con);
  499. }
  500. /**
  501. * Method to DELETE all rows from the cc_country table.
  502. *
  503. * @return int The number of affected rows (if supported by underlying database driver).
  504. */
  505. public static function doDeleteAll($con = null)
  506. {
  507. if ($con === null) {
  508. $con = Propel::getConnection(CcCountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  509. }
  510. $affectedRows = 0; // initialize var to track total num of affected rows
  511. try {
  512. // use transaction because $criteria could contain info
  513. // for more than one table or we could emulating ON DELETE CASCADE, etc.
  514. $con->beginTransaction();
  515. $affectedRows += BasePeer::doDeleteAll(CcCountryPeer::TABLE_NAME, $con, CcCountryPeer::DATABASE_NAME);
  516. // Because this db requires some delete cascade/set null emulation, we have to
  517. // clear the cached instance *after* the emulation has happened (since
  518. // instances get re-added by the select statement contained therein).
  519. CcCountryPeer::clearInstancePool();
  520. CcCountryPeer::clearRelatedInstancePool();
  521. $con->commit();
  522. return $affectedRows;
  523. } catch (PropelException $e) {
  524. $con->rollBack();
  525. throw $e;
  526. }
  527. }
  528. /**
  529. * Method perform a DELETE on the database, given a CcCountry or Criteria object OR a primary key value.
  530. *
  531. * @param mixed $values Criteria or CcCountry object or primary key or array of primary keys
  532. * which is used to create the DELETE statement
  533. * @param PropelPDO $con the connection to use
  534. * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
  535. * if supported by native driver or if emulated using Propel.
  536. * @throws PropelException Any exceptions caught during processing will be
  537. * rethrown wrapped into a PropelException.
  538. */
  539. public static function doDelete($values, PropelPDO $con = null)
  540. {
  541. if ($con === null) {
  542. $con = Propel::getConnection(CcCountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  543. }
  544. if ($values instanceof Criteria) {
  545. // invalidate the cache for all objects of this type, since we have no
  546. // way of knowing (without running a query) what objects should be invalidated
  547. // from the cache based on this Criteria.
  548. CcCountryPeer::clearInstancePool();
  549. // rename for clarity
  550. $criteria = clone $values;
  551. } elseif ($values instanceof CcCountry) { // it's a model object
  552. // invalidate the cache for this single object
  553. CcCountryPeer::removeInstanceFromPool($values);
  554. // create criteria based on pk values
  555. $criteria = $values->buildPkeyCriteria();
  556. } else { // it's a primary key, or an array of pks
  557. $criteria = new Criteria(self::DATABASE_NAME);
  558. $criteria->add(CcCountryPeer::ISOCODE, (array) $values, Criteria::IN);
  559. // invalidate the cache for this object(s)
  560. foreach ((array) $values as $singleval) {
  561. CcCountryPeer::removeInstanceFromPool($singleval);
  562. }
  563. }
  564. // Set the correct dbName
  565. $criteria->setDbName(self::DATABASE_NAME);
  566. $affectedRows = 0; // initialize var to track total num of affected rows
  567. try {
  568. // use transaction because $criteria could contain info
  569. // for more than one table or we could emulating ON DELETE CASCADE, etc.
  570. $con->beginTransaction();
  571. $affectedRows += BasePeer::doDelete($criteria, $con);
  572. CcCountryPeer::clearRelatedInstancePool();
  573. $con->commit();
  574. return $affectedRows;
  575. } catch (PropelException $e) {
  576. $con->rollBack();
  577. throw $e;
  578. }
  579. }
  580. /**
  581. * Validates all modified columns of given CcCountry object.
  582. * If parameter $columns is either a single column name or an array of column names
  583. * than only those columns are validated.
  584. *
  585. * NOTICE: This does not apply to primary or foreign keys for now.
  586. *
  587. * @param CcCountry $obj The object to validate.
  588. * @param mixed $cols Column name or array of column names.
  589. *
  590. * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
  591. */
  592. public static function doValidate(CcCountry $obj, $cols = null)
  593. {
  594. $columns = array();
  595. if ($cols) {
  596. $dbMap = Propel::getDatabaseMap(CcCountryPeer::DATABASE_NAME);
  597. $tableMap = $dbMap->getTable(CcCountryPeer::TABLE_NAME);
  598. if (! is_array($cols)) {
  599. $cols = array($cols);
  600. }
  601. foreach ($cols as $colName) {
  602. if ($tableMap->containsColumn($colName)) {
  603. $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
  604. $columns[$colName] = $obj->$get();
  605. }
  606. }
  607. } else {
  608. }
  609. return BasePeer::doValidate(CcCountryPeer::DATABASE_NAME, CcCountryPeer::TABLE_NAME, $columns);
  610. }
  611. /**
  612. * Retrieve a single object by pkey.
  613. *
  614. * @param string $pk the primary key.
  615. * @param PropelPDO $con the connection to use
  616. * @return CcCountry
  617. */
  618. public static function retrieveByPK($pk, PropelPDO $con = null)
  619. {
  620. if (null !== ($obj = CcCountryPeer::getInstanceFromPool((string) $pk))) {
  621. return $obj;
  622. }
  623. if ($con === null) {
  624. $con = Propel::getConnection(CcCountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  625. }
  626. $criteria = new Criteria(CcCountryPeer::DATABASE_NAME);
  627. $criteria->add(CcCountryPeer::ISOCODE, $pk);
  628. $v = CcCountryPeer::doSelect($criteria, $con);
  629. return !empty($v) > 0 ? $v[0] : null;
  630. }
  631. /**
  632. * Retrieve multiple objects by pkey.
  633. *
  634. * @param array $pks List of primary keys
  635. * @param PropelPDO $con the connection to use
  636. * @throws PropelException Any exceptions caught during processing will be
  637. * rethrown wrapped into a PropelException.
  638. */
  639. public static function retrieveByPKs($pks, PropelPDO $con = null)
  640. {
  641. if ($con === null) {
  642. $con = Propel::getConnection(CcCountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  643. }
  644. $objs = null;
  645. if (empty($pks)) {
  646. $objs = array();
  647. } else {
  648. $criteria = new Criteria(CcCountryPeer::DATABASE_NAME);
  649. $criteria->add(CcCountryPeer::ISOCODE, $pks, Criteria::IN);
  650. $objs = CcCountryPeer::doSelect($criteria, $con);
  651. }
  652. return $objs;
  653. }
  654. } // BaseCcCountryPeer
  655. // This is the static code needed to register the TableMap for this table with the main Propel class.
  656. //
  657. BaseCcCountryPeer::buildTableMap();