<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Michael Ivey&apos;s Blog</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/mdi/" />
<modified>2006-10-20T21:06:12Z</modified>
<tagline></tagline>
<id>tag:weblogs.java.net,2008:/blog/mdi/62</id>
<generator url="http://www.movabletype.org/" version="3.01D">Movable Type</generator>
<copyright>Copyright (c) 2006, mdi</copyright>
<entry>
<title>JRuby in Second Life</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/mdi/archive/2006/10/jruby_in_second.html" />
<modified>2006-10-20T21:06:12Z</modified>
<issued>2006-10-20T21:05:49Z</issued>
<id>tag:weblogs.java.net,2006:/blog/mdi/62.5767</id>
<created>2006-10-20T21:05:49Z</created>
<summary type="text/plain">JRuby developer Charles Oliver Nutter talks about the how and why of JRuby in the virtual world of Second Life.</summary>
<author>
<name>mdi</name>

<email>mdi@iveyandbrown.com</email>
</author>
<dc:subject>Programming</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/mdi/">
<![CDATA[<p>*dusts off the 2 year old blog*</p>

<p>Ahoy j.n'ers!  It's been a while, but I <b>had</b> to come share a fun experience from the other night.  Charles Oliver Nutter, one of the lead developers of <a href="http://www.jruby.org/">JRuby</a>, dropped in to the virtual world <a href="http://secondlife.com">Second Life</a> for a meeting of the <a href="http://rosl.iandb.net">Rubyists of Second Life</a>.  For an hour and a half or so, Charles, known in SL as Headius Exodus, shared the details of what JRuby is, why it matters to Java developers, and why it mattters to Ruby developers, too.</p>

<p>JRuby is a 100% Java implementation of the Ruby langauge that brings the power of a fantastic dynamically typed langauge into the Java enviroment, or the depth of Java libraries into Ruby.</p>

<p>The chat log and slides from the presentation are <a href="http://rosl.iandb.net/presentations/jruby/JRuby%20Presentation%2018%20Oct%2006.html">available at the RoSL website</a>, Charles Oliver Nutter has a <a href="http://headius.blogspot.com/">blog</a>, and there should be a JRuby community here eventually:</p>

<pre>
  [19:15] Headius Exodus: We will probably get a Java.net blog/site up soon
  [19:15] Headius Exodus: they're leaning on us to do it :)
</pre>

<p>Share your JRuby experiences in the comments!</p>]]>

</content>
</entry>
<entry>
<title>Groovy Markup BeanBuilder</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/mdi/archive/2004/05/groovy_markup_b.html" />
<modified>2008-01-02T17:42:16Z</modified>
<issued>2004-05-25T16:17:00Z</issued>
<id>tag:weblogs.java.net,2004:/blog/mdi/62.316</id>
<created>2004-05-25T16:17:00Z</created>
<summary type="text/plain">Wiring beans together with Groovy Markup.</summary>
<author>
<name>mdi</name>

<email>mdi@iveyandbrown.com</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/mdi/">
<![CDATA[<p>
In a followup to his <a href="http://www.behindthesite.com/blog/C912632915/E647248081/index.html">earlier post about using Groovy instead of XML for application config</a>, Michael Henderson has written a <a href="http://www.behindthesite.com/blog/C663408438/E876434710/index.html">Groovy Markup BeanBuilder class</a> to allow building complex trees of JavaBeans or GroovyBeans using the simple <a href="http://groovy.codehaus.org/GroovyMarkup">Groovy Markup syntax</a>.
</p>]]>

</content>
</entry>
<entry>
<title>Quick and Easy Object Persistence: pBeans + Groovy Beans</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/mdi/archive/2004/05/quick_and_easy.html" />
<modified>2008-01-02T17:42:16Z</modified>
<issued>2004-05-18T17:09:31Z</issued>
<id>tag:weblogs.java.net,2004:/blog/mdi/62.1134</id>
<created>2004-05-18T17:09:31Z</created>
<summary type="text/plain">In the quest for an object persistence solution that doesn&apos;t require duplication of information, writing XML mapping files, extending gross framework classes or implementing complicated interfaces, I stumbled across pBeans.  If you use it with Groovy Beans, you can build a database-backed persistent object system in literally minutes.</summary>
<author>
<name>mdi</name>

