Skip to content

Commit

Permalink
Improved usage of DimensionSpacePointsRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsunet committed Mar 18, 2024
1 parent 94cbe4f commit 882b572
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 37 deletions.
Expand Up @@ -84,23 +84,20 @@ final class DoctrineDbalContentGraphProjection implements ProjectionInterface, W

private DbalCheckpointStorage $checkpointStorage;

private DimensionSpacePointsRepository $dimensionSpacePointsRepository;

public function __construct(
private readonly DbalClientInterface $dbalClient,
private readonly NodeFactory $nodeFactory,
private readonly ContentRepositoryId $contentRepositoryId,
private readonly NodeTypeManager $nodeTypeManager,
private readonly ProjectionContentGraph $projectionContentGraph,
private readonly string $tableNamePrefix,
private readonly DimensionSpacePointsRepository $dimensionSpacePointsRepository
) {
$this->checkpointStorage = new DbalCheckpointStorage(
$this->dbalClient->getConnection(),
$this->tableNamePrefix . '_checkpoint',
self::class
);

$this->dimensionSpacePointsRepository = new DimensionSpacePointsRepository($this->dbalClient->getConnection(), $this->tableNamePrefix);
}

protected function getProjectionContentGraph(): ProjectionContentGraph
Expand Down
Expand Up @@ -41,7 +41,7 @@ public function build(
$projectionFactoryDependencies->contentRepositoryId
);


$dimensionSpacePointsRepository = new DimensionSpacePointsRepository($this->dbalClient->getConnection(), $tableNamePrefix);

return new ContentGraphProjection(
new DoctrineDbalContentGraphProjection(
Expand All @@ -50,15 +50,16 @@ public function build(
$projectionFactoryDependencies->contentRepositoryId,
$projectionFactoryDependencies->nodeTypeManager,
$projectionFactoryDependencies->propertyConverter,
new DimensionSpacePointsRepository($this->dbalClient->getConnection(), $tableNamePrefix)
$dimensionSpacePointsRepository
),
$projectionFactoryDependencies->contentRepositoryId,
$projectionFactoryDependencies->nodeTypeManager,
new ProjectionContentGraph(
$this->dbalClient,
$tableNamePrefix
),
$tableNamePrefix
$tableNamePrefix,
$dimensionSpacePointsRepository
)
);
}
Expand Down
Expand Up @@ -45,18 +45,22 @@ public function __construct(
*/
public function addToDatabase(Connection $databaseConnection, string $tableNamePrefix): void
{
$dimensionSpacePoints = new DimensionSpacePointsRepository($databaseConnection, $tableNamePrefix);
$dimensionSpacePoints->insertDimensionSpacePoint($this->dimensionSpacePoint);
$databaseConnection->transactional(function ($databaseConnection) use (
$tableNamePrefix
) {
$dimensionSpacePoints = new DimensionSpacePointsRepository($databaseConnection, $tableNamePrefix);
$dimensionSpacePoints->insertDimensionSpacePoint($this->dimensionSpacePoint);

$databaseConnection->insert($tableNamePrefix . '_hierarchyrelation', [
'parentnodeanchor' => $this->parentNodeAnchor->value,
'childnodeanchor' => $this->childNodeAnchor->value,
'name' => $this->name?->value,
'contentstreamid' => $this->contentStreamId->value,
'dimensionspacepointhash' => $this->dimensionSpacePointHash,
'position' => $this->position,
'subtreetags' => json_encode($this->subtreeTags, JSON_THROW_ON_ERROR | JSON_FORCE_OBJECT),
]);
$databaseConnection->insert($tableNamePrefix . '_hierarchyrelation', [
'parentnodeanchor' => $this->parentNodeAnchor->value,
'childnodeanchor' => $this->childNodeAnchor->value,
'name' => $this->name?->value,
'contentstreamid' => $this->contentStreamId->value,
'dimensionspacepointhash' => $this->dimensionSpacePointHash,
'position' => $this->position,
'subtreetags' => json_encode($this->subtreeTags, JSON_THROW_ON_ERROR | JSON_FORCE_OBJECT),
]);
});
}

/**
Expand Down
Expand Up @@ -139,27 +139,38 @@ public static function createNewInDatabase(
?NodeName $nodeName,
Timestamps $timestamps,
): self {
$dimensionSpacePoints = new DimensionSpacePointsRepository($databaseConnection, $tableNamePrefix);
$dimensionSpacePoints->insertDimensionSpacePointByHashAndCoordinates($originDimensionSpacePointHash, $originDimensionSpacePoint);
$relationAnchorPoint = $databaseConnection->transactional(function ($databaseConnection) use (
$tableNamePrefix,
$nodeAggregateId,
$originDimensionSpacePoint,
$originDimensionSpacePointHash,
$properties,
$nodeTypeName,
$classification,
$timestamps
) {
$dimensionSpacePoints = new DimensionSpacePointsRepository($databaseConnection, $tableNamePrefix);
$dimensionSpacePoints->insertDimensionSpacePointByHashAndCoordinates($originDimensionSpacePointHash, $originDimensionSpacePoint);

$databaseConnection->insert($tableNamePrefix . '_node', [
'nodeaggregateid' => $nodeAggregateId->value,
'origindimensionspacepointhash' => $originDimensionSpacePointHash,
'properties' => json_encode($properties),
'nodetypename' => $nodeTypeName->value,
'classification' => $classification->value,
'created' => $timestamps->created,
'originalcreated' => $timestamps->originalCreated,
'lastmodified' => $timestamps->lastModified,
'originallastmodified' => $timestamps->originalLastModified,
], [
'created' => Types::DATETIME_IMMUTABLE,
'originalcreated' => Types::DATETIME_IMMUTABLE,
'lastmodified' => Types::DATETIME_IMMUTABLE,
'originallastmodified' => Types::DATETIME_IMMUTABLE,
]);
$databaseConnection->insert($tableNamePrefix . '_node', [
'nodeaggregateid' => $nodeAggregateId->value,
'origindimensionspacepointhash' => $originDimensionSpacePointHash,
'properties' => json_encode($properties),
'nodetypename' => $nodeTypeName->value,
'classification' => $classification->value,
'created' => $timestamps->created,
'originalcreated' => $timestamps->originalCreated,
'lastmodified' => $timestamps->lastModified,
'originallastmodified' => $timestamps->originalLastModified,
], [
'created' => Types::DATETIME_IMMUTABLE,
'originalcreated' => Types::DATETIME_IMMUTABLE,
'lastmodified' => Types::DATETIME_IMMUTABLE,
'originallastmodified' => Types::DATETIME_IMMUTABLE,
]);

$relationAnchorPoint = NodeRelationAnchorPoint::fromInteger((int)$databaseConnection->lastInsertId());
return NodeRelationAnchorPoint::fromInteger((int)$databaseConnection->lastInsertId());
});

return new self(
$relationAnchorPoint,
Expand Down

0 comments on commit 882b572

Please sign in to comment.