*/
protected $exec;
+ /**
+ * @var \pq\Gateway\Table\Identity
+ */
+ protected $identity;
+
/**
* @var \pq\Gateway\Table\Relations
*/
*/
protected $metadataCache;
+ /**
+ * @var \pq\Gateway\Table\LockInterface
+ */
+ protected $lock;
+
/**
* @param string $table
* @return \pq\Gateway\Table
return $this;
}
+ /**
+ * Get the primary key
+ * @return \pq\Gateway\Table\Identity
+ */
+ function getIdentity() {
+ if (!isset($this->identity)) {
+ $this->identity = new Table\Identity($this);
+ }
+ return $this->identity;
+ }
+
/**
* Get foreign key relations
* @param string $to fkey
return $this->name;
}
+ /**
+ * Set a lock provider
+ * @param \pq\Gateway\Table\LockInterface $lock
+ * @return \pq\Gateway\Table
+ */
+ function setLock(Table\LockInterface $lock) {
+ $this->lock = $lock;
+ return $this;
+ }
+
+ /**
+ * Get any set lock provider
+ * @return \pq\Gateway\Table\LockIntferace
+ */
+ function getLock() {
+ return $this->lock;
+ }
+
/**
* Execute the query
* @param \pq\Query\WriterInterface $query
* @param array|string $order
* @param int $limit
* @param int $offset
+ * @param string $lock
* @return mixed
*/
- function find(array $where = null, $order = null, $limit = 0, $offset = 0) {
+ function find(array $where = null, $order = null, $limit = 0, $offset = 0, $lock = null) {
$query = $this->getQueryWriter()->reset();
$query->write("SELECT * FROM", $this->conn->quoteName($this->name));
if ($where) {
if ($limit) {
$query->write("LIMIT", $limit);
}
- $query->write("OFFSET", $offset);
+ if ($offset) {
+ $query->write("OFFSET", $offset);
+ }
+ if ($lock) {
+ $query->write("FOR", $lock);
+ }
return $this->execute($query);
}
// select * from $this where $this->$foreignColumn = $foreign->$referencedColumn
if (!isset($name)) {
- $name = $this->getName();
+ $name = $foreign->getTable()->getName();
}
if (!$foreign->getTable()->hasRelation($name, $this->getName())) {