<email>mdi@iveyandbrown.com</email>
</author>
<dc:subject>Databases</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/mdi/">
<![CDATA[<blockquote>
<strong>Laziness</strong>: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful, and document what you wrote so you don't have to answer so many questions about it.
<br>
-- Larry Wall, Tom Christiansen, and Randal L. Schwartz, <em>Programming Perl, 2nd Edition</em>
</blockquote>
<p>
I started my programming life in Perl, and I am a lazy programmer.  I get frustrated when I have to write duplicate code, or put information in more than one place.  I'll search the web for days, try sample applications in 10 different frameworks, and write hundreds of lines of test code to find a solution that saves me half an hour.  Now <em>that's</em> lazy.
</p>
<p>
I've been looking at persistence layers and frameworks lately.  I don't like having SQL in my objects, partially because it makes things more brittle, and partially because I don't like writing SQL <em>anywhere</em>.  I just want to write classes and instantiate objects, manipulate them for a while, and then have them stick around.  I don't really care about the database itself.  (In fact, most of the time I don't <em>need</em> a database, that's just a simple way to store stuff.)
</p>
<p>
I'm sure that somewhere there is a good list and comparison of available persistence layers, so I won't try to duplicate that here.  What I will say is that almost everything I looked at required at least one of the following, and usually more than one:
<ul>
<li>Extending a framework class</li>
<li>Implementing a complex interface</li>
<li>Writing XML mapping files</li>
<li>Writing mapping classes</li>
<li>Generating a database schema at compile time</li>
<li>Code generation</li>
</ul>
One word: gross.
</p>
<p>
Prevayler-style in-memory storage is kind of cool, but it also places restrictions on how you structure your client classes.  I don't want restrictions, I don't want extra work, and I don't want duplicated code or information.  How do I do it?
</p>
<p>
<a href="http://pbeans.sourceforge.net/">pBeans</a> is one way.  It really is as simple as I was looking for.  Make some Beans, tag them with <code>implements Persistent</code>, make a store, and then put objects in the store and take them out.  No SQL (one exception; read on), no XML, no mapping files.  Free as in speech.  Currently works with MySQL, Postgres, and SQL Server, and should be fairly easy to get working on other databases.
</p>
<p>
Here's how it works:
<ol>
<li>Create an instance of  <code>net.sourceforge.pbeans.data.GenericDataSource</code></li>
<li>Configure that <code>DataSource</code> with a JDBC driver and a database URL</li>
<li>Use that <code>DataSource</code> to get an instance of <code>net.sourceforge.pbeans.Store</code></li>
<li>Create some JavaBeans</li>
<li>Call <code>insert()</code>, <code>save()</code>, <code>delete()</code>, and <code>select()</code> on the <code>Store</code> with those beans</li>
<li>Laugh at how easy it was to get your objects stored in the database</li>
</ol>
Notice that we never created any database tables?  pBeans did that for us.  So far, I'm happy.
</p>
<p>
Well, mostly happy.  JavaBeans make persistence easy, but violate another of my lazy principles: duplication.  I can't <em>stand</em> writing getters and setters for every field.  Java is already too verbose for my tastes, coming from a loose typing background.  2 copy-paste methods for every field is too much.  Enter Groovy Beans.
</p>
<p>
Groovy is quite possibly the best thing I've encountered in the Java world, period.  It makes writing for the Java platform enjoyable for me, and it really helps my wrists not hurt so much.  Here's an example:
<hr>
<strong>Java bean:</strong>
<pre>
public class User {

    private Integer id;
    private String name;
    private String favoriteColor;

    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getFavoriteColor() {
        return favoriteColor;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setFavoriteColor(String favoriteColor) {
        this.favoriteColor = favoriteColor;
    }

}
</pre>
<strong>Groovy bean:</strong>
<pre>
class User {
   Integer id
   String name
   String favoriteColor
}
</pre>
Groovy takes care of the rest behind the scenes.  &lt;insert bad groovy pun here&gt;
</p>
<p>
<hr>
So, here's a basic object persistence example in 20 lines of Groovy:
<pre>
import net.sourceforge.pbeans.data.*
import net.sourceforge.pbeans.*

dataSource = new GenericDataSource()
dataSource.setDriverClassName("com.mysql.jdbc.Driver")
dataSource.setUrl("jdbc:mysql://localhost/test?user=test&password=test")

store = new Store(dataSource)

class User implements Persistent {
    Integer id
    String name
    Integer age
    String hometown
}

joe = new User(name:"Joe User", age:43, hometown:"Bay Minette, AL")
store.insert(joe)
newjoe = store.selectSingle(User.class, "name", "Joe User")
assert newjoe.hometown == "Bay Minette, AL"
</pre>
It's coding even the laziest programmer can handle.
</p>
<p>
<hr>
<strong>Exception to the no SQL statement:</strong> I wanted <code>id</code> to be  unique, and didn't have the time to figure out how to make pBeans do that for me.  After the first invocation, when pBeans had created the table for me, I manually altered the id column to be primary key and auto increment.  You'll have to do that once for each class.  There's probably a way to make pBeans do that.  Let me know if you figure it out.
</p>]]>

</content>
</entry>
<entry>
<title>SQLite ... quick and dirty SQL server</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/mdi/archive/2003/08/sqlite_quick_an.html" />
<modified>2008-01-02T17:42:16Z</modified>
<issued>2003-08-03T16:41:44Z</issued>
<id>tag:weblogs.java.net,2003:/blog/mdi/62.1546</id>
<created>2003-08-03T16:41:44Z</created>
<summary type="text/plain">Ever find that you need a database, but don&apos;t want to hassle with installing one?  Me too.  Then I stumbled on SQLite.</summary>
<author>
<name>mdi</name>

<email>mdi@iveyandbrown.com</email>
</author>
<dc:subject>Databases</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/mdi/">
<![CDATA[<p>
I was working on a Perl project this weekend. (You know, Perl. "It's like Java, only it lets you deliver on time and under budget." <a href="http://www.oreillynet.com/pub/wlg/1733">*</a>)  I was doing a bunch of awfulness with SQL-over-CSV files, but I <b>really</b> needed a database.  I didn't want to go through the hassle of installing one, even though, on <a href="http://www.debian.org">Debian</a>, it's just <tt>apt-get install postgresql-client postgresql-server</tt>.  Then I'd have to create database users, muck with security, and then my evening ends up diverted to system admin tasks. I just want a simple SQL engine that's easy to deploy.
</p>
<p>
You'd think I would have found it sooner.  If I didn't dislike PHP so much, I might have found it there.  As it was, I only stumbled across it because a module I was using wouldn't work with Postgres's sequences, and as I was wading through the code, I saw it mentioned: <a href="http://www.hwaci.com/sw/sqlite/">SQLite</a>.
</p>
<p>
So what is it?  "SQLite is a C library that implements an embeddable SQL database engine. Programs that link with the SQLite library can have SQL database access without running a separate RDBMS process. ... SQLite is not a client library used to connect to a big database server. SQLite is the server. The SQLite library reads and writes directly to and from the database files on disk."
</p>
<p>
It's beautiful.  It's simple.  It's embeddable.  There's a <a href="http://www.ch-werner.de/javasqlite/">Java binding wih JDBC</a>.  And it's "two times faster than PostgreSQL and MySQL for many common operations."
</p>
<p>
It's not for everyone.  The security is whatever the OS provides for files.  It's not fully SQL92 complete (<a href="http://www.hwaci.com/sw/sqlite/omitted.html">here's the list</a> of what it doesn't do), even compared to MySQL.  The locking is file-based and operates on the whole database.
</p>
<p>
Oh yeah, it's <a href="http://www.hwaci.com/sw/sqlite/datatypes.html">typeless</a>.  Want to shove some text in an int column?  Go ahead.  It's OK.
</p>
<p>
For simple apps that need to do a little SQL, but don't need all the bells and whistles, it's great.  And for developers running local test cases all over, without wiping out production or semi-production databases, it could be a lifesaver. 
</p>]]>

</content>
</entry>

</feed>