Git Product home page Git Product logo

orientdb.net's Introduction

OrientDB.Net.Core


Status: Experimental

OrientDB.Net.Core represents a re-imaging of the .NET OrientDB SDK for .NET Framework. Written targeting .NET Standard 2.0. The purpose in re-imaging the .NET OrientDB SDK, is to design an extensible base library that can support any number of implementations in the same vein as the Serilog project.

The current state of the driver and its derived components is pre-alpha. As such, the library itself can and will change substantially over the coming months.

OrientDB.Net.Core is the core library that provides the base classes and abstractions that represent the "core" of the API. It provides abstractions for communication with OrientDB and Serialization/De-Serialization of the output. The intent is to be able to flip between binary and http in the beginning and add any additional support that may arise.

To install the driver using NuGet:

Install-Package OrientDB.Net.Core

Quick Usage Example of SDK:

Person Entity:

public class Person : OrientDBEntity
{
    public int Age { get; set; }
    public string Name { get; set; }
    public string FirstName {get; set; }
    public string LastName { get; set; }
    public IList<string> FavoriteColors { get; set; }

    public override void Hydrate(IDictionary<string, object> data)
    {
            Age = (int)data?["Age"];
            FirstName = data?["FirstName"]?.ToString();
            LastName = data?["LastName"]?.ToString();
            FavoriteColors = data.ContainsKey("FavoriteColors") ? (data?["FavoriteColors"] as IList<object>).Select(n => n.ToString()).ToList() : new List<string>();
    }
}

SDK Interaction:

Install-Package OrientDB.Net.ConnectionProtocols.Binary
Install-Package OrientDB.Net.Serializers.RecordCSVSerializer
IEnumerable<Person> persons = new List<Person>();

IOrientServerConnection server = new OrientDBConfiguration()
    .ConnectWith<byte[]>()
    .Connect(new BinaryProtocol("127.0.0.1", "root", "root"))
    .SerializeWith.Serializer(new OrientDBRecordCSVSerializer())
    .LogWith.Logger(new ConsoleOrientDBLogger())
    .CreateFactory()
    .CreateConnection();

IOrientDatabaseConnection database;

if (server.DatabaseExists("ConnectionTest", StorageType.PLocal))
    database = server.DatabaseConnect("ConnectionTest", DatabaseType.Document);
else
    database = server.CreateDatabase("ConnectionTest", DatabaseType.Document, StorageType.PLocal);

database.ExecuteCommand("CREATE CLASS Person");

var transaction = database.CreateTransaction();
var person1 = new Person { Age = 33, FirstName = "Jane", LastName = "Doe", FavoriteColors = new[] { "black", "blue" } };
transaction.AddEntity(person1);
transaction.AddEntity(new Person { Age = 5, FirstName = "John", LastName = "Doe", FavoriteColors = new[] { "red", "blue" } });
transaction.Commit();
transaction = database.CreateTransaction();
transaction.Remove(person1);
transaction.Commit();

persons = database.ExecuteQuery<Person>("SELECT * FROM Person");    

Interface Documentation - OrientDB.Net.Core.Abstractions

IOrientDatabaseConnection

IOrientConnection provides an interface for interacting with an OrientDB database.

namespace OrientDB.Net.Core.Abstractions
{
    public interface IOrientDatabaseConnection
    {
        IEnumerable<TResultType> ExecuteQuery<TResultType>(string sql) where TResultType : OrientDBEntity;
        IEnumerable<TResultType> ExecutePreparedQuery<TResultType>(string sql, params string[] parameters) where TResultType : OrientDBEntity;
        IOrientDBCommandResult ExecuteCommand(string sql);
        IOrientDBTransaction CreateTransaction();
    }
}

IOrientServerConnection

IOrientServerConnection provides an interface for interacting with an OrientDB Server Host itself.

namespace OrientDB.Net.Core.Abstractions
{
    public interface IOrientServerConnection
    {
        IOrientDatabaseConnection CreateDatabase(string database, StorageType type);
        void DeleteDatabase(string database, StorageType type);
        bool DatabaseExists(string database, StorageType type);
        void Shutdown(string username, string password);
        IEnumerable<string> ListDatabases();
        string GetConfigValue(string name);
        void SetConfigValue(string name, string value);
    }
}

IOrientConnectionFactory

IOrientConnectionFactory provides the basic interface for implementing an OrientDB Connection Factory.

namespace OrientDB.Net.Core.Abstractions
{
    public interface IOrientConnectionFactory
    {
        IOrientDatabaseConnection GetClientConnection();
        IOrientServerConnection GetServerConnection();
    }
}

IOrientDBCommandResult

IOrientDBCommandResult provides the basic interface for implementing a Command Result. This is not for Queries. Also note that this interface is currently under review to possibly be removed or heavily modified.

namespace OrientDB.Net.Core.Abstractions
{
    public interface IOrientDBCommandResult
    {
        int RecordsAffected { get; }
    }
}

IOrientDBConnectionProtocol

IOrientDBConnectionProtocol interface is used to create an OrientDB Protocol implementation. This could be the binary, HTTP, or yet undeveloped means of communicating with the OrientDB server. The generic constraint is used to define what kind of IOrientDBRecordSerializer can be used with the protocol implementation. This is in place so that an incompatible IOrientDBRecordSerializer cannot be used.

