protected function getPropertyTuple(OrmProperty $property, array $tuple) { $propertyTuple = array(); foreach ($property->getFields() as $field) { $propertyTuple[] = $tuple[$field]; } $propertyType = $property->getType(); $propertyTuple = array_combine(array_keys($propertyType->getSqlTypes()), $propertyTuple); return $propertyTuple; }
private function touchEntity(array $tuple) { if (!$this->identifier) { return $this->logicalSchema->getNewEntity(); } $idTuple = array(); foreach ($this->identifier->getFields() as $field) { $idTuple[] = $tuple[$field]; } $idTuple = array_combine(array_keys($this->identifier->getType()->getSqlTypes()), array_values($idTuple)); $id = $this->identifier->getType()->assemble($idTuple, FetchStrategy::lazy()); return $this->getLazyEntityById($id); }
/** * @return void */ private function importProperty() { if (!sizeof($this->ormProperty->getFields())) { // columnless properties are skipped return; } $columns = array_combine($this->ormProperty->getFields(), $this->ormProperty->getType()->getSqlTypes()); $dbColumns = array(); foreach ($columns as $name => $dbType) { $dbColumns[$name] = new DBColumn($name, $dbType); } $fields = array_keys($dbColumns); $this->dbTable->addColumns($dbColumns); if ($this->ormProperty->getType() instanceof AssociationPropertyType) { $this->dbTable->addConstraint(new DBOneToOneConstraint($fields, $this->dbSchema->getTable($this->ormProperty->getType()->getContainer()->getTable()), $this->ormProperty->getType()->getAssociationBreakAction())); } if ($this->ormProperty->isIdentifier()) { $this->dbTable->addConstraint(new DBPrimaryKeyConstraint($fields)); } else { if ($this->ormProperty->isUnique()) { $this->dbTable->addConstraint(new DBUniqueConstraint($fields)); } } }
private function importConstraints(OrmProperty $property) { $name = $this->dbTable->getName() . '_' . $property->getName(); $fields = $property->getFields(); if ($property->isIdentifier()) { $this->dbTable->addConstraint(new DBPrimaryKeyConstraint($name . '_pk', $this->dbTable, $fields)); } else { if ($property->isUnique()) { $this->dbTable->addConstraint(new DBUniqueConstraint($name . '_uq', $this->dbTable, $fields)); } } $type = $property->getType(); if ($type instanceof AssociationPropertyType) { $this->dbTable->addConstraint(new DBOneToOneConstraint($name . '_fk', $this->dbTable, $fields, $this->dbSchema->getTable($property->getType()->getContainer()->getTable()), $property->getType()->getAssociationBreakAction())); } else { if ($type instanceof CompositePropertyType) { foreach ($type->getProperties($property) as $_property) { $this->importConstraints($_property); } } } if ($property->isQueryable()) { $this->dbTable->addIndex(new DBIndex($name . '_idx', $this->dbTable, $fields)); } }
/** * Gets the virtual property. * * This property is built in context of the owning property but contains inner info about * the composite property. * * This is needed because property type do not know about the database columns used to store * the value * * @param string $name name of the property to get from the composite type * @param OrmProperty $owner a property which owns the CompositePropertyType * @return OrmProperty */ function getVirtualProperty($name, OrmProperty $owner) { $idx = 0; $found = false; foreach ($this->entity->getLogicalSchema()->getProperties() as $property) { if ($property->getName() == $name) { $found = true; break; } $idx += $property->getType()->getColumnCount(); } if (!$found) { throw new OrmModelIntegrityException('property not found'); } return new OrmProperty($name, array_slice($owner->getFields(), $idx, $property->getType()->getColumnCount()), $property->getType(), $property->getVisibility(), $property->getMultiplicity(), $property->isUnique(), $property->isIdentifier()); }
/** * @return void */ private function join(OrmProperty $property, AssociationPropertyType $type, EntityQueryBuilder $builder, SelectQuerySource $source) { $joinMethod = $type->getAssociationMultiplicity()->is(AssociationMultiplicity::EXACTLY_ONE) ? SqlJoinMethod::INNER : SqlJoinMethod::LEFT; $condition = Expression::andChain(); $srcSqlFields = $property->getFields(); $dstSqlFields = $builder->entity->getLogicalSchema()->getIdentifier()->getFields(); foreach ($srcSqlFields as $k => $v) { $condition->add(Expression::eq(new SqlColumn($srcSqlFields[$k], $this->alias), new SqlColumn($dstSqlFields[$k], $builder->alias))); } $source->join(new SqlConditionalJoin(new SelectQuerySource(new AliasedSqlValueExpression(new SqlIdentifier($builder->table), $builder->alias)), new SqlJoinMethod($joinMethod), $condition)); }
/** * @return SqlColumn */ function getSqlColumn() { $fields = $this->property->getFields(); $field = reset($fields); return new SqlColumn($field, $this->owner); }