BaseCcMusicDirsPeer.php 27 KB

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