<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jim Cassidy &#187; Jython</title>
	<atom:link href="http://jimcassidy.ca/tag/jython/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimcassidy.ca</link>
	<description>Programming for fun and profit since 1989</description>
	<lastBuildDate>Mon, 02 Jan 2012 18:52:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Back To Jython/DB4O: Part 1</title>
		<link>http://jimcassidy.ca/2010/04/19/back-to-jythondb4o-part-1/</link>
		<comments>http://jimcassidy.ca/2010/04/19/back-to-jythondb4o-part-1/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 16:01:51 +0000</pubDate>
		<dc:creator>Jim Cassidy</dc:creator>
				<category><![CDATA[Jython]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Aptana]]></category>
		<category><![CDATA[DB4O]]></category>
		<category><![CDATA[PyDev]]></category>

		<guid isPermaLink="false">http://jimcassidy.ca/?p=886</guid>
		<description><![CDATA[Ok, I let this work drop a while ago, but I have received a few requests for more info on using DB4O in Jython. Let&#8217;s make it clear, I am just playing with Jython and DB4O, but if this information is useful to you, then that makes me happy. If you are impatient, like me, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://apress.com/book/view/9781430225270" target="_blank"><img class="alignleft" title="Radar" src="http://apress.com/resource/bookcover/9781430225270?size=medium" alt="Knight" width="125" height="164" /></a> Ok, I let this work drop a while ago, but I have received a few requests for more info on using DB4O in Jython. Let&#8217;s make it clear, I am just playing with Jython and DB4O, but if this information is useful to you, then that makes me happy.</p>
<p>If you are impatient, like me, follow the<a href="#steps"> steps</a> I outline below, and you can stop reading here. </p>
<p>First things first: <a title="Buy the Book" href="http://apress.com/book/view/9781430225270" target="_blank">get the book</a>. You can purchase the PDF of the Definitive Guide to Jython by clicking on the image of the book that appears above. Or, you can view a preview that is available at<a title="Google Books" href="http://books.google.ca/books?id=eoPGiDflrtkC&amp;lpg=PR26&amp;dq=appress%20definitive%20guide%20to%20jython&amp;pg=PA1#v=onepage&amp;q&amp;f=false" target="_blank"> Google Books</a>.</p>
<p>Last, but not least, there is also an <a href="http://jythonpodcast.hostjava.net/jythonbook/en/1.0/" target="_blank">open source version</a> of the book. I will refer to this version in my examples, but, if you own the book, follow along.</p>
<p>I suggest that you download <a title="Get Aptana" href="http://www.aptana.org/" target="_blank">Aptana</a> and install PyDev &#8211; that is the IDE I will be using in my examples. Since Aptana is based on Eclipse, you also have the option of installing the <a title="Get PyDev Plugin" href="http://pydev.org/manual_101_install.html" target="_blank">PyDev plugin in your current Eclipse Install</a>.</p>
<p>I am going to assume that you have Java running on your machine, but I will provide instructions for the other steps. So, just to keep things easy, to get started follow these steps:</p>
<p><strong>Get the software.<a name="steps"> </a></strong></p>
<ol>
<li><a title="Install Jython" href="http://jythonpodcast.hostjava.net/jythonbook/en/1.0/LangSyntax.html#installing-and-configuring-jython" target="_blank">Install Jython</a> on your machine.</li>
<li>Get Pydev running on your machine. (As part of <a title="Get Aptana" href="http://www.aptana.org/" target="_blank">Aptana</a>, or as an Eclipse<a title="Get the PyDev Plugin" href="http://pydev.org/manual_101_install.html" target="_blank"> plugin</a>.)</li>
<li>Get the <a title="Get DB4O" href="http://www.db4o.com/DownloadNow.aspx" target="_blank">latest version of DB4O</a> for Java.</li>
</ol>
<p><strong>Bookmark the useful resources:</strong></p>
<ol>
<li><a title="The Definitive Guide" href="http://jythonpodcast.hostjava.net/jythonbook/en/1.0/" target="_blank">The Definitive Guide to Jython</a></li>
<li><a title="PyDev Docs" href="http://pydev.org/manual.html" target="_self">The PyDev Documentation</a></li>
<li>T<a title="DB4O Documentation" href="http://developer.db4o.com/Resources.aspx" target="_blank">he DB4O Documentation</a></li>
</ol>
<p>You are free to bookmark these resources any way you please, but I am fond of <a title="Delicious" href="http://delicious.com/" target="_blank">Delicious</a> because I can access my links from anywhere, because there is a Delicious API and because there are some cool plugins for Firefox and Google Chrome that make it more fun to use the service.</p>
<p>Get this done, and move on to part 2 when I have written it.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimcassidy.ca/2010/04/19/back-to-jythondb4o-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Persisting Jython Objects Using DB4O</title>
		<link>http://jimcassidy.ca/2009/01/05/persisting-jython-objects-using-db4o/</link>
		<comments>http://jimcassidy.ca/2009/01/05/persisting-jython-objects-using-db4o/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 17:10:11 +0000</pubDate>
		<dc:creator>Jim Cassidy</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Python/Jython]]></category>
		<category><![CDATA[DB4O]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[Jython]]></category>

		<guid isPermaLink="false">http://www.jimcassidy.ca/?p=472</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>If you have been following my blog, you will know that I have been playing with the following technologies: <a title="db4o" href="http://db4o.com" target="_blank">DB4O</a> (an open source object database), <a title="jython" href="http://www.jython.org/Project/" target="_blank">Jython</a> (<a title="python" href="http://python.org" target="_blank">Python</a> 2.5, implemented on the <a title="JVM" href="http://en.wikipedia.org/wiki/Java_Virtual_Machine" target="_blank">JVM</a>), and <a title="Django" href="http://www.djangoproject.com/" target="_blank">Django</a> (A python based <a title="MVC" href="http://en.wikipedia.org/wiki/Model-view-controller" target="_blank">MVC</a>-style web application framework in the same class as <a title="RoR" href="http://rubyonrails.org/" target="_blank">Ruby on Rails</a>).</p>
