Permalink
Browse files

added TODO

  • Loading branch information...
1 parent e44b5a7 commit ffd685bbb39ef8de4e10605e0601142a46a04910 @chrisdew committed Feb 9, 2011
View
@@ -63,9 +63,8 @@
</pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Forcing this registration is required, as db.persist is currently
false.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">registerInstance</span><span class="p">(</span><span class="nx">object</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
<span class="p">}</span>
- <span class="k">this</span><span class="p">.</span><span class="nx">codec</span><span class="p">.</span><span class="nx">fixRefs</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">instances</span><span class="p">);</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>This will delete any pre-existing database files - for now it just moves them
-aside.</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">deleteSync</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>First get the contents of the path.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">contents</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">path</span><span class="p">);</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">codec</span><span class="p">.</span><span class="nx">fixRefs</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">instances</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>TODO: write all these instances to disk.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">}</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>This will delete any pre-existing database files - for now it just moves them
+aside.</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">deleteSync</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>First get the contents of the path.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">contents</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">path</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">contents</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">contents</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">===</span> <span class="k">this</span><span class="p">.</span><span class="nx">FILENAME</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">renameSync</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="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">FILENAME</span><span class="p">,</span>
@@ -84,6 +83,6 @@
<span class="nx">callback</span><span class="p">(</span><span class="kc">false</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">this</span><span class="p">.</span><span class="nx">ending</span> <span class="o">=</span> <span class="nx">callback</span><span class="p">;</span>
-<span class="p">}</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#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>
+<span class="p">}</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#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>
@@ -18,7 +18,8 @@
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">fred</span><span class="p">.</span><span class="nx">house</span><span class="p">.</span><span class="nx">address</span><span class="p">);</span>
<span class="cm">/* --&gt; &#39;301 Cobblestone Wy., Bedrock, 70777&#39; */</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>Show that the instances use the right constructors.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">fred</span><span class="p">.</span><span class="nx">house</span><span class="p">.</span><span class="nx">logConstructionMaterial</span><span class="p">();</span>
-<span class="cm">/* --&gt; &#39;301 Cobblestone Wy., Bedrock, 70777 is made of stone&#39; */</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>Finally, close the database.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">db</span><span class="p">.</span><span class="nx">end</span><span class="p">(</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="cm">/* --&gt; &#39;301 Cobblestone Wy., Bedrock, 70777 is made of stone&#39; */</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>Finally, close the database. Note that the file now only has three JSON
+objects in it, as opposed to the seven in the original.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">db</span><span class="p">.</span><span class="nx">end</span><span class="p">(</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="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">err</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="s1">&#39;database has persisted successfully&#39;</span><span class="p">);</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
@@ -42,7 +42,8 @@ console.log(fred.house.address);
fred.house.logConstructionMaterial();
/* --> '301 Cobblestone Wy., Bedrock, 70777 is made of stone' */
-// Finally, close the database.
+// Finally, close the database. Note that the file now only has three JSON
+// objects in it, as opposed to the seven in the original.
db.end(function(err, result) {
if (!err) {
console.log('database has persisted successfully');
View
@@ -100,6 +100,7 @@ DiskIO.prototype._load = function(filepath) {
this.db.registerInstance(object, true);
}
this.codec.fixRefs(this.db.instances);
+ // TODO: write all these instances to disk.
}
View
@@ -1,25 +0,0 @@
-// Copyright (c) 2010 Barricane Technology Ltd., All Rights Reserved.
-// Released under the MIT open source licence.
-
-var vows = require('vows')
- , assert = require('assert')
- , bdb = require('../lib/barricane-db')
- ;
-
-
-
-
-
-
-
-var suite = vows.describe('Setup').addBatch(
- { "dummy"
- : { topic
- : function() { return 42; }
- , "equal 42"
- : function(topic) { assert.equal(topic, 42); }
- }
- }
-)
-
-suite.export(module);
View
@@ -1,12 +0,0 @@
-var vows = require('vows')
- , assert = require('assert')
- , bdb = require('../lib/old-barricane-db')
- ;
-
-vows.describe('The First Test').addBatch({
- 'Hello World': { topic: bdb.hello_world
- , 'equals "Hello World"': function(topic) {
- assert.equal(topic, "Hello World");
- }
- }
-}).export(module);
View
@@ -1,67 +0,0 @@
-var vows = require('vows')
- , assert = require('assert')
- , bdb = require('../lib/old-barricane-db')
- , bdm = require('../lib/bdb-disk-manager')
- , fs = require('fs')
- ;
-require('datejs');
-
-
-// mock up uuids for testing
-var nextMockUuid = 0;
-function mockUuid() {
- return "" + nextMockUuid++;
-}
-
-
-
-var db = null;
-var dm = null;
-function setup() {
- // remove old files, if they exist
- try {
- fs.unlinkSync('/tmp/unnamed_db.bdb');
- fs.unlinkSync('/tmp/unnamed_db.log');
- } catch (e) {
- console.log("unable to remove files");
- }
-
- var dm = new bdm.BDBDiskManager({uuid: mockUuid});
- db = dm.db;
-
- function Customer(personal_name, family_name, dob) {
- this.personal_name = personal_name;
- this.family_name = family_name;
- this.dob = dob;
- db.register(this);
- }
-
- db.registerConstructors(Customer);
-
- var customer = new Customer("Fred", "Smith", Date.parse("2011-02-02"));
- customer.family_name = "Flintstone";
-}
-
-setup();
-
-var suite = vows.describe('disk-manager').addBatch({
- '.bdb file': { topic: function() {
- fs.readFile('/tmp/unnamed_db.bdb', 'utf8', this.callback);
- }
- , 'content': function(err, result) {
- assert.equal(result, '{}');
- }
- }
- , '.log file': { topic: function() {
- fs.readFile('/tmp/unnamed_db.log', 'utf8', this.callback);
- }
- , 'content': function(err, result) {
- assert.equal(result, '{"__constructor":"Customer","personal_name":"Fred","family_name":"Smith","dob":"__DATE__1296604800000","__uuid":"0"}\n{"__constructor":"Customer","personal_name":"Fred","family_name":"Flintstone","dob":"__DATE__1296604800000","__uuid":"0"}\n');
- }
- }
-})
-suite.export(module);
-
-setTimeout(function() {
- dm.end();
-}, 1000);
View
@@ -1,118 +0,0 @@
-var vows = require('vows')
- , assert = require('assert')
- , bdb = require('../lib/old-barricane-db')
- ;
-
-// mock up uuids for testing
-var nextMockUuid = 0;
-function mockUuid() {
- return "" + nextMockUuid++;
-}
-
-var db = new bdb.DB(options={ uuid: mockUuid
- } );
-//p.registerConstructors(Bank, Customer, Account);
-
-function Bank(name, sort_code, contacts) {
- this.name = name;
- this.sort_code = sort_code;
- this.contacts = contacts;
- db.register(this);
-}
-function Customer(personal_name, family_name, dob) {
- this.personal_name = personal_name;
- this.family_name = family_name;
- this.dob = dob;
- db.register(this);
-}
-function Account(bank, customer, balance) {
- this.bank = bank;
- this.customer = customer;
- this.balance = balance;
- db.register(this);
-}
-
-db.registerConstructors(Bank, Customer, Account);
-
-var lloyds = new Bank('lloyds', "01-02-03");
-lloyds.name = "LloydsTSB";
-var barclays = new Bank('barclays', "02-03-04",
- { tel: "02345 678901"
- , email: "info@barclays.com"
- } );
-var ben_dob = new Date();
-ben_dob.setTime(0);
-ben_dob.setYear("2001");
-ben_dob.setMonth("01");
-ben_dob.setDate("01");
-var ben = new Customer('ben', 'white', ben_dob);
-var ginny = new Customer('ginny', 'green');
-var ben_account = new Account(lloyds, ben, 100);
-var ginny_lloyds_account = new Account(lloyds, ginny, 10);
-var ginny_barclays_account = new Account(barclays, ginny, 1000);
-
-vows.describe('The First Test').addBatch({
- 'Setting Up': { topic: db
- , 'constructors are registered': function(topic) {
- assert.deepEqual(topic.constructors,
- { Bank: Bank
- , Customer: Customer
- , Account: Account
- } );
- }
- , 'serialisation_has_worked': function(topic) {
- assert.deepEqual(topic.toJSON(),
- {
- 0: {
- __constructor: 'Bank',
- name: 'LloydsTSB',
- sort_code: '01-02-03',
- contacts: undefined,
- __uuid: '0'
- },
- 1: {
- __constructor: 'Bank',
- name: 'barclays',
- sort_code: '02-03-04',
- contacts: { tel: '02345 678901', email: 'info@barclays.com' },
- __uuid: '1'
- },
- 2: {
- __constructor: 'Customer',
- personal_name: 'ben',
- family_name: 'white',
- dob: '__DATE__980985600000',
- __uuid: '2'
- },
- 3: {
- __constructor: 'Customer',
- personal_name: 'ginny',
- family_name: 'green',
- dob: undefined,
- __uuid: '3'
- },
- 4: {
- __constructor: 'Account',
- bank: '__ID__0',
- customer: '__ID__2',
- balance: 100,
- __uuid: '4'
- },
- 5: {
- __constructor: 'Account',
- bank: '__ID__0',
- customer: '__ID__3',
- balance: 10,
- __uuid: '5'
- },
- 6: {
- __constructor: 'Account',
- bank: '__ID__1',
- customer: '__ID__3',
- balance: 1000,
- __uuid: '6'
- }
- } );
- }
- }
-}).export(module);

0 comments on commit ffd685b

Please sign in to comment.