Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundarySqLiteDatabaseReader.cs
===================================================================
diff -u -r7235aeaea6e256141b54459aa33da203e84f280b -r16fef01c5d2d8ef8d15c652585efa85125ba7b25
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundarySqLiteDatabaseReader.cs (.../HydraulicBoundarySqLiteDatabaseReader.cs) (revision 7235aeaea6e256141b54459aa33da203e84f280b)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundarySqLiteDatabaseReader.cs (.../HydraulicBoundarySqLiteDatabaseReader.cs) (revision 16fef01c5d2d8ef8d15c652585efa85125ba7b25)
@@ -26,31 +26,33 @@
using Core.Common.IO.Readers;
using Core.Common.Utils.Builders;
using Ringtoets.HydraRing.Data;
+using Ringtoets.HydraRing.IO.HydraulicBoundaryDatabase;
using Ringtoets.HydraRing.IO.Properties;
namespace Ringtoets.HydraRing.IO
{
///
- /// This class reads a SqLite database file and constructs instances from this database.
+ /// This class reads a SqLite database file and constructs
+ /// instances from this database.
///
- public class HydraulicBoundarySqLiteDatabaseReader : SqLiteDatabaseReaderBase, IRowBasedDatabaseReader
+ public class HydraulicBoundarySqLiteDatabaseReader : SqLiteDatabaseReaderBase
{
private SQLiteDataReader dataReader;
///
- /// Creates a new instance of , which will use the
+ /// Creates a new instance of , which will use
+ /// the
/// as its source.
///
/// The path of the database file to open.
/// Thrown when:
///
/// - The contains invalid characters.
/// - No file could be found at .
- /// - Preparing the queries to read from the database failed.
+ /// - Preparing the database queries failed.
///
///
- public HydraulicBoundarySqLiteDatabaseReader(string databaseFilePath)
- : base(databaseFilePath)
+ public HydraulicBoundarySqLiteDatabaseReader(string databaseFilePath) : base(databaseFilePath)
{
InitializeReader();
}
@@ -74,8 +76,10 @@
///
/// Reads the next location from the database.
///
- /// New instance of , based on the data read from the database or null if no data is available.
- /// Thrown when the database returned incorrect values for required properties.
+ /// New instance of , based on the data read from the
+ /// database or null if no data is available.
+ /// Thrown when the database returned incorrect values for
+ /// required properties.
public HydraulicBoundaryLocation ReadLocation()
{
if (!HasNext)
@@ -89,14 +93,12 @@
}
catch (InvalidCastException e)
{
- var message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column);
- throw new CriticalFileReadException(message, e);
+ var message = new FileReaderErrorMessageBuilder(Path).
+ Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column);
+ throw new LineParseException(message, e);
}
}
- ///
- /// Disposes the reader.
- ///
public override void Dispose()
{
if (dataReader != null)
@@ -109,7 +111,7 @@
///
/// Moves the reader to the next record in the database.
///
- public void MoveNext()
+ private void MoveNext()
{
HasNext = dataReader.Read() || (dataReader.NextResult() && dataReader.Read());
}
@@ -120,34 +122,19 @@
/// The expected type of value in the column with name .
/// The name of the column to read from.
/// The read value from the column with name .
- /// Thrown when the value in the column was not of type .
- public T Read(string columnName)
+ /// Thrown when the value in the column was not of type
+ /// .
+ private T Read(string columnName)
{
return (T) dataReader[columnName];
}
///
- /// Reads the value in the column with name from the currently pointed row.
- ///
- /// The type of object to read.
- /// The name of the column to read from.
- /// The value in the column, or null if the value was .
- /// Thrown when the value in the column could not be casted to type .
- public T? ReadOrNull(string columnName) where T : struct
- {
- var valueObject = dataReader[columnName];
- if (valueObject.Equals(DBNull.Value))
- {
- return null;
- }
- return (T) valueObject;
- }
-
- ///
/// Reads the current row into a new instance of .
///
/// A new instance of , based upon the current row.
- /// Thrown when the database returned incorrect values for required properties.
+ /// Thrown when the database returned incorrect values for
+ /// required properties.
private HydraulicBoundaryLocation ReadHydraulicBoundaryLocation()
{
try
@@ -159,7 +146,7 @@
MoveNext();
return new HydraulicBoundaryLocation(id, name, x, y);
}
- catch (InvalidCastException exception)
+ catch (InvalidCastException)
{
MoveNext();
throw;
@@ -181,16 +168,10 @@
///
private void PrepareReader()
{
- var versionQuery = string.Format("SELECT (NameRegion || CreationDate) as {0} FROM General LIMIT 0,1;", HydraulicBoundaryDatabaseColumns.Version);
- var countQuery = string.Format("SELECT count(*) as {0} FROM HRDLocations WHERE LocationTypeId > 1 ;", HydraulicBoundaryDatabaseColumns.LocationCount);
+ var versionQuery = HydraulicBoundaryDatabaseQueryBuilder.GetVersionQuery();
+ var countQuery = HydraulicBoundaryDatabaseQueryBuilder.GetLocationsCountQuery();
+ var locationsQuery = HydraulicBoundaryDatabaseQueryBuilder.GetLocationsQuery();
- var locationsQuery = string.Format(
- "SELECT HRDLocationId as {0}, Name as {1}, XCoordinate as {2}, YCoordinate as {3} FROM HRDLocations WHERE LocationTypeId > 1;",
- HydraulicBoundaryDatabaseColumns.LocationId,
- HydraulicBoundaryDatabaseColumns.LocationName,
- HydraulicBoundaryDatabaseColumns.LocationX,
- HydraulicBoundaryDatabaseColumns.LocationY);
-
CreateDataReader(string.Join(" ", versionQuery, countQuery, locationsQuery), new SQLiteParameter
{
DbType = DbType.String