Beispiel #1
0
        internal void Update <T>(T obj)
        {
            ODocument document;

            if (obj is ODocument)
            {
                document = obj as ODocument;
            }
            else
            {
                document = ODocument.ToDocument(obj);
            }

            if (!string.IsNullOrEmpty(document.OClassName))
            {
                Class(document.OClassName);
            }

            if (document.ORID != null)
            {
                Record(document.ORID);
            }

            Set(document);
        }
Beispiel #2
0
        internal void Delete <T>(T obj)
        {
            ODocument document;

            if (obj is ODocument)
            {
                document = obj as ODocument;
            }
            else
            {
                document = ODocument.ToDocument(obj);
            }

            if (!string.IsNullOrEmpty(document.OClassName))
            {
                Class(document.OClassName);
            }
            else
            {
                throw new OException(OExceptionType.Query, "Document doesn't contain OClassName value.");
            }

            if (document.ORID != null)
            {
                // check if the @rid is correct in real example
                Where("@rid");

                Equals(document.ORID);
            }
        }
 public IOCreateDocument Document <T>(T obj)
 {
     if (obj is ODocument)
     {
         _document = obj as ODocument;
     }
     else
     {
         _document = ODocument.ToDocument(obj);
     }
     return(this);
 }
        public OSqlCreateEdge Set <T>(T obj)
        {
            var document = obj is ODocument ? obj as ODocument : ODocument.ToDocument(obj);

            // TODO: go also through embedded fields
            foreach (KeyValuePair <string, object> field in document)
            {
                // set only fields which doesn't start with @ character
                if ((field.Key.Length > 0) && (field.Key[0] != '@'))
                {
                    Set(field.Key, field.Value);
                }
            }

            return(this);
        }
        public OSqlCreateEdge Edge <T>(T obj)
        {
            if (obj is ODocument)
            {
                _document = obj as ODocument;
            }
            else
            {
                _document = ODocument.ToDocument(obj);
            }

            if (string.IsNullOrEmpty(_document.OClassName))
            {
                throw new OException(OExceptionType.Query, "Document doesn't contain OClassName value.");
            }

            return(this);
        }
        private static ODocument ToODocument <T>(T obj)
        {
            ODocument document;

            if (obj is ODocument)
            {
                document = obj as ODocument;
            }
            else
            {
                document = ODocument.ToDocument(obj);
            }

            if (document.ORID == null)
            {
                throw new OException(OExceptionType.Query, "Document doesn't contain ORID value.");
            }
            return(document);
        }
Beispiel #7
0
        public void TestSerializationMapping()
        {
            // important if you use ordered edges, since if more than 1 they appear as a list, if only one then as a single object, ie
            //    db.Create.Class<Person>().Extends("V").Run();
            //    db.Command("create property Person.in_FriendOf ANY");
            //    db.Command("alter property Person.in_FriendOf custom ordered=true");

            string recordString = "TestObject@Value:17,Text:\"some text\",Link:#11:123,single:[#10:12345],list:[#11:123,#22:1234,#33:1234567],data:_AQIDBAU=_";

            var       rawRecord = Encoding.UTF8.GetBytes(recordString);
            ODocument document  = serializer.Deserialize(rawRecord, new ODocument());

            document.ORID = new ORID("#123:45");
            Assert.Equal(document.HasField("single"), true);
            Assert.Equal(document.HasField("Link"), true);
            Assert.Equal(document.HasField("Value"), true);
            Assert.Equal(document.HasField("Text"), true);
            Assert.Equal(document.HasField("data"), true);


            TypeMapper <TestObject> tm = TypeMapper <TestObject> .Instance;
            var testObj = new TestObject();

            tm.ToObject(document, testObj);

            Assert.Equal("#123:45", testObj.ORID.RID);
            Assert.True(testObj.data.SequenceEqual(new byte[] { 1, 2, 3, 4, 5 }));

            Assert.Equal(17, testObj.Value);
            Assert.Equal("some text", testObj.Text);
            Assert.NotNull(testObj.Link);
            Assert.Equal("#11:123", testObj.Link.RID);
            Assert.NotNull(testObj);
            Assert.NotNull(testObj.single);
            Assert.NotNull(testObj.list);
            Assert.Equal(1, testObj.single.Count);
            Assert.Equal(3, testObj.list.Count);

            ODocument newODocument = ODocument.ToDocument(testObj);
            var       serialized   = Encoding.UTF8.GetString(serializer.Serialize(newODocument));

            Assert.Equal(recordString, serialized);
        }
