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