/** * @test * @expectedException \Neos\Flow\Error\Exception */ public function persistAllReconnectsConnectionOnFailure() { $this->mockEntityManager->expects($this->exactly(2))->method('flush')->will($this->throwException(new FlowError\Exception('Dummy connection error'))); $this->mockConnection->expects($this->at(0))->method('close'); $this->mockConnection->expects($this->at(1))->method('connect'); $this->persistenceManager->persistAll(); }
/** * @param DoctrineSqlFilter $sqlFilter * @param QuoteStrategy $quoteStrategy * @param ClassMetadata $targetEntity * @param string $targetTableAlias * @param string $targetEntityPropertyName * @return string * @throws InvalidQueryRewritingConstraintException * @throws \Exception */ protected function getSqlForManyToOneAndOneToOneRelationsWithPropertyPath(DoctrineSqlFilter $sqlFilter, QuoteStrategy $quoteStrategy, ClassMetadata $targetEntity, $targetTableAlias, $targetEntityPropertyName) { $subselectQuery = $this->getSubselectQuery($targetEntity, $targetEntityPropertyName); $associationMapping = $targetEntity->getAssociationMapping($targetEntityPropertyName); $subselectConstraintQueries = []; foreach ($associationMapping['joinColumns'] as $joinColumn) { $rootAliases = $subselectQuery->getQueryBuilder()->getRootAliases(); $subselectQuery->getQueryBuilder()->select($rootAliases[0] . '.' . $targetEntity->getFieldForColumn($joinColumn['referencedColumnName'])); $subselectSql = $subselectQuery->getSql(); foreach ($subselectQuery->getParameters() as $parameter) { $parameterValue = $parameter->getValue(); if (is_object($parameterValue)) { $parameterValue = $this->persistenceManager->getIdentifierByObject($parameter->getValue()); } $subselectSql = preg_replace('/\\?/', $this->entityManager->getConnection()->quote($parameterValue, $parameter->getType()), $subselectSql, 1); } $quotedColumnName = $quoteStrategy->getJoinColumnName($joinColumn, $targetEntity, $this->entityManager->getConnection()->getDatabasePlatform()); $subselectIdentifier = 'subselect' . md5($subselectSql); $subselectConstraintQueries[] = $targetTableAlias . '.' . $quotedColumnName . ' IN (SELECT ' . $subselectIdentifier . '.' . $joinColumn['referencedColumnName'] . '_0 FROM (' . $subselectSql . ') AS ' . $subselectIdentifier . ' ) '; } return ' (' . implode(' ) AND ( ', $subselectConstraintQueries) . ') '; }