Beispiel #8
0
        internal void Insert <T>(T obj)
        {
            ODocument document;

            if (obj is ODocument)
            {
                document = obj as ODocument;
            }
            else
            {
                document = ODocument.ToDocument(obj);
            }

            if (!string.IsNullOrEmpty(document.OClassName))
            {
                Class(document.OClassName);
            }

            Set(document);
        }
Beispiel #9
0
        public void TestSerializeEmptySubObjectArray()
        {
            string recordString = "TestHasThings@TheThings:[]";

            var       rawRecord = Encoding.UTF8.GetBytes(recordString);
            ODocument document  = serializer.Deserialize(rawRecord, new ODocument());

            TypeMapper <TestHasThings> tm = TypeMapper <TestHasThings> .Instance;
            var t = new TestHasThings();

            tm.ToObject(document, t);

            Assert.NotNull(t.TheThings); // much easier for consumers to have a consistent behaviour - collections always created but empty, rather than having to test for nullness
            Assert.Equal(0, t.TheThings.Length);

            ODocument newODocument = ODocument.ToDocument(t);
            var       serialized   = Encoding.UTF8.GetString(serializer.Serialize(newODocument));

            Assert.Equal(recordString, serialized);
        }
Beispiel #10
0
        public void TestSerializeSingleSubObjectList()
        {
            string recordString = "TestHasListThings@TheThings:[(Value:18,Text:\"foo\")]";

            var       rawRecord = Encoding.UTF8.GetBytes(recordString);
            ODocument document  = serializer.Deserialize(rawRecord, new ODocument());

            TypeMapper <TestHasListThings> tm = TypeMapper <TestHasListThings> .Instance;
            var t = new TestHasListThings();

            tm.ToObject(document, t);

            Assert.NotNull(t.TheThings);
            Assert.Equal(1, t.TheThings.Count);

            ODocument newODocument = ODocument.ToDocument(t);
            var       serialized   = Encoding.UTF8.GetString(serializer.Serialize(newODocument));

            Assert.Equal(recordString, serialized);
        }
        public void TestSerializeArray()
        {
            string recordString = "TestArray@values:[1,2,3,4,5]";

            ODocument document = ODocument.Deserialize(recordString);

            TypeMapper <TestArray> tm = TypeMapper <TestArray> .Instance;
            var t = new TestArray();

            tm.ToObject(document, t);

            Assert.IsNotNull(t.values);
            Assert.AreEqual(5, t.values.Length);
            Assert.AreEqual(3, t.values[2]);

            ODocument newODocument = ODocument.ToDocument(t);
            var       serialized   = newODocument.Serialize();

            Assert.AreEqual(recordString, serialized);
        }
        public void TestSerializeSingleSubObjectList()
        {
            string recordString = "TestHasListThings@TheThings:[(Value:18,Text:\"foo\")]";

            ODocument document = ODocument.Deserialize(recordString);


            TypeMapper <TestHasListThings> tm = TypeMapper <TestHasListThings> .Instance;
            var t = new TestHasListThings();

            tm.ToObject(document, t);

            Assert.IsNotNull(t.TheThings);
            Assert.AreEqual(1, t.TheThings.Count);

            ODocument newODocument = ODocument.ToDocument(t);
            var       serialized   = newODocument.Serialize();

            Assert.AreEqual(recordString, serialized);
        }
        public void TestSerializeEmptySubObjectArray()
        {
            string recordString = "TestHasThings@TheThings:[]";

            ODocument document = ODocument.Deserialize(recordString);


            TypeMapper <TestHasThings> tm = TypeMapper <TestHasThings> .Instance;
            var t = new TestHasThings();

            tm.ToObject(document, t);

            Assert.IsNotNull(t.TheThings, "much easier for consumers to have a consistent behaviour - collections always created but empty, rather than having to test for nullness");
            Assert.AreEqual(0, t.TheThings.Length);

            ODocument newODocument = ODocument.ToDocument(t);
            var       serialized   = newODocument.Serialize();

            Assert.AreEqual(recordString, serialized);
        }
