Exemplo n.º 1
0
        /// <summary>
        /// Initializing Root Node
        /// </summary>
        /// <param name="DBreezeTableName">Real table name in DBreeze, that will hold the structure, must be synchronized with other tables in transaction</param>
        /// <param name="tran"></param>
        /// <param name="maximalInsertSpeed">will use DBreeze Technical_SetTable_OverwriteIsNotAllowed among transaction for DBreezeTableName</param>
        public DataAsTree(string DBreezeTableName, DBreeze.Transactions.Transaction tran, bool maximalInsertSpeed = false)
        {
            if (tran == null)
                throw new Exception("Transaction is null");

            if (RootNode != null)
                throw new Exception("Can't be more then one root node, use other constructor");

            //Setting up RootNode
            this.RootNode = this;

            this.Transaction = tran;
            this.maximalInsertSpeed = maximalInsertSpeed;
            this.DBreezeTableName = DBreezeTableName;
            this.NodeId = 0;
            this.ParentNodeId = 0;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Internal
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        DataAsTree SetupNodeFromRow(DBreeze.DataTypes.Row<byte[], byte[]> row)
        {
            DataAsTree node = null;
            byte[] val = row.Value;

            /*
            Protocol:
                1byte - protocol version (starting from 1)
                ...
                than due to the protocol description
            */

            node = new DataAsTree();

            switch (val[0])
            {
                case 1: //First protocol type
                        /*
                        Protocol:
                            1byte - protocol version (starting from 1)
                            16bytes link to content (or 0)
                            1byte - lenght of NodeName
                            Nbytes - Name
                        */

                    if ((val[1] | val[2] | val[3] | val[4] | val[5] | val[6] | val[7] | val[8]) != 0)
                    {
                        //We got content
                        node.ContentRef = val.Substring(1, 16);
                    }
                    node.NodeName = System.Text.Encoding.UTF8.GetString(val.Substring(18, val[17]));
                    break;
            }

            node.ParentNodeId = row.Key.Substring(0, 8).To_Int64_BigEndian();
            node.NodeId = row.Key.Substring(8, 8).To_Int64_BigEndian();

            CopyInternals(node);

            return node;
        }
Exemplo n.º 3
0
 private void TEST_START_WITH_insert(DBreeze.Transactions.Transaction tran, int tro,int din)
 {
     string tn = "Tro" + tro.ToString() + "/Din" + din.ToString() + "/Year";
     tran.Insert<int, int>(tn, 1, 1);
     tran.Commit();
 }
Exemplo n.º 4
0
 private void TEST_START_WITH_insert1(DBreeze.Transactions.Transaction tran, string tn)
 {
     tran.Insert<int, int>(tn, 1, 1);
     tran.Commit();
 }
Exemplo n.º 5
0
        /// <summary>
        /// Function to be used inside of internal transaction
        /// </summary>
        /// <param name="tran"></param>
        /// <param name="documentSpace"></param>
        /// <returns></returns>
        public long InTran_GetDocumentSpaceId(DBreeze.Transactions.Transaction tran, string documentSpace)
        {
            var mt = tran.SelectTable<int>(DocumentsStorageTablesPrefix + "m", 1, 0);
            var docSpaceId = mt.Select<string, long>(documentSpace).Value;

            return docSpaceId;
        }
Exemplo n.º 6
0
        private void MATRIX_BUILD_RECURSE(int q, int xgl, byte[] parent,DBreeze.Transactions.Transaction tran)
        {
            if (xgl > BM_deep)
                return;

            xgl++;

            byte[] actual = parent;

            for (int i = 0; i < BM_rowlen; i++)
            {
                BM_count++;
                actual = parent.Concat(new byte[] { (byte)i });

                if(BM_console_out_build)
                    Console.WriteLine(actual.ToBytesString(""));

                tran.Insert<byte[], byte?>("t1", actual, null);

                MATRIX_BUILD_RECURSE(i, xgl, actual,tran);
            }
        }
Exemplo n.º 7
0
            /// <summary>
            /// 
            /// </summary>
            /// <param name="_tran"></param>
            /// <param name="_DocumentsStorageTablesPrefix"></param>
            public InTran_DocumentAppender(DBreeze.Transactions.Transaction _tran, string _DocumentsStorageTablesPrefix)
            {
                if(_tran == null)
                    throw new Exception("DocumentAppender transaction is null");

                tran = _tran;
                //documentSpaceId = _documentSpaceId;
                DocumentsStorageTablesPrefix = _DocumentsStorageTablesPrefix;
            }
Exemplo n.º 8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="includeContent"></param>
        /// <param name="includeSearchables"></param>
        /// <param name="dt"></param>
        /// <param name="docRow"></param>
        /// <returns></returns>
        Document RetrieveDocument(bool includeContent, bool includeSearchables, DBreeze.DataTypes.NestedTable dt, DBreeze.DataTypes.Row<int,byte[]> docRow)
        {
            byte[] btDoc = docRow.Value;
            Document doc = null;

            if (btDoc[0] == 0)
            {
                //Non compressed
                doc = btDoc.Substring(1).DeserializeProtobuf<Document>();
            }
            else
            {
                doc = btDoc.Substring(1).DecompressGZip().DeserializeProtobuf<Document>();
            }

            if (includeContent && doc.Content != null)
            {
                //16 bytes link to Content
                doc.Content = dt.SelectDataBlock(doc.Content);
            }

            if (includeSearchables && doc.InternalStructure != null)
            {
                byte[] btSearchables = dt.SelectDataBlock(doc.InternalStructure);
                if (btSearchables[0] == 1)
                {
                    //Zipped
                    btSearchables = btSearchables.Substring(1).DecompressGZip();
                }
                else
                    btSearchables = btSearchables.Substring(1);

                doc.Searchables = System.Text.Encoding.UTF8.GetString(btSearchables);
            }

            doc.DocumentSequentialId = docRow.Key;
            return doc;
        }
Exemplo n.º 9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="docSpaceId"></param>
        /// <param name="internalId"></param>
        /// <param name="tran"></param>
        void RemoveDocumentInternal(long docSpaceId, int internalId, string externalId, DBreeze.Transactions.Transaction tran)
        {
            string docTable = DocumentsStorageTablesPrefix + "d" + docSpaceId.ToString();
            tran.SynchronizeTables(docTable, DocumentsStorageTablesPrefix + "p");
            //Getting document using internalID
            var dt = tran.InsertTable<int>(docTable, 1, 0); //document table
            var vt = tran.InsertTable<int>(docTable, 3, 0); //Version table Key
            vt.ValuesLazyLoadingIsOn = false;

            if (!String.IsNullOrEmpty(externalId))  //Getting internalId via external
            {
                var et = tran.InsertTable<int>(docTable, 2, 0); //ExternalId to InternalId relation
                internalId = et.Select<string, int>(externalId).Value;
            }

            if (internalId == 0)
                return;    //No such document

            //Iterating through all versions of the document
            foreach (var vtRow in vt.SelectBackwardFromTo<byte[], byte>
               (
               internalId.To_4_bytes_array_BigEndian().ConcatMany(int.MaxValue.To_4_bytes_array_BigEndian(), int.MaxValue.To_4_bytes_array_BigEndian()), true,
               internalId.To_4_bytes_array_BigEndian().ConcatMany(int.MinValue.To_4_bytes_array_BigEndian(), int.MinValue.To_4_bytes_array_BigEndian()), true
               , true
               ))
            {
                if (vtRow.Value == 0)
                {
                    //Including the last one into processing list with the value 1 (to be deleted)
                    tran.Insert<byte[], byte>(DocumentsStorageTablesPrefix + "p", docSpaceId.To_8_bytes_array_BigEndian().Concat(vtRow.Key.Substring(8, 4)), 1);
                }
                break;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="internalId"></param>
        /// <returns></returns>
        void GetListOfDocumentVersionsInternal(long docSpaceId, int internalId, DBreeze.Transactions.Transaction tran, List<int> res)
        {
            string DocTableName = DocumentsStorageTablesPrefix + "d" + docSpaceId.ToString();
            var vt = tran.SelectTable<int>(DocTableName, 3, 0);

            foreach (var row in vt.SelectForwardFromTo<byte[], byte>(
                                    internalId.To_4_bytes_array_BigEndian().ConcatMany(int.MinValue.To_4_bytes_array_BigEndian(), int.MinValue.To_4_bytes_array_BigEndian()), true,
                                    internalId.To_4_bytes_array_BigEndian().ConcatMany(int.MaxValue.To_4_bytes_array_BigEndian(), int.MaxValue.To_4_bytes_array_BigEndian()), true
                                    ))
                                {
                                   res.Add(row.Key.Substring(8,4).To_Int32_BigEndian());
                                }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="docSpaceId"></param>
        /// <param name="internalId"></param>
        /// <param name="includeContent"></param>
        /// <param name="includeSearchables"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        Document GetDocById(long docSpaceId, int internalId, bool includeContent, bool includeSearchables, DBreeze.Transactions.Transaction tran)
        {
            try
            {
                if (docSpaceId < 1 || internalId < 1)
                        return null;    //No such document

                string docTable = DocumentsStorageTablesPrefix + "d" + docSpaceId.ToString();

                //Getting latest document correct version
                string DocTableName = DocumentsStorageTablesPrefix + "d" + docSpaceId.ToString();
                var vt = tran.SelectTable<int>(DocTableName, 3, 0);
                int sequentialId = 0;

                foreach (var row1 in vt.SelectBackwardFromTo<byte[], byte>(
                                        internalId.To_4_bytes_array_BigEndian().ConcatMany(int.MaxValue.To_4_bytes_array_BigEndian(), int.MaxValue.To_4_bytes_array_BigEndian()), true,
                                        internalId.To_4_bytes_array_BigEndian().ConcatMany(int.MinValue.To_4_bytes_array_BigEndian(), int.MinValue.To_4_bytes_array_BigEndian()), true
                                        ))
                {
                    if (row1.Value == 1)    //Document is completely deleted
                        break;

                    //Getting the latest version of the document index
                    sequentialId = row1.Key.Substring(8, 4).To_Int32_BigEndian();

                    break;
                }

                if (sequentialId == 0)
                    return null;    //Probably Doc is deleted

                //Getting document using internalID
                var dt = tran.SelectTable<int>(docTable, 1, 0); //document table

                dt.ValuesLazyLoadingIsOn = false;
                var row = dt.Select<int, byte[]>(sequentialId);
                if (!row.Exists)
                    return null;    //No such document

                return RetrieveDocument(includeContent, includeSearchables, dt, row);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }