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