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