(self, index, relation, documentindex, initializator, callback, between, recovered)
| 839 | |
| 840 | // Pushs "documentindex" to "index" document (document with all relations) |
| 841 | function pushRelationDocument(self, index, relation, documentindex, initializator, callback, between, recovered) { |
| 842 | |
| 843 | var offset = offsetDocument(self, index); |
| 844 | var buf = U.createBufferSize(self.header.documentsize); |
| 845 | |
| 846 | Fs.read(self.fd, buf, 0, buf.length, offset, function() { |
| 847 | |
| 848 | // type (1b) = from: 0 |
| 849 | // index (1b) = from: 1 |
| 850 | // state (1b) = from: 2 |
| 851 | // pageindex (4b) = from: 3 |
| 852 | // relationindex (4b) = from: 7 (it's for relations between two documents in TYPE_RELATION page) |
| 853 | // parentindex (4b) = from: 11 |
| 854 | // size/count (2b) = from: 15 |
| 855 | // data = from: 17 |
| 856 | |
| 857 | var count = buf.readUInt16LE(15); |
| 858 | if (count + 1 > self.header.relationlimit) { |
| 859 | findRelationDocument(self, buf.readUInt32LE(7), function(err, newindex) { |
| 860 | |
| 861 | // Is some relation document exist? |
| 862 | if (newindex && !recovered) { |
| 863 | pushRelationDocument(self, newindex, relation, documentindex, initializator, callback, between, true); |
| 864 | return; |
| 865 | } |
| 866 | |
| 867 | // meta.typeid (1 CLASS, 2 RELATION) |
| 868 | // meta.type (link to type class/relation) |
| 869 | // meta.state |
| 870 | // meta.parentindex |
| 871 | // meta.relationindex |
| 872 | // meta.size |
| 873 | // meta.buffer |
| 874 | |
| 875 | var meta = {}; |
| 876 | meta.typeid = relation.private ? TYPE_RELATION_DOCUMENT : TYPE_RELATION; |
| 877 | meta.type = relation; |
| 878 | meta.state = STATE_UNCOMPRESSED; |
| 879 | meta.parentindex = 0; |
| 880 | meta.relationindex = index; |
| 881 | meta.size = 0; |
| 882 | |
| 883 | addNode(self, meta, function(err, docindex, pageindex) { |
| 884 | relation.pageindex = pageindex; |
| 885 | relation.documentindex = docindex; |
| 886 | updDocumentRelation(self, relation.documentindex, index, function() { |
| 887 | updDocumentParent(self, index, relation.documentindex, function() { |
| 888 | pushRelationDocument(self, relation.documentindex, relation, documentindex, initializator, callback, between); |
| 889 | }); |
| 890 | }); |
| 891 | }); |
| 892 | }); |
| 893 | |
| 894 | } else { |
| 895 | |
| 896 | var buffer = U.createBufferSize(6); |
| 897 | buffer.writeUInt8(relation.index, 0); |
| 898 | buffer.writeUInt8(initializator ? 1 : 0, 1); |
no test coverage detected