internal static ODocument Deserialize(ORID orid, int version, ORecordType type, short classId, byte[] rawRecord)
        {
            ODocument document = new ODocument();
            document.ORID = orid;
            document.OVersion = version;
            document.OType = type;
            document.OClassId = classId;

            string recordString = BinarySerializer.ToString(rawRecord).Trim();

            int atIndex = recordString.IndexOf('@');
            int colonIndex = recordString.IndexOf(':');
            int index = 0;

            // parse class name
            if ((atIndex != -1) && (atIndex < colonIndex))
            {
                document.OClassName = recordString.Substring(0, atIndex);
                index = atIndex + 1;
            }

            // start document parsing with first field name
            do
            {
                index = ParseFieldName(index, recordString, document);
            }
            while (index < recordString.Length);

            return document;
        }
        public override ODocument Response(Response response)
        {
            Dictionary<ORID, int> entries = new Dictionary<ORID, int>();

            ODocument document = new ODocument();
            if (response == null)
            {
                return document;
            }

            var reader = response.Reader;
            if (response.Connection.ProtocolVersion > 26 && response.Connection.UseTokenBasedSession)
                ReadToken(reader);

            // (count:int)[(key:binary)(value:binary)]
            var bytesLength = reader.ReadInt32EndianAware();
            var count = reader.ReadInt32EndianAware();
            for (int i = 0; i < count; i++)
            {
                // key
                short clusterId = reader.ReadInt16EndianAware();
                long clusterPosition = reader.ReadInt64EndianAware();
                var rid = new ORID(clusterId, clusterPosition);

                // value
                var value = reader.ReadInt32EndianAware();

                entries.Add(rid, value);
            }
            document.SetField<Dictionary<ORID, int>>("entries", entries);
            return document;
        }
 public LoadRecord(ORID orid, string fetchPlan, ODatabase database)
     : base(database)
 {
     _orid      = orid;
     _fetchPlan = fetchPlan;
     _database  = database;
 }
 public static ORID ReadRid(this BinaryReader binRdr)
 {
     ORID orid = new ORID();
     orid.ClusterId = binRdr.ReadInt16EndianAware();
     orid.ClusterPosition = binRdr.ReadInt64EndianAware();
     return orid;
 }
        internal static ODocument Deserialize(ORID orid, int version, ORecordType type, short classId, byte[] rawRecord)
        {
            ODocument document = new ODocument();

            document.ORID     = orid;
            document.OVersion = version;
            document.OType    = type;
            document.OClassId = classId;

            string recordString = BinarySerializer.ToString(rawRecord).Trim();

            int atIndex    = recordString.IndexOf('@');
            int colonIndex = recordString.IndexOf(':');
            int index      = 0;

            // parse class name
            if ((atIndex != -1) && (atIndex < colonIndex))
            {
                document.OClassName = recordString.Substring(0, atIndex);
                index = atIndex + 1;
            }

            // start document parsing with first field name
            do
            {
                index = ParseFieldName(index, recordString, document);
            }while (index < recordString.Length);

            return(document);
        }
        public override ODocument Response(Response response)
        {
            Dictionary <ORID, int> entries = new Dictionary <ORID, int>();

            ODocument document = new ODocument();

            if (response == null)
            {
                return(document);
            }

            var reader = response.Reader;

            // (count:int)[(key:binary)(value:binary)]
            var bytesLength = reader.ReadInt32EndianAware();
            var count       = reader.ReadInt32EndianAware();

            for (int i = 0; i < count; i++)
            {
                // key
                short clusterId       = reader.ReadInt16EndianAware();
                long  clusterPosition = reader.ReadInt64EndianAware();
                var   rid             = new ORID(clusterId, clusterPosition);

                // value
                var value = reader.ReadInt32EndianAware();

                entries.Add(rid, value);
            }
            document.SetField <Dictionary <ORID, int> >("entries", entries);
            return(document);
        }
 public LoadRecord(ORID orid, string fetchPlan, ODatabase database)
     : this(database)
 {
     _orid = orid;
     _fetchPlan = fetchPlan;
     _database = database;
 }