<p>So far, in <a title="Tutorials" href="http://www.jimcassidy.ca/2008/10/28/jython-formula-one-tutorial/" target="_blank">tutorials</a> 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 <a title="Formula One Tutorial" href="http://developer.db4o.com/Resources/view.aspx/Formula_One_Tutorial" target="_blank">DB4O Formula One tutorial</a> using Jython instead of Java, and showed that we can persist and retrieve objects using this technology.</p>
<p>I also mentioned that Django, a Python based web application framework, also runs on Jython.</p>
<p>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.</p>
<p>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.</p>
<p><strong>Persisting Objects:</strong></p>
<p>In my previous <a title="Formula One Tutorial" href="http://www.jimcassidy.ca/2008/10/28/jython-formula-one-tutorial/" target="_blank">example</a>, I created Plain Old Java Objects (Pojos), and created a <a title="JAR" href="http://java.sun.com/developer/Books/javaprogramming/JAR/basics/" target="_blank">JAR</a>. 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.</p>
<p>Therefore, I have resolved to persist Python classes by providing the means to automagically inspect these classes and generate the JAR files. I shared <a title="Plug into Django" href="http://www.jimcassidy.ca/2008/11/20/plug-db4o-into-django/" target="_blank">these thoughts</a> over a month ago.</p>
<p>Before writing any code, I just want to reflect on the task at hand. Let&#8217;s gather our assumptions.</p>
<ul style="list-style-type: square;padding-left: 30px">
<li>For every Python data type, there is a corresponding Java data type.</li>
<li>A &#8220;simple&#8221; object is based on a class that contains primitive types only.</li>
<li>A complex object contains other objects, or collections of objects.</li>
<li>We may need to make two passes to persist objects &#8211; first simple objects, and then complex.</li>
<li>A class contains an implementation as well as data, and we want to persist both.</li>
<li>If we change the definition of a class in our project, we need to think about what happens to our previously stored objects.</li>
<li>Our Jython classes must inherit from a single class only, or we will not be able to produce an equivalent Java class.</li>
</ul>
<p>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).</p>
<p>We want our DB4O objects to behave in the same way &#8211; as much as possible, we do not want to violate the expectations of Django programmers who have used Django with relational databases.</p>
<p>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.</p>
<p>Our first model will be simple &#8211; a class with a few attributes of various types. The output will be a class files &#8211; we will not worry about creating the JAR just yet.</p>
<p>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.</p>
<p>Code to come in a day or two.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimcassidy.ca/2009/01/05/persisting-jython-objects-using-db4o/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Django/DB4O Continues</title>
		<link>http://jimcassidy.ca/2008/12/16/djangodb4o-continues/</link>
		<comments>http://jimcassidy.ca/2008/12/16/djangodb4o-continues/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 19:02:05 +0000</pubDate>
		<dc:creator>Jim Cassidy</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[DB4O]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[Jython]]></category>

		<guid isPermaLink="false">http://www.jimcassidy.ca/?p=468</guid>
		<description><![CDATA[Hi Folks &#8211; I have read that it is considered poor form to make a post on your blog that does nothing more than promise that you will post soon. It is also considered poor form to apologize for not posting. Still, that is why I am writing today. I live in Ottawa, Canada. We [...]]]></description>
			<content:encoded><![CDATA[<p>Hi Folks &#8211; I have read that it is considered poor form to make a post on your blog that does nothing more than promise that you will post soon. It is also considered poor form to apologize for not posting. Still, that is why I am writing today.</p>
<p>I live in Ottawa, Canada. We are currently experiencing a bus strike &#8211; traffic is a nightmare. Some people are reporting that it it is taking up to four times longer to get to work and home. My experience is similar. Combine that with the Christmas season, and my time for blogging and coding is drastically reduced.</p>
<p>Still, I can see that many of you continue to visit. You are eagarly waiting for continued information on my progress with DB4O and Django running in Jython. Last month, I received blog visits from 411 cities in 69 different countries.  I am proud to report that 57% of you are using the Firefox browser &#8211; only 21% are using Internet Explorer. As an aside, I was surprised to see that 6% of you are using Chrome.</p>
<p>So, my friends, if you can forgive me &#8211; I will contnue the work soon. And, I am sorry for not blogging. All the best. I am not writing, but I am developing and tinkering &#8211; the work continues.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimcassidy.ca/2008/12/16/djangodb4o-continues/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Learn Python, Why Don&#8217;t You?</title>
		<link>http://jimcassidy.ca/2008/12/03/learn-python-why-dont-you/</link>
		<comments>http://jimcassidy.ca/2008/12/03/learn-python-why-dont-you/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 16:13:34 +0000</pubDate>
		<dc:creator>Jim Cassidy</dc:creator>
				<category><![CDATA[Cranky Rants]]></category>
		<category><![CDATA[Python/Jython]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[DB4O]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[Jython]]></category>

		<guid isPermaLink="false">http://www.jimcassidy.ca/?p=448</guid>
		<description><![CDATA[Since I have been writing about Jython, a version of Python implemented on the JVM, I thought I would provide a link to some Python resources for Java programmers who are using DB4O: Learn Python, why don&#8217;t you? If you like what Java has to offer in terms of class libraries, but you like the [...]]]></description>
			<content:encoded><![CDATA[<p>Since I have been writing about <a title="Jython" href="http://www.jython.org/Project/" target="_blank">Jython</a>, a version of Python implemented on the JVM, I thought I would provide a link to some Python resources for Java programmers who are using DB4O: <a title="Learn Python" href="http://arstechnica.com/news.ars/post/20081202-getting-a-grip-on-python-six-ways-to-learn-online.html" target="_blank">Learn Python, why don&#8217;t you?</a></p>
<p>If you like what Java has to offer in terms of class libraries, but you like the Python language and its <a title="idioms" href="http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html" target="_blank">idioms</a>, then Jython is the best of both worlds.</p>
<p>To prepare for my next installments on Jython, <a title="Django" href="http://www.djangoproject.com/" target="_blank">Django </a>and <a title="db4o" href="http://db4o.com" target="_blank">DB4O</a>, read about <a title="introspection" href="http://diveintopython.org/power_of_introspection/index.html" target="_blank">introspection</a> in Python.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimcassidy.ca/2008/12/03/learn-python-why-dont-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plug DB4O Into Django</title>
		<link>http://jimcassidy.ca/2008/11/20/plug-db4o-into-django/</link>
		<comments>http://jimcassidy.ca/2008/11/20/plug-db4o-into-django/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 03:03:10 +0000</pubDate>
		<dc:creator>Jim Cassidy</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Python/Jython]]></category>
		<category><![CDATA[DB4O]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[Jython]]></category>

		<guid isPermaLink="false">http://www.jimcassidy.ca/?p=360</guid>
		<description><![CDATA[As I continue to work with Django, I am coming to appreciate the elegance and simplicity of its design. Less Ruby on Rails style &#8220;magic&#8221; gives us more flexibility. You can store your models any way you like. Last weekend, I played with the possibility of using Couchdb, and I found an example that seemed [...]]]></description>
			<content:encoded><![CDATA[<p>As I continue to work with Django, I am coming to appreciate the elegance and simplicity of its design. Less Ruby on Rails style &#8220;magic&#8221; gives us more flexibility. You can store your models any way you like. Last weekend, I played with the possibility of using <a title="Couchdb" href="http://incubator.apache.org/couchdb/" target="_blank">Couchdb</a>, and I found an<a title="couch on django" href="http://lethain.com/entry/2008/aug/18/an-introduction-to-using-couchdb-with-django/" target="_blank"> example</a> that seemed easy to understand. (Couchdb is another open source project that I may write about later.)</p>
<p>There should be two steps to plugging DB4O into Django. First, we should be able to store settings in the settings.py file to specify where and how we will be storing our objects. The second step should be to create and use our models almost exactly as we would in a regular Django application. It should be that easy.</p>
<p><strong>Editing Settings</strong></p>
<p>It is not my goal to duplicate information you can get elsewhere. To find out how to set up a Django project, and to understand the files that are created for you, see the following <a title="Django Tutorials" href="http://docs.djangoproject.com/en/dev/" target="_blank">tutorials</a>.</p>
<p>In this entry, we are going to look at how to use the <a title="settings" href="http://docs.djangoproject.com/en/dev/topics/settings/#topics-settings" target="_blank">setting file</a> in Django to store settings for DB4O. You can store anything in the settings file you like, and you can store these settings in separate settings files named prodsettings.py, devsettings.py etc. These settings are easy to retrieve from views and models.</p>
<p>We are going to make the following assumptions in our example: we only have one settings file, and it is called settings.py. Also, we are persisting objects to a file, and we are not using an object server.</p>
<p>A cllient/server mode is available in DB4O, and we will have to provide for it later. (DB4O client/server mode is covered in Chapter 8 of the book, <strong>The Definitive Guide to db4o</strong>. The chapter about client/server mode is <a title="chapter eight" href="http://www.springerlink.com/content/h204p31282862143/" target="_blank">available for free</a>, if you are curious.)</p>
<p>To create settings, find your settings file, called settings.py, and add values. To see what entries look like, see below:</p>
<pre>	# Django settings for mysite project.

	DEBUG = True
	TEMPLATE_DEBUG = DEBUG

	ADMINS = (
	    # ('Your Name', 'your_email@domain.com'),
	)

	MANAGERS = ADMINS

	DATABASE_ENGINE = ''
	DATABASE_NAME = '/path/to/file.db4o'
	DATABASE_USER = ''     # Not used with db4o in file mode.
	DATABASE_PASSWORD = '' # Not used with db4o in file mode.
	DATABASE_HOST = ''     # Not used with db4o in file mode.

	# Local time zone for this installation. Choices can be found here:
	# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
	# although not all choices may be available on all operating systems.
	# If running in a Windows environment this must be set to the same as your
	# system time zone.
	TIME_ZONE = 'America/Chicago'

	# Language code for this installation. All choices can be found here:
	# http://www.i18nguy.com/unicode/language-identifiers.html
	LANGUAGE_CODE = 'en-us'

        .  .  .  .  .  .  .</pre>
<p>For our purposes, DATABASE_NAME will be the name of the file used by DB4O to persist objects. If you have read the DB4O documentation, you will know that you also have the option of running a server, in which case we could also use the DATABASE_HOST and DATABASE_PORT settings.</p>
<p>We also have the option of creating any settings we want to help us manage our application&#8217;s behavior. Django&#8217;s convention is to use capital letters for settings and to separate words with underscores.</p>
<p>At this point, we have enough information to find and connect to our DB4O file and we have stored it in the settings file. These settings will be used by our models to create objects and manage them. Our models will be written in such a way as to hide DB4O specific details from programmers. In my next installment, I will think about how to create a model for us to use with DB4O running in Django/Jython.</p>
<p>My thinking is that I will create my models in Jython, but I will create a command line script to create plain old Java objects (POJOs) and place them in a jar for us. I am lazy, and I always use Eclipse to create my jars for me. I expect to face some challenges at the command line, but I am up for it.</p>
<p>Therefore, the steps will be:</p>
<ol>
<li>Create models in a file called models.py.</li>
<li> Run a command line command to generate a jar that contains classes for the the Java objects we want to persist. This jar will need to be in Jython&#8217;s classpath when the application runs. Corresponds to python manage.py syncdb for regular Django models.</li>
<li> Build views, and use Django just as you would to create any other Django application.</li>
</ol>
<p>The only difference will be in the behavior of the models, but our goal will be not to violate too many expectations. Regular Django models subclass <em>django.db.models.Model</em>, but ours will subclass <em>DB4OModel</em>, a class we will create. Our DB4O should resemble Django models as much as possible.</p>
<p>In my next installment, let&#8217;s look at <em>DB4OModel</em>. What does it need to look like?</p>
]]></content:encoded>
			<wfw:commentRss>http://jimcassidy.ca/2008/11/20/plug-db4o-into-django/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Background: Python Virtual Machines etc.</title>
		<link>http://jimcassidy.ca/2008/11/07/background-python-virtual-machines-etc/</link>
		<comments>http://jimcassidy.ca/2008/11/07/background-python-virtual-machines-etc/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 13:14:02 +0000</pubDate>
		<dc:creator>Jim Cassidy</dc:creator>
				<category><![CDATA[Python/Jython]]></category>
		<category><![CDATA[Ruby/JRuby]]></category>
		<category><![CDATA[Jython]]></category>

		<guid isPermaLink="false">http://www.jimcassidy.ca/?p=337</guid>
		<description><![CDATA[Since my last few entries have covered Jython, I thought it would be useful to provide information about the various flavors of Python that can be found in the wild. There is an excellent article at Polishlinux. Give it a read to get the lay of the land. Also, some of you will be think [...]]]></description>
			<content:encoded><![CDATA[<p>Since my last few entries have covered <a title="Jython" href="http://www.jython.org/Project/" target="_blank">Jython</a>, I thought it would be useful to provide information about the various flavors of Python that can be found in the wild. There is an excellent article at <a title="python" href="http://polishlinux.org/apps/cli/comparison-of-python-virtual-machines/" target="_blank">Polishlinux</a>. Give it a read to get the lay of the land.</p>
<p>Also, some of you will be think about Jython performance. Performance is not everything, but if that is what you care about, then Dhananjay Nene has written this <a title="performance" href="http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/" target="_blank">excellent article</a> to help you understand where Jython stands compared to other languages and implementations, including <a title="Ruby" href="http://www.ruby-lang.org/en/" target="_blank">Ruby</a>. (Be sure to note that Python produces the fewest lines of code.)</p>
]]></content:encoded>
			<wfw:commentRss>http://jimcassidy.ca/2008/11/07/background-python-virtual-machines-etc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jython: Formula One Tutorial: Part Three</title>
		<link>http://jimcassidy.ca/2008/11/05/jython-formula-one-tutorial-part-three/</link>
		<comments>http://jimcassidy.ca/2008/11/05/jython-formula-one-tutorial-part-three/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 23:59:58 +0000</pubDate>
		<dc:creator>Jim Cassidy</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Python/Jython]]></category>
		<category><![CDATA[DB4O]]></category>
		<category><![CDATA[Jython]]></category>

		<guid isPermaLink="false">http://www.jimcassidy.ca/?p=296</guid>
		<description><![CDATA[In our first installment, we configured Eclipse to use Jython and DB4O, and we wrote some simple code to create Pilot objects and store them. In our second installment, we used Jython to retrieve the objects we save in the first part of the tutorial. Now, we need to update and delete these objects. Then [...]]]></description>
			<content:encoded><![CDATA[<p>In our <a title="First Installment" href="http://www.jimcassidy.ca/2008/10/28/jython-formula-one-tutorial/" target="_blank">first installment</a>, we configured Eclipse to use Jython and DB4O, and we wrote some simple code to create Pilot objects and store them.</p>
<p>In our <a title="second installment" href="http://www.jimcassidy.ca/2008/10/31/jython-formula-one-tutorial-part-two/" target="_blank">second installment</a>, we used Jython to retrieve the objects we save in the first part of the tutorial. Now, we need to update and delete these objects.</p>
<p>Then we will have learned how to perform the four basic functions of persistent storage: create, retrieve, update and delete &#8211; often referred to as <a title="CRUD" href="http://en.wikipedia.org/wiki/CRUD_(acronym)" target="_blank">CRUD</a></p>
<p>This tutorial is based on the <a title="formula one tutorial" href="http://developer.db4o.com/Resources/view.aspx/Formula_One_Tutorial" target="_blank">Formula One DB4O tutorial</a>.</p>
<p><strong>Updating objects</strong></p>
<p>Updating objects is just as easy as storing them. In fact, you use the same set() method to update your objects: just call set() again after modifying any object.</p>
<p><em>Java Code:</em></p>
<pre>    // updatePilot
    ObjectSet result=db.get(new Pilot("Michael Schumacher",0));
    Pilot found=(Pilot)result.next();
    found.addPoints(11);
    db.set(found);
    System.out.println("Added 11 points for "+found);
    retrieveAllPilots(db);

<strong>   OUTPUT:</strong>
    Added 11 points for Michael Schumacher/111
    2
    Michael Schumacher/111
    Rubens Barrichello/99</pre>
<p><em>Jython Code:</em></p>
<pre>    result=db.get(Pilot("Michael Schumacher",0))
    found=result.next()
    found.addPoints(11)
    db.set(found)
    print "Added 11 points for "+found
    retrieveAllPilots(db)</pre>
<p>Notice that we query for the object first. This is an important point. When you call set() to modify a stored object, if the object is not &#8216;known&#8217; (having been previously stored or retrieved during the current session), db4o will insert a new object. db4o does this because it does not automatically match up objects to be stored, with objects previously stored. It assumes you are inserting a second object which happens to have the same field values.</p>
<p>To make sure you&#8217;ve updated the pilot, please return to any of the retrieval examples above and run them again.</p>
<p><strong>Deleting objects</strong></p>
<p>Objects are removed from the database using the delete() method.</p>
<p><em>Java Code:</em></p>
<pre>   // deleteFirstPilotByName

   ObjectSet result=db.get(new Pilot("Michael Schumacher",0));
   Pilot found=(Pilot)result.next();
   db.delete(found);
   System.out.println("Deleted "+found);
   retrieveAllPilots(db);</pre>
<p><em>Jython Code:</em></p>
<pre>   result=db.get(Pilot("Michael Schumacher",0))
   found=result.next()
   db.delete(found)
   print "Deleted ", found
   proto=Pilot(None,0)
   result=db.get(proto)
   listResult(result)</pre>
<p>Let&#8217;s delete the other one, too.</p>
<pre>    result=db.get(Pilot("Rubens Barrichello",0))
    found=result.next()
    db.delete(found)
    print "Deleted "+found
    proto=Pilot(None,0)
    result=db.get(proto)
    listResult(result)</pre>
<p>Please check the deletion with the retrieval examples above.</p>
<p>As with updating objects, the object to be deleted has to be &#8216;known&#8217; to db4o. It is not sufficient to provide a prototype object with the same field values.</p>
<p><strong>Next Installment:</strong></p>
<p>In our next installment, we will provide the full source code for this tutorial. We will also reflect on the differences between the Jython code and the Java code.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimcassidy.ca/2008/11/05/jython-formula-one-tutorial-part-three/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jython News!</title>
		<link>http://jimcassidy.ca/2008/11/04/jython-news/</link>
		<comments>http://jimcassidy.ca/2008/11/04/jython-news/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 14:43:11 +0000</pubDate>
		<dc:creator>Jim Cassidy</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Python/Jython]]></category>
		<category><![CDATA[DB4O]]></category>
		<category><![CDATA[Jython]]></category>

		<guid isPermaLink="false">http://www.jimcassidy.ca/?p=300</guid>
		<description><![CDATA[Good news on the Jython front. For everyone who is following the DB4O with Jython series, the next version of Jython, Jython 2.5 Beta0, has been released. You may miss this because it is not posted on the Jython main page at the time of this writing. Also, the Jython road map has been updated. [...]]]></description>
			<content:encoded><![CDATA[<p>Good news on the <a title="Jython" href="http://www.jython.org/Project/" target="_blank">Jython </a>front. For everyone who is following the <a title="Jython with DB4O" href="http://www.jimcassidy.ca/2008/10/28/jython-formula-one-tutorial/" target="_blank">DB4O with Jython series</a>, the next version of Jython, <a title="Next Jython release" href="http://fwierzbicki.blogspot.com/2008/10/jython-25-beta0-released.html" target="_blank">Jython 2.5 Beta0</a>, has been released. You may miss this because it is not posted on the Jython main page at the time of this writing.</p>
<p>Also, the <a title="Jython road map" href="http://fwierzbicki.blogspot.com/2008/10/updated-jython-roadmap.html" target="_blank">Jython road map</a> has been updated. It looks like Jython 2.5 Final will be out in January. This is great news. Kudos to the Jython team!</p>
]]></content:encoded>
			<wfw:commentRss>http://jimcassidy.ca/2008/11/04/jython-news/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jython Goodness With DB4O</title>
		<link>http://jimcassidy.ca/2008/10/30/jython-goodness-with-db4o/</link>
		<comments>http://jimcassidy.ca/2008/10/30/jython-goodness-with-db4o/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 11:34:27 +0000</pubDate>
		<dc:creator>Jim Cassidy</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Python/Jython]]></category>
		<category><![CDATA[DB4O]]></category>
		<category><![CDATA[Jython]]></category>

		<guid isPermaLink="false">http://www.jimcassidy.ca/?p=247</guid>
		<description><![CDATA[I have watched Carl Rosenberger&#8217;s talk at ICOODB 2008 in Berlin. You can find it on German Viscuso&#8217;s blog. You will notice that he not only talks about LINQ, and LINQ for Java, but he also talks about the possible use of annotations for transactional demarkation. Separation of Concerns Using Decorators I was thinking that [...]]]></description>
			<content:encoded><![CDATA[<p>I have watched Carl Rosenberger&#8217;s talk at ICOODB 2008 in Berlin. You can find it on <a title="Carl's talk" href="http://planetgerman.blogspot.com/2008/05/just-objects-no-limits.html" target="_blank">German Viscuso&#8217;s blog</a>. You will notice that he not only talks about LINQ, and LINQ for Java, but he also talks about the possible use of annotations for transactional demarkation.</p>
<p><strong>Separation of Concerns Using Decorators</strong></p>
<p>I was thinking that I could have some fun with DB4O and Jython. If I create a generic object factory to instantiate the Java classes I want to use with DB4O, it would be possible for me to wrap the Java classes in a Python class. This would allow me to decorate method calls to indicate that a method is transactional &#8211; basically, by using a Python adapter on a Java class, I could use decorators to separate any one of a number of concerns.</p>
<p>I was thinking that when the object factory produces an object, it would use the generic reflector to populate a dictionary of methods or properties that can be called &#8211; basically, the factory would examine the Java object to identify its attributes. For the wrapper/mapper to work, I may have to impose some conventions &#8211; the basic idea could be useful and cool.</p>
<p>Remember, the far off goal is something that looks and works like Active Record, but for DB40 using Jython. The programmer would need to know very little about DB4O, but each object would know how to save, update and delete itself, and there would a simply way to dynamically query the repository.</p>
<p>Basically, I think Jython may provide the means to play with syntax, and to toy with various nifty ideas. I will post my next installment in the Formula One tutorial series soon.</p>
<p>Forgive me for blithering &#8211; I just want to use my blog entries to record my thoughts where I can.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimcassidy.ca/2008/10/30/jython-goodness-with-db4o/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DB4O With Jython</title>
		<link>http://jimcassidy.ca/2008/10/23/db4o-with-jython/</link>
		<comments>http://jimcassidy.ca/2008/10/23/db4o-with-jython/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 13:41:03 +0000</pubDate>
		<dc:creator>Jim Cassidy</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Python/Jython]]></category>
		<category><![CDATA[DB4O]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[Jython]]></category>

		<guid isPermaLink="false">http://www.jimcassidy.ca/?p=184</guid>
		<description><![CDATA[Why Jython? As programming languages go, Python is beautiful, elegant, fun, powerful, concise, and easy to learn. Python is written in C, but Jython is a version of Python that is written in Java. This means that you can write a program using Python, which has all of the niceness of Python, but also has [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Why Jython?</strong></p>
<p>As programming languages go, <a title="Python" href="http://Python.org" target="_blank">Python</a> is beautiful, elegant, fun, powerful, concise, and easy to learn. Python is written in C, but <a title="Jython" href="http://www.jython.org/Project/" target="_blank">Jython</a> is a version of Python that is written in Java. This means that you can write a program using Python, which has all of the <a title="niceness" href="http://www.python.org/about/" target="_blank">niceness of Python</a>, but also has access to class libraries that are available in Java. Remember, Java is both a language and a platform, which supports many other languages, including <a title="Ruby" href="http://www.ruby-lang.org/en/" target="_blank">Ruby</a>, <a title="lua" href="http://www.keplerproject.org/luajava/" target="_blank">Lua</a>, and <a title="scripting languages" href="http://java-source.net/open-source/scripting-languages" target="_blank">many others</a>.</p>
<p>Python is popular, and <a title="widely used" href="http://www.python.org/about/quotes/" target="_blank">widely used</a>. It comes installed on the vast majority of popular Linux distributions. It runs on Windows. And,  and the latest version of Jython not only allows you to use Java libraries, but it also allows you to use popular Python based frameworks like <a title="Django" href="http://www.djangoproject.com/" target="_blank">Django</a>, a Python based alternative to <a title="Ruby on rails" href="http://www.rubyonrails.org/" target="_blank">Ruby on Rails</a>.</p>
<p>The development of Jython is being undertaken by <a title="Jython developed by Sun" href="http://www.tbray.org/ongoing/When/200x/2008/03/03/Python-at-Sun" target="_blank">Sun</a>, which bodes well for its future development.</p>
<p><strong>Why DB4O?</strong></p>
<p>After years of using databases any time I needed to persist information, I have finally rejected that appraoch. One day, will working with an elaborate library of objects that hid the database from programmers, I realized that it would be a lot less work if I could just persist the objects as-is. My code would look pretty well the same, but I would not have to maintain a web server or write stored procedures.</p>
<p>Less work is always a good thing, especially if you lose nothing in the process. DB4O is fast, and it saves objects to the file system &#8211; that&#8217;s just what I thought I needed. I looked at other products, but DB4O is the leader as far as I am concerned.</p>
<p><strong>Why DB4O and Jython?</strong></p>
<p>There are many reasons. One is that Jython allows you to write less code and to be more productive. Another is that it is not possible to use DB40 with Python unless you willing to use Jython.</p>
<p>Personally, I am attacted to the idea of using DB4O to persist objects with the Django framework. Django, an alternative to Ruby on Rails, will run on Jython. I do not anticipate being able to find the time to dig in to this problem. What would be required is an <a title="active record" href="http://en.wikipedia.org/wiki/Active_record_pattern" target="_blank">Active Record like</a> wrapper around DB4O. I would be inclined to develop something that looks as much like Django&#8217;s data modelling framework as possible.</p>
<p>The first thing to be aware of is that DB4O persists Java objects, but it does not persist Python objects. Therefore, as you use DB4O with Jython, you need to define the classes you want to persist in Java. I usually put these classes in a JAR, and place them in my Jython classpath.</p>
<p>In an upcoming blog entry, I will use some of the DB4O samples and implement then in Jython. I will show you how to define the classes and create JARs using the Eclipse IDE. You can use Netbeans if you like, but I only have time to provide examples using the tools I commonly use.</p>
<p>Then I will show you how to use Jython to work with objects that have been persisted using DB4O. I hope to show you that you can do this in less time using Jython because you are writing less code. Where I can, I hope to showcase the features of Python that can make working with DB4O more fun.</p>
<p><strong>Join In, If You Wish</strong></p>
<p>If you become interested in these examples, please feel free to correct me or to offer better solutions. I will be sure to give you the credit. If you decide to extend Django for Jython using DB4O, I will participate where I can and provide whatever help I can. I can provide some space on a server for a web site, but you have many other options.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimcassidy.ca/2008/10/23/db4o-with-jython/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

