Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
MalcolmCrowe committed May 14, 2019
1 parent db98744 commit 9579b4e
Show file tree
Hide file tree
Showing 323 changed files with 7,297 additions and 3,127 deletions.
Binary file added 0.0/Binaries.zip
Binary file not shown.
Binary file modified 0.1/Binaries.zip
Binary file not shown.
5 changes: 1 addition & 4 deletions 0.1/Shareable/Shareable/Integer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,10 @@ public int BitsNeeded()
/// <returns>The corresponding int value</returns>
static public explicit operator int(Integer x)
{
int n = x.bytes.Length;
int n = x.bytes.Length;
if (n > 4)
{
Console.WriteLine("PE13");
for (var i = 0; i < n; i++)
Console.Write(" " + x.bytes[i]);
Console.WriteLine();
throw new Exception("PE13");
}
int j=0;
Expand Down
57 changes: 19 additions & 38 deletions 0.1/Shareable/Shareable/RowSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace Shareable
public abstract class RowSet : Collection<Serialisable>
{
public readonly SQuery _qry;
public readonly STransaction _tr;
public readonly SDatabase _tr;
public readonly Context _cx;
public RowSet(STransaction tr, SQuery q, Context cx, int? n):base(n)
public RowSet(SDatabase tr, SQuery q, Context cx, int? n):base(n)
{
_tr = tr; _qry = q; _cx = cx;
}
Expand Down Expand Up @@ -211,8 +211,8 @@ public class TableRowSet : RowSet
/// </summary>
/// <param name="db"></param>
/// <param name="t"></param>
public TableRowSet(STransaction db,STable t,Context cx)
: base(db+t.uid /*read constraint*/,t,
public TableRowSet(SDatabase db,STable t,Context cx)
: base(db.Rdc(t.uid),t,
cx,t.rows.Length)
{
_tb = t;
Expand Down Expand Up @@ -243,12 +243,12 @@ protected TableRowBookmark(TableRowSet trs,Bookmark<(long,long)>bm,int p)
public override STransaction Update(STransaction tr, SDict<long, Serialisable> assigs)
{
var rc = _ob.rec ?? throw new Exception("PE01");
return (STransaction)tr.Install(new SUpdate(tr,rc, assigs),rc,tr.curpos);
return (STransaction)tr.Install(new SUpdate(tr,rc, assigs),tr.curpos);
}
public override STransaction Delete(STransaction tr)
{
var rc = _ob.rec ?? throw new Exception("PE02");
return (STransaction)tr.Install(new SDelete(tr,rc.table, rc.Defpos),rc,tr.curpos); // ok
return (STransaction)tr.Install(new SDelete(tr,rc),tr.curpos); // ok
}
}
}
Expand All @@ -259,32 +259,13 @@ public class IndexRowSet : RowSet
public readonly SCList<Variant> _key;
public readonly SExpression.Op _op;
public readonly bool _unique;
public IndexRowSet(STransaction tr,STable t,SIndex ix,SCList<Variant> key,
public IndexRowSet(SDatabase tr,STable t,SIndex ix,SCList<Variant> key,
SExpression.Op op,SList<Serialisable> wh,Context cx)
:base(Rdc(tr,ix,key),t, cx, t.rows.Length)
:base(tr.Rdc(ix,key),t, cx, t.rows.Length)
{
_ix = ix; _key = key; _wh = wh; _op = op;
_unique = key.Length == _ix.cols.Length && _ix.references==-1;
}
/// <summary>
/// Add in read constraints: a key specifies just one row as the read
/// Constraint. Otherwise lock the entire table
/// </summary>
/// <param name="tr"></param>
/// <param name="ix"></param>
/// <param name="_key"></param>
/// <returns></returns>
static STransaction Rdc(STransaction tr,SIndex ix,SCList<Variant> _key)
{
if (_key.Length ==0)
return tr + ix.table;
var mb = ix.rows.PositionAt(_key);
if (mb == null)
return tr;
if (mb.hasMore(tr, ix.cols.Length??0))
return tr + ix.table;
return tr + mb.Value.Item2;
}
public override Bookmark<Serialisable>? First()
{
return IndexRowBookmark.New(this);
Expand Down Expand Up @@ -346,12 +327,12 @@ protected IndexRowBookmark(IndexRowSet irs,SRow ob,MTreeBookmark<Serialisable> m
public override STransaction Update(STransaction tr, SDict<long, Serialisable> assigs)
{
var rc = _ob.rec ?? throw new System.Exception("PE41");
return (STransaction)tr.Install(new SUpdate(tr, rc, assigs),rc,tr.curpos); // ok
return (STransaction)tr.Install(new SUpdate(tr, rc, assigs),tr.curpos); // ok
}
public override STransaction Delete(STransaction tr)
{
var rc = _ob.rec ?? throw new System.Exception("PE42");
return (STransaction)tr.Install(new SDelete(tr, rc.table, rc.Defpos),rc,tr.curpos); // ok
return (STransaction)tr.Install(new SDelete(tr, rc),tr.curpos); // ok
}
}
}
Expand Down Expand Up @@ -405,15 +386,15 @@ public class SearchRowSet : RowSet
public readonly SSearch _sch;
public readonly RowSet _sce;

public SearchRowSet(STransaction tr, SQuery top, SSearch sc, Context cx)
public SearchRowSet(SDatabase tr, SQuery top, SSearch sc, Context cx)
: this(Source(tr, top, sc, cx), sc, cx)
{ }
SearchRowSet(RowSet sce, SSearch sc, Context cx) : base(sce._tr, sc, cx, null)
{
_sch = sc;
_sce = sce;
}
static RowSet Source(STransaction tr,SQuery top, SSearch sc,Context cx)
static RowSet Source(SDatabase tr,SQuery top, SSearch sc,Context cx)
{
RowSet? s = null;
var matches = SDict<long,(Serialisable,SExpression.Op)>.Empty;
Expand Down Expand Up @@ -573,7 +554,7 @@ public class GroupRowSet : RowSet
public readonly SDict<long, SDict<long,Serialisable>> _grouprows; // accumulators for the aggregates
public readonly SQuery _top;
public readonly RowSet _sce;
public GroupRowSet(STransaction tr, SQuery top, SGroupQuery gqry,
public GroupRowSet(SDatabase tr, SQuery top, SGroupQuery gqry,
Context cx)
: this(gqry.source.RowSet(tr, top, cx), top, gqry, cx)
{
Expand Down Expand Up @@ -626,7 +607,7 @@ protected SRow _Row(MTreeBookmark<long> b)
r += (ab.Value.Item2,cb.Value.Item2.Lookup(_tr,cx));
return r;
}
static SDict<long,Serialisable> AddIn(STransaction tr,SDict<long,Serialisable> cur, Context cx)
static SDict<long,Serialisable> AddIn(SDatabase tr,SDict<long,Serialisable> cur, Context cx)
{
var ags = cx.Ags();
for (var b = ags.First(); b != null; b = b.Next())
Expand Down Expand Up @@ -738,7 +719,7 @@ public class JoinRowSet : RowSet
public readonly SJoin _join;
public readonly RowSet _left, _right;
public readonly int _klen;
internal JoinRowSet(STransaction tr,SQuery top, SJoin j, RowSet lf, RowSet rg,
internal JoinRowSet(SDatabase tr,SQuery top, SJoin j, RowSet lf, RowSet rg,
Context cx)
: base(tr, j, cx, null)
{
Expand Down Expand Up @@ -952,7 +933,7 @@ static SRow _Row(JoinRowSet jrs,RowBookmark? lbm,bool ul,RowBookmark? rbm,bool u
public class SysRows : RowSet
{
public readonly SysTable tb;
internal SysRows(STransaction tr, SysTable t)
internal SysRows(SDatabase tr, SysTable t)
: base(tr, t, Context.Empty, null)
{
tb = t;
Expand Down Expand Up @@ -983,7 +964,7 @@ internal class LogRowSet : SysRows
{
readonly long uPos = 0;
readonly SExpression.Op uOp = SExpression.Op.Eql;
public LogRowSet(STransaction tr,SysTable tb,Context cx) : base(tr,tb)
public LogRowSet(SDatabase tr,SysTable tb,Context cx) : base(tr,tb)
{
var u = SysTable._SysUid - 3; // Log.Uid
if (cx.defines(u) && cx[u] is SExpression e && e.right is SString s
Expand Down Expand Up @@ -1080,7 +1061,7 @@ internal ConstraintsBookmark(SysRows rs, ColumnsBookmark cbm, SFunction cf,
{
_srs = rs; _cbm = cbm; _cf = cf; _id = id;
}
static string Check(STransaction tr,SFunction cf,string id)
static string Check(SDatabase tr,SFunction cf,string id)
{
return (cf.func == SFunction.Func.Constraint) ? id :
cf.func.ToString().ToUpper();
Expand Down Expand Up @@ -1147,7 +1128,7 @@ static string Cols(SysRows rs,SIndex ix)
sb.Append(")");
return sb.ToString();
}
static string References(STransaction tr,SIndex ix)
static string References(SDatabase tr,SIndex ix)
{
return (ix.references < 0) ? "" : ("" + tr.Name(ix.references));
}
Expand Down
59 changes: 34 additions & 25 deletions 0.1/Shareable/Shareable/SDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,8 @@ protected SDatabase _Add(SDbObject s, long p)
case Types.SDrop: return Install((SDrop)s, p);
case Types.SIndex: return Install((SIndex)s, p);
case Types.SDropIndex: return Install((SDropIndex)s,p);
}
return this;
}
protected SDatabase _Add(SDbObject s, SRecord r, long p)
{
switch (s.type)
{
case Types.SUpdate: return Install((SUpdate)s, r, p);
case Types.SDelete: return Install((SDelete)s, r, p);
case Types.SUpdate: return Install((SUpdate)s, p);
case Types.SDelete: return Install((SDelete)s, p);
}
return this;
}
Expand Down Expand Up @@ -159,20 +152,16 @@ protected SDatabase _Add(SDbObject s, string nm, long p)
case Types.SDelete:
{
var del = (SDelete)x.Item1;
return d._Add(x.Item1,d.Get(del.delpos), x.Item2);
return d._Add(del, x.Item2);
}
case Types.SUpdate:
{
var upd = (SUpdate)x.Item1;
return d._Add(x.Item1,d.Get(upd.defpos), x.Item2);
return d._Add(upd,x.Item2);
}
}
return d._Add(x.Item1, x.Item2);
}
public static SDatabase operator +(SDatabase d, (SDbObject, SRecord, long) x)
{
return d._Add(x.Item1, x.Item2, x.Item3);
}
public static SDatabase operator+(SDatabase d,(SDbObject,string,long)x)
{
return d._Add(x.Item1, x.Item2, x.Item3);
Expand Down Expand Up @@ -250,7 +239,7 @@ public SDatabase Install(SRecord r, long c)
}
return New(obs, ro, c);
}
public SDatabase Install(SUpdate u, SRecord sr, long c)
public SDatabase Install(SUpdate u, long c)
{
var obs = objects;
var ro = role;
Expand All @@ -261,14 +250,14 @@ public SDatabase Install(SUpdate u, SRecord sr, long c)
for (var b = st.indexes.First(); b != null; b = b.Next())
{
var x = (SIndex)obs[b.Value.Item1];
var ok = x.Key(sr, x.cols);
var ok = x.Key(u.oldrec, x.cols);
var uk = x.Key(u, x.cols);
x.Check(this, u, ok.CompareTo(uk)==0);
obs += (x.uid, x.Update(sr,ok,u,uk,c));
obs += (x.uid, x.Update(u.oldrec,ok,u,uk,c));
}
return New(obs, ro, c);
}
public SDatabase Install(SDelete d, SRecord sr, long c)
public SDatabase Install(SDelete d, long c)
{
var obs = objects;
if (d.uid >= STransaction._uid)
Expand All @@ -277,10 +266,10 @@ public SDatabase Install(SDelete d, SRecord sr, long c)
for (var b = st.indexes.First(); b != null; b = b.Next())
{
var px = (SIndex)obs[b.Value.Item1];
obs += (px.uid, px - (sr, c));
obs += (px.uid, px - (d.oldrec, c));
if (!px.primary)
continue;
var k = px.Key(sr, px.cols);
var k = px.Key(d.oldrec, px.cols);
for (var ob = obs.PositionAt(0); ob != null; ob = ob.Next()) // don't bother with system tables
if (ob.Value.Item2 is STable ot)
for (var ox = ot.indexes.First(); ox != null; ox = ox.Next())
Expand All @@ -291,9 +280,9 @@ public SDatabase Install(SDelete d, SRecord sr, long c)
}
}
var ro = role;
if (sr != null)
if (d.oldrec != null)
{
st = st.Remove(sr.Defpos);
st = st.Remove(d.oldrec.Defpos);
obs += (d.table, st);
}
return New(obs, ro, c);
Expand Down Expand Up @@ -393,14 +382,34 @@ public virtual STransaction Transact(ReaderBase rdr,bool auto = true)
rdr.db = tr;
return tr;
}
public SDatabase MaybeAutoCommit(STransaction tr)
public virtual SDatabase MaybeAutoCommit()
{
return tr.autoCommit ? tr.Commit() : tr;
return this;
}
public virtual SDatabase Rollback()
{
return this;
}
/// <summary>
/// Add in read constraints: a key specifies just one row as the read
/// Constraint. Otherwise lock the entire table
/// </summary>
/// <param name="ix"></param>
/// <param name="_key"></param>
/// <returns></returns>
public virtual SDatabase Rdc(SIndex ix, SCList<Variant> _key)
{
return this;
}
/// <summary>
/// Add in a read constraint to lock a table
/// </summary>
/// <param name="uid">The table uid</param>
/// <returns></returns>
public virtual SDatabase Rdc(long uid)
{
return this;
}
public virtual STable? GetTable(string tn)
{
return role.globalNames.Contains(tn)?(STable)objects[role.globalNames[tn]]:null;
Expand Down
4 changes: 2 additions & 2 deletions 0.1/Shareable/Shareable/SMTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public SRecord Get(SDatabase db)
/// </summary>
/// <param name="depth"></param>
/// <returns>an earlier bookmark or null</returns>
internal MTreeBookmark<K> ResetToTiesStart(STransaction tr, int depth)
internal MTreeBookmark<K> ResetToTiesStart(SDatabase tr, int depth)
{
var m = (depth > 1) ? _inner?.ResetToTiesStart(tr, depth - 1) : null;
var ov = (depth == 1) ? _outer.Value.Item2.ob as SDict<long, bool> : null;
Expand All @@ -509,7 +509,7 @@ internal MTreeBookmark<K> ResetToTiesStart(STransaction tr, int depth)
/// </summary>
/// <param name="depth">The depth in the key</param>
/// <returns>whether there are more matches</returns>
internal bool hasMore(STransaction tr, int depth)
internal bool hasMore(SDatabase tr, int depth)
{
if (depth > 1)
return _pmk?.Next() != null || (_inner != null && _inner.hasMore(tr, depth - 1));
Expand Down
Loading

0 comments on commit 9579b4e

Please sign in to comment.