示例#8
0
 private ORID ReadORID(BinaryReader reader)
 {
     ORID result = new ORID();
     result.ClusterId = reader.ReadInt16EndianAware();
     result.ClusterPosition = reader.ReadInt64EndianAware();
     return result;
 }
        internal static ORecord ToRecord(ORID orid, int version, ORecordType type, short classId, byte[] rawRecord)
        {
            ORecord record = new ORecord(orid, version, type, classId);

            string recordString = BinarySerializer.ToString(rawRecord).Trim();

            int atIndex = recordString.IndexOf('@');
            int colonIndex = recordString.IndexOf(':');
            int index = 0;

            // parse class name
            if ((atIndex != -1) && (atIndex < colonIndex))
            {
                record.ClassName = recordString.Substring(0, atIndex);
                index = atIndex + 1;
            }

            // start document parsing with first field name
            do
            {
                index = ParseFieldName(index, recordString, record.Document);
            }
            while (index < recordString.Length);

            return record;
        }
示例#10
0
        private ODocument ParseDocument(BinaryReader reader)
        {
            ODocument document = null;

            short classId = reader.ReadInt16EndianAware();

            if (classId == -2) // NULL
            {
            }
            else if (classId == -3) // record id
            {
                ORID orid = new ORID();
                orid.ClusterId       = reader.ReadInt16EndianAware();
                orid.ClusterPosition = reader.ReadInt64EndianAware();

                document          = new ODocument();
                document.ORID     = orid;
                document.OClassId = classId;
            }
            else
            {
                ORecordType type = (ORecordType)reader.ReadByte();

                ORID orid = new ORID();
                orid.ClusterId       = reader.ReadInt16EndianAware();
                orid.ClusterPosition = reader.ReadInt64EndianAware();
                int    version      = reader.ReadInt32EndianAware();
                int    recordLength = reader.ReadInt32EndianAware();
                byte[] rawRecord    = reader.ReadBytes(recordLength);
                document = RecordSerializer.Deserialize(orid, version, type, classId, rawRecord);
            }

            return(document);
        }
        internal int Write(ORID rid)
        {
            var pos = Length;

            WriteVariant(rid.ClusterId);
            WriteVariant(rid.ClusterPosition);
            return(pos);
        }
        private ORID ReadORID(BinaryReader reader)
        {
            ORID result = new ORID();

            result.ClusterId       = reader.ReadInt16EndianAware();
            result.ClusterPosition = reader.ReadInt64EndianAware();
            return(result);
        }
        private void HandleCreateEdge(TransactionEdge transaction)
        {
            var fromId = new ORID(transaction.From.Id);
            var toId   = new ORID(transaction.To.Id);

            database.Command(new PreparedCommand($"CREATE EDGE {transaction.EdgeClassName} FROM :out TO :in")
                             .Set("out", fromId)
                             .Set("in", toId))
            .Run();
        }
示例#14
0
        public T GetPendingObject <T>(ORID orid) where T : IBaseRecord
        {
            TransactionRecord record;

            if (_records.TryGetValue(orid, out record))
            {
                return((T)record.Object);
            }
            return(default(T));
        }
