BloggingAbout.NET
Thoughts of developers
Native Objects - Persistance Layer Generator
Robert Jan van Holland

Syndication

News

  • Hey! It's me!


    <!-- Begin Nedstat Basic code --> <!-- Title: Robert Jan van Holland --> <!-- URL: http://bloggingabout.net/rj/ --> <script language="JavaScript" type="text/javascript" src="http://m1.nedstatbasic.net/basic.js"> </script> <script language="JavaScript" type="text/javascript" > <!-- nedstatbasic("ADQEqQkgn3Dw8t7jLnYe0vJBScRw", 0); // --> </script> <noscript>
    Gratis teller </noscript> <!-- End Nedstat Basic code --> <iframe src="http://bloggie.vanholland.net/Statistics.aspx" width="130" height="40" frameborder=0 scrolling="no" name="content"></iframe> Download Bloggie here! Installation & Configuration!

The last two weeks I have been looking into DB4O's object database.
I really wanted to do someting with it and thought why not create something generic to generate a persistance layer for business objects.

Wouldn't it be nice if you would just create your object oriented business layer and generate some object oriented persistance layer so objects can be stored and retrieved with real ease? This persistance layer doesn's have to be the final persistance layer; during development it can sometimes be a hazzle to create and maintain tables, stored procedures and data layer classes. What if we could use a tool which would look into your business DLL's and generate an assembly with persistance and retrieval methods for those objects and would delegate that persistance to DB4O?

First a note... this application is a personal project and in a test phase. Normally this tool is meant for personal, non-commercial use only. If you do want to use this tool otherwise, contact me and DB4O. DB4O deserves credits and payments for their software when used commercially. So if you intend to use this that way, buy sufficient licenses for DB4O.

Okay, let's continue..

Lets have a simple class model with 3 classes (Customer, Order and Product). Our generator will use System.Reflection to look into the classes in your business DLL and simply create a Persist method for each class it encounters. This persist method will take care of storing the object in DB4O.

Then, the generator will examine which private fields are available on the class. It will generate a RetrieveBy method for every private field it encounters. Because I couldn't find out if and how DB4O is capable of retrieving objects using public properties, for now the generator uses the private fields.

So this is simply what it does... how do you use it?
First download the generator here. It contains the .EXE and the DB4O 4.3 dll.

Well, the generator is simply a console application. For the above example I have built a VS.NET 2003 project which is available here. It contains the three classes but there is something you have to take a look at. If you look in the project properties , Common Properties and then Build Events, you can see that there is a Post-Build Event supplied. It contains :

C:\temp\nofgen.exe /o:"c:\temp" /s /a:"$(TargetPath)"

So, put the generator in c:\temp (or adjust this post build event). The $(TargetPath) just points to the DLL built by this project. This is great, don't you think!? Create (and update) a persistance layer every time you build the business layer?....
The /o argument means the outputpath, /s means it should also generate a source code file and the /a targets the business dll.

Off course, it is also possible to run the generator as a stand alone console application :

If the build was succesfull, you will find a DLL called 'NOFPersistanceLayer.dll' in the Bin directory in the supplied output folder.
You can reference this DLL from your application to utilize the persist and retrieval methods :

 1: NOFGenTestLibrary.Customer c = new NOFGenTestLibrary.Customer("Robert Jan");
 2: NOFPersistanceLayer.Customer.Persist(c);
 3: NOFGenTestLibrary.Customer[] temp = NOFPersistanceLayer.Customer.RetrieveBy_name("Robert Jan");

First this will create an instance of a Customer with the name 'Robert Jan'. Then, it will call the persist method in the generated assembly to store this instance. Afterwards, the retrieval method 'by name' is used to retrieve all Customers with the name 'Robert Jan'.
Cool isn't it?

I am really interested in your opinions and suggestions.. is this usefull or not? what else do you think it should or shouldn't do? let me know!..


Posted 03-11-2005 4:37 PM by Robert Jan van Holland
Filed under: ,

Comments

Robert Jan van Holland wrote re: Native Objects - Persistance Layer Generator
on 04-16-2005 7:42 AM
Just discovered db4o.
I'm gonna try some things out.

I understand you only can generate persistence for the privaye fields?

You got any examples of projects you built with db4o?
Robert Jan van Holland wrote re: Native Objects - Persistance Layer Generator
on 04-16-2005 8:19 AM
Kris

The tool will create a persist method for every class is encounters.
But because I noticed that is isn't possible to query db4o on public properties, the tool only creates retrieve methods for the private fields.
Far more information can be found on the Db4O site and in it's knowledge base.
If you install it, you get a nice Help with logs of info.
Robert Jan van Holland wrote re: Native Objects - Persistance Layer Generator
on 05-07-2005 1:30 PM
It's been a while since I passed by your blog.
I downloaded the thing (4.4 now) and must say it looks promising.
Will try to work out a project.

Are you still using db4o?
Robert Jan van Holland wrote re: Native Objects - Persistance Layer Generator
on 05-09-2005 9:38 AM
At the moment I'm paying most of my attention to Bloggie 2.0 (http://bloggingabout.net/rj/archive/2005/05/02/3760.aspx), so I haven't much time left to play around with db4o.
However, I am really enthousiastic about this product, and is has (shown) real potential.
Let me know when you have/find something interesting!

Regards,
RJ

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Copyright © 2003-2008 BloggingAbout.NET
Powered by Community Server (Commercial Edition), by Telligent Systems