Skip to content

Commit acfad25

Browse files
committed
RoadNetworkTopologyProjection: add roadnodes and is_v2
1 parent de4440c commit acfad25

File tree

3 files changed

+217
-90
lines changed

3 files changed

+217
-90
lines changed

src/RoadRegistry.Infrastructure.MartenDb/Projections/RoadNetworkTopologyProjection-EventsV1.cs

Lines changed: 84 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,131 +9,171 @@
99

1010
public partial class RoadNetworkTopologyProjection
1111
{
12+
public void Project(IEvent<ImportedRoadNode> e, IDocumentOperations ops)
13+
{
14+
ops.QueueSqlCommand($"INSERT INTO {RoadNodesTableName} (id, geometry, timestamp, is_v2) VALUES (?, ST_GeomFromText(?, ?), ?, FALSE)",
15+
e.Data.RoadNodeId,
16+
e.Data.Geometry.WKT,
17+
e.Data.Geometry.SRID,
18+
e.Timestamp
19+
);
20+
}
21+
22+
public void Project(IEvent<RoadNodeAdded> e, IDocumentOperations ops)
23+
{
24+
ops.QueueSqlCommand($"INSERT INTO {RoadNodesTableName} (id, geometry, timestamp, is_v2) VALUES (?, ST_GeomFromText(?, ?), ?, FALSE)",
25+
e.Data.RoadNodeId,
26+
e.Data.Geometry.WKT,
27+
e.Data.Geometry.SRID,
28+
e.Timestamp
29+
);
30+
}
31+
32+
public void Project(IEvent<RoadNodeModified> e, IDocumentOperations ops)
33+
{
34+
ops.QueueSqlCommand("SELECT projections.networktopology_update_roadnode(?, ?, ?, ?);",
35+
e.Data.RoadNodeId,
36+
e.Timestamp,
37+
e.Data.Geometry.WKT,
38+
e.Data.Geometry.SRID
39+
);
40+
}
41+
42+
public void Project(IEvent<RoadNodeRemoved> e, IDocumentOperations ops)
43+
{
44+
ops.QueueSqlCommand("SELECT projections.networktopology_delete_roadnode(?, ?);",
45+
e.Data.RoadNodeId,
46+
e.Timestamp
47+
);
48+
}
49+
1250
public void Project(IEvent<ImportedRoadSegment> e, IDocumentOperations ops)
1351
{
14-
ops.QueueSqlCommand($"INSERT INTO {RoadSegmentsTableName} (id, geometry, start_node_id, end_node_id, timestamp) VALUES (?, ST_GeomFromText(?, ?), ?, ?, ?)",
15-
e.Data.RoadSegmentId, e.Data.Geometry.WKT, e.Data.Geometry.SRID, e.Data.StartNodeId, e.Data.EndNodeId, e.Timestamp
52+
ops.QueueSqlCommand($"INSERT INTO {RoadSegmentsTableName} (id, geometry, start_node_id, end_node_id, timestamp, is_v2) VALUES (?, ST_GeomFromText(?, ?), ?, ?, ?, FALSE)",
53+
e.Data.RoadSegmentId,
54+
e.Data.Geometry.WKT,
55+
e.Data.Geometry.SRID,
56+
e.Data.StartNodeId,
57+
e.Data.EndNodeId,
58+
e.Timestamp
1659
);
1760
}
61+
1862
public void Project(IEvent<RoadSegmentAdded> e, IDocumentOperations ops)
1963
{
20-
ops.QueueSqlCommand($"INSERT INTO {RoadSegmentsTableName} (id, geometry, start_node_id, end_node_id, timestamp) VALUES (?, ST_GeomFromText(?, ?), ?, ?, ?)",
21-
e.Data.RoadSegmentId, e.Data.Geometry.WKT, e.Data.Geometry.SRID, e.Data.StartNodeId, e.Data.EndNodeId, e.Timestamp
64+
ops.QueueSqlCommand($"INSERT INTO {RoadSegmentsTableName} (id, geometry, start_node_id, end_node_id, timestamp, is_v2) VALUES (?, ST_GeomFromText(?, ?), ?, ?, ?, FALSE)",
65+
e.Data.RoadSegmentId,
66+
e.Data.Geometry.WKT,
67+
e.Data.Geometry.SRID,
68+
e.Data.StartNodeId,
69+
e.Data.EndNodeId,
70+
e.Timestamp
2271
);
2372
}
73+
2474
public void Project(IEvent<RoadSegmentModified> e, IDocumentOperations ops)
2575
{
26-
var parameters = new object?[]
27-
{
76+
ops.QueueSqlCommand("SELECT projections.networktopology_update_roadsegment(?, ?, ?, ?, ?, ?);",
2877
e.Data.RoadSegmentId,
2978
e.Timestamp,
3079
e.Data.Geometry.WKT,
3180
e.Data.Geometry.SRID,
3281
e.Data.StartNodeId,
3382
e.Data.EndNodeId
34-
};
35-
36-
ops.QueueSqlCommand("SELECT projections.networktopology_update_roadsegment(?, ?, ?, ?, ?, ?);", parameters);
83+
);
3784
}
85+
3886
public void Project(IEvent<RoadSegmentGeometryModified> e, IDocumentOperations ops)
3987
{
40-
var parameters = new object?[]
41-
{
88+
ops.QueueSqlCommand("SELECT projections.networktopology_update_roadsegment(?, ?, ?, ?, null, null);",
4289
e.Data.RoadSegmentId,
4390
e.Timestamp,
4491
e.Data.Geometry.WKT,
4592
e.Data.Geometry.SRID
46-
};
47-
48-
ops.QueueSqlCommand("SELECT projections.networktopology_update_roadsegment(?, ?, ?, ?, null, null);", parameters);
93+
);
4994
}
5095

5196
public void Project(IEvent<RoadSegmentRemoved> e, IDocumentOperations ops)
5297
{
53-
var parameters = new object[]
54-
{
98+
ops.QueueSqlCommand("SELECT projections.networktopology_delete_roadsegment(?, ?);",
5599
e.Data.RoadSegmentId,
56100
e.Timestamp
57-
};
58-
59-
ops.QueueSqlCommand("SELECT projections.networktopology_delete_roadsegment(?, ?);", parameters);
101+
);
60102
}
61103

62104
public void Project(IEvent<ImportedGradeSeparatedJunction> e, IDocumentOperations ops)
63105
{
64-
ops.QueueSqlCommand($"INSERT INTO {GradeSeparatedJunctionsTableName} (id, lower_road_segment_id, upper_road_segment_id, timestamp) VALUES (?, ?, ?, ?)",
65-
e.Data.Id, e.Data.LowerRoadSegmentId, e.Data.UpperRoadSegmentId, e.Timestamp
106+
ops.QueueSqlCommand($"INSERT INTO {GradeSeparatedJunctionsTableName} (id, lower_road_segment_id, upper_road_segment_id, timestamp, is_v2) VALUES (?, ?, ?, ?, FALSE)",
107+
e.Data.Id,
108+
e.Data.LowerRoadSegmentId,
109+
e.Data.UpperRoadSegmentId,
110+
e.Timestamp
66111
);
67112
}
113+
68114
public void Project(IEvent<GradeSeparatedJunctionAdded> e, IDocumentOperations ops)
69115
{
70-
ops.QueueSqlCommand($"INSERT INTO {GradeSeparatedJunctionsTableName} (id, lower_road_segment_id, upper_road_segment_id, timestamp) VALUES (?, ?, ?, ?)",
71-
e.Data.Id, e.Data.LowerRoadSegmentId, e.Data.UpperRoadSegmentId, e.Timestamp
116+
ops.QueueSqlCommand($"INSERT INTO {GradeSeparatedJunctionsTableName} (id, lower_road_segment_id, upper_road_segment_id, timestamp, is_v2) VALUES (?, ?, ?, ?, FALSE)",
117+
e.Data.Id,
118+
e.Data.LowerRoadSegmentId,
119+
e.Data.UpperRoadSegmentId,
120+
e.Timestamp
72121
);
73122
}
123+
74124
public void Project(IEvent<GradeSeparatedJunctionRemoved> e, IDocumentOperations ops)
75125
{
76-
var parameters = new object[]
77-
{
126+
ops.QueueSqlCommand("SELECT projections.networktopology_delete_gradeseparatedjunction(?, ?);",
78127
e.Data.Id,
79128
e.Timestamp
80-
};
81-
82-
ops.QueueSqlCommand("SELECT projections.networktopology_delete_gradeseparatedjunction(?, ?);", parameters);
129+
);
83130
}
84131

85-
public void Project(IEvent<ImportedRoadNode> e, IDocumentOperations ops)
86-
{
87-
// Do nothing
88-
}
89-
public void Project(IEvent<RoadNodeAdded> e, IDocumentOperations ops)
90-
{
91-
// Do nothing
92-
}
93-
public void Project(IEvent<RoadNodeModified> e, IDocumentOperations ops)
94-
{
95-
// Do nothing
96-
}
97-
public void Project(IEvent<RoadNodeRemoved> e, IDocumentOperations ops)
98-
{
99-
// Do nothing
100-
}
101132
public void Project(IEvent<RoadNetworkChangesAccepted> e, IDocumentOperations ops)
102133
{
103134
// Do nothing
104135
}
136+
105137
public void Project(IEvent<RoadSegmentAttributesModified> e, IDocumentOperations ops)
106138
{
107139
// Do nothing
108140
}
141+
109142
public void Project(IEvent<RoadSegmentAddedToEuropeanRoad> e, IDocumentOperations ops)
110143
{
111144
// Do nothing
112145
}
146+
113147
public void Project(IEvent<RoadSegmentAddedToNationalRoad> e, IDocumentOperations ops)
114148
{
115149
// Do nothing
116150
}
151+
117152
public void Project(IEvent<RoadSegmentAddedToNumberedRoad> e, IDocumentOperations ops)
118153
{
119154
// Do nothing
120155
}
156+
121157
public void Project(IEvent<RoadSegmentRemovedFromEuropeanRoad> e, IDocumentOperations ops)
122158
{
123159
// Do nothing
124160
}
161+
125162
public void Project(IEvent<RoadSegmentRemovedFromNationalRoad> e, IDocumentOperations ops)
126163
{
127164
// Do nothing
128165
}
166+
129167
public void Project(IEvent<RoadSegmentRemovedFromNumberedRoad> e, IDocumentOperations ops)
130168
{
131169
// Do nothing
132170
}
171+
133172
public void Project(IEvent<OutlinedRoadSegmentRemoved> e, IDocumentOperations ops)
134173
{
135174
// Do nothing
136175
}
176+
137177
public void Project(IEvent<RoadSegmentStreetNamesChanged> e, IDocumentOperations ops)
138178
{
139179
// Do nothing

src/RoadRegistry.Infrastructure.MartenDb/Projections/RoadNetworkTopologyProjection-EventsV2.cs

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,43 @@
99

1010
public partial class RoadNetworkTopologyProjection
1111
{
12+
public void Project(IEvent<RoadNodeAdded> e, IDocumentOperations ops)
13+
{
14+
ops.QueueSqlCommand($"INSERT INTO {RoadNodesTableName} (id, geometry, timestamp, is_v2) VALUES (?, ST_GeomFromText(?, ?), ?, TRUE)",
15+
e.Data.RoadNodeId,
16+
e.Data.Geometry.WKT,
17+
e.Data.Geometry.SRID,
18+
e.Timestamp
19+
);
20+
}
21+
22+
public void Project(IEvent<RoadNodeModified> e, IDocumentOperations ops)
23+
{
24+
ops.QueueSqlCommand("SELECT projections.networktopology_update_roadnode(?, ?, ?, ?);",
25+
e.Data.RoadNodeId,
26+
e.Timestamp,
27+
e.Data.Geometry.WKT,
28+
e.Data.Geometry.SRID
29+
);
30+
}
31+
32+
public void Project(IEvent<RoadNodeRemoved> e, IDocumentOperations ops)
33+
{
34+
ops.QueueSqlCommand("SELECT projections.networktopology_delete_roadnode(?, ?);",
35+
e.Data.RoadNodeId,
36+
e.Timestamp
37+
);
38+
}
39+
1240
public void Project(IEvent<RoadSegmentAdded> e, IDocumentOperations ops)
1341
{
14-
ops.QueueSqlCommand($"INSERT INTO {RoadSegmentsTableName} (id, geometry, start_node_id, end_node_id, timestamp) VALUES (?, ST_GeomFromText(?, ?), ?, ?, ?)",
15-
e.Data.RoadSegmentId.ToInt32(), e.Data.Geometry.WKT, e.Data.Geometry.SRID, e.Data.StartNodeId.ToInt32(), e.Data.EndNodeId.ToInt32(), e.Timestamp
42+
ops.QueueSqlCommand($"INSERT INTO {RoadSegmentsTableName} (id, geometry, start_node_id, end_node_id, timestamp, is_v2) VALUES (?, ST_GeomFromText(?, ?), ?, ?, ?, TRUE)",
43+
e.Data.RoadSegmentId.ToInt32(),
44+
e.Data.Geometry.WKT,
45+
e.Data.Geometry.SRID,
46+
e.Data.StartNodeId.ToInt32(),
47+
e.Data.EndNodeId.ToInt32(),
48+
e.Timestamp
1649
);
1750
}
1851

@@ -23,34 +56,31 @@ public void Project(IEvent<RoadSegmentModified> e, IDocumentOperations ops)
2356
return;
2457
}
2558

26-
var parameters = new object?[]
27-
{
59+
ops.QueueSqlCommand("SELECT projections.networktopology_update_roadsegment(?, ?, ?, ?, ?, ?);",
2860
e.Data.RoadSegmentId.ToInt32(),
2961
e.Timestamp,
3062
e.Data.Geometry?.WKT,
3163
e.Data.Geometry?.SRID,
3264
e.Data.StartNodeId?.ToInt32(),
3365
e.Data.EndNodeId?.ToInt32()
34-
};
35-
36-
ops.QueueSqlCommand("SELECT projections.networktopology_update_roadsegment(?, ?, ?, ?, ?, ?);", parameters);
66+
);
3767
}
3868

3969
public void Project(IEvent<RoadSegmentRemoved> e, IDocumentOperations ops)
4070
{
41-
var parameters = new object[]
42-
{
71+
ops.QueueSqlCommand("SELECT projections.networktopology_delete_roadsegment(?, ?);",
4372
e.Data.RoadSegmentId.ToInt32(),
4473
e.Timestamp
45-
};
46-
47-
ops.QueueSqlCommand("SELECT projections.networktopology_delete_roadsegment(?, ?);", parameters);
74+
);
4875
}
4976

5077
public void Project(IEvent<GradeSeparatedJunctionAdded> e, IDocumentOperations ops)
5178
{
52-
ops.QueueSqlCommand($"INSERT INTO {GradeSeparatedJunctionsTableName} (id, lower_road_segment_id, upper_road_segment_id, timestamp) VALUES (?, ?, ?, ?)",
53-
e.Data.GradeSeparatedJunctionId.ToInt32(), e.Data.LowerRoadSegmentId.ToInt32(), e.Data.UpperRoadSegmentId.ToInt32(), e.Timestamp
79+
ops.QueueSqlCommand($"INSERT INTO {GradeSeparatedJunctionsTableName} (id, lower_road_segment_id, upper_road_segment_id, timestamp, is_v2) VALUES (?, ?, ?, ?, TRUE)",
80+
e.Data.GradeSeparatedJunctionId.ToInt32(),
81+
e.Data.LowerRoadSegmentId.ToInt32(),
82+
e.Data.UpperRoadSegmentId.ToInt32(),
83+
e.Timestamp
5484
);
5585
}
5686

@@ -61,40 +91,22 @@ public void Project(IEvent<GradeSeparatedJunctionModified> e, IDocumentOperation
6191
return;
6292
}
6393

64-
var parameters = new object?[]
65-
{
94+
ops.QueueSqlCommand("SELECT projections.networktopology_update_gradeseparatedjunction(?, ?, ?, ?);",
6695
e.Data.GradeSeparatedJunctionId.ToInt32(),
6796
e.Timestamp,
6897
e.Data.LowerRoadSegmentId?.ToInt32(),
6998
e.Data.UpperRoadSegmentId?.ToInt32()
70-
};
71-
72-
ops.QueueSqlCommand("SELECT projections.networktopology_update_gradeseparatedjunction(?, ?, ?, ?);", parameters);
99+
);
73100
}
74101

75102
public void Project(IEvent<GradeSeparatedJunctionRemoved> e, IDocumentOperations ops)
76103
{
77-
var parameters = new object[]
78-
{
104+
ops.QueueSqlCommand("SELECT projections.networktopology_delete_gradeseparatedjunction(?, ?);",
79105
e.Data.GradeSeparatedJunctionId.ToInt32(),
80106
e.Timestamp
81-
};
82-
83-
ops.QueueSqlCommand("SELECT projections.networktopology_delete_gradeseparatedjunction(?, ?);", parameters);
107+
);
84108
}
85109

86-
public void Project(IEvent<RoadNodeAdded> e, IDocumentOperations ops)
87-
{
88-
// Do nothing
89-
}
90-
public void Project(IEvent<RoadNodeModified> e, IDocumentOperations ops)
91-
{
92-
// Do nothing
93-
}
94-
public void Project(IEvent<RoadNodeRemoved> e, IDocumentOperations ops)
95-
{
96-
// Do nothing
97-
}
98110
public void Project(IEvent<RoadNetworkChanged> e, IDocumentOperations ops)
99111
{
100112
// Do nothing

0 commit comments

Comments
 (0)