示例#15
0
 internal void AddDataItem(ORID _orid)
 {
     DataItems.Add(new RequestDataItem()
     {
         Type = "short", Data = BinarySerializer.ToArray(_orid.ClusterId)
     });
     DataItems.Add(new RequestDataItem()
     {
         Type = "long", Data = BinarySerializer.ToArray(_orid.ClusterPosition)
     });
 }
        public bool DeleteVertex(string database, ORID orid)
        {
            database.ThrowIfNullOrEmpty("database");
            orid.ThrowIfNull("orid");

            string command = "DELETE VERTEX {0}".F(orid.RID);

            OrientdbResponse <DynamicDictionary> response = Command(command, database, CommandLanguage.Sql);

            return(response.Success);
        }
        internal static ODocument Deserialize(ORID orid, int version, ORecordType type, short classId, byte[] rawRecord)
        {
            ODocument document = new ODocument();
            document.ORID = orid;
            document.OVersion = version;
            document.OType = type;
            document.OClassId = classId;

            string recordString = BinarySerializer.ToString(rawRecord).Trim();

            return Deserialize(recordString, document);
        }
        internal ODocument Deserialize(ORID orid, int version, ORecordType type, short classId, byte[] rawRecord)
        {
            ODocument document = new ODocument();

            document.ORID     = orid;
            document.OVersion = version;
            document.OType    = type;
            document.OClassId = classId;

            string recordString = BinarySerializer.ToString(rawRecord).Trim();

            return(Deserialize(recordString, document));
        }
        public static void UpdateDesktop(String name, String OS, String LanMacAddress, String nameOld, String LanMacAddressOld)
        {
            ODatabase database = InitDB();

            string query = String.Format("SELECT * FROM Desktop WHERE name=\"" + nameOld + "\" AND LanMacAddress=\""
                                         + LanMacAddressOld + "\"");
            List <ODocument> result = database.Query(query).ToList();

            ODocument o = result[0];
            ORID      z = o.GetField <ORID>("@ORID");

            database.Update(z).Set("name", name).Set("OS", OS).Set("LanMacAddress", LanMacAddress).Run();
        }
示例#20
0
 private void appendOridToField(ODocument document, string field, ORID orid)
 {
     if (document.HasField(field))
     {
         document.GetField <HashSet <ORID> >(field).Add(orid);
     }
     else
     {
         var orids = new HashSet <ORID>();
         orids.Add(orid);
         document.SetField(field, orids);
     }
 }
示例#21
0
        private ODocument ParseDocument(ref int offset, byte[] data)
        {
            ODocument document = null;

            short classId = BinarySerializer.ToShort(data.Skip(offset).Take(2).ToArray());

            offset += 2;

            if (classId == -2) // NULL
            {
            }
            else if (classId == -3) // record id
            {
                ORID orid = new ORID();
                orid.ClusterId = BinarySerializer.ToShort(data.Skip(offset).Take(2).ToArray());
                offset        += 2;

                orid.ClusterPosition = BinarySerializer.ToLong(data.Skip(offset).Take(8).ToArray());
                offset += 8;

                document          = new ODocument();
                document.ORID     = orid;
                document.OClassId = classId;
            }
            else
            {
                ORecordType type = (ORecordType)BinarySerializer.ToByte(data.Skip(offset).Take(1).ToArray());
                offset += 1;

                ORID orid = new ORID();
                orid.ClusterId = BinarySerializer.ToShort(data.Skip(offset).Take(2).ToArray());
                offset        += 2;

                orid.ClusterPosition = BinarySerializer.ToLong(data.Skip(offset).Take(8).ToArray());
                offset += 8;

                int version = BinarySerializer.ToInt(data.Skip(offset).Take(4).ToArray());
                offset += 4;

                int recordLength = BinarySerializer.ToInt(data.Skip(offset).Take(4).ToArray());
                offset += 4;

                byte[] rawRecord = data.Skip(offset).Take(recordLength).ToArray();
                offset += recordLength;

                document = RecordSerializer.Deserialize(orid, version, type, classId, rawRecord);
            }

            return(document);
        }
        public override void Update(object oTarget, Dictionary <ORID, ORID> mappings)
        {
            ORID orid = GetValue(oTarget);

            if (orid == null)
            {
                return;
            }
            ORID replacement;

            if (mappings.TryGetValue(orid, out replacement))
            {
                SetValue(oTarget, replacement);
            }
        }
 private void removeFromOridField(ODocument document, string field, ORID orid)
 {
     if (document.HasField(field))
     {
         var oridCollection = document[field] as ICollection <ORID>;
         if (oridCollection != null)
         {
             oridCollection.Remove(orid);
         }
         else
         {
             ((ICollection <object>)document[field]).Remove(orid);
         }
     }
 }
示例#24
0
        public void CanDeserializeARecordIdInEmbeddedMap()
        {
            // Arrange
            var       recordCsvSerializer = new RecordCSVSerializer(null);
            const int integerField        = 1;
            var       orid = new ORID(1, 2);

            string recordString = "TestClassName@EmbeddedMap:{\"RecordIdField\":" + orid + "},TestField:" + integerField;

            // Act
            var actualDocument = recordCsvSerializer.Deserialize(recordString);

            // Assert
            Assert.AreEqual(orid, actualDocument.GetField <ORID>("EmbeddedMap.RecordIdField"));
            Assert.AreEqual(integerField, actualDocument.GetField <int>("TestField"));
        }
