1: <?php
2:
3: namespace cli_db\propel\om;
4:
5: use \BasePeer;
6: use \Criteria;
7: use \PDO;
8: use \PDOStatement;
9: use \Propel;
10: use \PropelException;
11: use \PropelPDO;
12: use cli_db\propel\CvtermPeer;
13: use cli_db\propel\FeatureCvtermPeer;
14: use cli_db\propel\FeatureCvtermPubPeer;
15: use cli_db\propel\FeaturePubPeer;
16: use cli_db\propel\FeatureSynonymPeer;
17: use cli_db\propel\Pub;
18: use cli_db\propel\PubDbxrefPeer;
19: use cli_db\propel\PubPeer;
20: use cli_db\propel\PubRelationshipPeer;
21: use cli_db\propel\PubauthorPeer;
22: use cli_db\propel\PubpropPeer;
23: use cli_db\propel\map\PubTableMap;
24:
25: /**
26: * Base static class for performing query and update operations on the 'pub' table.
27: *
28: *
29: *
30: * @package propel.generator.cli_db.om
31: */
32: abstract class BasePubPeer
33: {
34:
35: /** the default database name for this class */
36: const DATABASE_NAME = 'cli_db';
37:
38: /** the table name for this class */
39: const TABLE_NAME = 'pub';
40:
41: /** the related Propel class for this table */
42: const OM_CLASS = 'cli_db\\propel\\Pub';
43:
44: /** the related TableMap class for this table */
45: const TM_CLASS = 'PubTableMap';
46:
47: /** The total number of columns. */
48: const NUM_COLUMNS = 14;
49:
50: /** The number of lazy-loaded columns. */
51: const NUM_LAZY_LOAD_COLUMNS = 0;
52:
53: /** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
54: const NUM_HYDRATE_COLUMNS = 14;
55:
56: /** the column name for the pub_id field */
57: const PUB_ID = 'pub.pub_id';
58:
59: /** the column name for the title field */
60: const TITLE = 'pub.title';
61:
62: /** the column name for the volumetitle field */
63: const VOLUMETITLE = 'pub.volumetitle';
64:
65: /** the column name for the volume field */
66: const VOLUME = 'pub.volume';
67:
68: /** the column name for the series_name field */
69: const SERIES_NAME = 'pub.series_name';
70:
71: /** the column name for the issue field */
72: const ISSUE = 'pub.issue';
73:
74: /** the column name for the pyear field */
75: const PYEAR = 'pub.pyear';
76:
77: /** the column name for the pages field */
78: const PAGES = 'pub.pages';
79:
80: /** the column name for the miniref field */
81: const MINIREF = 'pub.miniref';
82:
83: /** the column name for the uniquename field */
84: const UNIQUENAME = 'pub.uniquename';
85:
86: /** the column name for the type_id field */
87: const TYPE_ID = 'pub.type_id';
88:
89: /** the column name for the is_obsolete field */
90: const IS_OBSOLETE = 'pub.is_obsolete';
91:
92: /** the column name for the publisher field */
93: const PUBLISHER = 'pub.publisher';
94:
95: /** the column name for the pubplace field */
96: const PUBPLACE = 'pub.pubplace';
97:
98: /** The default string format for model objects of the related table **/
99: const DEFAULT_STRING_FORMAT = 'YAML';
100:
101: /**
102: * An identiy map to hold any loaded instances of Pub objects.
103: * This must be public so that other peer classes can access this when hydrating from JOIN
104: * queries.
105: * @var array Pub[]
106: */
107: public static $instances = array();
108:
109:
110: /**
111: * holds an array of fieldnames
112: *
113: * first dimension keys are the type constants
114: * e.g. PubPeer::$fieldNames[PubPeer::TYPE_PHPNAME][0] = 'Id'
115: */
116: protected static $fieldNames = array (
117: BasePeer::TYPE_PHPNAME => array ('PubId', 'Title', 'Volumetitle', 'Volume', 'SeriesName', 'Issue', 'Pyear', 'Pages', 'Miniref', 'Uniquename', 'TypeId', 'IsObsolete', 'Publisher', 'Pubplace', ),
118: BasePeer::TYPE_STUDLYPHPNAME => array ('pubId', 'title', 'volumetitle', 'volume', 'seriesName', 'issue', 'pyear', 'pages', 'miniref', 'uniquename', 'typeId', 'isObsolete', 'publisher', 'pubplace', ),
119: BasePeer::TYPE_COLNAME => array (PubPeer::PUB_ID, PubPeer::TITLE, PubPeer::VOLUMETITLE, PubPeer::VOLUME, PubPeer::SERIES_NAME, PubPeer::ISSUE, PubPeer::PYEAR, PubPeer::PAGES, PubPeer::MINIREF, PubPeer::UNIQUENAME, PubPeer::TYPE_ID, PubPeer::IS_OBSOLETE, PubPeer::PUBLISHER, PubPeer::PUBPLACE, ),
120: BasePeer::TYPE_RAW_COLNAME => array ('PUB_ID', 'TITLE', 'VOLUMETITLE', 'VOLUME', 'SERIES_NAME', 'ISSUE', 'PYEAR', 'PAGES', 'MINIREF', 'UNIQUENAME', 'TYPE_ID', 'IS_OBSOLETE', 'PUBLISHER', 'PUBPLACE', ),
121: BasePeer::TYPE_FIELDNAME => array ('pub_id', 'title', 'volumetitle', 'volume', 'series_name', 'issue', 'pyear', 'pages', 'miniref', 'uniquename', 'type_id', 'is_obsolete', 'publisher', 'pubplace', ),
122: BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, )
123: );
124:
125: /**
126: * holds an array of keys for quick access to the fieldnames array
127: *
128: * first dimension keys are the type constants
129: * e.g. PubPeer::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
130: */
131: protected static $fieldKeys = array (
132: BasePeer::TYPE_PHPNAME => array ('PubId' => 0, 'Title' => 1, 'Volumetitle' => 2, 'Volume' => 3, 'SeriesName' => 4, 'Issue' => 5, 'Pyear' => 6, 'Pages' => 7, 'Miniref' => 8, 'Uniquename' => 9, 'TypeId' => 10, 'IsObsolete' => 11, 'Publisher' => 12, 'Pubplace' => 13, ),
133: BasePeer::TYPE_STUDLYPHPNAME => array ('pubId' => 0, 'title' => 1, 'volumetitle' => 2, 'volume' => 3, 'seriesName' => 4, 'issue' => 5, 'pyear' => 6, 'pages' => 7, 'miniref' => 8, 'uniquename' => 9, 'typeId' => 10, 'isObsolete' => 11, 'publisher' => 12, 'pubplace' => 13, ),
134: BasePeer::TYPE_COLNAME => array (PubPeer::PUB_ID => 0, PubPeer::TITLE => 1, PubPeer::VOLUMETITLE => 2, PubPeer::VOLUME => 3, PubPeer::SERIES_NAME => 4, PubPeer::ISSUE => 5, PubPeer::PYEAR => 6, PubPeer::PAGES => 7, PubPeer::MINIREF => 8, PubPeer::UNIQUENAME => 9, PubPeer::TYPE_ID => 10, PubPeer::IS_OBSOLETE => 11, PubPeer::PUBLISHER => 12, PubPeer::PUBPLACE => 13, ),
135: BasePeer::TYPE_RAW_COLNAME => array ('PUB_ID' => 0, 'TITLE' => 1, 'VOLUMETITLE' => 2, 'VOLUME' => 3, 'SERIES_NAME' => 4, 'ISSUE' => 5, 'PYEAR' => 6, 'PAGES' => 7, 'MINIREF' => 8, 'UNIQUENAME' => 9, 'TYPE_ID' => 10, 'IS_OBSOLETE' => 11, 'PUBLISHER' => 12, 'PUBPLACE' => 13, ),
136: BasePeer::TYPE_FIELDNAME => array ('pub_id' => 0, 'title' => 1, 'volumetitle' => 2, 'volume' => 3, 'series_name' => 4, 'issue' => 5, 'pyear' => 6, 'pages' => 7, 'miniref' => 8, 'uniquename' => 9, 'type_id' => 10, 'is_obsolete' => 11, 'publisher' => 12, 'pubplace' => 13, ),
137: BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, )
138: );
139:
140: /**
141: * Translates a fieldname to another type
142: *
143: * @param string $name field name
144: * @param string $fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
145: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
146: * @param string $toType One of the class type constants
147: * @return string translated name of the field.
148: * @throws PropelException - if the specified name could not be found in the fieldname mappings.
149: */
150: public static function translateFieldName($name, $fromType, $toType)
151: {
152: $toNames = PubPeer::getFieldNames($toType);
153: $key = isset(PubPeer::$fieldKeys[$fromType][$name]) ? PubPeer::$fieldKeys[$fromType][$name] : null;
154: if ($key === null) {
155: throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(PubPeer::$fieldKeys[$fromType], true));
156: }
157:
158: return $toNames[$key];
159: }
160:
161: /**
162: * Returns an array of field names.
163: *
164: * @param string $type The type of fieldnames to return:
165: * One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
166: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
167: * @return array A list of field names
168: * @throws PropelException - if the type is not valid.
169: */
170: public static function getFieldNames($type = BasePeer::TYPE_PHPNAME)
171: {
172: if (!array_key_exists($type, PubPeer::$fieldNames)) {
173: 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.');
174: }
175:
176: return PubPeer::$fieldNames[$type];
177: }
178:
179: /**
180: * Convenience method which changes table.column to alias.column.
181: *
182: * Using this method you can maintain SQL abstraction while using column aliases.
183: * <code>
184: * $c->addAlias("alias1", TablePeer::TABLE_NAME);
185: * $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
186: * </code>
187: * @param string $alias The alias for the current table.
188: * @param string $column The column name for current table. (i.e. PubPeer::COLUMN_NAME).
189: * @return string
190: */
191: public static function alias($alias, $column)
192: {
193: return str_replace(PubPeer::TABLE_NAME.'.', $alias.'.', $column);
194: }
195:
196: /**
197: * Add all the columns needed to create a new object.
198: *
199: * Note: any columns that were marked with lazyLoad="true" in the
200: * XML schema will not be added to the select list and only loaded
201: * on demand.
202: *
203: * @param Criteria $criteria object containing the columns to add.
204: * @param string $alias optional table alias
205: * @throws PropelException Any exceptions caught during processing will be
206: * rethrown wrapped into a PropelException.
207: */
208: public static function addSelectColumns(Criteria $criteria, $alias = null)
209: {
210: if (null === $alias) {
211: $criteria->addSelectColumn(PubPeer::PUB_ID);
212: $criteria->addSelectColumn(PubPeer::TITLE);
213: $criteria->addSelectColumn(PubPeer::VOLUMETITLE);
214: $criteria->addSelectColumn(PubPeer::VOLUME);
215: $criteria->addSelectColumn(PubPeer::SERIES_NAME);
216: $criteria->addSelectColumn(PubPeer::ISSUE);
217: $criteria->addSelectColumn(PubPeer::PYEAR);
218: $criteria->addSelectColumn(PubPeer::PAGES);
219: $criteria->addSelectColumn(PubPeer::MINIREF);
220: $criteria->addSelectColumn(PubPeer::UNIQUENAME);
221: $criteria->addSelectColumn(PubPeer::TYPE_ID);
222: $criteria->addSelectColumn(PubPeer::IS_OBSOLETE);
223: $criteria->addSelectColumn(PubPeer::PUBLISHER);
224: $criteria->addSelectColumn(PubPeer::PUBPLACE);
225: } else {
226: $criteria->addSelectColumn($alias . '.pub_id');
227: $criteria->addSelectColumn($alias . '.title');
228: $criteria->addSelectColumn($alias . '.volumetitle');
229: $criteria->addSelectColumn($alias . '.volume');
230: $criteria->addSelectColumn($alias . '.series_name');
231: $criteria->addSelectColumn($alias . '.issue');
232: $criteria->addSelectColumn($alias . '.pyear');
233: $criteria->addSelectColumn($alias . '.pages');
234: $criteria->addSelectColumn($alias . '.miniref');
235: $criteria->addSelectColumn($alias . '.uniquename');
236: $criteria->addSelectColumn($alias . '.type_id');
237: $criteria->addSelectColumn($alias . '.is_obsolete');
238: $criteria->addSelectColumn($alias . '.publisher');
239: $criteria->addSelectColumn($alias . '.pubplace');
240: }
241: }
242:
243: /**
244: * Returns the number of rows matching criteria.
245: *
246: * @param Criteria $criteria
247: * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
248: * @param PropelPDO $con
249: * @return int Number of matching rows.
250: */
251: public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
252: {
253: // we may modify criteria, so copy it first
254: $criteria = clone $criteria;
255:
256: // We need to set the primary table name, since in the case that there are no WHERE columns
257: // it will be impossible for the BasePeer::createSelectSql() method to determine which
258: // tables go into the FROM clause.
259: $criteria->setPrimaryTableName(PubPeer::TABLE_NAME);
260:
261: if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
262: $criteria->setDistinct();
263: }
264:
265: if (!$criteria->hasSelectClause()) {
266: PubPeer::addSelectColumns($criteria);
267: }
268:
269: $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
270: $criteria->setDbName(PubPeer::DATABASE_NAME); // Set the correct dbName
271:
272: if ($con === null) {
273: $con = Propel::getConnection(PubPeer::DATABASE_NAME, Propel::CONNECTION_READ);
274: }
275: // BasePeer returns a PDOStatement
276: $stmt = BasePeer::doCount($criteria, $con);
277:
278: if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
279: $count = (int) $row[0];
280: } else {
281: $count = 0; // no rows returned; we infer that means 0 matches.
282: }
283: $stmt->closeCursor();
284:
285: return $count;
286: }
287: /**
288: * Selects one object from the DB.
289: *
290: * @param Criteria $criteria object used to create the SELECT statement.
291: * @param PropelPDO $con
292: * @return Pub
293: * @throws PropelException Any exceptions caught during processing will be
294: * rethrown wrapped into a PropelException.
295: */
296: public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
297: {
298: $critcopy = clone $criteria;
299: $critcopy->setLimit(1);
300: $objects = PubPeer::doSelect($critcopy, $con);
301: if ($objects) {
302: return $objects[0];
303: }
304:
305: return null;
306: }
307: /**
308: * Selects several row from the DB.
309: *
310: * @param Criteria $criteria The Criteria object used to build the SELECT statement.
311: * @param PropelPDO $con
312: * @return array Array of selected Objects
313: * @throws PropelException Any exceptions caught during processing will be
314: * rethrown wrapped into a PropelException.
315: */
316: public static function doSelect(Criteria $criteria, PropelPDO $con = null)
317: {
318: return PubPeer::populateObjects(PubPeer::doSelectStmt($criteria, $con));
319: }
320: /**
321: * Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
322: *
323: * Use this method directly if you want to work with an executed statement directly (for example
324: * to perform your own object hydration).
325: *
326: * @param Criteria $criteria The Criteria object used to build the SELECT statement.
327: * @param PropelPDO $con The connection to use
328: * @throws PropelException Any exceptions caught during processing will be
329: * rethrown wrapped into a PropelException.
330: * @return PDOStatement The executed PDOStatement object.
331: * @see BasePeer::doSelect()
332: */
333: public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
334: {
335: if ($con === null) {
336: $con = Propel::getConnection(PubPeer::DATABASE_NAME, Propel::CONNECTION_READ);
337: }
338:
339: if (!$criteria->hasSelectClause()) {
340: $criteria = clone $criteria;
341: PubPeer::addSelectColumns($criteria);
342: }
343:
344: // Set the correct dbName
345: $criteria->setDbName(PubPeer::DATABASE_NAME);
346:
347: // BasePeer returns a PDOStatement
348: return BasePeer::doSelect($criteria, $con);
349: }
350: /**
351: * Adds an object to the instance pool.
352: *
353: * Propel keeps cached copies of objects in an instance pool when they are retrieved
354: * from the database. In some cases -- especially when you override doSelect*()
355: * methods in your stub classes -- you may need to explicitly add objects
356: * to the cache in order to ensure that the same objects are always returned by doSelect*()
357: * and retrieveByPK*() calls.
358: *
359: * @param Pub $obj A Pub object.
360: * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
361: */
362: public static function addInstanceToPool($obj, $key = null)
363: {
364: if (Propel::isInstancePoolingEnabled()) {
365: if ($key === null) {
366: $key = (string) $obj->getPubId();
367: } // if key === null
368: PubPeer::$instances[$key] = $obj;
369: }
370: }
371:
372: /**
373: * Removes an object from the instance pool.
374: *
375: * Propel keeps cached copies of objects in an instance pool when they are retrieved
376: * from the database. In some cases -- especially when you override doDelete
377: * methods in your stub classes -- you may need to explicitly remove objects
378: * from the cache in order to prevent returning objects that no longer exist.
379: *
380: * @param mixed $value A Pub object or a primary key value.
381: *
382: * @return void
383: * @throws PropelException - if the value is invalid.
384: */
385: public static function removeInstanceFromPool($value)
386: {
387: if (Propel::isInstancePoolingEnabled() && $value !== null) {
388: if (is_object($value) && $value instanceof Pub) {
389: $key = (string) $value->getPubId();
390: } elseif (is_scalar($value)) {
391: // assume we've been passed a primary key
392: $key = (string) $value;
393: } else {
394: $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or Pub object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
395: throw $e;
396: }
397:
398: unset(PubPeer::$instances[$key]);
399: }
400: } // removeInstanceFromPool()
401:
402: /**
403: * 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.
404: *
405: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
406: * a multi-column primary key, a serialize()d version of the primary key will be returned.
407: *
408: * @param string $key The key (@see getPrimaryKeyHash()) for this instance.
409: * @return Pub Found object or null if 1) no instance exists for specified key or 2) instance pooling has been disabled.
410: * @see getPrimaryKeyHash()
411: */
412: public static function getInstanceFromPool($key)
413: {
414: if (Propel::isInstancePoolingEnabled()) {
415: if (isset(PubPeer::$instances[$key])) {
416: return PubPeer::$instances[$key];
417: }
418: }
419:
420: return null; // just to be explicit
421: }
422:
423: /**
424: * Clear the instance pool.
425: *
426: * @return void
427: */
428: public static function clearInstancePool($and_clear_all_references = false)
429: {
430: if ($and_clear_all_references)
431: {
432: foreach (PubPeer::$instances as $instance)
433: {
434: $instance->clearAllReferences(true);
435: }
436: }
437: PubPeer::$instances = array();
438: }
439:
440: /**
441: * Method to invalidate the instance pool of all tables related to pub
442: * by a foreign key with ON DELETE CASCADE
443: */
444: public static function clearRelatedInstancePool()
445: {
446: // Invalidate objects in FeatureCvtermPeer instance pool,
447: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
448: FeatureCvtermPeer::clearInstancePool();
449: // Invalidate objects in FeatureCvtermPubPeer instance pool,
450: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
451: FeatureCvtermPubPeer::clearInstancePool();
452: // Invalidate objects in FeaturePubPeer instance pool,
453: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
454: FeaturePubPeer::clearInstancePool();
455: // Invalidate objects in FeatureSynonymPeer instance pool,
456: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
457: FeatureSynonymPeer::clearInstancePool();
458: // Invalidate objects in PubDbxrefPeer instance pool,
459: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
460: PubDbxrefPeer::clearInstancePool();
461: // Invalidate objects in PubRelationshipPeer instance pool,
462: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
463: PubRelationshipPeer::clearInstancePool();
464: // Invalidate objects in PubRelationshipPeer instance pool,
465: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
466: PubRelationshipPeer::clearInstancePool();
467: // Invalidate objects in PubauthorPeer instance pool,
468: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
469: PubauthorPeer::clearInstancePool();
470: // Invalidate objects in PubpropPeer instance pool,
471: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
472: PubpropPeer::clearInstancePool();
473: }
474:
475: /**
476: * 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.
477: *
478: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
479: * a multi-column primary key, a serialize()d version of the primary key will be returned.
480: *
481: * @param array $row PropelPDO resultset row.
482: * @param int $startcol The 0-based offset for reading from the resultset row.
483: * @return string A string version of PK or null if the components of primary key in result array are all null.
484: */
485: public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
486: {
487: // If the PK cannot be derived from the row, return null.
488: if ($row[$startcol] === null) {
489: return null;
490: }
491:
492: return (string) $row[$startcol];
493: }
494:
495: /**
496: * Retrieves the primary key from the DB resultset row
497: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
498: * a multi-column primary key, an array of the primary key columns will be returned.
499: *
500: * @param array $row PropelPDO resultset row.
501: * @param int $startcol The 0-based offset for reading from the resultset row.
502: * @return mixed The primary key of the row
503: */
504: public static function getPrimaryKeyFromRow($row, $startcol = 0)
505: {
506:
507: return (int) $row[$startcol];
508: }
509:
510: /**
511: * The returned array will contain objects of the default type or
512: * objects that inherit from the default.
513: *
514: * @throws PropelException Any exceptions caught during processing will be
515: * rethrown wrapped into a PropelException.
516: */
517: public static function populateObjects(PDOStatement $stmt)
518: {
519: $results = array();
520:
521: // set the class once to avoid overhead in the loop
522: $cls = PubPeer::getOMClass();
523: // populate the object(s)
524: while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
525: $key = PubPeer::getPrimaryKeyHashFromRow($row, 0);
526: if (null !== ($obj = PubPeer::getInstanceFromPool($key))) {
527: // We no longer rehydrate the object, since this can cause data loss.
528: // See http://www.propelorm.org/ticket/509
529: // $obj->hydrate($row, 0, true); // rehydrate
530: $results[] = $obj;
531: } else {
532: $obj = new $cls();
533: $obj->hydrate($row);
534: $results[] = $obj;
535: PubPeer::addInstanceToPool($obj, $key);
536: } // if key exists
537: }
538: $stmt->closeCursor();
539:
540: return $results;
541: }
542: /**
543: * Populates an object of the default type or an object that inherit from the default.
544: *
545: * @param array $row PropelPDO resultset row.
546: * @param int $startcol The 0-based offset for reading from the resultset row.
547: * @throws PropelException Any exceptions caught during processing will be
548: * rethrown wrapped into a PropelException.
549: * @return array (Pub object, last column rank)
550: */
551: public static function populateObject($row, $startcol = 0)
552: {
553: $key = PubPeer::getPrimaryKeyHashFromRow($row, $startcol);
554: if (null !== ($obj = PubPeer::getInstanceFromPool($key))) {
555: // We no longer rehydrate the object, since this can cause data loss.
556: // See http://www.propelorm.org/ticket/509
557: // $obj->hydrate($row, $startcol, true); // rehydrate
558: $col = $startcol + PubPeer::NUM_HYDRATE_COLUMNS;
559: } else {
560: $cls = PubPeer::OM_CLASS;
561: $obj = new $cls();
562: $col = $obj->hydrate($row, $startcol);
563: PubPeer::addInstanceToPool($obj, $key);
564: }
565:
566: return array($obj, $col);
567: }
568:
569:
570: /**
571: * Returns the number of rows matching criteria, joining the related Cvterm table
572: *
573: * @param Criteria $criteria
574: * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
575: * @param PropelPDO $con
576: * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
577: * @return int Number of matching rows.
578: */
579: public static function doCountJoinCvterm(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
580: {
581: // we're going to modify criteria, so copy it first
582: $criteria = clone $criteria;
583:
584: // We need to set the primary table name, since in the case that there are no WHERE columns
585: // it will be impossible for the BasePeer::createSelectSql() method to determine which
586: // tables go into the FROM clause.
587: $criteria->setPrimaryTableName(PubPeer::TABLE_NAME);
588:
589: if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
590: $criteria->setDistinct();
591: }
592:
593: if (!$criteria->hasSelectClause()) {
594: PubPeer::addSelectColumns($criteria);
595: }
596:
597: $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
598:
599: // Set the correct dbName
600: $criteria->setDbName(PubPeer::DATABASE_NAME);
601:
602: if ($con === null) {
603: $con = Propel::getConnection(PubPeer::DATABASE_NAME, Propel::CONNECTION_READ);
604: }
605:
606: $criteria->addJoin(PubPeer::TYPE_ID, CvtermPeer::CVTERM_ID, $join_behavior);
607:
608: $stmt = BasePeer::doCount($criteria, $con);
609:
610: if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
611: $count = (int) $row[0];
612: } else {
613: $count = 0; // no rows returned; we infer that means 0 matches.
614: }
615: $stmt->closeCursor();
616:
617: return $count;
618: }
619:
620:
621: /**
622: * Selects a collection of Pub objects pre-filled with their Cvterm objects.
623: * @param Criteria $criteria
624: * @param PropelPDO $con
625: * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
626: * @return array Array of Pub objects.
627: * @throws PropelException Any exceptions caught during processing will be
628: * rethrown wrapped into a PropelException.
629: */
630: public static function doSelectJoinCvterm(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
631: {
632: $criteria = clone $criteria;
633:
634: // Set the correct dbName if it has not been overridden
635: if ($criteria->getDbName() == Propel::getDefaultDB()) {
636: $criteria->setDbName(PubPeer::DATABASE_NAME);
637: }
638:
639: PubPeer::addSelectColumns($criteria);
640: $startcol = PubPeer::NUM_HYDRATE_COLUMNS;
641: CvtermPeer::addSelectColumns($criteria);
642:
643: $criteria->addJoin(PubPeer::TYPE_ID, CvtermPeer::CVTERM_ID, $join_behavior);
644:
645: $stmt = BasePeer::doSelect($criteria, $con);
646: $results = array();
647:
648: while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
649: $key1 = PubPeer::getPrimaryKeyHashFromRow($row, 0);
650: if (null !== ($obj1 = PubPeer::getInstanceFromPool($key1))) {
651: // We no longer rehydrate the object, since this can cause data loss.
652: // See http://www.propelorm.org/ticket/509
653: // $obj1->hydrate($row, 0, true); // rehydrate
654: } else {
655:
656: $cls = PubPeer::getOMClass();
657:
658: $obj1 = new $cls();
659: $obj1->hydrate($row);
660: PubPeer::addInstanceToPool($obj1, $key1);
661: } // if $obj1 already loaded
662:
663: $key2 = CvtermPeer::getPrimaryKeyHashFromRow($row, $startcol);
664: if ($key2 !== null) {
665: $obj2 = CvtermPeer::getInstanceFromPool($key2);
666: if (!$obj2) {
667:
668: $cls = CvtermPeer::getOMClass();
669:
670: $obj2 = new $cls();
671: $obj2->hydrate($row, $startcol);
672: CvtermPeer::addInstanceToPool($obj2, $key2);
673: } // if obj2 already loaded
674:
675: // Add the $obj1 (Pub) to $obj2 (Cvterm)
676: $obj2->addPub($obj1);
677:
678: } // if joined row was not null
679:
680: $results[] = $obj1;
681: }
682: $stmt->closeCursor();
683:
684: return $results;
685: }
686:
687:
688: /**
689: * Returns the number of rows matching criteria, joining all related tables
690: *
691: * @param Criteria $criteria
692: * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
693: * @param PropelPDO $con
694: * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
695: * @return int Number of matching rows.
696: */
697: public static function doCountJoinAll(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
698: {
699: // we're going to modify criteria, so copy it first
700: $criteria = clone $criteria;
701:
702: // We need to set the primary table name, since in the case that there are no WHERE columns
703: // it will be impossible for the BasePeer::createSelectSql() method to determine which
704: // tables go into the FROM clause.
705: $criteria->setPrimaryTableName(PubPeer::TABLE_NAME);
706:
707: if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
708: $criteria->setDistinct();
709: }
710:
711: if (!$criteria->hasSelectClause()) {
712: PubPeer::addSelectColumns($criteria);
713: }
714:
715: $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
716:
717: // Set the correct dbName
718: $criteria->setDbName(PubPeer::DATABASE_NAME);
719:
720: if ($con === null) {
721: $con = Propel::getConnection(PubPeer::DATABASE_NAME, Propel::CONNECTION_READ);
722: }
723:
724: $criteria->addJoin(PubPeer::TYPE_ID, CvtermPeer::CVTERM_ID, $join_behavior);
725:
726: $stmt = BasePeer::doCount($criteria, $con);
727:
728: if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
729: $count = (int) $row[0];
730: } else {
731: $count = 0; // no rows returned; we infer that means 0 matches.
732: }
733: $stmt->closeCursor();
734:
735: return $count;
736: }
737:
738: /**
739: * Selects a collection of Pub objects pre-filled with all related objects.
740: *
741: * @param Criteria $criteria
742: * @param PropelPDO $con
743: * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
744: * @return array Array of Pub objects.
745: * @throws PropelException Any exceptions caught during processing will be
746: * rethrown wrapped into a PropelException.
747: */
748: public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
749: {
750: $criteria = clone $criteria;
751:
752: // Set the correct dbName if it has not been overridden
753: if ($criteria->getDbName() == Propel::getDefaultDB()) {
754: $criteria->setDbName(PubPeer::DATABASE_NAME);
755: }
756:
757: PubPeer::addSelectColumns($criteria);
758: $startcol2 = PubPeer::NUM_HYDRATE_COLUMNS;
759:
760: CvtermPeer::addSelectColumns($criteria);
761: $startcol3 = $startcol2 + CvtermPeer::NUM_HYDRATE_COLUMNS;
762:
763: $criteria->addJoin(PubPeer::TYPE_ID, CvtermPeer::CVTERM_ID, $join_behavior);
764:
765: $stmt = BasePeer::doSelect($criteria, $con);
766: $results = array();
767:
768: while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
769: $key1 = PubPeer::getPrimaryKeyHashFromRow($row, 0);
770: if (null !== ($obj1 = PubPeer::getInstanceFromPool($key1))) {
771: // We no longer rehydrate the object, since this can cause data loss.
772: // See http://www.propelorm.org/ticket/509
773: // $obj1->hydrate($row, 0, true); // rehydrate
774: } else {
775: $cls = PubPeer::getOMClass();
776:
777: $obj1 = new $cls();
778: $obj1->hydrate($row);
779: PubPeer::addInstanceToPool($obj1, $key1);
780: } // if obj1 already loaded
781:
782: // Add objects for joined Cvterm rows
783:
784: $key2 = CvtermPeer::getPrimaryKeyHashFromRow($row, $startcol2);
785: if ($key2 !== null) {
786: $obj2 = CvtermPeer::getInstanceFromPool($key2);
787: if (!$obj2) {
788:
789: $cls = CvtermPeer::getOMClass();
790:
791: $obj2 = new $cls();
792: $obj2->hydrate($row, $startcol2);
793: CvtermPeer::addInstanceToPool($obj2, $key2);
794: } // if obj2 loaded
795:
796: // Add the $obj1 (Pub) to the collection in $obj2 (Cvterm)
797: $obj2->addPub($obj1);
798: } // if joined row not null
799:
800: $results[] = $obj1;
801: }
802: $stmt->closeCursor();
803:
804: return $results;
805: }
806:
807: /**
808: * Returns the TableMap related to this peer.
809: * This method is not needed for general use but a specific application could have a need.
810: * @return TableMap
811: * @throws PropelException Any exceptions caught during processing will be
812: * rethrown wrapped into a PropelException.
813: */
814: public static function getTableMap()
815: {
816: return Propel::getDatabaseMap(PubPeer::DATABASE_NAME)->getTable(PubPeer::TABLE_NAME);
817: }
818:
819: /**
820: * Add a TableMap instance to the database for this peer class.
821: */
822: public static function buildTableMap()
823: {
824: $dbMap = Propel::getDatabaseMap(BasePubPeer::DATABASE_NAME);
825: if (!$dbMap->hasTable(BasePubPeer::TABLE_NAME)) {
826: $dbMap->addTableObject(new PubTableMap());
827: }
828: }
829:
830: /**
831: * The class that the Peer will make instances of.
832: *
833: *
834: * @return string ClassName
835: */
836: public static function getOMClass($row = 0, $colnum = 0)
837: {
838: return PubPeer::OM_CLASS;
839: }
840:
841: /**
842: * Performs an INSERT on the database, given a Pub or Criteria object.
843: *
844: * @param mixed $values Criteria or Pub object containing data that is used to create the INSERT statement.
845: * @param PropelPDO $con the PropelPDO connection to use
846: * @return mixed The new primary key.
847: * @throws PropelException Any exceptions caught during processing will be
848: * rethrown wrapped into a PropelException.
849: */
850: public static function doInsert($values, PropelPDO $con = null)
851: {
852: if ($con === null) {
853: $con = Propel::getConnection(PubPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
854: }
855:
856: if ($values instanceof Criteria) {
857: $criteria = clone $values; // rename for clarity
858: } else {
859: $criteria = $values->buildCriteria(); // build Criteria from Pub object
860: }
861:
862: if ($criteria->containsKey(PubPeer::PUB_ID) && $criteria->keyContainsValue(PubPeer::PUB_ID) ) {
863: throw new PropelException('Cannot insert a value for auto-increment primary key ('.PubPeer::PUB_ID.')');
864: }
865:
866:
867: // Set the correct dbName
868: $criteria->setDbName(PubPeer::DATABASE_NAME);
869:
870: try {
871: // use transaction because $criteria could contain info
872: // for more than one table (I guess, conceivably)
873: $con->beginTransaction();
874: $pk = BasePeer::doInsert($criteria, $con);
875: $con->commit();
876: } catch (PropelException $e) {
877: $con->rollBack();
878: throw $e;
879: }
880:
881: return $pk;
882: }
883:
884: /**
885: * Performs an UPDATE on the database, given a Pub or Criteria object.
886: *
887: * @param mixed $values Criteria or Pub object containing data that is used to create the UPDATE statement.
888: * @param PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
889: * @return int The number of affected rows (if supported by underlying database driver).
890: * @throws PropelException Any exceptions caught during processing will be
891: * rethrown wrapped into a PropelException.
892: */
893: public static function doUpdate($values, PropelPDO $con = null)
894: {
895: if ($con === null) {
896: $con = Propel::getConnection(PubPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
897: }
898:
899: $selectCriteria = new Criteria(PubPeer::DATABASE_NAME);
900:
901: if ($values instanceof Criteria) {
902: $criteria = clone $values; // rename for clarity
903:
904: $comparison = $criteria->getComparison(PubPeer::PUB_ID);
905: $value = $criteria->remove(PubPeer::PUB_ID);
906: if ($value) {
907: $selectCriteria->add(PubPeer::PUB_ID, $value, $comparison);
908: } else {
909: $selectCriteria->setPrimaryTableName(PubPeer::TABLE_NAME);
910: }
911:
912: } else { // $values is Pub object
913: $criteria = $values->buildCriteria(); // gets full criteria
914: $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
915: }
916:
917: // set the correct dbName
918: $criteria->setDbName(PubPeer::DATABASE_NAME);
919:
920: return BasePeer::doUpdate($selectCriteria, $criteria, $con);
921: }
922:
923: /**
924: * Deletes all rows from the pub table.
925: *
926: * @param PropelPDO $con the connection to use
927: * @return int The number of affected rows (if supported by underlying database driver).
928: * @throws PropelException
929: */
930: public static function doDeleteAll(PropelPDO $con = null)
931: {
932: if ($con === null) {
933: $con = Propel::getConnection(PubPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
934: }
935: $affectedRows = 0; // initialize var to track total num of affected rows
936: try {
937: // use transaction because $criteria could contain info
938: // for more than one table or we could emulating ON DELETE CASCADE, etc.
939: $con->beginTransaction();
940: $affectedRows += BasePeer::doDeleteAll(PubPeer::TABLE_NAME, $con, PubPeer::DATABASE_NAME);
941: // Because this db requires some delete cascade/set null emulation, we have to
942: // clear the cached instance *after* the emulation has happened (since
943: // instances get re-added by the select statement contained therein).
944: PubPeer::clearInstancePool();
945: PubPeer::clearRelatedInstancePool();
946: $con->commit();
947:
948: return $affectedRows;
949: } catch (PropelException $e) {
950: $con->rollBack();
951: throw $e;
952: }
953: }
954:
955: /**
956: * Performs a DELETE on the database, given a Pub or Criteria object OR a primary key value.
957: *
958: * @param mixed $values Criteria or Pub object or primary key or array of primary keys
959: * which is used to create the DELETE statement
960: * @param PropelPDO $con the connection to use
961: * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
962: * if supported by native driver or if emulated using Propel.
963: * @throws PropelException Any exceptions caught during processing will be
964: * rethrown wrapped into a PropelException.
965: */
966: public static function doDelete($values, PropelPDO $con = null)
967: {
968: if ($con === null) {
969: $con = Propel::getConnection(PubPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
970: }
971:
972: if ($values instanceof Criteria) {
973: // invalidate the cache for all objects of this type, since we have no
974: // way of knowing (without running a query) what objects should be invalidated
975: // from the cache based on this Criteria.
976: PubPeer::clearInstancePool();
977: // rename for clarity
978: $criteria = clone $values;
979: } elseif ($values instanceof Pub) { // it's a model object
980: // invalidate the cache for this single object
981: PubPeer::removeInstanceFromPool($values);
982: // create criteria based on pk values
983: $criteria = $values->buildPkeyCriteria();
984: } else { // it's a primary key, or an array of pks
985: $criteria = new Criteria(PubPeer::DATABASE_NAME);
986: $criteria->add(PubPeer::PUB_ID, (array) $values, Criteria::IN);
987: // invalidate the cache for this object(s)
988: foreach ((array) $values as $singleval) {
989: PubPeer::removeInstanceFromPool($singleval);
990: }
991: }
992:
993: // Set the correct dbName
994: $criteria->setDbName(PubPeer::DATABASE_NAME);
995:
996: $affectedRows = 0; // initialize var to track total num of affected rows
997:
998: try {
999: // use transaction because $criteria could contain info
1000: // for more than one table or we could emulating ON DELETE CASCADE, etc.
1001: $con->beginTransaction();
1002:
1003: $affectedRows += BasePeer::doDelete($criteria, $con);
1004: PubPeer::clearRelatedInstancePool();
1005: $con->commit();
1006:
1007: return $affectedRows;
1008: } catch (PropelException $e) {
1009: $con->rollBack();
1010: throw $e;
1011: }
1012: }
1013:
1014: /**
1015: * Validates all modified columns of given Pub object.
1016: * If parameter $columns is either a single column name or an array of column names
1017: * than only those columns are validated.
1018: *
1019: * NOTICE: This does not apply to primary or foreign keys for now.
1020: *
1021: * @param Pub $obj The object to validate.
1022: * @param mixed $cols Column name or array of column names.
1023: *
1024: * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
1025: */
1026: public static function doValidate($obj, $cols = null)
1027: {
1028: $columns = array();
1029:
1030: if ($cols) {
1031: $dbMap = Propel::getDatabaseMap(PubPeer::DATABASE_NAME);
1032: $tableMap = $dbMap->getTable(PubPeer::TABLE_NAME);
1033:
1034: if (! is_array($cols)) {
1035: $cols = array($cols);
1036: }
1037:
1038: foreach ($cols as $colName) {
1039: if ($tableMap->hasColumn($colName)) {
1040: $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
1041: $columns[$colName] = $obj->$get();
1042: }
1043: }
1044: } else {
1045:
1046: }
1047:
1048: return BasePeer::doValidate(PubPeer::DATABASE_NAME, PubPeer::TABLE_NAME, $columns);
1049: }
1050:
1051: /**
1052: * Retrieve a single object by pkey.
1053: *
1054: * @param int $pk the primary key.
1055: * @param PropelPDO $con the connection to use
1056: * @return Pub
1057: */
1058: public static function retrieveByPK($pk, PropelPDO $con = null)
1059: {
1060:
1061: if (null !== ($obj = PubPeer::getInstanceFromPool((string) $pk))) {
1062: return $obj;
1063: }
1064:
1065: if ($con === null) {
1066: $con = Propel::getConnection(PubPeer::DATABASE_NAME, Propel::CONNECTION_READ);
1067: }
1068:
1069: $criteria = new Criteria(PubPeer::DATABASE_NAME);
1070: $criteria->add(PubPeer::PUB_ID, $pk);
1071:
1072: $v = PubPeer::doSelect($criteria, $con);
1073:
1074: return !empty($v) > 0 ? $v[0] : null;
1075: }
1076:
1077: /**
1078: * Retrieve multiple objects by pkey.
1079: *
1080: * @param array $pks List of primary keys
1081: * @param PropelPDO $con the connection to use
1082: * @return Pub[]
1083: * @throws PropelException Any exceptions caught during processing will be
1084: * rethrown wrapped into a PropelException.
1085: */
1086: public static function retrieveByPKs($pks, PropelPDO $con = null)
1087: {
1088: if ($con === null) {
1089: $con = Propel::getConnection(PubPeer::DATABASE_NAME, Propel::CONNECTION_READ);
1090: }
1091:
1092: $objs = null;
1093: if (empty($pks)) {
1094: $objs = array();
1095: } else {
1096: $criteria = new Criteria(PubPeer::DATABASE_NAME);
1097: $criteria->add(PubPeer::PUB_ID, $pks, Criteria::IN);
1098: $objs = PubPeer::doSelect($criteria, $con);
1099: }
1100:
1101: return $objs;
1102: }
1103:
1104: } // BasePubPeer
1105:
1106: // This is the static code needed to register the TableMap for this table with the main Propel class.
1107: //
1108: BasePubPeer::buildTableMap();
1109:
1110: