Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

literate code

  • Loading branch information...
commit 8c3cf26b02faa198e857829023041342bf68efa2 1 parent ecadfed
chrisdew authored
View
10 Makefile
@@ -0,0 +1,10 @@
+all: clean docs
+
+clean:
+ rm -rf docs
+
+docs:
+ docco lib/*.js test/*.js
+ google-chrome ./docs
+
+
View
2  README.md
@@ -8,7 +8,7 @@ BarricaneDB is a loose implementation of the [Prevalence](http://www.ibm.com/dev
Features
--------
* Fantastically fast.
-* Stupidly simple, thank you __defineSetter__ and friends.
+* Stupidly simple, thank you <code>__defineSetter__</code> and friends.
* ORM-less, just work with your objects directly.
* Snapshot plus transaction log gives persistance in event of an application crash.
View
7 docs/barricane-db.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html> <html> <head> <title>barricane-db.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="demo.html"> demo.js </a> <a class="source" href="hello_world.html"> hello_world.js </a> <a class="source" href="model.html"> model.js </a> <a class="source" href="old-disk-manager.html"> old-disk-manager.js </a> <a class="source" href="old-serialisation.html"> old-serialisation.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> barricane-db.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+Released under the MIT open source licence.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>This file is the entry point for the NPM barricane-db package.
+It only exports symbols required from other modules.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">db_mod</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./db&#39;</span><span class="p">);</span>
+<span class="kd">var</span> <span class="nx">disk_io_mod</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./disk-io&#39;</span><span class="p">);</span>
+<span class="nx">exports</span><span class="p">.</span><span class="nx">DB</span> <span class="o">=</span> <span class="nx">db_mod</span><span class="p">.</span><span class="nx">DB</span><span class="p">;</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
43 docs/bdb-disk-manager.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html> <html> <head> <title>bdb-disk-manager.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="demo.html"> demo.js </a> <a class="source" href="hello_world.html"> hello_world.js </a> <a class="source" href="model.html"> model.js </a> <a class="source" href="old-disk-manager.html"> old-disk-manager.js </a> <a class="source" href="old-serialisation.html"> old-serialisation.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> bdb-disk-manager.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>The DB Manager handles aspects such as loading DBs from disk and persistence.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">bdb</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../lib/old-barricane-db&#39;</span><span class="p">);</span>
+<span class="kd">var</span> <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;fs&#39;</span><span class="p">);</span>
+
+<span class="kd">function</span> <span class="nx">BDBDiskManager</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">that</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
+
+ <span class="k">this</span><span class="p">.</span><span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span> <span class="o">===</span> <span class="kc">undefined</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">options</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">path</span> <span class="o">===</span> <span class="kc">undefined</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">path</span> <span class="o">=</span> <span class="s2">&quot;/tmp/&quot;</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">name</span> <span class="o">===</span> <span class="kc">undefined</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">name</span> <span class="o">=</span> <span class="s2">&quot;unnamed_db&quot;</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">db</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">bdb</span><span class="p">.</span><span class="nx">DB</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">);</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">txnlog</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">txnlogPath</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">path</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">&quot;.log&quot;</span><span class="p">;</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">snapshot</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">snapshotPath</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">path</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">&quot;.bdb&quot;</span><span class="p">;</span>
+
+ <span class="k">try</span> <span class="p">{</span> <span class="c1">// FIXME: do this properly</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">statSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">snapshotPath</span><span class="p">);</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;loadDB&quot;</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;createDB&quot;</span><span class="p">);</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">snapshot_fd</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">openSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">snapshotPath</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">);</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">txnlog_fd</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">openSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">txnlogPath</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">);</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">write</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">arg</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>console.log(arg);</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">fs</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">that</span><span class="p">.</span><span class="nx">txnlog_fd</span><span class="p">,</span> <span class="nx">arg</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">writeSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">snapshot_fd</span><span class="p">,</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">));</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">closeSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">snapshot_fd</span><span class="p">);</span>
+ <span class="p">}</span>
+<span class="p">}</span>
+
+<span class="nx">BDBDiskManager</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">write</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{};</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">closeSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">txnlog_fd</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>this.txnlog.destroy();</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">}</span>
+
+<span class="nx">exports</span><span class="p">.</span><span class="nx">BDBDiskManager</span> <span class="o">=</span> <span class="nx">BDBDiskManager</span><span class="p">;</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
22 docs/db.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html> <html> <head> <title>db.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="demo.html"> demo.js </a> <a class="source" href="hello_world.html"> hello_world.js </a> <a class="source" href="model.html"> model.js </a> <a class="source" href="old-disk-manager.html"> old-disk-manager.js </a> <a class="source" href="old-serialisation.html"> old-serialisation.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> db.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+Released under the MIT open source licence.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>This module contains the database code.
+It specifically eschews serialisation and io concerns.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">uuid</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;uuid&#39;</span><span class="p">)</span><span class="nx">l</span>
+ <span class="p">,</span> <span class="nx">dio</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./disk-io&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>The DB constructor represents the database. In almost all circumstances only
+one database will exist per process. More can be used, if needed, but the
+application will become more complex, as it cannot use
+<code>process.db</code> in constructors.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">DB</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">options</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p><code>magic</code> is a string which must not normally occur in your application's
+property names. Double underscore is the default.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">magic</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">magic</span> <span class="o">||</span> <span class="s2">&quot;__&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p><code>uuid</code> is the function used to generate unique IDs for each
+managed object. It is overridable for testing purposes, where the IDs
+need to be deterministic.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">uuid</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">uuid</span> <span class="o">||</span> <span class="nx">uuid</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>The <code>io</code> manager is responsible for IO. By default BarricaneDB
+uses simple disk-nased persistence. The <code>ioManager</code> is
+separated so that it can be optionally replaced with ReplicationIO at
+some point in the future.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">io</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">io</span> <span class="o">||</span> <span class="k">new</span> <span class="nx">dio</span><span class="p">.</span><span class="nx">DiskIO</span><span class="p">(</span><span class="nx">options</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p><code>instances</code> contains all of the <em>managed</em> objects, indexed
+by uuid.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">instances</span> <span class="o">=</span> <span class="p">{};</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p><code>stores</code> contains all of the <em>managed</em> objects' data, indexed
+by uuid. The data is separate as the properties in the instances have
+custom getters/setters, via <code><strong>defineSetter</strong></code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">stores</span> <span class="o">=</span> <span class="p">{};</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Export the symbols.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">exports</span><span class="p">.</span><span class="nx">DB</span> <span class="o">=</span> <span class="nx">DB</span><span class="p">;</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
16 docs/demo.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html> <html> <head> <title>demo.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="demo.html"> demo.js </a> <a class="source" href="hello_world.html"> hello_world.js </a> <a class="source" href="model.html"> model.js </a> <a class="source" href="old-disk-manager.html"> old-disk-manager.js </a> <a class="source" href="old-serialisation.html"> old-serialisation.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> demo.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">vows</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;vows&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="nx">assert</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;assert&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="nx">bdb</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../lib/barricane-db&#39;</span><span class="p">)</span>
+ <span class="p">;</span>
+
+<span class="nx">vows</span><span class="p">.</span><span class="nx">describe</span><span class="p">(</span><span class="s1">&#39;Setup&#39;</span><span class="p">).</span><span class="nx">addBatch</span><span class="p">(</span>
+ <span class="p">{</span> <span class="s2">&quot;dummy&quot;</span>
+ <span class="o">:</span> <span class="p">{</span> <span class="nx">topic</span>
+ <span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="k">return</span> <span class="mi">42</span><span class="p">;</span> <span class="p">}</span>
+ <span class="p">,</span> <span class="s2">&quot;equal 42&quot;</span>
+ <span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">topic</span><span class="p">)</span> <span class="p">{</span> <span class="nx">assert</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="nx">topic</span><span class="p">,</span> <span class="mi">42</span><span class="p">);</span> <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+<span class="p">);</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
15 docs/disk-io.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html> <html> <head> <title>disk-io.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="demo.html"> demo.js </a> <a class="source" href="hello_world.html"> hello_world.js </a> <a class="source" href="model.html"> model.js </a> <a class="source" href="old-disk-manager.html"> old-disk-manager.js </a> <a class="source" href="old-serialisation.html"> old-serialisation.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> disk-io.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+/ Released under the MIT open source licence.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>This module contains the DiskIO code.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>The DiskIO constructor creates an object which can be used by DB to interact
+with the outside world. Other IOs will be possible in future, including
+ReplicationIO.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">DiskIO</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">options</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="p">}</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">path</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">path</span> <span class="o">||</span> <span class="s1">&#39;/tmp/barricane.db&#39;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Writes must be counted, so we only close the file whwn all has been
+written.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">outstandingWrites</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>This writes the serialise object to disk.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DiskIO</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">write</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">serialisedObject</span><span class="p">)</span> <span class="p">{</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Read serialises objects back from disk, and
+<code>callback(err, result)</code> for each one.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DiskIO</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">read</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Export the symbols.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">exports</span><span class="p">.</span><span class="nx">DiskIO</span> <span class="o">=</span> <span class="nx">DiskIO</span><span class="p">;</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
186 docs/docco.css
@@ -0,0 +1,186 @@
+/*--------------------- Layout and Typography ----------------------------*/
+body {
+ font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
+ font-size: 15px;
+ line-height: 22px;
+ color: #252519;
+ margin: 0; padding: 0;
+}
+a {
+ color: #261a3b;
+}
+ a:visited {
+ color: #261a3b;
+ }
+p {
+ margin: 0 0 15px 0;
+}
+h1, h2, h3, h4, h5, h6 {
+ margin: 0px 0 15px 0;
+}
+ h1 {
+ margin-top: 40px;
+ }
+#container {
+ position: relative;
+}
+#background {
+ position: fixed;
+ top: 0; left: 525px; right: 0; bottom: 0;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ z-index: -1;
+}
+#jump_to, #jump_page {
+ background: white;
+ -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
+ -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
+ font: 10px Arial;
+ text-transform: uppercase;
+ cursor: pointer;
+ text-align: right;
+}
+#jump_to, #jump_wrapper {
+ position: fixed;
+ right: 0; top: 0;
+ padding: 5px 10px;
+}
+ #jump_wrapper {
+ padding: 0;
+ display: none;
+ }
+ #jump_to:hover #jump_wrapper {
+ display: block;
+ }
+ #jump_page {
+ padding: 5px 0 3px;
+ margin: 0 0 25px 25px;
+ }
+ #jump_page .source {
+ display: block;
+ padding: 5px 10px;
+ text-decoration: none;
+ border-top: 1px solid #eee;
+ }
+ #jump_page .source:hover {
+ background: #f5f5ff;
+ }
+ #jump_page .source:first-child {
+ }
+table td {
+ border: 0;
+ outline: 0;
+}
+ td.docs, th.docs {
+ max-width: 450px;
+ min-width: 450px;
+ min-height: 5px;
+ padding: 10px 25px 1px 50px;
+ overflow-x: hidden;
+ vertical-align: top;
+ text-align: left;
+ }
+ .docs pre {
+ margin: 15px 0 15px;
+ padding-left: 15px;
+ }
+ .docs p tt, .docs p code {
+ background: #f8f8ff;
+ border: 1px solid #dedede;
+ font-size: 12px;
+ padding: 0 0.2em;
+ }
+ .pilwrap {
+ position: relative;
+ }
+ .pilcrow {
+ font: 12px Arial;
+ text-decoration: none;
+ color: #454545;
+ position: absolute;
+ top: 3px; left: -20px;
+ padding: 1px 2px;
+ opacity: 0;
+ -webkit-transition: opacity 0.2s linear;
+ }
+ td.docs:hover .pilcrow {
+ opacity: 1;
+ }
+ td.code, th.code {
+ padding: 14px 15px 16px 25px;
+ width: 100%;
+ vertical-align: top;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ }
+ pre, tt, code {
+ font-size: 12px; line-height: 18px;
+ font-family: Monaco, Consolas, "Lucida Console", monospace;
+ margin: 0; padding: 0;
+ }
+
+
+/*---------------------- Syntax Highlighting -----------------------------*/
+td.linenos { background-color: #f0f0f0; padding-right: 10px; }
+span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
+body .hll { background-color: #ffffcc }
+body .c { color: #408080; font-style: italic } /* Comment */
+body .err { border: 1px solid #FF0000 } /* Error */
+body .k { color: #954121 } /* Keyword */
+body .o { color: #666666 } /* Operator */
+body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
+body .cp { color: #BC7A00 } /* Comment.Preproc */
+body .c1 { color: #408080; font-style: italic } /* Comment.Single */
+body .cs { color: #408080; font-style: italic } /* Comment.Special */
+body .gd { color: #A00000 } /* Generic.Deleted */
+body .ge { font-style: italic } /* Generic.Emph */
+body .gr { color: #FF0000 } /* Generic.Error */
+body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+body .gi { color: #00A000 } /* Generic.Inserted */
+body .go { color: #808080 } /* Generic.Output */
+body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
+body .gs { font-weight: bold } /* Generic.Strong */
+body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+body .gt { color: #0040D0 } /* Generic.Traceback */
+body .kc { color: #954121 } /* Keyword.Constant */
+body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
+body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
+body .kp { color: #954121 } /* Keyword.Pseudo */
+body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
+body .kt { color: #B00040 } /* Keyword.Type */
+body .m { color: #666666 } /* Literal.Number */
+body .s { color: #219161 } /* Literal.String */
+body .na { color: #7D9029 } /* Name.Attribute */
+body .nb { color: #954121 } /* Name.Builtin */
+body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
+body .no { color: #880000 } /* Name.Constant */
+body .nd { color: #AA22FF } /* Name.Decorator */
+body .ni { color: #999999; font-weight: bold } /* Name.Entity */
+body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
+body .nf { color: #0000FF } /* Name.Function */
+body .nl { color: #A0A000 } /* Name.Label */
+body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
+body .nt { color: #954121; font-weight: bold } /* Name.Tag */
+body .nv { color: #19469D } /* Name.Variable */
+body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
+body .w { color: #bbbbbb } /* Text.Whitespace */
+body .mf { color: #666666 } /* Literal.Number.Float */
+body .mh { color: #666666 } /* Literal.Number.Hex */
+body .mi { color: #666666 } /* Literal.Number.Integer */
+body .mo { color: #666666 } /* Literal.Number.Oct */
+body .sb { color: #219161 } /* Literal.String.Backtick */
+body .sc { color: #219161 } /* Literal.String.Char */
+body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
+body .s2 { color: #219161 } /* Literal.String.Double */
+body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
+body .sh { color: #219161 } /* Literal.String.Heredoc */
+body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
+body .sx { color: #954121 } /* Literal.String.Other */
+body .sr { color: #BB6688 } /* Literal.String.Regex */
+body .s1 { color: #219161 } /* Literal.String.Single */
+body .ss { color: #19469D } /* Literal.String.Symbol */
+body .bp { color: #954121 } /* Name.Builtin.Pseudo */
+body .vc { color: #19469D } /* Name.Variable.Class */
+body .vg { color: #19469D } /* Name.Variable.Global */
+body .vi { color: #19469D } /* Name.Variable.Instance */
+body .il { color: #666666 } /* Literal.Number.Integer.Long */
View
14 docs/hello_world.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html> <html> <head> <title>hello_world.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="demo.html"> demo.js </a> <a class="source" href="hello_world.html"> hello_world.js </a> <a class="source" href="model.html"> model.js </a> <a class="source" href="old-disk-manager.html"> old-disk-manager.js </a> <a class="source" href="old-serialisation.html"> old-serialisation.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> hello_world.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">vows</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;vows&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="nx">assert</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;assert&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="nx">bdb</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../lib/old-barricane-db&#39;</span><span class="p">)</span>
+ <span class="p">;</span>
+
+<span class="nx">vows</span><span class="p">.</span><span class="nx">describe</span><span class="p">(</span><span class="s1">&#39;The First Test&#39;</span><span class="p">).</span><span class="nx">addBatch</span><span class="p">({</span>
+ <span class="s1">&#39;Hello World&#39;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">topic</span><span class="o">:</span> <span class="nx">bdb</span><span class="p">.</span><span class="nx">hello_world</span>
+ <span class="p">,</span> <span class="s1">&#39;equals &quot;Hello World&quot;&#39;</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">topic</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">assert</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="nx">topic</span><span class="p">,</span> <span class="s2">&quot;Hello World&quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+<span class="p">}).</span><span class="kr">export</span><span class="p">(</span><span class="nx">module</span><span class="p">);</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
16 docs/model.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html> <html> <head> <title>model.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="demo.html"> demo.js </a> <a class="source" href="hello_world.html"> hello_world.js </a> <a class="source" href="model.html"> model.js </a> <a class="source" href="old-disk-manager.html"> old-disk-manager.js </a> <a class="source" href="old-serialisation.html"> old-serialisation.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> model.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>This is demonstration model code.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>A house constructor.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">House</span><span class="p">(</span><span class="nx">address</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">address</span> <span class="o">=</span> <span class="nx">address</span><span class="p">;</span>
+ <span class="nx">process</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">register</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>A pointless method, just because.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">House</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">logConstructionMaterial</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">address</span> <span class="o">+</span> <span class="s1">&#39; is made of stone&#39;</span><span class="p">);</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>A person constructor.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">Person</span><span class="p">(</span><span class="nx">personalName</span><span class="p">,</span> <span class="nx">familyName</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">personalName</span> <span class="o">=</span> <span class="nx">personalName</span><span class="p">;</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">familyName</span> <span class="o">=</span> <span class="nx">familyName</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>MUST declare any field which needs to trigger persistance.
+ONLY registered constructors, plain objects, arrays, strings, numbers and
+dates will be persisted.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">spouse</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
+
+ <span class="nx">process</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">register</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Export the symbols.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">exports</span><span class="p">.</span><span class="nx">House</span> <span class="o">=</span> <span class="nx">House</span><span class="p">;</span>
+<span class="nx">exports</span><span class="p">.</span><span class="nx">Person</span> <span class="o">=</span> <span class="nx">Person</span><span class="p">;</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
151 docs/old-barricane-db.html
@@ -0,0 +1,151 @@
+<!DOCTYPE html> <html> <head> <title>old-barricane-db.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="demo.html"> demo.js </a> <a class="source" href="hello_world.html"> hello_world.js </a> <a class="source" href="model.html"> model.js </a> <a class="source" href="old-disk-manager.html"> old-disk-manager.js </a> <a class="source" href="old-serialisation.html"> old-serialisation.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> old-barricane-db.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">uuid</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;node-uuid&#39;</span><span class="p">)</span>
+
+<span class="nx">exports</span><span class="p">.</span><span class="nx">hello_world</span> <span class="o">=</span> <span class="s2">&quot;Hello World&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>newClosure([args... ,] function<em>to</em>call)</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">newClosure</span><span class="p">()</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">);</span>
+ <span class="k">return</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
+ <span class="nx">args</span><span class="p">[</span><span class="nx">args</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">].</span><span class="nx">apply</span><span class="p">(</span><span class="kc">undefined</span><span class="p">,</span> <span class="nx">args</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">args</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">))</span>
+ <span class="p">}</span>
+<span class="p">}</span>
+
+<span class="kd">function</span> <span class="nx">ownKeys</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">accumulator</span> <span class="o">=</span> <span class="p">[];</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">propertyName</span> <span class="k">in</span> <span class="nx">o</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">o</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">propertyName</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">accumulator</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">propertyName</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">return</span> <span class="nx">accumulator</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">ownRealKeys</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">accumulator</span> <span class="o">=</span> <span class="p">[];</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">propertyName</span> <span class="k">in</span> <span class="nx">o</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">o</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">propertyName</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nx">propertyName</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">magic</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="o">!==</span> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">magic</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">accumulator</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">propertyName</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">return</span> <span class="nx">accumulator</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="kd">function</span> <span class="nx">DB</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span> <span class="o">===</span> <span class="kc">undefined</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">options</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">uuid</span> <span class="o">===</span> <span class="kc">undefined</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">uuid</span> <span class="o">=</span> <span class="nx">uuid</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">write</span> <span class="o">===</span> <span class="kc">undefined</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">write</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{};</span> <span class="c1">// do nothing</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">magic</span> <span class="o">===</span> <span class="kc">undefined</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">magic</span> <span class="o">=</span> <span class="s2">&quot;__&quot;</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">name</span> <span class="o">===</span> <span class="kc">undefined</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">name</span> <span class="o">=</span> <span class="s2">&quot;unnamed_db&quot;</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="k">this</span><span class="p">.</span><span class="nx">constructors</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">instances</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">stores</span> <span class="o">=</span> <span class="p">{};</span>
+
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>var args = Array.prototype.slice.call(arguments); </p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">serialise</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">ob</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="nx">ret</span><span class="p">.</span><span class="nx">__constructor</span> <span class="o">=</span> <span class="nx">ob</span><span class="p">.</span><span class="nx">constructor</span><span class="p">.</span><span class="nx">name</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">p</span> <span class="k">in</span> <span class="nx">ob</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">ob</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">p</span><span class="p">))</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>is this property a registered instance</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">ob</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span> <span class="o">!==</span> <span class="kc">undefined</span> <span class="o">&amp;&amp;</span> <span class="nx">ob</span><span class="p">[</span><span class="nx">p</span><span class="p">].</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">magic</span> <span class="o">+</span> <span class="s2">&quot;uuid&quot;</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">ret</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">magic</span> <span class="o">+</span> <span class="s2">&quot;ID&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">magic</span> <span class="o">+</span> <span class="nx">ob</span><span class="p">[</span><span class="nx">p</span><span class="p">].</span><span class="nx">__uuid</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">ob</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span> <span class="k">instanceof</span> <span class="nb">Date</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">ret</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">magic</span> <span class="o">+</span> <span class="s2">&quot;DATE&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">magic</span> <span class="o">+</span> <span class="nx">ob</span><span class="p">[</span><span class="nx">p</span><span class="p">].</span><span class="nx">getTime</span><span class="p">();;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">ret</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span> <span class="o">=</span> <span class="nx">ob</span><span class="p">[</span><span class="nx">p</span><span class="p">];</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">return</span> <span class="nx">ret</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">registerConstructors</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">);</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">args</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">constructors</span><span class="p">[</span><span class="nx">args</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">args</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
+ <span class="p">}</span>
+<span class="p">}</span>
+
+<span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">register</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">instance</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">that</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
+
+ <span class="nx">instance</span><span class="p">.</span><span class="nx">__uuid</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">uuid</span><span class="p">();</span>
+ </pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>constructor = instance.constructor;
+// is it the first time we;ve seen an object of this type?
+if (this.constructors[constructor.name] === undefined) {
+this.constructors[constructor.name] = constructor;
+}</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">instances</span><span class="p">[</span><span class="nx">instance</span><span class="p">.</span><span class="nx">__uuid</span><span class="p">]</span> <span class="o">=</span> <span class="nx">instance</span><span class="p">;</span>
+ <span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="p">{};</span> <span class="c1">// the backing store for the instance data</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">stores</span><span class="p">[</span><span class="nx">instance</span><span class="p">.</span><span class="nx">__uuid</span><span class="p">]</span> <span class="o">=</span> <span class="nx">store</span><span class="p">;</span>
+ </pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>setup setter handlers FIXME
+for (var p in instance) {
+if (instance.hasOwnProperty(p) &amp;&amp; p.slice(0,2) != "<strong>") {
+ console.log("defineSetter", instance[p], p);
+ instance.</strong>defineSetter__(p, newClosure(p, function(q) {
+ console.log("outerSetter", instance[q], q);
+ return (function(val) {
+ console.log("Setter", instance[q], q, val);
+ instance[q] = val;
+ that.options.write(that.serialise(instance));
+ })
+ }));
+}
+}</p> </td> <td class="code"> <div class="highlight"><pre> </pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>FIXME</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">ownRealKeys</span><span class="p">(</span><span class="nx">instance</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">p</span><span class="p">,</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">all</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>var args = Array.prototype.slice.call(arguments);
+console.log("Setter0", JSON.stringify(instance), instance[p], p);
+var old = instance[p];</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">store</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span> <span class="o">=</span> <span class="nx">instance</span><span class="p">[</span><span class="nx">p</span><span class="p">];</span>
+ <span class="nx">instance</span><span class="p">.</span><span class="nx">__defineSetter__</span><span class="p">(</span><span class="nx">p</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>console.log("Setter", JSON.stringify(instance), instance[p], p, val);</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">store</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span> <span class="o">=</span> <span class="nx">val</span><span class="p">;</span>
+ <span class="nx">that</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">that</span><span class="p">.</span><span class="nx">serialise</span><span class="p">(</span><span class="nx">instance</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;\n&quot;</span><span class="p">);</span>
+ <span class="p">});</span>
+ <span class="nx">instance</span><span class="p">.</span><span class="nx">__defineGetter__</span><span class="p">(</span><span class="nx">p</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">store</span><span class="p">[</span><span class="nx">p</span><span class="p">];</span>
+ <span class="p">});</span>
+ <span class="p">});</span>
+
+ </pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>finally add the object to the log
+console.log("write0", this.options.write);</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">options</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">that</span><span class="p">.</span><span class="nx">serialise</span><span class="p">(</span><span class="nx">instance</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&quot;\n&quot;</span><span class="p">);</span>
+
+<span class="p">}</span>
+
+<span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">toJSON</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">p</span> <span class="k">in</span> <span class="k">this</span><span class="p">.</span><span class="nx">instances</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">instances</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">p</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">ret</span><span class="p">[</span><span class="nx">p</span><span class="p">]</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">serialise</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">instances</span><span class="p">[</span><span class="nx">p</span><span class="p">]);</span>
+ <span class="p">}</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>console.log(JSON.stringify(ret));</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="nx">ret</span><span class="p">;</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>This method sets up the instances from their serialised form.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">fromJSON</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">json</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">uuid</span> <span class="k">in</span> <span class="nx">json</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">json</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">uuid</span><span class="p">))</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>FIXME create the object using it's constructor
+findout about modifying the constructors to automatically add a 'register' call.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">instances</span><span class="p">[</span><span class="nx">uuid</span><span class="p">]</span> <span class="o">=</span> <span class="nx">json</span><span class="p">[</span><span class="nx">uuid</span><span class="p">];</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">uuid</span> <span class="k">in</span> <span class="k">this</span><span class="p">.</span><span class="nx">instances</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">instances</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">uuid</span><span class="p">))</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">ob</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">instances</span><span class="p">[</span><span class="nx">uuid</span><span class="p">];</span>
+ <span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">p</span> <span class="k">in</span> <span class="nx">ob</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">ob</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">p</span><span class="p">))</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">value</span> <span class="o">=</span> <span class="nx">json</span><span class="p">[</span><span class="nx">p</span><span class="p">];</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">value</span> <span class="k">instanceof</span> <span class="nb">String</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>FIXME
+if it's a <strong>ID</strong> or <strong>DATE</strong>
+substitute in the real link/date</p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>This method amends the instances from the transaction log.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">DB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">fromLog</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">log</span><span class="p">)</span> <span class="p">{</span>
+
+<span class="p">}</span>
+
+
+<span class="nx">exports</span><span class="p">.</span><span class="nx">DB</span> <span class="o">=</span> <span class="nx">DB</span><span class="p">;</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
63 docs/old-disk-manager.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html> <html> <head> <title>old-disk-manager.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="demo.html"> demo.js </a> <a class="source" href="hello_world.html"> hello_world.js </a> <a class="source" href="model.html"> model.js </a> <a class="source" href="old-disk-manager.html"> old-disk-manager.js </a> <a class="source" href="old-serialisation.html"> old-serialisation.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> old-disk-manager.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">vows</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;vows&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="nx">assert</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;assert&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="nx">bdb</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../lib/old-barricane-db&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="nx">bdm</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../lib/bdb-disk-manager&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;fs&#39;</span><span class="p">)</span>
+ <span class="p">;</span>
+<span class="nx">require</span><span class="p">(</span><span class="s1">&#39;datejs&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>mock up uuids for testing</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">nextMockUuid</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+<span class="kd">function</span> <span class="nx">mockUuid</span><span class="p">()</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="s2">&quot;&quot;</span> <span class="o">+</span> <span class="nx">nextMockUuid</span><span class="o">++</span><span class="p">;</span>
+<span class="p">}</span>
+
+
+
+<span class="kd">var</span> <span class="nx">db</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
+<span class="kd">var</span> <span class="nx">dm</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
+<span class="kd">function</span> <span class="nx">setup</span><span class="p">()</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>remove old files, if they exist</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">try</span> <span class="p">{</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">unlinkSync</span><span class="p">(</span><span class="s1">&#39;/tmp/unnamed_db.bdb&#39;</span><span class="p">);</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">unlinkSync</span><span class="p">(</span><span class="s1">&#39;/tmp/unnamed_db.log&#39;</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;unable to remove files&quot;</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="kd">var</span> <span class="nx">dm</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">bdm</span><span class="p">.</span><span class="nx">BDBDiskManager</span><span class="p">({</span><span class="nx">uuid</span><span class="o">:</span> <span class="nx">mockUuid</span><span class="p">});</span>
+ <span class="nx">db</span> <span class="o">=</span> <span class="nx">dm</span><span class="p">.</span><span class="nx">db</span><span class="p">;</span>
+
+ <span class="kd">function</span> <span class="nx">Customer</span><span class="p">(</span><span class="nx">personal_name</span><span class="p">,</span> <span class="nx">family_name</span><span class="p">,</span> <span class="nx">dob</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">personal_name</span> <span class="o">=</span> <span class="nx">personal_name</span><span class="p">;</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">family_name</span> <span class="o">=</span> <span class="nx">family_name</span><span class="p">;</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">dob</span> <span class="o">=</span> <span class="nx">dob</span><span class="p">;</span>
+ <span class="nx">db</span><span class="p">.</span><span class="nx">register</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="nx">db</span><span class="p">.</span><span class="nx">registerConstructors</span><span class="p">(</span><span class="nx">Customer</span><span class="p">);</span>
+
+ <span class="kd">var</span> <span class="nx">customer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Customer</span><span class="p">(</span><span class="s2">&quot;Fred&quot;</span><span class="p">,</span> <span class="s2">&quot;Smith&quot;</span><span class="p">,</span> <span class="nb">Date</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="s2">&quot;2011-02-02&quot;</span><span class="p">));</span>
+ <span class="nx">customer</span><span class="p">.</span><span class="nx">family_name</span> <span class="o">=</span> <span class="s2">&quot;Flintstone&quot;</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="nx">setup</span><span class="p">();</span>
+
+<span class="kd">var</span> <span class="nx">suite</span> <span class="o">=</span> <span class="nx">vows</span><span class="p">.</span><span class="nx">describe</span><span class="p">(</span><span class="s1">&#39;disk-manager&#39;</span><span class="p">).</span><span class="nx">addBatch</span><span class="p">({</span>
+ <span class="s1">&#39;.bdb file&#39;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">topic</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">readFile</span><span class="p">(</span><span class="s1">&#39;/tmp/unnamed_db.bdb&#39;</span><span class="p">,</span> <span class="s1">&#39;utf8&#39;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">callback</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">,</span> <span class="s1">&#39;content&#39;</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">result</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">assert</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="nx">result</span><span class="p">,</span> <span class="s1">&#39;{}&#39;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">,</span> <span class="s1">&#39;.log file&#39;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">topic</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">readFile</span><span class="p">(</span><span class="s1">&#39;/tmp/unnamed_db.log&#39;</span><span class="p">,</span> <span class="s1">&#39;utf8&#39;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">callback</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">,</span> <span class="s1">&#39;content&#39;</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">result</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">assert</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="nx">result</span><span class="p">,</span> <span class="s1">&#39;{&quot;__constructor&quot;:&quot;Customer&quot;,&quot;personal_name&quot;:&quot;Fred&quot;,&quot;family_name&quot;:&quot;Smith&quot;,&quot;dob&quot;:&quot;__DATE__1296604800000&quot;,&quot;__uuid&quot;:&quot;0&quot;}\n{&quot;__constructor&quot;:&quot;Customer&quot;,&quot;personal_name&quot;:&quot;Fred&quot;,&quot;family_name&quot;:&quot;Flintstone&quot;,&quot;dob&quot;:&quot;__DATE__1296604800000&quot;,&quot;__uuid&quot;:&quot;0&quot;}\n&#39;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+<span class="p">})</span>
+<span class="nx">suite</span><span class="p">.</span><span class="kr">export</span><span class="p">(</span><span class="nx">module</span><span class="p">);</span>
+
+<span class="nx">setTimeout</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
+ <span class="nx">dm</span><span class="p">.</span><span class="nx">end</span><span class="p">();</span>
+<span class="p">},</span> <span class="mi">1000</span><span class="p">);</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
114 docs/old-serialisation.html
@@ -0,0 +1,114 @@
+<!DOCTYPE html> <html> <head> <title>old-serialisation.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="demo.html"> demo.js </a> <a class="source" href="hello_world.html"> hello_world.js </a> <a class="source" href="model.html"> model.js </a> <a class="source" href="old-disk-manager.html"> old-disk-manager.js </a> <a class="source" href="old-serialisation.html"> old-serialisation.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> old-serialisation.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">vows</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;vows&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="nx">assert</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;assert&#39;</span><span class="p">)</span>
+ <span class="p">,</span> <span class="nx">bdb</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../lib/old-barricane-db&#39;</span><span class="p">)</span>
+ <span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>mock up uuids for testing</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">nextMockUuid</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+<span class="kd">function</span> <span class="nx">mockUuid</span><span class="p">()</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="s2">&quot;&quot;</span> <span class="o">+</span> <span class="nx">nextMockUuid</span><span class="o">++</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="kd">var</span> <span class="nx">db</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">bdb</span><span class="p">.</span><span class="nx">DB</span><span class="p">(</span><span class="nx">options</span><span class="o">=</span><span class="p">{</span> <span class="nx">uuid</span><span class="o">:</span> <span class="nx">mockUuid</span>
+ <span class="p">}</span> <span class="p">);</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>p.registerConstructors(Bank, Customer, Account);</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">Bank</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">sort_code</span><span class="p">,</span> <span class="nx">contacts</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">name</span> <span class="o">=</span> <span class="nx">name</span><span class="p">;</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">sort_code</span> <span class="o">=</span> <span class="nx">sort_code</span><span class="p">;</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">contacts</span> <span class="o">=</span> <span class="nx">contacts</span><span class="p">;</span>
+ <span class="nx">db</span><span class="p">.</span><span class="nx">register</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
+<span class="p">}</span>
+<span class="kd">function</span> <span class="nx">Customer</span><span class="p">(</span><span class="nx">personal_name</span><span class="p">,</span> <span class="nx">family_name</span><span class="p">,</span> <span class="nx">dob</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">personal_name</span> <span class="o">=</span> <span class="nx">personal_name</span><span class="p">;</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">family_name</span> <span class="o">=</span> <span class="nx">family_name</span><span class="p">;</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">dob</span> <span class="o">=</span> <span class="nx">dob</span><span class="p">;</span>
+ <span class="nx">db</span><span class="p">.</span><span class="nx">register</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
+<span class="p">}</span>
+<span class="kd">function</span> <span class="nx">Account</span><span class="p">(</span><span class="nx">bank</span><span class="p">,</span> <span class="nx">customer</span><span class="p">,</span> <span class="nx">balance</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">bank</span> <span class="o">=</span> <span class="nx">bank</span><span class="p">;</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">customer</span> <span class="o">=</span> <span class="nx">customer</span><span class="p">;</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">balance</span> <span class="o">=</span> <span class="nx">balance</span><span class="p">;</span>
+ <span class="nx">db</span><span class="p">.</span><span class="nx">register</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="nx">db</span><span class="p">.</span><span class="nx">registerConstructors</span><span class="p">(</span><span class="nx">Bank</span><span class="p">,</span> <span class="nx">Customer</span><span class="p">,</span> <span class="nx">Account</span><span class="p">);</span>
+
+<span class="kd">var</span> <span class="nx">lloyds</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Bank</span><span class="p">(</span><span class="s1">&#39;lloyds&#39;</span><span class="p">,</span> <span class="s2">&quot;01-02-03&quot;</span><span class="p">);</span>
+<span class="nx">lloyds</span><span class="p">.</span><span class="nx">name</span> <span class="o">=</span> <span class="s2">&quot;LloydsTSB&quot;</span><span class="p">;</span>
+<span class="kd">var</span> <span class="nx">barclays</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Bank</span><span class="p">(</span><span class="s1">&#39;barclays&#39;</span><span class="p">,</span> <span class="s2">&quot;02-03-04&quot;</span><span class="p">,</span>
+ <span class="p">{</span> <span class="nx">tel</span><span class="o">:</span> <span class="s2">&quot;02345 678901&quot;</span>
+ <span class="p">,</span> <span class="nx">email</span><span class="o">:</span> <span class="s2">&quot;info@barclays.com&quot;</span>
+ <span class="p">}</span> <span class="p">);</span>
+<span class="kd">var</span> <span class="nx">ben_dob</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">();</span>
+<span class="nx">ben_dob</span><span class="p">.</span><span class="nx">setTime</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
+<span class="nx">ben_dob</span><span class="p">.</span><span class="nx">setYear</span><span class="p">(</span><span class="s2">&quot;2001&quot;</span><span class="p">);</span>
+<span class="nx">ben_dob</span><span class="p">.</span><span class="nx">setMonth</span><span class="p">(</span><span class="s2">&quot;01&quot;</span><span class="p">);</span>
+<span class="nx">ben_dob</span><span class="p">.</span><span class="nx">setDate</span><span class="p">(</span><span class="s2">&quot;01&quot;</span><span class="p">);</span>
+<span class="kd">var</span> <span class="nx">ben</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Customer</span><span class="p">(</span><span class="s1">&#39;ben&#39;</span><span class="p">,</span> <span class="s1">&#39;white&#39;</span><span class="p">,</span> <span class="nx">ben_dob</span><span class="p">);</span>
+<span class="kd">var</span> <span class="nx">ginny</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Customer</span><span class="p">(</span><span class="s1">&#39;ginny&#39;</span><span class="p">,</span> <span class="s1">&#39;green&#39;</span><span class="p">);</span>
+<span class="kd">var</span> <span class="nx">ben_account</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Account</span><span class="p">(</span><span class="nx">lloyds</span><span class="p">,</span> <span class="nx">ben</span><span class="p">,</span> <span class="mi">100</span><span class="p">);</span>
+<span class="kd">var</span> <span class="nx">ginny_lloyds_account</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Account</span><span class="p">(</span><span class="nx">lloyds</span><span class="p">,</span> <span class="nx">ginny</span><span class="p">,</span> <span class="mi">10</span><span class="p">);</span>
+<span class="kd">var</span> <span class="nx">ginny_barclays_account</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Account</span><span class="p">(</span><span class="nx">barclays</span><span class="p">,</span> <span class="nx">ginny</span><span class="p">,</span> <span class="mi">1000</span><span class="p">);</span>
+
+<span class="nx">vows</span><span class="p">.</span><span class="nx">describe</span><span class="p">(</span><span class="s1">&#39;The First Test&#39;</span><span class="p">).</span><span class="nx">addBatch</span><span class="p">({</span>
+ <span class="s1">&#39;Setting Up&#39;</span><span class="o">:</span> <span class="p">{</span> <span class="nx">topic</span><span class="o">:</span> <span class="nx">db</span>
+ <span class="p">,</span> <span class="s1">&#39;constructors are registered&#39;</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">topic</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">assert</span><span class="p">.</span><span class="nx">deepEqual</span><span class="p">(</span><span class="nx">topic</span><span class="p">.</span><span class="nx">constructors</span><span class="p">,</span>
+ <span class="p">{</span> <span class="nx">Bank</span><span class="o">:</span> <span class="nx">Bank</span>
+ <span class="p">,</span> <span class="nx">Customer</span><span class="o">:</span> <span class="nx">Customer</span>
+ <span class="p">,</span> <span class="nx">Account</span><span class="o">:</span> <span class="nx">Account</span>
+ <span class="p">}</span> <span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">,</span> <span class="s1">&#39;serialisation_has_worked&#39;</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">topic</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">assert</span><span class="p">.</span><span class="nx">deepEqual</span><span class="p">(</span><span class="nx">topic</span><span class="p">.</span><span class="nx">toJSON</span><span class="p">(),</span>
+ <span class="p">{</span>
+ <span class="mi">0</span><span class="o">:</span> <span class="p">{</span>
+ <span class="nx">__constructor</span><span class="o">:</span> <span class="s1">&#39;Bank&#39;</span><span class="p">,</span>
+ <span class="nx">name</span><span class="o">:</span> <span class="s1">&#39;LloydsTSB&#39;</span><span class="p">,</span>
+ <span class="nx">sort_code</span><span class="o">:</span> <span class="s1">&#39;01-02-03&#39;</span><span class="p">,</span>
+ <span class="nx">contacts</span><span class="o">:</span> <span class="kc">undefined</span><span class="p">,</span>
+ <span class="nx">__uuid</span><span class="o">:</span> <span class="s1">&#39;0&#39;</span>
+ <span class="p">},</span>
+ <span class="mi">1</span><span class="o">:</span> <span class="p">{</span>
+ <span class="nx">__constructor</span><span class="o">:</span> <span class="s1">&#39;Bank&#39;</span><span class="p">,</span>
+ <span class="nx">name</span><span class="o">:</span> <span class="s1">&#39;barclays&#39;</span><span class="p">,</span>
+ <span class="nx">sort_code</span><span class="o">:</span> <span class="s1">&#39;02-03-04&#39;</span><span class="p">,</span>
+ <span class="nx">contacts</span><span class="o">:</span> <span class="p">{</span> <span class="nx">tel</span><span class="o">:</span> <span class="s1">&#39;02345 678901&#39;</span><span class="p">,</span> <span class="nx">email</span><span class="o">:</span> <span class="s1">&#39;info@barclays.com&#39;</span> <span class="p">},</span>
+ <span class="nx">__uuid</span><span class="o">:</span> <span class="s1">&#39;1&#39;</span>
+ <span class="p">},</span>
+ <span class="mi">2</span><span class="o">:</span> <span class="p">{</span>
+ <span class="nx">__constructor</span><span class="o">:</span> <span class="s1">&#39;Customer&#39;</span><span class="p">,</span>
+ <span class="nx">personal_name</span><span class="o">:</span> <span class="s1">&#39;ben&#39;</span><span class="p">,</span>
+ <span class="nx">family_name</span><span class="o">:</span> <span class="s1">&#39;white&#39;</span><span class="p">,</span>
+ <span class="nx">dob</span><span class="o">:</span> <span class="s1">&#39;__DATE__980985600000&#39;</span><span class="p">,</span>
+ <span class="nx">__uuid</span><span class="o">:</span> <span class="s1">&#39;2&#39;</span>
+ <span class="p">},</span>
+ <span class="mi">3</span><span class="o">:</span> <span class="p">{</span>
+ <span class="nx">__constructor</span><span class="o">:</span> <span class="s1">&#39;Customer&#39;</span><span class="p">,</span>
+ <span class="nx">personal_name</span><span class="o">:</span> <span class="s1">&#39;ginny&#39;</span><span class="p">,</span>
+ <span class="nx">family_name</span><span class="o">:</span> <span class="s1">&#39;green&#39;</span><span class="p">,</span>
+ <span class="nx">dob</span><span class="o">:</span> <span class="kc">undefined</span><span class="p">,</span>
+ <span class="nx">__uuid</span><span class="o">:</span> <span class="s1">&#39;3&#39;</span>
+ <span class="p">},</span>
+ <span class="mi">4</span><span class="o">:</span> <span class="p">{</span>
+ <span class="nx">__constructor</span><span class="o">:</span> <span class="s1">&#39;Account&#39;</span><span class="p">,</span>
+ <span class="nx">bank</span><span class="o">:</span> <span class="s1">&#39;__ID__0&#39;</span><span class="p">,</span>
+ <span class="nx">customer</span><span class="o">:</span> <span class="s1">&#39;__ID__2&#39;</span><span class="p">,</span>
+ <span class="nx">balance</span><span class="o">:</span> <span class="mi">100</span><span class="p">,</span>
+ <span class="nx">__uuid</span><span class="o">:</span> <span class="s1">&#39;4&#39;</span>
+ <span class="p">},</span>
+ <span class="mi">5</span><span class="o">:</span> <span class="p">{</span>
+ <span class="nx">__constructor</span><span class="o">:</span> <span class="s1">&#39;Account&#39;</span><span class="p">,</span>
+ <span class="nx">bank</span><span class="o">:</span> <span class="s1">&#39;__ID__0&#39;</span><span class="p">,</span>
+ <span class="nx">customer</span><span class="o">:</span> <span class="s1">&#39;__ID__3&#39;</span><span class="p">,</span>
+ <span class="nx">balance</span><span class="o">:</span> <span class="mi">10</span><span class="p">,</span>
+ <span class="nx">__uuid</span><span class="o">:</span> <span class="s1">&#39;5&#39;</span>
+ <span class="p">},</span>
+ <span class="mi">6</span><span class="o">:</span> <span class="p">{</span>
+ <span class="nx">__constructor</span><span class="o">:</span> <span class="s1">&#39;Account&#39;</span><span class="p">,</span>
+ <span class="nx">bank</span><span class="o">:</span> <span class="s1">&#39;__ID__1&#39;</span><span class="p">,</span>
+ <span class="nx">customer</span><span class="o">:</span> <span class="s1">&#39;__ID__3&#39;</span><span class="p">,</span>
+ <span class="nx">balance</span><span class="o">:</span> <span class="mi">1000</span><span class="p">,</span>
+ <span class="nx">__uuid</span><span class="o">:</span> <span class="s1">&#39;6&#39;</span>
+ <span class="p">}</span>
+ <span class="p">}</span> <span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+<span class="p">}).</span><span class="kr">export</span><span class="p">(</span><span class="nx">module</span><span class="p">);</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
11 docs/serialisation.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html> <html> <head> <title>serialisation.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="barricane-db.html"> barricane-db.js </a> <a class="source" href="bdb-disk-manager.html"> bdb-disk-manager.js </a> <a class="source" href="db.html"> db.js </a> <a class="source" href="disk-io.html"> disk-io.js </a> <a class="source" href="old-barricane-db.html"> old-barricane-db.js </a> <a class="source" href="serialisation.html"> serialisation.js </a> <a class="source" href="demo.html"> demo.js </a> <a class="source" href="hello_world.html"> hello_world.js </a> <a class="source" href="model.html"> model.js </a> <a class="source" href="old-disk-manager.html"> old-disk-manager.js </a> <a class="source" href="old-serialisation.html"> old-serialisation.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> serialisation.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
+<span class="cm"> * Serialisation (yes, I&#39;m English)</span>
+<span class="cm"> * Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.</span>
+<span class="cm"> * Released under the MIT open source licence.</span>
+<span class="cm"> */</span>
+
+<span class="cm">/*</span>
+<span class="cm"> * This module contains the Serialisation code.</span>
+<span class="cm"> */</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
13 lib/barricane-db.js
@@ -1,13 +1,8 @@
-/*
- * BarricaneDB
- * Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
- * Released under the MIT open source licence.
- */
+// Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+// Released under the MIT open source licence.
-/*
- * This file is the entry point for the NPM barricane-db package.
- * It only exports symbols required from other modules.
- */
+// This file is the entry point for the NPM barricane-db package.
+// It only exports symbols required from other modules.
var db_mod = require('./db');
var disk_io_mod = require('./disk-io');
View
50 lib/db.js
@@ -1,10 +1,40 @@
-/*
- * DB
- * Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
- * Released under the MIT open source licence.
- */
-
-/*
- * This module contains the database code.
- * It specifically eschews serialisation and io concerns.
- */
+// Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+// Released under the MIT open source licence.
+
+// This module contains the database code.
+// It specifically eschews serialisation and io concerns.
+
+var uuid = require('uuid')l
+ , dio = require('./disk-io');
+
+// The DB constructor represents the database. In almost all circumstances only
+// one database will exist per process. More can be used, if needed, but the
+// application will become more complex, as it cannot use
+// <code>process.db</code> in constructors.
+function DB(options) {
+ if (!options) {
+ options = {};
+ }
+ // <code>magic</code> is a string which must not normally occur in your application's
+ // property names. Double underscore is the default.
+ this.magic = options.magic || "__";
+ // <code>uuid</code> is the function used to generate unique IDs for each
+ // managed object. It is overridable for testing purposes, where the IDs
+ // need to be deterministic.
+ this.uuid = options.uuid || uuid;
+ // The <code>io</code> manager is responsible for IO. By default BarricaneDB
+ // uses simple disk-nased persistence. The <code>ioManager</code> is
+ // separated so that it can be optionally replaced with ReplicationIO at
+ // some point in the future.
+ this.io = options.io || new dio.DiskIO(options);
+ // <code>instances</code> contains all of the *managed* objects, indexed
+ // by uuid.
+ this.instances = {};
+ // <code>stores</code> contains all of the *managed* objects' data, indexed
+ // by uuid. The data is separate as the properties in the instances have
+ // custom getters/setters, via <code>__defineSetter__</code>.
+ this.stores = {};
+}
+
+// Export the symbols.
+exports.DB = DB;
View
39 lib/disk-io.js
@@ -1,9 +1,30 @@
-/*
- * DiskIO
- * Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
- * Released under the MIT open source licence.
- */
-
-/*
- * This module contains the DiskIO code.
- */
+// Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
+/// Released under the MIT open source licence.
+
+// This module contains the DiskIO code.
+
+// The DiskIO constructor creates an object which can be used by DB to interact
+// with the outside world. Other IOs will be possible in future, including
+// ReplicationIO.
+function DiskIO(options) {
+ if (!options) {
+ options = {};
+ }
+ this.path = options.path || '/tmp/barricane.db';
+ // Writes must be counted, so we only close the file whwn all has been
+ // written.
+ this.outstandingWrites = 0;
+}
+
+// This writes the serialise object to disk.
+DiskIO.prototype.write = function(serialisedObject) {
+}
+
+// Read serialises objects back from disk, and
+// <code>callback(err, result)</code> for each one.
+DiskIO.prototype.read = function(callback) {
+}
+
+
+// Export the symbols.
+exports.DiskIO = DiskIO;
View
27 test/model.js
@@ -0,0 +1,27 @@
+// This is demonstration model code.
+
+// A house constructor.
+function House(address) {
+ this.address = address;
+ process.db.register(this);
+}
+// A pointless method, just because.
+House.prototype.logConstructionMaterial = function() {
+ console.log(this.address + ' is made of stone');
+}
+
+// A person constructor.
+function Person(personalName, familyName) {
+ this.personalName = personalName;
+ this.familyName = familyName;
+ // MUST declare any field which needs to trigger persistance.
+ // ONLY registered constructors, plain objects, arrays, strings, numbers and
+ // dates will be persisted.
+ this.spouse = null;
+
+ process.db.register(this);
+}
+
+// Export the symbols.
+exports.House = House;
+exports.Person = Person;
Please sign in to comment.
Something went wrong with that request. Please try again.