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