diff --git a/Core/Core.csproj b/Core/Core.csproj index e36b53d..cad1790 100644 --- a/Core/Core.csproj +++ b/Core/Core.csproj @@ -47,6 +47,23 @@ + + + + + + + + + + + + + + + + + diff --git a/Core/DB/ColumnOrValue.cs b/Core/DB/ColumnOrValue.cs new file mode 100644 index 0000000..9893d71 --- /dev/null +++ b/Core/DB/ColumnOrValue.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB { + class ColumnOrValue { + + private bool _isColumn; + + private ColumnSpec _column; + + private string _value; + + private ColumnOrValue() { } + + public static ColumnOrValue createColumn(ColumnSpec column) { + return new ColumnOrValue{_isColumn = true, _column = column}; + } + + public static ColumnOrValue createValue(string value) { + return new ColumnOrValue{_isColumn = false, _value = value}; + } + + public bool isColumn { + get { + return this._isColumn; + } + } + + public ColumnSpec column { + get { + if(!this.isColumn) throw new CriticalException("Not a column"); + return this._column; + } + } + + public string value { + get { + if(this.isColumn) throw new CriticalException("not a value"); + return this._value; + } + } + + } +} diff --git a/Core/DB/ColumnSpec.cs b/Core/DB/ColumnSpec.cs new file mode 100644 index 0000000..328c1cc --- /dev/null +++ b/Core/DB/ColumnSpec.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB { + public class ColumnSpec { + + public readonly ITableSpec table; + + public readonly string name; + + public ColumnSpec(ITableSpec table, string name) { + this.table = table; + this.name = name; + } + + } +} diff --git a/Core/DB/Diapasone.cs b/Core/DB/Diapasone.cs new file mode 100644 index 0000000..b04cf6c --- /dev/null +++ b/Core/DB/Diapasone.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB { + class Diapasone { + + public readonly int start; + public readonly int count; + public int total { + get; + private set; + } + + public Diapasone(int start, int count) { + this.start = start; + this.count = count; + } + + } +} diff --git a/Core/DB/IDBConnection.cs b/Core/DB/IDBConnection.cs new file mode 100644 index 0000000..9e844a8 --- /dev/null +++ b/Core/DB/IDBConnection.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB { + interface IDBConnection { + + Dictionary LoadById(ITableSpec table, int id); + Dictionary[] LoadByIds(ITableSpec table, int[] ids); + + int[] LoadIdsByConditions(ITableSpec table, conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts); + + ILock lockTable(ITableSpec table); + + ILock lockRow(ITableSpec table, int id); + + void update(ITableSpec table, int id, Dictionary data); + + void delete(ITableSpec table, int id); //do we really need this? + + } + + static class IDBConnectionExtensions { + + public static int[] LoadIdsByConditions(this IDBConnection connection, ITableSpec table, conditions.AbstractCondition conditions, Diapasone diapasone, params JoinSpec[] joins) { + return connection.LoadIdsByConditions(table, conditions, diapasone, joins, new SortSpec[] { new SortSpec(table.getIdSpec(), true) }); + } + + } + +} diff --git a/Core/DB/ILock.cs b/Core/DB/ILock.cs new file mode 100644 index 0000000..99769a9 --- /dev/null +++ b/Core/DB/ILock.cs @@ -0,0 +1,9 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB { + public interface ILock : IDisposable { + } +} diff --git a/Core/DB/ITableSpec.cs b/Core/DB/ITableSpec.cs new file mode 100644 index 0000000..8b4eac3 --- /dev/null +++ b/Core/DB/ITableSpec.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB { + public interface ITableSpec { + string name { + get; + } + + string idName { + get; + } + + } + + public static class ITableSpecExtensions { + + public static ColumnSpec getIdSpec(this ITableSpec table) { + return new ColumnSpec(table, table.idName); + } + + } + +} diff --git a/Core/DB/JoinSpec.cs b/Core/DB/JoinSpec.cs new file mode 100644 index 0000000..80ed097 --- /dev/null +++ b/Core/DB/JoinSpec.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB { + class JoinSpec { + + public readonly ColumnSpec mainColumn; + + public readonly ITableSpec additionalTable; + + public JoinSpec(ColumnSpec mainColumn, ITableSpec additionalTable) { + this.mainColumn = mainColumn; + this.additionalTable = additionalTable; + } + + } +} diff --git a/Core/DB/SortSpec.cs b/Core/DB/SortSpec.cs new file mode 100644 index 0000000..c1379c7 --- /dev/null +++ b/Core/DB/SortSpec.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB { + class SortSpec { + + public readonly ColumnSpec column; + + public readonly bool ascending; + + public SortSpec(ColumnSpec column, bool ascending) { + this.column = column; + this.ascending = ascending; + } + + } +} diff --git a/Core/DB/conditions/AbstractCondition.cs b/Core/DB/conditions/AbstractCondition.cs new file mode 100644 index 0000000..5f05ff1 --- /dev/null +++ b/Core/DB/conditions/AbstractCondition.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB.conditions { + public abstract class AbstractCondition { + + } +} diff --git a/Core/DB/conditions/ComparisonCondition.cs b/Core/DB/conditions/ComparisonCondition.cs new file mode 100644 index 0000000..5442116 --- /dev/null +++ b/Core/DB/conditions/ComparisonCondition.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB.conditions { + class ComparisonCondition : SimpleCondition { + + public readonly ColumnSpec left; + public readonly ComparisonType comparison; + public readonly ColumnOrValue right; + + public ComparisonCondition(ColumnSpec left, ComparisonType comparison, ColumnSpec right) { + this.left = left; + this.comparison = comparison; + this.right = ColumnOrValue.createColumn(right); + } + + public ComparisonCondition(ColumnSpec left, ComparisonType comparison, string right) { + this.left = left; + this.comparison = comparison; + this.right = ColumnOrValue.createValue(right); + } + + } +} diff --git a/Core/DB/conditions/ComparisonType.cs b/Core/DB/conditions/ComparisonType.cs new file mode 100644 index 0000000..3ce1397 --- /dev/null +++ b/Core/DB/conditions/ComparisonType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB.conditions { + enum ComparisonType { + EQUAL, + NOTEQUAL, + LESSTHAN, + GREATERTHAN, + LESSOREQUAL, + GREATEROREQUAL, + } +} diff --git a/Core/DB/conditions/ComplexCondition.cs b/Core/DB/conditions/ComplexCondition.cs new file mode 100644 index 0000000..077c4ab --- /dev/null +++ b/Core/DB/conditions/ComplexCondition.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB.conditions { + class ComplexCondition : AbstractCondition { + + public readonly ConditionsJoinType type; + + public readonly List innerConditions; + + public ComplexCondition(ConditionsJoinType type, List innerConditions) { + this.type = type; + this.innerConditions = innerConditions; + } + + } +} diff --git a/Core/DB/conditions/ConditionsJoinType.cs b/Core/DB/conditions/ConditionsJoinType.cs new file mode 100644 index 0000000..8514aec --- /dev/null +++ b/Core/DB/conditions/ConditionsJoinType.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB.conditions { + enum ConditionsJoinType { + AND, + OR, + } +} diff --git a/Core/DB/conditions/IsNullCondition.cs b/Core/DB/conditions/IsNullCondition.cs new file mode 100644 index 0000000..c82d8a7 --- /dev/null +++ b/Core/DB/conditions/IsNullCondition.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB.conditions { + public class IsNullCondition : SimpleCondition { + + public readonly ColumnSpec column; + + public IsNullCondition(ColumnSpec column) { + this.column = column; + } + + } +} diff --git a/Core/DB/conditions/MultiValueCondition.cs b/Core/DB/conditions/MultiValueCondition.cs new file mode 100644 index 0000000..492259f --- /dev/null +++ b/Core/DB/conditions/MultiValueCondition.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB.conditions { + class MultiValueCondition : SimpleCondition { + + public readonly ColumnSpec column; + + public readonly bool inclusive; + + public readonly string[] values; + + public MultiValueCondition(ColumnSpec column, string[] values, bool inclusive) { + this.column = column; + this.values = values; + this.inclusive = inclusive; + } + + public MultiValueCondition(ColumnSpec column, string[] values) : this(column, values, true) { + } + + } +} diff --git a/Core/DB/conditions/NotIsNullCondition.cs b/Core/DB/conditions/NotIsNullCondition.cs new file mode 100644 index 0000000..27f26d0 --- /dev/null +++ b/Core/DB/conditions/NotIsNullCondition.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB.conditions { + public class NotIsNullCondition : SimpleCondition { + + public readonly ColumnSpec column; + + public NotIsNullCondition(ColumnSpec column) { + this.column = column; + } + + } +} diff --git a/Core/DB/conditions/SimpleCondition.cs b/Core/DB/conditions/SimpleCondition.cs new file mode 100644 index 0000000..acadaca --- /dev/null +++ b/Core/DB/conditions/SimpleCondition.cs @@ -0,0 +1,9 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB.conditions { + public abstract class SimpleCondition : AbstractCondition { + } +}