DB interfaces initial commit

main
Inga 🏳‍🌈 15 years ago
parent 63f50209d9
commit 7901f25ed7
  1. 17
      Core/Core.csproj
  2. 46
      Core/DB/ColumnOrValue.cs
  3. 19
      Core/DB/ColumnSpec.cs
  4. 22
      Core/DB/Diapasone.cs
  5. 32
      Core/DB/IDBConnection.cs
  6. 9
      Core/DB/ILock.cs
  7. 26
      Core/DB/ITableSpec.cs
  8. 19
      Core/DB/JoinSpec.cs
  9. 19
      Core/DB/SortSpec.cs
  10. 10
      Core/DB/conditions/AbstractCondition.cs
  11. 26
      Core/DB/conditions/ComparisonCondition.cs
  12. 15
      Core/DB/conditions/ComparisonType.cs
  13. 19
      Core/DB/conditions/ComplexCondition.cs
  14. 11
      Core/DB/conditions/ConditionsJoinType.cs
  15. 16
      Core/DB/conditions/IsNullCondition.cs
  16. 25
      Core/DB/conditions/MultiValueCondition.cs
  17. 16
      Core/DB/conditions/NotIsNullCondition.cs
  18. 9
      Core/DB/conditions/SimpleCondition.cs

@ -47,6 +47,23 @@
<ItemGroup> <ItemGroup>
<Compile Include="Config.cs" /> <Compile Include="Config.cs" />
<Compile Include="DataObject.cs" /> <Compile Include="DataObject.cs" />
<Compile Include="DB\conditions\AbstractCondition.cs" />
<Compile Include="DB\ColumnOrValue.cs" />
<Compile Include="DB\ColumnSpec.cs" />
<Compile Include="DB\conditions\ComparisonCondition.cs" />
<Compile Include="DB\conditions\ComparisonType.cs" />
<Compile Include="DB\conditions\ComplexCondition.cs" />
<Compile Include="DB\conditions\ConditionsJoinType.cs" />
<Compile Include="DB\conditions\IsNullCondition.cs" />
<Compile Include="DB\conditions\MultiValueCondition.cs" />
<Compile Include="DB\conditions\NotIsNullCondition.cs" />
<Compile Include="DB\conditions\SimpleCondition.cs" />
<Compile Include="DB\Diapasone.cs" />
<Compile Include="DB\IDBConnection.cs" />
<Compile Include="DB\ILock.cs" />
<Compile Include="DB\ITableSpec.cs" />
<Compile Include="DB\JoinSpec.cs" />
<Compile Include="DB\SortSpec.cs" />
<Compile Include="delegates\Lazy.cs" /> <Compile Include="delegates\Lazy.cs" />
<Compile Include="delegates\Predicate.cs" /> <Compile Include="delegates\Predicate.cs" />
<Compile Include="exceptions\CriticalException.cs" /> <Compile Include="exceptions\CriticalException.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;
}
}
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.Core.DB {
interface IDBConnection {
Dictionary<string, string> LoadById(ITableSpec table, int id);
Dictionary<string, string>[] 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<string, string> 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) });
}
}
}

@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.Core.DB {
public interface ILock : IDisposable {
}
}

@ -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);
}
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -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 {
}
}

@ -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);
}
}
}

@ -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,
}
}

@ -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<AbstractCondition> innerConditions;
public ComplexCondition(ConditionsJoinType type, List<AbstractCondition> innerConditions) {
this.type = type;
this.innerConditions = innerConditions;
}
}
}

@ -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,
}
}

@ -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;
}
}
}

@ -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) {
}
}
}

@ -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;
}
}
}

@ -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 {
}
}
Loading…
Cancel
Save