Beispiel #14
0
        public void TestSerializeArray()
        {
            string recordString = "TestArray@values:[1,2,3,4,5]";

            var       rawRecord = Encoding.UTF8.GetBytes(recordString);
            ODocument document  = serializer.Deserialize(rawRecord, new ODocument());

            TypeMapper <TestArray> tm = TypeMapper <TestArray> .Instance;
            var t = new TestArray();

            tm.ToObject(document, t);

            Assert.NotNull(t.values);
            Assert.Equal(5, t.values.Length);
            Assert.Equal(3, t.values[2]);

            ODocument newODocument = ODocument.ToDocument(t);
            var       serialized   = Encoding.UTF8.GetString(serializer.Serialize(newODocument));

            Assert.Equal(recordString, serialized);
        }
        public void TestSerializeSubObject()
        {
            string recordString = "TestHasAThing@TheThing:(Value:17,Text:\"blah\")";

            ODocument document = ODocument.Deserialize(recordString);


            TypeMapper <TestHasAThing> tm = TypeMapper <TestHasAThing> .Instance;
            var t = new TestHasAThing();

            tm.ToObject(document, t);

            Assert.IsNotNull(t.TheThing);
            Assert.AreEqual(17, t.TheThing.Value);
            Assert.AreEqual("blah", t.TheThing.Text);

            ODocument newODocument = ODocument.ToDocument(t);
            var       serialized   = newODocument.Serialize();

            Assert.AreEqual(recordString, serialized);
        }
        public void TestSerializeSubObjectArray()
        {
            string recordString = "TestHasThings@TheThings:[(Value:17,Text:\"blah\"),(Value:18,Text:\"foo\")]";

            ODocument document = ODocument.Deserialize(recordString);


            TypeMapper <TestHasThings> tm = TypeMapper <TestHasThings> .Instance;
            var t = new TestHasThings();

            tm.ToObject(document, t);

            Assert.IsNotNull(t.TheThings);
            Assert.AreEqual(2, t.TheThings.Length);
            Assert.AreEqual(18, t.TheThings[1].Value);
            Assert.AreEqual("foo", t.TheThings[1].Text);

            ODocument newODocument = ODocument.ToDocument(t);
            var       serialized   = newODocument.Serialize();

            Assert.AreEqual(recordString, serialized);
        }
Beispiel #17
0
        public void TestSerializeSubObject()
        {
            string recordString = "TestHasAThing@TheThing:(Value:17,Text:\"blah\")";

            var       rawRecord = Encoding.UTF8.GetBytes(recordString);
            ODocument document  = serializer.Deserialize(rawRecord, new ODocument());


            TypeMapper <TestHasAThing> tm = TypeMapper <TestHasAThing> .Instance;
            var t = new TestHasAThing();

            tm.ToObject(document, t);

            Assert.NotNull(t.TheThing);
            Assert.Equal(17, t.TheThing.Value);
            Assert.Equal("blah", t.TheThing.Text);

            ODocument newODocument = ODocument.ToDocument(t);
            var       serialized   = Encoding.UTF8.GetString(serializer.Serialize(newODocument));

            Assert.Equal(recordString, serialized);
        }
Beispiel #18
0
        internal void Set <T>(T obj)
        {
            ODocument document;

            if (obj is ODocument)
            {
                document = obj as ODocument;
            }
            else
            {
                document = ODocument.ToDocument(obj);
            }

            // TODO: go also through embedded fields
            foreach (KeyValuePair <string, object> field in document)
            {
                // set only fields which doesn't start with @ character
                if ((field.Key.Length > 0) && (field.Key[0] != '@'))
                {
                    Set(field.Key, field.Value);
                }
            }
        }
Beispiel #19
0
        public void TestSerializeSubObjectArray()
        {
            string recordString = "TestHasThings@TheThings:[(Value:17,Text:\"blah\"),(Value:18,Text:\"foo\")]";

            var       rawRecord = Encoding.UTF8.GetBytes(recordString);
            ODocument document  = serializer.Deserialize(rawRecord, new ODocument());


            TypeMapper <TestHasThings> tm = TypeMapper <TestHasThings> .Instance;
            var t = new TestHasThings();

            tm.ToObject(document, t);

            Assert.NotNull(t.TheThings);
            Assert.Equal(2, t.TheThings.Length);
            Assert.Equal(18, t.TheThings[1].Value);
            Assert.Equal("foo", t.TheThings[1].Text);

            ODocument newODocument = ODocument.ToDocument(t);
            var       serialized   = Encoding.UTF8.GetString(serializer.Serialize(newODocument));

            Assert.Equal(recordString, serialized);
        }
 private ODocument GetDocument()
 {
     return(Document ?? (Document = ODocument.ToDocument(Object)));
 }