db4o - how do I get a distinct list of classes contained in a .db4o DB file?

StackOverflow https://stackoverflow.com/questions/18412473

  •  26-06-2022
  •  | 
  •  

문제

Say I open a .db4o file. What would be the Java code (psuedo) that would generate a list of unique Java CLASSES/TYPES contained in the database?

I am sure I could write the code to do it, but I am afraid it could be quite slow. Is there a good way to do this without querying for every object in the database? Could I use some sort of index?

I'd rather not rely on stored metadata about the database, I'd rather rely on the true information about what objects are actually stored within.

도움이 되었습니까?

해결책

You can use something like (C# but it can be easily converted to Java :)

const string DatabaseFileName = "c:\\temp\\Learning.odb";
static void Main(string[] args)
{
    using (var db = Db4oEmbedded.OpenFile(DatabaseFileName))
    {
        var classes = db.Ext().StoredClasses();
        foreach (var @class in classes)
        {
            Console.WriteLine();
            Console.WriteLine(@class.GetName());
            foreach (var field in @class.GetStoredFields())
            {
                Console.WriteLine("\t{1} {0}", field.GetName(), field.GetStoredType().GetName());
            }
        }
    }
}

Note that you have more interesting methods in ExtObjectContainer interface.

Hope this helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top