Dec 29, 2010

What's wrong with this code (Part XII)

In the last post in this series ("what's wrong with this code") we discussed how db4o's reference system remembers which objects have been stored / retrieved.

In this post I'll show you another piece of code that doesn't always work as the developer expects:

class User
{
   public string Name;
   public User Manager;
   public IList Addresses;

   public User(string name, User manager)
   {
      Name = name;
      Manager = manager;
   }
}

class Address
{
   public string Street;

   public Address(string street)
   {
      Street = street;
   }
}  


using (var db = Db4oEmbedded.OpenFile(databaseFileName))
{
   List<Address> addrs = new List();
   addrs.Add(new Address("Street1"));
   addrs.Add(new Address("Street2"));
   User fooManager = new User("Foo") { Addresses = addrs };

   User fooBarManager = new User("FooBar", fooManager);
   User barManager = new User("John Doe",  fooBarManager);
   User user = new User("Adriano",  barManager);
    
   db.Store(user);
}

using (var db = Db4oEmbedded.OpenFile(databaseFileName))
{
   var query = db.Query();
   query.Constrain(typeof (User));
   query.Descend("Name").Constrain("Adriano");
   
   User user = (User) query.Execute()[0];
   Console.WriteLine(user.Manager.Manager.Manager.Addresses[0].Street);
}

Can you see the problem? No, I am not talking about Law of Demeter "violation" :) (By the way, if you are interested in this subject you can find a nice discussion here).

Again, if you have been working with db4o for some time I am sure you already spent some time debugging this kind of issue.

As always, the answer comes in a future post.

Have fun!

Adriano

May 16, 2010

Installing Nokia SDK on a Windows 7 box

Hi


As you can figure out based on the post title, I want to start to play with Mobile development using Java (no, I haven't gave up on .Net :); it just happens that I own an N95 and I want to write a little application for it1).


After downloading latest Nokia SDK I  tried to follow the steps in the documentation (IDEs for Java Development) but I just get the infamous error:


Cannot start Series 60 SDK for MIDP


while importing the device.


Thanks God, it was just a matter of "googling" for the error message and I got the following page


http://wiki.urban.cens.ucla.edu/index.php?title=Nokia's_Java_Platform_(Carbide.j)


which fixed the issue (I just search in my hard disks and found 5 copies of the offending DLL).


Well, since my daughter has just born I guess this project will run really slowly but I hope it will not stall :) 


Best


Adriano


1. I am planning to write an application that stores information about gym exercises in a db4o database. 





May 11, 2010

Project deployed

Hi


In the latest days I've been really busy with the deployment of the project formerly known as "baby 2.0" (by the way, the official project name is Gabriela). 


Last Thursday (May, 6) my daughter was born with 4.1 Kg and 52 cm. Of course my whole family if very happy and I an my wife are very proud :)


Following you can see some pictures of her:


 


   

That's it for now (I'm gonna to sleep :))

Best

Adriano

Mar 18, 2010

I am not dead. Not yet

Warning: Personal content ahead

I can hear someone screaming already: but it really looked like you have died! :)
Well, you know, I have been having to much work fun lately.

Also, more or less 7 months ago, I and my wife decided to start a new project, daughter 2.0, and since then we have been working hard to get the environment ready to the deployment (there are too many details in such projects deployment). 

At this stage we can say that the project is growing as expected and that we are looking forward to the deployment date.

As always we expect the maintenance phase to consume much more time/resources than the development phase, but we are more than willing to do the required investment so the project will be able to meet its goals; after all, this is our baby :).

Last but not least, as you can see, I am actually alive :). So, bear with me! As soon as I get some spare time I'll do some more posts!

Good to get back to posting!

See you all.