namespace OrientDB.Net.Core.Abstractions
{
    public interface IOrientDBConnectionProtocol<TDataType> : IDisposable
    {
        IOrientServerConnection CreateServerConnection(IOrientDBRecordSerializer<TDataType> serializer, IOrientDBLogger logger);
    }
}

IOrientDBRecordSerializer

The IOrientDBRecordSerializer interface is used to create Record Serializers for IOrientDBConnectionProtocols. It should be used to effectively serialize records for the chosen protocol and deserialize results in a way that the protocol implementation can reason about.

namespace OrientDB.Net.Core.Abstractions
{
    public interface IOrientDBRecordSerializer<TDataType>
    {
        OrientDBRecordFormat RecordFormat { get; }
        TResultType Deserialize<TResultType>(TDataType data) where TResultType : OrientDBEntity;
        TDataType Serialize<T>(T input) where T : OrientDBEntity;
    }
}

IOrientDBTransaction

IOrientDBTransaction is used to create Transaction implementations for OrientDB.Net Protocols.

namespace OrientDB.Net.Core.Abstractions
{
    public interface IOrientDBTransaction
    {
        void AddEntity<T>(T entity) where T : OrientDBEntity;
        void Remove<T>(T entity) where T : OrientDBEntity;
        void Update<T>(T entity) where T : OrientDBEntity;
        void AddEdge(Edge edge, Vertex from, Vertex to);
        void Commit();
        void Reset();
    }
}

orientdb.net's People

Contributors

gar-ema avatar sarvasana avatar

Stargazers

tristan avatar Volodymyr Kostochka avatar Hans Halim avatar Michael A Davidson avatar

Watchers

Luca Garulli avatar Hans Halim avatar James Cloos avatar Ajay Sharma avatar Michael A Davidson avatar André Leblanc avatar  avatar  avatar  avatar

orientdb.net's Issues

If an OrientDBEntity implements IDictionary<string, object> then also serialize its key-value pairs

Currently the only objects that can naturally be serialized/deserialized are OrientDBEntities. For those serialization will try to serialize each property.
We can have properties of type Dictionary that will turn into subobjects but we cannot currently use OrientDB as a document database which reads and writes dictionaries of keys and values.
As a remedy I suggest we allow an OrientDBEntity to be such a document by implementing IDictionary<string, object> if desired. The existing entity-style behavior will be unaffected.

Allow setting a class name different from the entity name

From @weizensnake on August 2, 2017 21:31

Currently when adding an entity via a transaction we always look up the cluster to which to save by trying to find a class with the same name as the entity (C#) type.
That is not necessarily what the user wants. For example some users might simply want to use a generic dictionary-type entity that can hold records of any class.

As a solution I suggest that in BinaryOrientDBTransaction.AddToRecords(), when we don't have an ORID and we resolve the cluster we should check if the entity has an OClassName. If that has been set then we resolve using that. If not we fall back to resolving by the entity's type name.

Copied from original issue: orientechnologies/OrientDB.Net.ConnectionProtocols.Binary#2

Roadmap

It would be very nice to have a road map for this implementation.

Our team would like to use OrientDb along with this driver and are willing to contribute to this project.
But in order to do so, we need to have clear where this driver is now and what direction it is going.

Create a base interface for OrientDBEntity and use it in IOrientDBRecordSerializer

It is problematic that the API is centered around the base class OrientDBEntity. Every class that wants to be (de)serializable into OrientDB would have to inherit from it which makes things awkward if that class also needs to inherit from other classes.
We really should isolate the contract of OrientDBEntity into an interface. We can keep OrientDBEntity around as a convenient base implementation.

EF Core

From @esamk on August 16, 2017 7:50

I am not quite sure if this is the right place to talk about this, but here goes.

Did you ever consider creating EF core database provider instead of a stand-alone driver as per this discussion:

orientechnologies/OrientDB-NET.binary#9

Being able to use OrientDb through Entity Framework would mean, IMHO, a huge boost for developer productivity.

If you did consider the EF option at some point, could you elaborate on what made you decide against it?

Copied from original issue: orientechnologies/OrientDB.Net.Core#14

Cannot create class properties

The OSqlCreateProperty class has an internal constructor, making it impossible to use the class to create a property. We have to change the constructor to public to create properties. We couldn’t find any other way to create a Property.

Target .net standard 2.0

Since .net standard 2.0 and dotnet core 2.0 have been released, I was wondering if OrientDb.NET could start targeting .net standard 2.0?

High-level overview of driver architecture

To make it easier for other community developers to contribute to this project a high level overview of the drivers architecture should be documented. It will help others, like myself, stay within architectural boundaries.

Infinite loop in OrientDBBinaryConnectionStream

Process in this class will call Destroy if an exception occurs during processing. Destroy in turn will dispose the stream that Process was trying to use and will attempt to create a new stream by opening the database.
That leads to an infinite loop if opening the database itself fails, for example because the connection options were created with a null database name.

New driver does not support ODocument or Dictionary

The existing driver allows us top fetch vertices from the graph as ODocument, and this allows us to work without the entity classes being defined in the source code, as the schema of the database is dynamically built.

The new driver does not support ODocument.

In OrientDBEntityExtensions the ToDictionaryOrientDBEntity method doesn't handle DictionaryOrientDBEntity as an parameter properly.

This led to exceptions further in our test, we had to overcome the problem by making a change in the driver to explicitly check for an object of type DictionaryOrientDBEntity and handle that accordingly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.