]> wagnertech.de Git - projects.git/blob - verleihnix/Verleihnix/impl/data/build/classes/propel/om/BaseMediumPeer.php
verleihnix komplett eingescheckt
[projects.git] / verleihnix / Verleihnix / impl / data / build / classes / propel / om / BaseMediumPeer.php
1 <?php
2
3
4 /**
5  * Base static class for performing query and update operations on the 'medium' table.
6  *
7  *
8  *
9  * @package propel.generator.propel.om
10  */
11 abstract class BaseMediumPeer
12 {
13
14     /** the default database name for this class */
15     const DATABASE_NAME = 'mkrimi';
16
17     /** the table name for this class */
18     const TABLE_NAME = 'medium';
19
20     /** the related Propel class for this table */
21     const OM_CLASS = 'Medium';
22
23     /** the related TableMap class for this table */
24     const TM_CLASS = 'MediumTableMap';
25
26     /** The total number of columns. */
27     const NUM_COLUMNS = 8;
28
29     /** The number of lazy-loaded columns. */
30     const NUM_LAZY_LOAD_COLUMNS = 0;
31
32     /** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
33     const NUM_HYDRATE_COLUMNS = 8;
34
35     /** the column name for the id field */
36     const ID = 'medium.id';
37
38     /** the column name for the mod field */
39     const MOD = 'medium.mod';
40
41     /** the column name for the autor field */
42     const AUTOR = 'medium.autor';
43
44     /** the column name for the titel field */
45     const TITEL = 'medium.titel';
46
47     /** the column name for the eigentumer field */
48     const EIGENTUMER = 'medium.eigentumer';
49
50     /** the column name for the zz_bei field */
51     const ZZ_BEI = 'medium.zz_bei';
52
53     /** the column name for the kommentar field */
54     const KOMMENTAR = 'medium.kommentar';
55
56     /** the column name for the class_key field */
57     const CLASS_KEY = 'medium.class_key';
58
59     /** A key representing a particular subclass */
60     const CLASSKEY_1 = '1';
61
62     /** A key representing a particular subclass */
63     const CLASSKEY_KRIMI = '1';
64
65     /** A class that can be returned by this peer. */
66     const CLASSNAME_1 = 'Krimi';
67
68     /** A key representing a particular subclass */
69     const CLASSKEY_2 = '2';
70
71     /** A key representing a particular subclass */
72     const CLASSKEY_HORBUCH = '2';
73
74     /** A class that can be returned by this peer. */
75     const CLASSNAME_2 = 'Horbuch';
76
77     /** A key representing a particular subclass */
78     const CLASSKEY_3 = '3';
79
80     /** A key representing a particular subclass */
81     const CLASSKEY_ROMAN = '3';
82
83     /** A class that can be returned by this peer. */
84     const CLASSNAME_3 = 'Roman';
85
86     /** The default string format for model objects of the related table **/
87     const DEFAULT_STRING_FORMAT = 'YAML';
88
89     /**
90      * An identity map to hold any loaded instances of Medium objects.
91      * This must be public so that other peer classes can access this when hydrating from JOIN
92      * queries.
93      * @var        array Medium[]
94      */
95     public static $instances = array();
96
97
98     /**
99      * holds an array of fieldnames
100      *
101      * first dimension keys are the type constants
102      * e.g. MediumPeer::$fieldNames[MediumPeer::TYPE_PHPNAME][0] = 'Id'
103      */
104     protected static $fieldNames = array (
105         BasePeer::TYPE_PHPNAME => array ('Id', 'Mod', 'Autor', 'Titel', 'Eigentumer', 'ZzBei', 'Kommentar', 'ClassKey', ),
106         BasePeer::TYPE_STUDLYPHPNAME => array ('id', 'mod', 'autor', 'titel', 'eigentumer', 'zzBei', 'kommentar', 'classKey', ),
107         BasePeer::TYPE_COLNAME => array (MediumPeer::ID, MediumPeer::MOD, MediumPeer::AUTOR, MediumPeer::TITEL, MediumPeer::EIGENTUMER, MediumPeer::ZZ_BEI, MediumPeer::KOMMENTAR, MediumPeer::CLASS_KEY, ),
108         BasePeer::TYPE_RAW_COLNAME => array ('ID', 'MOD', 'AUTOR', 'TITEL', 'EIGENTUMER', 'ZZ_BEI', 'KOMMENTAR', 'CLASS_KEY', ),
109         BasePeer::TYPE_FIELDNAME => array ('id', 'mod', 'autor', 'titel', 'eigentumer', 'zz_bei', 'kommentar', 'class_key', ),
110         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, )
111     );
112
113     /**
114      * holds an array of keys for quick access to the fieldnames array
115      *
116      * first dimension keys are the type constants
117      * e.g. MediumPeer::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
118      */
119     protected static $fieldKeys = array (
120         BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Mod' => 1, 'Autor' => 2, 'Titel' => 3, 'Eigentumer' => 4, 'ZzBei' => 5, 'Kommentar' => 6, 'ClassKey' => 7, ),
121         BasePeer::TYPE_STUDLYPHPNAME => array ('id' => 0, 'mod' => 1, 'autor' => 2, 'titel' => 3, 'eigentumer' => 4, 'zzBei' => 5, 'kommentar' => 6, 'classKey' => 7, ),
122         BasePeer::TYPE_COLNAME => array (MediumPeer::ID => 0, MediumPeer::MOD => 1, MediumPeer::AUTOR => 2, MediumPeer::TITEL => 3, MediumPeer::EIGENTUMER => 4, MediumPeer::ZZ_BEI => 5, MediumPeer::KOMMENTAR => 6, MediumPeer::CLASS_KEY => 7, ),
123         BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'MOD' => 1, 'AUTOR' => 2, 'TITEL' => 3, 'EIGENTUMER' => 4, 'ZZ_BEI' => 5, 'KOMMENTAR' => 6, 'CLASS_KEY' => 7, ),
124         BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'mod' => 1, 'autor' => 2, 'titel' => 3, 'eigentumer' => 4, 'zz_bei' => 5, 'kommentar' => 6, 'class_key' => 7, ),
125         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, )
126     );
127
128     /**
129      * Translates a fieldname to another type
130      *
131      * @param      string $name field name
132      * @param      string $fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
133      *                         BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
134      * @param      string $toType   One of the class type constants
135      * @return string          translated name of the field.
136      * @throws PropelException - if the specified name could not be found in the fieldname mappings.
137      */
138     public static function translateFieldName($name, $fromType, $toType)
139     {
140         $toNames = MediumPeer::getFieldNames($toType);
141         $key = isset(MediumPeer::$fieldKeys[$fromType][$name]) ? MediumPeer::$fieldKeys[$fromType][$name] : null;
142         if ($key === null) {
143             throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(MediumPeer::$fieldKeys[$fromType], true));
144         }
145
146         return $toNames[$key];
147     }
148
149     /**
150      * Returns an array of field names.
151      *
152      * @param      string $type The type of fieldnames to return:
153      *                      One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
154      *                      BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
155      * @return array           A list of field names
156      * @throws PropelException - if the type is not valid.
157      */
158     public static function getFieldNames($type = BasePeer::TYPE_PHPNAME)
159     {
160         if (!array_key_exists($type, MediumPeer::$fieldNames)) {
161             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.');
162         }
163
164         return MediumPeer::$fieldNames[$type];
165     }
166
167     /**
168      * Convenience method which changes table.column to alias.column.
169      *
170      * Using this method you can maintain SQL abstraction while using column aliases.
171      * <code>
172      *          $c->addAlias("alias1", TablePeer::TABLE_NAME);
173      *          $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
174      * </code>
175      * @param      string $alias The alias for the current table.
176      * @param      string $column The column name for current table. (i.e. MediumPeer::COLUMN_NAME).
177      * @return string
178      */
179     public static function alias($alias, $column)
180     {
181         return str_replace(MediumPeer::TABLE_NAME.'.', $alias.'.', $column);
182     }
183
184     /**
185      * Add all the columns needed to create a new object.
186      *
187      * Note: any columns that were marked with lazyLoad="true" in the
188      * XML schema will not be added to the select list and only loaded
189      * on demand.
190      *
191      * @param      Criteria $criteria object containing the columns to add.
192      * @param      string   $alias    optional table alias
193      * @throws PropelException Any exceptions caught during processing will be
194      *           rethrown wrapped into a PropelException.
195      */
196     public static function addSelectColumns(Criteria $criteria, $alias = null)
197     {
198         if (null === $alias) {
199             $criteria->addSelectColumn(MediumPeer::ID);
200             $criteria->addSelectColumn(MediumPeer::MOD);
201             $criteria->addSelectColumn(MediumPeer::AUTOR);
202             $criteria->addSelectColumn(MediumPeer::TITEL);
203             $criteria->addSelectColumn(MediumPeer::EIGENTUMER);
204             $criteria->addSelectColumn(MediumPeer::ZZ_BEI);
205             $criteria->addSelectColumn(MediumPeer::KOMMENTAR);
206             $criteria->addSelectColumn(MediumPeer::CLASS_KEY);
207         } else {
208             $criteria->addSelectColumn($alias . '.id');
209             $criteria->addSelectColumn($alias . '.mod');
210             $criteria->addSelectColumn($alias . '.autor');
211             $criteria->addSelectColumn($alias . '.titel');
212             $criteria->addSelectColumn($alias . '.eigentumer');
213             $criteria->addSelectColumn($alias . '.zz_bei');
214             $criteria->addSelectColumn($alias . '.kommentar');
215             $criteria->addSelectColumn($alias . '.class_key');
216         }
217     }
218
219     /**
220      * Returns the number of rows matching criteria.
221      *
222      * @param      Criteria $criteria
223      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
224      * @param      PropelPDO $con
225      * @return int Number of matching rows.
226      */
227     public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
228     {
229         // we may modify criteria, so copy it first
230         $criteria = clone $criteria;
231
232         // We need to set the primary table name, since in the case that there are no WHERE columns
233         // it will be impossible for the BasePeer::createSelectSql() method to determine which
234         // tables go into the FROM clause.
235         $criteria->setPrimaryTableName(MediumPeer::TABLE_NAME);
236
237         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
238             $criteria->setDistinct();
239         }
240
241         if (!$criteria->hasSelectClause()) {
242             MediumPeer::addSelectColumns($criteria);
243         }
244
245         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
246         $criteria->setDbName(MediumPeer::DATABASE_NAME); // Set the correct dbName
247
248         if ($con === null) {
249             $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_READ);
250         }
251         // BasePeer returns a PDOStatement
252         $stmt = BasePeer::doCount($criteria, $con);
253
254         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
255             $count = (int) $row[0];
256         } else {
257             $count = 0; // no rows returned; we infer that means 0 matches.
258         }
259         $stmt->closeCursor();
260
261         return $count;
262     }
263     /**
264      * Selects one object from the DB.
265      *
266      * @param      Criteria $criteria object used to create the SELECT statement.
267      * @param      PropelPDO $con
268      * @return Medium
269      * @throws PropelException Any exceptions caught during processing will be
270      *           rethrown wrapped into a PropelException.
271      */
272     public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
273     {
274         $critcopy = clone $criteria;
275         $critcopy->setLimit(1);
276         $objects = MediumPeer::doSelect($critcopy, $con);
277         if ($objects) {
278             return $objects[0];
279         }
280
281         return null;
282     }
283     /**
284      * Selects several row from the DB.
285      *
286      * @param      Criteria $criteria The Criteria object used to build the SELECT statement.
287      * @param      PropelPDO $con
288      * @return array           Array of selected Objects
289      * @throws PropelException Any exceptions caught during processing will be
290      *           rethrown wrapped into a PropelException.
291      */
292     public static function doSelect(Criteria $criteria, PropelPDO $con = null)
293     {
294         return MediumPeer::populateObjects(MediumPeer::doSelectStmt($criteria, $con));
295     }
296     /**
297      * Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
298      *
299      * Use this method directly if you want to work with an executed statement directly (for example
300      * to perform your own object hydration).
301      *
302      * @param      Criteria $criteria The Criteria object used to build the SELECT statement.
303      * @param      PropelPDO $con The connection to use
304      * @throws PropelException Any exceptions caught during processing will be
305      *           rethrown wrapped into a PropelException.
306      * @return PDOStatement The executed PDOStatement object.
307      * @see        BasePeer::doSelect()
308      */
309     public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
310     {
311         if ($con === null) {
312             $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_READ);
313         }
314
315         if (!$criteria->hasSelectClause()) {
316             $criteria = clone $criteria;
317             MediumPeer::addSelectColumns($criteria);
318         }
319
320         // Set the correct dbName
321         $criteria->setDbName(MediumPeer::DATABASE_NAME);
322
323         // BasePeer returns a PDOStatement
324         return BasePeer::doSelect($criteria, $con);
325     }
326     /**
327      * Adds an object to the instance pool.
328      *
329      * Propel keeps cached copies of objects in an instance pool when they are retrieved
330      * from the database.  In some cases -- especially when you override doSelect*()
331      * methods in your stub classes -- you may need to explicitly add objects
332      * to the cache in order to ensure that the same objects are always returned by doSelect*()
333      * and retrieveByPK*() calls.
334      *
335      * @param Medium $obj A Medium object.
336      * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
337      */
338     public static function addInstanceToPool($obj, $key = null)
339     {
340         if (Propel::isInstancePoolingEnabled()) {
341             if ($key === null) {
342                 $key = (string) $obj->getId();
343             } // if key === null
344             MediumPeer::$instances[$key] = $obj;
345         }
346     }
347
348     /**
349      * Removes an object from the instance pool.
350      *
351      * Propel keeps cached copies of objects in an instance pool when they are retrieved
352      * from the database.  In some cases -- especially when you override doDelete
353      * methods in your stub classes -- you may need to explicitly remove objects
354      * from the cache in order to prevent returning objects that no longer exist.
355      *
356      * @param      mixed $value A Medium object or a primary key value.
357      *
358      * @return void
359      * @throws PropelException - if the value is invalid.
360      */
361     public static function removeInstanceFromPool($value)
362     {
363         if (Propel::isInstancePoolingEnabled() && $value !== null) {
364             if (is_object($value) && $value instanceof Medium) {
365                 $key = (string) $value->getId();
366             } elseif (is_scalar($value)) {
367                 // assume we've been passed a primary key
368                 $key = (string) $value;
369             } else {
370                 $e = new PropelException("Invalid value passed to removeInstanceFromPool().  Expected primary key or Medium object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
371                 throw $e;
372             }
373
374             unset(MediumPeer::$instances[$key]);
375         }
376     } // removeInstanceFromPool()
377
378     /**
379      * 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.
380      *
381      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
382      * a multi-column primary key, a serialize()d version of the primary key will be returned.
383      *
384      * @param      string $key The key (@see getPrimaryKeyHash()) for this instance.
385      * @return Medium Found object or null if 1) no instance exists for specified key or 2) instance pooling has been disabled.
386      * @see        getPrimaryKeyHash()
387      */
388     public static function getInstanceFromPool($key)
389     {
390         if (Propel::isInstancePoolingEnabled()) {
391             if (isset(MediumPeer::$instances[$key])) {
392                 return MediumPeer::$instances[$key];
393             }
394         }
395
396         return null; // just to be explicit
397     }
398
399     /**
400      * Clear the instance pool.
401      *
402      * @return void
403      */
404     public static function clearInstancePool($and_clear_all_references = false)
405     {
406       if ($and_clear_all_references) {
407         foreach (MediumPeer::$instances as $instance) {
408           $instance->clearAllReferences(true);
409         }
410       }
411         MediumPeer::$instances = array();
412     }
413
414     /**
415      * Method to invalidate the instance pool of all tables related to medium
416      * by a foreign key with ON DELETE CASCADE
417      */
418     public static function clearRelatedInstancePool()
419     {
420     }
421
422     /**
423      * 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.
424      *
425      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
426      * a multi-column primary key, a serialize()d version of the primary key will be returned.
427      *
428      * @param      array $row PropelPDO resultset row.
429      * @param      int $startcol The 0-based offset for reading from the resultset row.
430      * @return string A string version of PK or null if the components of primary key in result array are all null.
431      */
432     public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
433     {
434         // If the PK cannot be derived from the row, return null.
435         if ($row[$startcol] === null) {
436             return null;
437         }
438
439         return (string) $row[$startcol];
440     }
441
442     /**
443      * Retrieves the primary key from the DB resultset row
444      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
445      * a multi-column primary key, an array of the primary key columns will be returned.
446      *
447      * @param      array $row PropelPDO resultset row.
448      * @param      int $startcol The 0-based offset for reading from the resultset row.
449      * @return mixed The primary key of the row
450      */
451     public static function getPrimaryKeyFromRow($row, $startcol = 0)
452     {
453
454         return (int) $row[$startcol];
455     }
456
457     /**
458      * The returned array will contain objects of the default type or
459      * objects that inherit from the default.
460      *
461      * @throws PropelException Any exceptions caught during processing will be
462      *           rethrown wrapped into a PropelException.
463      */
464     public static function populateObjects(PDOStatement $stmt)
465     {
466         $results = array();
467
468         // populate the object(s)
469         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
470             $key = MediumPeer::getPrimaryKeyHashFromRow($row, 0);
471             if (null !== ($obj = MediumPeer::getInstanceFromPool($key))) {
472                 // We no longer rehydrate the object, since this can cause data loss.
473                 // See http://www.propelorm.org/ticket/509
474                 // $obj->hydrate($row, 0, true); // rehydrate
475                 $results[] = $obj;
476             } else {
477                 // class must be set each time from the record row
478                 $cls = MediumPeer::getOMClass($row, 0);
479                 $cls = substr('.'.$cls, strrpos('.'.$cls, '.') + 1);
480                 $obj = new $cls();
481                 $obj->hydrate($row);
482                 $results[] = $obj;
483                 MediumPeer::addInstanceToPool($obj, $key);
484             } // if key exists
485         }
486         $stmt->closeCursor();
487
488         return $results;
489     }
490     /**
491      * Populates an object of the default type or an object that inherit from the default.
492      *
493      * @param      array $row PropelPDO resultset row.
494      * @param      int $startcol The 0-based offset for reading from the resultset row.
495      * @throws PropelException Any exceptions caught during processing will be
496      *           rethrown wrapped into a PropelException.
497      * @return array (Medium object, last column rank)
498      */
499     public static function populateObject($row, $startcol = 0)
500     {
501         $key = MediumPeer::getPrimaryKeyHashFromRow($row, $startcol);
502         if (null !== ($obj = MediumPeer::getInstanceFromPool($key))) {
503             // We no longer rehydrate the object, since this can cause data loss.
504             // See http://www.propelorm.org/ticket/509
505             // $obj->hydrate($row, $startcol, true); // rehydrate
506             $col = $startcol + MediumPeer::NUM_HYDRATE_COLUMNS;
507         } else {
508             $cls = MediumPeer::getOMClass($row, $startcol);
509             $obj = new $cls();
510             $col = $obj->hydrate($row, $startcol);
511             MediumPeer::addInstanceToPool($obj, $key);
512         }
513
514         return array($obj, $col);
515     }
516
517     /**
518      * Returns the TableMap related to this peer.
519      * This method is not needed for general use but a specific application could have a need.
520      * @return TableMap
521      * @throws PropelException Any exceptions caught during processing will be
522      *           rethrown wrapped into a PropelException.
523      */
524     public static function getTableMap()
525     {
526         return Propel::getDatabaseMap(MediumPeer::DATABASE_NAME)->getTable(MediumPeer::TABLE_NAME);
527     }
528
529     /**
530      * Add a TableMap instance to the database for this peer class.
531      */
532     public static function buildTableMap()
533     {
534       $dbMap = Propel::getDatabaseMap(BaseMediumPeer::DATABASE_NAME);
535       if (!$dbMap->hasTable(BaseMediumPeer::TABLE_NAME)) {
536         $dbMap->addTableObject(new \MediumTableMap());
537       }
538     }
539
540     /**
541      * The returned Class will contain objects of the default type or
542      * objects that inherit from the default.
543      *
544      * @param      array $row PropelPDO result row.
545      * @param      int $colnum Column to examine for OM class information (first is 0).
546      * @throws PropelException Any exceptions caught during processing will be
547      *           rethrown wrapped into a PropelException.
548      */
549     public static function getOMClass($row = 0, $colnum = 0)
550     {
551         try {
552
553             $omClass = null;
554             $classKey = $row[$colnum + 7];
555
556             switch ($classKey) {
557
558                 case MediumPeer::CLASSKEY_1:
559                     $omClass = MediumPeer::CLASSNAME_1;
560                     break;
561
562                 case MediumPeer::CLASSKEY_2:
563                     $omClass = MediumPeer::CLASSNAME_2;
564                     break;
565
566                 case MediumPeer::CLASSKEY_3:
567                     $omClass = MediumPeer::CLASSNAME_3;
568                     break;
569
570                 default:
571                     $omClass = MediumPeer::OM_CLASS;
572
573             } // switch
574
575         } catch (Exception $e) {
576             throw new PropelException('Unable to get OM class.', $e);
577         }
578
579         return $omClass;
580     }
581
582     /**
583      * Performs an INSERT on the database, given a Medium or Criteria object.
584      *
585      * @param      mixed $values Criteria or Medium object containing data that is used to create the INSERT statement.
586      * @param      PropelPDO $con the PropelPDO connection to use
587      * @return mixed           The new primary key.
588      * @throws PropelException Any exceptions caught during processing will be
589      *           rethrown wrapped into a PropelException.
590      */
591     public static function doInsert($values, PropelPDO $con = null)
592     {
593         if ($con === null) {
594             $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
595         }
596
597         if ($values instanceof Criteria) {
598             $criteria = clone $values; // rename for clarity
599         } else {
600             $criteria = $values->buildCriteria(); // build Criteria from Medium object
601         }
602
603         if ($criteria->containsKey(MediumPeer::ID) && $criteria->keyContainsValue(MediumPeer::ID) ) {
604             throw new PropelException('Cannot insert a value for auto-increment primary key ('.MediumPeer::ID.')');
605         }
606
607
608         // Set the correct dbName
609         $criteria->setDbName(MediumPeer::DATABASE_NAME);
610
611         try {
612             // use transaction because $criteria could contain info
613             // for more than one table (I guess, conceivably)
614             $con->beginTransaction();
615             $pk = BasePeer::doInsert($criteria, $con);
616             $con->commit();
617         } catch (Exception $e) {
618             $con->rollBack();
619             throw $e;
620         }
621
622         return $pk;
623     }
624
625     /**
626      * Performs an UPDATE on the database, given a Medium or Criteria object.
627      *
628      * @param      mixed $values Criteria or Medium object containing data that is used to create the UPDATE statement.
629      * @param      PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
630      * @return int             The number of affected rows (if supported by underlying database driver).
631      * @throws PropelException Any exceptions caught during processing will be
632      *           rethrown wrapped into a PropelException.
633      */
634     public static function doUpdate($values, PropelPDO $con = null)
635     {
636         if ($con === null) {
637             $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
638         }
639
640         $selectCriteria = new Criteria(MediumPeer::DATABASE_NAME);
641
642         if ($values instanceof Criteria) {
643             $criteria = clone $values; // rename for clarity
644
645             $comparison = $criteria->getComparison(MediumPeer::ID);
646             $value = $criteria->remove(MediumPeer::ID);
647             if ($value) {
648                 $selectCriteria->add(MediumPeer::ID, $value, $comparison);
649             } else {
650                 $selectCriteria->setPrimaryTableName(MediumPeer::TABLE_NAME);
651             }
652
653         } else { // $values is Medium object
654             $criteria = $values->buildCriteria(); // gets full criteria
655             $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
656         }
657
658         // set the correct dbName
659         $criteria->setDbName(MediumPeer::DATABASE_NAME);
660
661         return BasePeer::doUpdate($selectCriteria, $criteria, $con);
662     }
663
664     /**
665      * Deletes all rows from the medium table.
666      *
667      * @param      PropelPDO $con the connection to use
668      * @return int             The number of affected rows (if supported by underlying database driver).
669      * @throws PropelException
670      */
671     public static function doDeleteAll(PropelPDO $con = null)
672     {
673         if ($con === null) {
674             $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
675         }
676         $affectedRows = 0; // initialize var to track total num of affected rows
677         try {
678             // use transaction because $criteria could contain info
679             // for more than one table or we could emulating ON DELETE CASCADE, etc.
680             $con->beginTransaction();
681             $affectedRows += BasePeer::doDeleteAll(MediumPeer::TABLE_NAME, $con, MediumPeer::DATABASE_NAME);
682             // Because this db requires some delete cascade/set null emulation, we have to
683             // clear the cached instance *after* the emulation has happened (since
684             // instances get re-added by the select statement contained therein).
685             MediumPeer::clearInstancePool();
686             MediumPeer::clearRelatedInstancePool();
687             $con->commit();
688
689             return $affectedRows;
690         } catch (Exception $e) {
691             $con->rollBack();
692             throw $e;
693         }
694     }
695
696     /**
697      * Performs a DELETE on the database, given a Medium or Criteria object OR a primary key value.
698      *
699      * @param      mixed $values Criteria or Medium object or primary key or array of primary keys
700      *              which is used to create the DELETE statement
701      * @param      PropelPDO $con the connection to use
702      * @return int The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
703      *                          if supported by native driver or if emulated using Propel.
704      * @throws PropelException Any exceptions caught during processing will be
705      *           rethrown wrapped into a PropelException.
706      */
707      public static function doDelete($values, PropelPDO $con = null)
708      {
709         if ($con === null) {
710             $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
711         }
712
713         if ($values instanceof Criteria) {
714             // invalidate the cache for all objects of this type, since we have no
715             // way of knowing (without running a query) what objects should be invalidated
716             // from the cache based on this Criteria.
717             MediumPeer::clearInstancePool();
718             // rename for clarity
719             $criteria = clone $values;
720         } elseif ($values instanceof Medium) { // it's a model object
721             // invalidate the cache for this single object
722             MediumPeer::removeInstanceFromPool($values);
723             // create criteria based on pk values
724             $criteria = $values->buildPkeyCriteria();
725         } else { // it's a primary key, or an array of pks
726             $criteria = new Criteria(MediumPeer::DATABASE_NAME);
727             $criteria->add(MediumPeer::ID, (array) $values, Criteria::IN);
728             // invalidate the cache for this object(s)
729             foreach ((array) $values as $singleval) {
730                 MediumPeer::removeInstanceFromPool($singleval);
731             }
732         }
733
734         // Set the correct dbName
735         $criteria->setDbName(MediumPeer::DATABASE_NAME);
736
737         $affectedRows = 0; // initialize var to track total num of affected rows
738
739         try {
740             // use transaction because $criteria could contain info
741             // for more than one table or we could emulating ON DELETE CASCADE, etc.
742             $con->beginTransaction();
743
744             $affectedRows += BasePeer::doDelete($criteria, $con);
745             MediumPeer::clearRelatedInstancePool();
746             $con->commit();
747
748             return $affectedRows;
749         } catch (Exception $e) {
750             $con->rollBack();
751             throw $e;
752         }
753     }
754
755     /**
756      * Validates all modified columns of given Medium object.
757      * If parameter $columns is either a single column name or an array of column names
758      * than only those columns are validated.
759      *
760      * NOTICE: This does not apply to primary or foreign keys for now.
761      *
762      * @param Medium $obj The object to validate.
763      * @param      mixed $cols Column name or array of column names.
764      *
765      * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
766      */
767     public static function doValidate($obj, $cols = null)
768     {
769         $columns = array();
770
771         if ($cols) {
772             $dbMap = Propel::getDatabaseMap(MediumPeer::DATABASE_NAME);
773             $tableMap = $dbMap->getTable(MediumPeer::TABLE_NAME);
774
775             if (! is_array($cols)) {
776                 $cols = array($cols);
777             }
778
779             foreach ($cols as $colName) {
780                 if ($tableMap->hasColumn($colName)) {
781                     $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
782                     $columns[$colName] = $obj->$get();
783                 }
784             }
785         } else {
786
787         }
788
789         return BasePeer::doValidate(MediumPeer::DATABASE_NAME, MediumPeer::TABLE_NAME, $columns);
790     }
791
792     /**
793      * Retrieve a single object by pkey.
794      *
795      * @param int $pk the primary key.
796      * @param      PropelPDO $con the connection to use
797      * @return Medium
798      */
799     public static function retrieveByPK($pk, PropelPDO $con = null)
800     {
801
802         if (null !== ($obj = MediumPeer::getInstanceFromPool((string) $pk))) {
803             return $obj;
804         }
805
806         if ($con === null) {
807             $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_READ);
808         }
809
810         $criteria = new Criteria(MediumPeer::DATABASE_NAME);
811         $criteria->add(MediumPeer::ID, $pk);
812
813         $v = MediumPeer::doSelect($criteria, $con);
814
815         return !empty($v) > 0 ? $v[0] : null;
816     }
817
818     /**
819      * Retrieve multiple objects by pkey.
820      *
821      * @param      array $pks List of primary keys
822      * @param      PropelPDO $con the connection to use
823      * @return Medium[]
824      * @throws PropelException Any exceptions caught during processing will be
825      *           rethrown wrapped into a PropelException.
826      */
827     public static function retrieveByPKs($pks, PropelPDO $con = null)
828     {
829         if ($con === null) {
830             $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_READ);
831         }
832
833         $objs = null;
834         if (empty($pks)) {
835             $objs = array();
836         } else {
837             $criteria = new Criteria(MediumPeer::DATABASE_NAME);
838             $criteria->add(MediumPeer::ID, $pks, Criteria::IN);
839             $objs = MediumPeer::doSelect($criteria, $con);
840         }
841
842         return $objs;
843     }
844
845 } // BaseMediumPeer
846
847 // This is the static code needed to register the TableMap for this table with the main Propel class.
848 //
849 BaseMediumPeer::buildTableMap();
850