zoukankan      html  css  js  c++  java
  • 嵌入式NOSQL数据库db4o

        NOSQL属于最近比较热门的话题,在高性能和大并发系统中,都能够见到NOSQL的影子。如memcached和mongodb等,memcached只支持列存储,mongodb不支持事务等,最重要的是,这些都需要服务器支持。在一些嵌入式系统中,老牛一样硬件环境,根本就不堪重负。

         在朋友的推荐下,尝试的使用db4o,发现还有如此好的数据库。

         主要的优势有:

              1、完全开源。

              2、支持ACID。

              3、支持所有。

              4、提供vs2010的插件设计器。

              5、提供嵌入式版本和服务器两种集成方式。

        先以一个例子看看db4o的好处。

    创建对象:

    namespace Db4objects.Db4o.Tutorial.F1.Chapter1
    {
        public class Pilot
        {
            string _name;
            int _points;
            
            public Pilot(string name, int points)
            {
                _name = name;
                _points = points;
            }
            
            public string Name
            {
                get
                {
                    return _name;
                }
            }
            
            public int Points
            {
                get
                {
                    return _points;
                }
            }   
            
            public void AddPoints(int points)
            {
                _points += points;
            }    
            
            override public string ToString()
            {
                return string.Format("{0}/{1}", _name, _points);
            }
        }
    }

    打开连接

    // accessDb4o
    IObjectContainer db = Db4oFactory.OpenFile(Util.YapFileName);
    try
    {
        // do something with db4o
    }
    finally
    {
        db.Close();
    } 

    存储对象:

    // storeFirstPilot
    Pilot pilot1 = new Pilot("Michael Schumacher", 100);
    db.Set(pilot1);
    Console.WriteLine("Stored {0}", pilot1);

    在开发的时候,代码非常精简明了。

  • 相关阅读:
    poj 1579(动态规划初探之记忆化搜索)
    hdu 1133(卡特兰数变形)
    CodeForces 625A Guest From the Past
    CodeForces 625D Finals in arithmetic
    CDOJ 1268 Open the lightings
    HDU 4008 Parent and son
    HDU 4044 GeoDefense
    HDU 4169 UVALive 5741 Wealthy Family
    HDU 3452 Bonsai
    HDU 3586 Information Disturbing
  • 原文地址:https://www.cnblogs.com/lirenqing/p/2836562.html
Copyright © 2011-2022 走看看