示例#25
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            // if parameter cannot be cast to ORID return false.
            ORID orid = obj as ORID;

            if ((System.Object)orid == null)
            {
                return(false);
            }

            return(this.ToString() == orid.ToString());
        }
        public static List <ODocument> FindServerConnections(String name, String LanMacAddress)
        {
            ODatabase database = InitDB();
            string    query    = String.Format("SELECT * FROM Server WHERE name=\"" + name + "\" AND LanMacAddress=\""
                                               + LanMacAddress + "\"");
            List <ODocument> result = database.Query(query).ToList();

            ODocument o = result[0];
            ORID      z = o.GetField <ORID>("@ORID");


            String           querry    = "TRAVERSE * FROM " + z + " WHILE $depth<=2";
            List <ODocument> resultset = database.Query(querry).ToList <ODocument>();

            database.Close();
            return(resultset);
        }
示例#27
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            // if parameter cannot be cast to ORID return false.
            ORID orid = obj as ORID;

            if (orid == null)
            {
                return(false);
            }

            return(ClusterId == orid.ClusterId && ClusterPosition == orid.ClusterPosition);
        }
        public static void UpdateRouter(String name, String OS, String SerialNumber, String Manufacturer,
                                        int NumberOfPorts, int NumberOfTakenPorts, String WiFiNetworkName,
                                        List <String> MacAddressList, String RouterNameOld, String SerialNumberOld)
        {
            ODatabase database = InitDB();

            string query = String.Format("SELECT * FROM Router WHERE name=\"" + RouterNameOld + "\" AND SerialNumber=\""
                                         + SerialNumberOld + "\"");
            List <ODocument> result = database.Query(query).ToList();

            ODocument o = result[0];
            ORID      z = o.GetField <ORID>("@ORID");

            database.Update(z).Set("name", name).Set("OS", OS).Set("SerialNumber", SerialNumber)
            .Set("Manufacturer", Manufacturer).Set("NumberOfPorts", NumberOfPorts)
            .Set("NumberOfTakenPorts", NumberOfTakenPorts).Set("WiFiNetworkName", WiFiNetworkName)
            .Set("MacAddressList", MacAddressList).Run();
        }
示例#29
0
        private T ParseDocument(BinaryReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException($"{nameof(reader)} cannot be null.");
            }

            T document;

            short classId = reader.ReadInt16EndianAware();

            if (classId == -2) // NULL
            {
                document = null;
            }
            else if (classId == -3) // record id
            {
                ORID orid = new ORID();
                orid.ClusterId       = reader.ReadInt16EndianAware();
                orid.ClusterPosition = reader.ReadInt64EndianAware();

                document          = Activator.CreateInstance <T>();
                document.ORID     = orid;
                document.OClassId = classId;
            }
            else
            {
                ORecordType type = (ORecordType)reader.ReadByte();

                ORID orid = new ORID();
                orid.ClusterId       = reader.ReadInt16EndianAware();
                orid.ClusterPosition = reader.ReadInt64EndianAware();
                int    version      = reader.ReadInt32EndianAware();
                int    recordLength = reader.ReadInt32EndianAware();
                byte[] rawRecord    = reader.ReadBytes(recordLength);

                document          = _serializer.Deserialize <T>(rawRecord);
                document.ORID     = orid;
                document.OVersion = version;
                document.OClassId = classId;
            }

            return(document);
        }
        private int ParseRecordID(int i, string recordString, ODocument document, string fieldName)
        {
            int startIndex = i;

            // search for end of parsed record ID value
            while (
                (i < recordString.Length) &&
                (recordString[i] != ',') &&
                (recordString[i] != ')') &&
                (recordString[i] != ']') &&
                (recordString[i] != '}') &&
                (recordString[i] != '>'))
            {
                i++;
            }


            //assign field value
            if (document[fieldName] == null)
            {
                // there is a special case when OEdge InV/OutV fields contains only single ORID instead of HashSet<ORID>
                // therefore single ORID should be deserialized into HashSet<ORID> type
                if (fieldName.Equals("in_") || fieldName.Equals("out_"))
                {
                    document[fieldName] = new HashSet <ORID>();
                    ((HashSet <ORID>)document[fieldName]).Add(new ORID(recordString, startIndex));
                }
                else
                {
                    document[fieldName] = new ORID(recordString, startIndex);
                }
            }
            else if (document[fieldName] is HashSet <object> )
            {
                ((HashSet <object>)document[fieldName]).Add(new ORID(recordString, startIndex));
            }
            else
            {
                ((List <object>)document[fieldName]).Add(new ORID(recordString, startIndex));
            }

            return(i);
        }
 private void appendOridToField(ODocument document, string field, ORID orid)
 {
     if (document.HasField(field))
     {
         var oridCollection = document[field] as ICollection <ORID>;
         if (oridCollection != null)
         {
             oridCollection.Add(orid);
         }
         else
         {
             ((ICollection <object>)document[field]).Add(orid);
         }
     }
     else
     {
         var orids = new HashSet <object>();
         orids.Add(orid);
         document.SetField(field, orids);
     }
 }
