If you have been following my blog, you will know that I have been playing with the following technologies: DB4O (an open source object database), Jython (Python 2.5, implemented on the JVM), and Django (A python based MVC-style web application framework in the same class as Ruby on Rails).
So far, in tutorials I wrote in November of last year, we have seen that Jython allows us to write Python code that uses Java libraries, such as DB40. I altered the standard DB4O Formula One tutorial using Jython instead of Java, and showed that we can persist and retrieve objects using this technology.
I also mentioned that Django, a Python based web application framework, also runs on Jython.
Which leads us to this entry, where I will start thinking and tinkering to find a way to use DB4O with Django/Jython rather than a relational database.
I am doing this for fun, not for profit. I am not an expert with any of the technologies I am using. I stand in awe of the very talented open source programmers who precede me. I hope to learn as much as I hope to teach and share what I know, or think I know.
Persisting Objects:
In my previous example, I created Plain Old Java Objects (Pojos), and created a JAR. I used the classes in the JAR to create the objects I persisted using DB4O. I have since decided that this is not desirable. I think this creates a barrier to Python programmers who want to use Django, Python and DB4O togther.
Therefore, I have resolved to persist Python classes by providing the means to automagically inspect these classes and generate the JAR files. I shared these thoughts over a month ago.
Before writing any code, I just want to reflect on the task at hand. Let’s gather our assumptions.
In Django, we define models, and then use a command (python manage.py syncdb) to generate the corresponding database. The database is created automagically, based on the settings in the settings file (settings.py). The model is able to perform basic operations to create, read, update and delete objects (CRUD).
We want our DB4O objects to behave in the same way – as much as possible, we do not want to violate the expectations of Django programmers who have used Django with relational databases.
In my next entry, I will try to write code that creates a Java class based on a Jython class and saves it in a file. I will keep it simple to start, and the code will evolve as we go.
Our first model will be simple – a class with a few attributes of various types. The output will be a class files – we will not worry about creating the JAR just yet.
Once we have produced a simple class file, we will produce class that make two passes and resolve inheritance issues as well as contained objects that inherit from previously defined classes.
Code to come in a day or two.
Very interesting idea and I would loive to see it. Has anything happened on this?
Also interested, did you do anything more on this?