db4o Developer Community

db4o open source object database, native to Java and .NET
Welcome to db4o Developer Community Sign in | Join

Re: can't find any saved objects

  •  08-01-2008, 03:01 AM

    Re: can't find any saved objects

    responding to scruz:

    It's not possible to store Value Types directly. If you enable "ExceptionsOnNotStorable" in
    configuration db4o will throw an exception when try to store such "objects".

    To be able to store Value Types wrap them in a class. For instance, the following test will store
    "Wrapper" object successfully but will throw in the next line.

    using System;
    using Db4objects.Db4o;
    using Db4objects.Db4o.Config;

    namespace TestBed
    {
    public class Db4oTest
    {
    public static void Main()
    {
    IObjectContainer db = Db4oFactory.OpenFile(config(), "sampler.db4o");

    DateTime myTime = DateTime.Now;
    Console.WriteLine("Time is {0}", myTime);
    db.Store(new Wrapper(myTime));
    db.Store(myTime);

    db.Commit();

    IObjectSet items = db.QueryByExample(DateTime.Now);

    foreach (object item in items)
    Console.WriteLine("Retrieved item: {0}", item);
    }

    private static IConfiguration config()
    {
    IConfiguration config = Db4oFactory.NewConfiguration();
    config.ExceptionsOnNotStorable(true);

    return config;
    }
    }

    internal class Wrapper
    {
    public DateTime _date;
    public Wrapper(DateTime date)
    {
    _date = date;
    }
    }
    }



    --
    *Adriano Carlos Verona* � *db4objects*
    http://programing-fun.blogspot.com



    scruz wrote:
    > hi,
    >
    > i'm new to db4o and just stepping through the tutorial. this is my
    > second time trying, but i retrieve nothing from the database. here's my
    > code:
    >
    > using System;
    > using System.Collections.Generic;
    > using System.IO;
    >
    > using Db4objects.Db4o;
    > using Db4objects.Db4o.Query;
    >
    > namespace TestBed
    > {
    > � public class Db4oTest
    > � {
    > � public static void Main()
    > � {
    > � IObjectContainer db = Db4oFactory.OpenFile("sampler.db4o");
    > � DateTime myTime = DateTime.Now;
    > � Console.WriteLine("Time is {0}", myTime);
    > � �
    > � db.Store(myTime);
    > � db.Commit();
    > � �
    > � IObjectSet items = db.QueryByExample(DateTime.Now);
    > � �
    > � foreach (object item in items)
    > � Console.WriteLine("Retrieved item: {0}", item);
    > � }
    > � }
    > }
    >
    > the console output:
    >
    > Time is 8/1/2008 1:21:04 AM
    > [db4o 7.2.39.10644 2008-08-01 01:21:04]
    > � 'sampler.db4o' closed by ShutdownHook.
    >
    > i've already tried with my custom storage class without success. is
    > there anything i'm doing wrong?
    >
    >
    > ------------------------------------------------------------------------
    > http://developer.db4o.com/forums/thread/50437.aspx
    >
View Complete Thread