示例#32
0
        private void AddToRecords(DatabaseTransactionRequest record)
        {
            bool hasOrid   = record.RecordORID != null;
            bool needsOrid = record.RecordType != TransactionRecordType.Create;

            if (!hasOrid)
            {
                record.RecordORID           = ORID.NewORID();
                record.RecordORID.ClusterId = _clusterIdResolver(record.EntityName);
            }

            if (_records.ContainsKey(record.RecordORID))
            {
                if (record.RecordType != _records[record.RecordORID].RecordType)
                {
                    throw new OrientDBException(OrientDBExceptionType.Query, "Record has already been added as part of another operation within this transaction."); // Fix the Exception Type.
                }
                _records[record.RecordORID] = record;
            }
            else
            {
                _records.Add(record.RecordORID, record);
            }
        }
示例#33
0
 internal void To(ORID orid)
 {
     _compiler.Unique(Q.To, orid.ToString());
 }
示例#34
0
 internal void From(ORID orid)
 {
     _compiler.Unique(Q.From, orid.ToString());
 }
示例#35
0
 internal DtoRecord()
 {
     ORID = new ORID();
 }
示例#36
0
 public OLoadRecord ORID(ORID orid)
 {
     _orid = orid;
     return this;
 }
示例#37
0
 internal void AddDataItem(ORID _orid)
 {
     DataItems.Add(new RequestDataItem() { Type = "short", Data = BinarySerializer.ToArray(_orid.ClusterId) });
     DataItems.Add(new RequestDataItem() { Type = "long", Data = BinarySerializer.ToArray(_orid.ClusterPosition) });
 }
示例#38
0
 public RecordMetadata(ORID rid)
 {
     _orid = rid;
 }
 public OSqlCreateEdge To <T>(T obj)
 {
     _dest = ToODocument(obj).ORID;
     return(this);
 }
示例#40
0
        private ODocument ParseDocument(BinaryReader reader)
        {
            ODocument document = null;

            short classId = reader.ReadInt16EndianAware();

            if (classId == -2) // NULL
            {
            }
            else if (classId == -3) // record id
            {
                ORID orid = new ORID();
                orid.ClusterId = reader.ReadInt16EndianAware();
                orid.ClusterPosition = reader.ReadInt64EndianAware();

                document = new ODocument();
                document.ORID = orid;
                document.OClassId = classId;
            }
            else
            {
                ORecordType type = (ORecordType)reader.ReadByte();

                ORID orid = new ORID();
                orid.ClusterId = reader.ReadInt16EndianAware();
                orid.ClusterPosition = reader.ReadInt64EndianAware();
                int version = reader.ReadInt32EndianAware();
                int recordLength = reader.ReadInt32EndianAware();
                byte[] rawRecord = reader.ReadBytes(recordLength);

                document = new ODocument { ORID = orid, OVersion = version, OType = ORecordType.Document, OClassId = classId };

                document = Serializer.Deserialize(rawRecord, document);

            }

            return document;
        }
