Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SegmentPointReader.cs =================================================================== diff -u -r1d91b8411e6db990c17fade0ad12aa8ac0e54865 -rbe3fdb23bcc3b82eb8766e2cc22221862634224e --- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SegmentPointReader.cs (.../SegmentPointReader.cs) (revision 1d91b8411e6db990c17fade0ad12aa8ac0e54865) +++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SegmentPointReader.cs (.../SegmentPointReader.cs) (revision be3fdb23bcc3b82eb8766e2cc22221862634224e) @@ -48,7 +48,7 @@ public IEnumerable ReadSegmentPoints(long stochasticSoilModelId) { - while (HasNext && ReadStochasticSoilModelSegmentId() == stochasticSoilModelId) + while (HasNext && ReadStochasticSoilModelSegmentId() <= stochasticSoilModelId) { yield return ReadSegmentPoint(); MoveNext(); Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilDatabaseQueryBuilder.cs =================================================================== diff -u -r1d91b8411e6db990c17fade0ad12aa8ac0e54865 -rbe3fdb23bcc3b82eb8766e2cc22221862634224e --- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilDatabaseQueryBuilder.cs (.../SoilDatabaseQueryBuilder.cs) (revision 1d91b8411e6db990c17fade0ad12aa8ac0e54865) +++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilDatabaseQueryBuilder.cs (.../SoilDatabaseQueryBuilder.cs) (revision be3fdb23bcc3b82eb8766e2cc22221862634224e) @@ -79,39 +79,10 @@ /// per failure mechanism from the DSoil-Model database. /// /// The SQL query to execute. - public static string GetStochasticSoilModelOfMechanismQuery() - { - return string.Format(@"SELECT M.{7}, SP.{8}, SP.{9}, S.{10}, SSM.{11}, SSM.{12} " + - "FROM {0} M " + - "INNER JOIN {1} S USING({4}) " + - "INNER JOIN {2} SSM USING({5}) " + - "INNER JOIN {3} SP USING({6}) " + - "ORDER BY M.{7}, SSM.{12};", - MechanismTableDefinitions.TableName, - SegmentTableDefinitions.TableName, - StochasticSoilModelTableDefinitions.TableName, - SegmentPointsTableDefinitions.TableName, - MechanismTableDefinitions.MechanismId, - StochasticSoilModelTableDefinitions.StochasticSoilModelId, - SegmentPointsTableDefinitions.SegmentId, - MechanismTableDefinitions.MechanismName, - SegmentPointsTableDefinitions.CoordinateX, - SegmentPointsTableDefinitions.CoordinateY, - SegmentTableDefinitions.SegmentName, - StochasticSoilModelTableDefinitions.StochasticSoilModelName, - StochasticSoilModelTableDefinitions.StochasticSoilModelId - ); - } - - /// - /// Returns the SQL query to execute to fetch stochastic soil models - /// per failure mechanism from the DSoil-Model database. - /// - /// The SQL query to execute. public static string GetStochasticSoilModelPerMechanismQuery() { - return $"SELECT M.{MechanismTableDefinitions.MechanismName}, " + - $"SSM.{StochasticSoilModelTableDefinitions.StochasticSoilModelId}, " + + return $"SELECT SSM.{StochasticSoilModelTableDefinitions.StochasticSoilModelId}, " + + $"M.{MechanismTableDefinitions.MechanismName}, " + $"SSM.{StochasticSoilModelTableDefinitions.StochasticSoilModelName}, " + $"SSP.{StochasticSoilProfileTableDefinitions.Probability}, " + $"SSP.{StochasticSoilProfileTableDefinitions.SoilProfile1DId}, " + @@ -120,7 +91,7 @@ $"INNER JOIN {SegmentTableDefinitions.TableName} S USING({MechanismTableDefinitions.MechanismId}) " + $"INNER JOIN {StochasticSoilModelTableDefinitions.TableName} SSM USING({StochasticSoilModelTableDefinitions.StochasticSoilModelId}) " + $"INNER JOIN {StochasticSoilProfileTableDefinitions.TableName} SSP USING({StochasticSoilModelTableDefinitions.StochasticSoilModelId}) " + - $"ORDER BY M.{MechanismTableDefinitions.MechanismName}, SSM.{StochasticSoilModelTableDefinitions.StochasticSoilModelId};"; + $"ORDER BY SSM.{StochasticSoilModelTableDefinitions.StochasticSoilModelId};"; } /// Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs =================================================================== diff -u -r0ec64f4150d76a9530b3bed3f1af18334b5bf673 -rbe3fdb23bcc3b82eb8766e2cc22221862634224e --- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs (.../StochasticSoilModelReader.cs) (revision 0ec64f4150d76a9530b3bed3f1af18334b5bf673) +++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs (.../StochasticSoilModelReader.cs) (revision be3fdb23bcc3b82eb8766e2cc22221862634224e) @@ -22,7 +22,6 @@ using System; using System.Data; using System.Data.SQLite; -using Core.Common.Base.Geometry; using Core.Common.Base.IO; using Core.Common.IO.Readers; using Core.Common.Utils.Builders; @@ -37,6 +36,8 @@ public class StochasticSoilModelReader : SqLiteDatabaseReaderBase { private IDataReader dataReader; + private SegmentPointReader segmentPointReader; + private SoilProfile1DReader soilProfile1DReader; /// /// Creates a new instance of , @@ -73,7 +74,7 @@ { VerifyVersion(Path); VerifyConstraints(Path); - InitializeReader(); + InitializeReaders(); } /// @@ -107,6 +108,18 @@ dataReader.Dispose(); dataReader = null; } + + if (segmentPointReader != null) + { + segmentPointReader.Dispose(); + segmentPointReader = null; + } + + if (soilProfile1DReader != null) + { + soilProfile1DReader.Dispose(); + soilProfile1DReader = null; + } base.Dispose(disposing); } @@ -121,20 +134,13 @@ long currentSegmentSoilModelId = ReadStochasticSoilModelSegmentId(); do { - stochasticSoilModel.Geometry.Add(ReadSegmentPoint()); + stochasticSoilModel.Geometry.AddRange(segmentPointReader.ReadSegmentPoints(currentSegmentSoilModelId)); MoveNext(); } while (HasNext && ReadStochasticSoilModelSegmentId() == currentSegmentSoilModelId); return stochasticSoilModel; } - private Point2D ReadSegmentPoint() - { - double coordinateX = Convert.ToDouble(dataReader[SegmentPointsTableDefinitions.CoordinateX]); - double coordinateY = Convert.ToDouble(dataReader[SegmentPointsTableDefinitions.CoordinateY]); - return new Point2D(coordinateX, coordinateY); - } - private long ReadStochasticSoilModelSegmentId() { return Convert.ToInt64(dataReader[StochasticSoilModelTableDefinitions.StochasticSoilModelId]); @@ -153,10 +159,16 @@ /// Initializes a new . /// /// Thrown when failed to fetch stochastic soil models from the database. - private void InitializeReader() + private void InitializeReaders() { CreateDataReader(); MoveNext(); + + segmentPointReader = new SegmentPointReader(Path); + segmentPointReader.Initialize(); + + soilProfile1DReader = new SoilProfile1DReader(Path); + soilProfile1DReader.Initialize(); } private void MoveNext() @@ -171,7 +183,7 @@ /// models from the database failed. private void CreateDataReader() { - string stochasticSoilModelSegmentsQuery = SoilDatabaseQueryBuilder.GetStochasticSoilModelOfMechanismQuery(); + string stochasticSoilModelSegmentsQuery = SoilDatabaseQueryBuilder.GetStochasticSoilModelPerMechanismQuery(); try { dataReader = CreateDataReader(stochasticSoilModelSegmentsQuery); Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SegmentPointReaderTest.cs =================================================================== diff -u -r1d91b8411e6db990c17fade0ad12aa8ac0e54865 -rbe3fdb23bcc3b82eb8766e2cc22221862634224e --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SegmentPointReaderTest.cs (.../SegmentPointReaderTest.cs) (revision 1d91b8411e6db990c17fade0ad12aa8ac0e54865) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SegmentPointReaderTest.cs (.../SegmentPointReaderTest.cs) (revision be3fdb23bcc3b82eb8766e2cc22221862634224e) @@ -126,5 +126,25 @@ Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); } + + [Test] + public void ReadSegmentPoints_FirstModelInCompleteDatabase_ReturnsExpectedSegmentPoints() + { + // Setup + string dbFile = Path.Combine(testDataPath, "complete.soil"); + + using (var reader = new SegmentPointReader(dbFile)) + { + reader.Initialize(); + + // Call + Point2D[] segmentPoints = reader.ReadSegmentPoints(1).ToArray(); + + // Assert + Assert.AreEqual(1797, segmentPoints.Length); + } + + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilDatabaseQueryBuilderTest.cs =================================================================== diff -u -r1d91b8411e6db990c17fade0ad12aa8ac0e54865 -rbe3fdb23bcc3b82eb8766e2cc22221862634224e --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilDatabaseQueryBuilderTest.cs (.../SoilDatabaseQueryBuilderTest.cs) (revision 1d91b8411e6db990c17fade0ad12aa8ac0e54865) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilDatabaseQueryBuilderTest.cs (.../SoilDatabaseQueryBuilderTest.cs) (revision be3fdb23bcc3b82eb8766e2cc22221862634224e) @@ -71,36 +71,19 @@ } [Test] - public void GetStochasticSoilModelOfMechanismQuery_ReturnsExpectedValues() - { - // Call - string query = SoilDatabaseQueryBuilder.GetStochasticSoilModelOfMechanismQuery(); - - // Assert - const string expectedQuery = - "SELECT M.ME_Name, SP.XWorld, SP.YWorld, S.SE_Name, SSM.SSM_Name, SSM.SSM_ID " + - "FROM Mechanism M " + - "INNER JOIN Segment S USING(ME_ID) " + - "INNER JOIN StochasticSoilModel SSM USING(SSM_ID) " + - "INNER JOIN SegmentPoints SP USING(SE_ID) " + - "ORDER BY M.ME_Name, SSM.SSM_ID;"; - Assert.AreEqual(expectedQuery, query); - } - - [Test] public void GetStochasticSoilModelPerMechanismQuery_ReturnsExpectedValues() { // Call string query = SoilDatabaseQueryBuilder.GetStochasticSoilModelPerMechanismQuery(); // Assert const string expectedQuery = - "SELECT M.ME_Name, SSM.SSM_ID, SSM.SSM_Name, SSP.Probability, SSP.SP1D_ID, SSP.SP2D_ID " + + "SELECT SSM.SSM_ID, M.ME_Name, SSM.SSM_Name, SSP.Probability, SSP.SP1D_ID, SSP.SP2D_ID " + "FROM Mechanism M " + "INNER JOIN Segment S USING(ME_ID) " + "INNER JOIN StochasticSoilModel SSM USING(SSM_ID) " + "INNER JOIN StochasticSoilProfile SSP USING(SSM_ID) " + - "ORDER BY M.ME_Name, SSM.SSM_ID;"; + "ORDER BY SSM.SSM_ID;"; Assert.AreEqual(expectedQuery, query); } Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs =================================================================== diff -u -r0ec64f4150d76a9530b3bed3f1af18334b5bf673 -rbe3fdb23bcc3b82eb8766e2cc22221862634224e --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs (.../StochasticSoilModelReaderTest.cs) (revision 0ec64f4150d76a9530b3bed3f1af18334b5bf673) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs (.../StochasticSoilModelReaderTest.cs) (revision be3fdb23bcc3b82eb8766e2cc22221862634224e) @@ -224,10 +224,12 @@ // Setup string dbFile = Path.Combine(testDataPath, "emptySchema.soil"); - using (var stochasticSoilModelDatabaseReader = new StochasticSoilModelReader(dbFile)) + using (var reader = new StochasticSoilModelReader(dbFile)) { + reader.Validate(); + // Call - StochasticSoilModel model = stochasticSoilModelDatabaseReader.ReadStochasticSoilModel(); + StochasticSoilModel model = reader.ReadStochasticSoilModel(); // Assert Assert.IsNull(model); @@ -259,20 +261,20 @@ var expectedSegmentAndModelNames = new[] { - "36005_Piping", - "36006_Piping", - "36007_Piping", "36005_Stability", + "36005_Piping", "36006_Stability", - "36007_Stability" + "36006_Piping", + "36007_Stability", + "36007_Piping" }; var expectedSegmentPointCount = new[] { 1797, - 144, - 606, 1797, 144, + 144, + 606, 606 }; Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/SegmentPointReader/complete.soil =================================================================== diff -u Binary files differ