示例#41
0
        private static int ParseRecordID(int i, string recordString, Dictionary<string, object> document, string fieldName)
        {
            int startIndex = i;

            // search for end of parsed record ID value
            while ((i < recordString.Length) && (recordString[i] != ',') && (recordString[i] != ')') && (recordString[i] != ']'))
            {
                i++;
            }

            string orid = recordString.Substring(startIndex, i - startIndex);

            //assign field value
            if (document[fieldName] == null)
            {
                document[fieldName] = new ORID(orid);
            }
            else
            {
                ((List<object>)document[fieldName]).Add(new ORID(orid));
            }

            return i;
        }
 public ORecordMetadata ORID(ORID orid)
 {
     _orid = orid;
     return this;
 }
示例#43
0
 public ORID(ORID other)
 {
     ClusterId = other.ClusterId;
     ClusterPosition = other.ClusterPosition;
 }
示例#44
0
 internal void Record(ORID orid)
 {
     _compiler.Unique(Q.Record, orid.ToString());
 }
示例#45
0
        private ODocument ParseDocument(ref int offset, byte[] data)
        {
            ODocument document = null;

            short classId = BinarySerializer.ToShort(data.Skip(offset).Take(2).ToArray());
            offset += 2;

            if (classId == -2) // NULL
            {
            }
            else if (classId == -3) // record id
            {
                ORID orid = new ORID();
                orid.ClusterId = BinarySerializer.ToShort(data.Skip(offset).Take(2).ToArray());
                offset += 2;

                orid.ClusterPosition = BinarySerializer.ToLong(data.Skip(offset).Take(8).ToArray());
                offset += 8;

                document = new ODocument();
                document.ORID = orid;
                document.OClassId = classId;
            }
            else
            {
                ORecordType type = (ORecordType)BinarySerializer.ToByte(data.Skip(offset).Take(1).ToArray());
                offset += 1;

                ORID orid = new ORID();
                orid.ClusterId = BinarySerializer.ToShort(data.Skip(offset).Take(2).ToArray());
                offset += 2;

                orid.ClusterPosition = BinarySerializer.ToLong(data.Skip(offset).Take(8).ToArray());
                offset += 8;

                int version = BinarySerializer.ToInt(data.Skip(offset).Take(4).ToArray());
                offset += 4;

                int recordLength = BinarySerializer.ToInt(data.Skip(offset).Take(4).ToArray());
                offset += 4;

                byte[] rawRecord = data.Skip(offset).Take(recordLength).ToArray();
                offset += recordLength;

                document = RecordSerializer.Deserialize(orid, version, type, classId, rawRecord);
            }

            return document;
        }
        private static int ParseRecordID(int i, string recordString, ODocument document, string fieldName)
        {
            int startIndex = i;

            // search for end of parsed record ID value
            while (
                (i < recordString.Length) && 
                (recordString[i] != ',') && 
                (recordString[i] != ')') && 
                (recordString[i] != ']') &&
                (recordString[i] != '>'))
            {
                i++;
            }

            string orid = recordString.Substring(startIndex, i - startIndex);

            //assign field value
            if (document[fieldName] == null)
            {
                // there is a special case when OEdge InV/OutV fields contains only single ORID instead of HashSet<ORID>
                // therefore single ORID should be deserialized into HashSet<ORID> type
                if (fieldName.Equals("in_") || fieldName.Equals("out_"))
                {
                    document[fieldName] = new HashSet<ORID>();
                    ((HashSet<ORID>)document[fieldName]).Add(new ORID(orid));
                }
                else
                {
                    document[fieldName] = new ORID(orid);
                }
            }
            else if (document[fieldName] is HashSet<object>)
            {
                ((HashSet<object>)document[fieldName]).Add(new ORID(orid));
            }
            else
            {
                ((List<object>)document[fieldName]).Add(new ORID(orid));
            }

            return i;
        }
 public RecordMetadata(ORID rid, ODatabase database)
     : base(database)
 {
     _orid = rid;
     _operationType = OperationType.RECORD_METADATA;
 }