<?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>java rants &#187; database</title> <atom:link href="http://www.javarants.com/tag/database/feed/" rel="self" type="application/rss+xml" /><link>http://www.javarants.com</link> <description>Rants about Java and other internet technologies by Sam Pullara</description> <lastBuildDate>Sun, 09 Oct 2011 23:29:31 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>Generate JPA (or GORM) classes from your database for Java and Grails</title><link>http://www.javarants.com/2007/10/14/generate-jpa-or-gorm-classes-from-your-database-for-java-and-grails/</link> <comments>http://www.javarants.com/2007/10/14/generate-jpa-or-gorm-classes-from-your-database-for-java-and-grails/#comments</comments> <pubDate>Sun, 14 Oct 2007 17:14:47 +0000</pubDate> <dc:creator>Sam Pullara</dc:creator> <category><![CDATA[Java]]></category> <category><![CDATA[Technology]]></category> <category><![CDATA[database]]></category> <category><![CDATA[dbmapper]]></category> <category><![CDATA[domain]]></category> <category><![CDATA[gorm]]></category> <category><![CDATA[grails]]></category> <category><![CDATA[hibernate]]></category> <category><![CDATA[jpa]]></category> <category><![CDATA[mapping]]></category> <category><![CDATA[orm]]></category> <category><![CDATA[schema]]></category> <guid
isPermaLink="false">http://www.javarants.com/2007/10/14/generate-jpa-or-gorm-classes-from-your-database-for-java-and-grails/</guid> <description><![CDATA[Whether you start with the database or start with code, no one wants to do the other one. Certainly by the DRY principle it is a waste of time and potentially a place where you could introduce bugs into your &#8230; <a
href="http://www.javarants.com/2007/10/14/generate-jpa-or-gorm-classes-from-your-database-for-java-and-grails/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>Whether you start with the database or start with code, no one wants to do the other one.  Certainly by the <a
href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" title="DRY Principle">DRY principle</a> it is a waste of time and potentially a place where you could introduce bugs into your code.  Today <a
href="http://www.moonspider.com/">Dave</a> and I are releasing a command-line utility that will handle the case where you start with the database and want to use <a
href="http://java.sun.com/developer/technicalArticles/J2EE/jpa/" title="JPA">JPA</a> to access it.  There are other utilities that do this that are generally built into IDEs, however this one fills the niche for those that want to do it in a more automated fashion and don&#8217;t want to edit the actual generated code.  In fact, we used a previous version of this tool at <a
href="http://www.borland.com/us/products/silk/gauntlet/index.html">Gauntlet</a> throughout the development process to keep our database and <a
href="http://java.sun.com/developer/technicalArticles/J2EE/jpa/" title="JPA">JPA</a> classes in sync with one another.</p><p>Introducing&#8230; <a
href="http://code.google.com/p/dbmapper/">dbmapper</a>:</p><pre>
Usage: com.moonspider.dbmap.GenerateConfig
  -type (-t) [String] The type to generate, either 'jpa' or 'gorm' (experimental) (jpa)
  -destinationDirectory (-d) [String] Destination directory
  -url [String] The url of the database
  -pkg (-package) [String] The target package ()
  -user (-u) [String] Database user (sa)
  -password (-p) [String] Database password ()
  -globalExtends (-extends) [String] Class for all Java classes to extend
  -globalImplements (-implements) [String] Class for all Java classes to implement
  -driver [String] Database drive class
  -extension (-ext) [String] File extension for the generated code (java)
  -hibernate [String] Generate hibernate.cfg.xml to this directory
  -jaxb [flag] Enable xml binding generation</pre><p>By default, the tool has a number of rules built into it that I will call &#8216;best practices&#8217; at least as far as we are concerned:</p><ol><li>Tables should have a primary key column named <strong>id</strong> and it should auto increment.</li><li>Foreign keys should be named ${foreignTableName}_id and be specified in the database.</li><li>Many-to-many join tables should be named ${tableName1}_${tableName2}.</li></ol><p>If for some reason you want to break one of these rules you will need to dig into the configuration of <a
href="http://code.google.com/p/dbmapper/">dbmapper</a>. On the JPA side there are a number of conventions that it uses:</p><ol><li>Class and property names are converted from _ separated to <a
href="http://en.wikipedia.org/wiki/CamelCase">CamelCase.</a></li><li>Many-to-one and one-to-one relationships are marked as eager.</li><li>One-to-many and many-to-many relationships are marked as lazy.</li><li>Relationship collections are suffixed with List rather than making them plural.</li></ol><p>Again, these are adjustable through a configuration file that I suggest that you never use unless absolutely necessary.  The most typical use case for the configuration file is when a database identifier conflicts with an identifier used in Java or Grails.  In this case you can either configure dbmapper or change your database.  DBMapper is designed to work well with the <a
href="http://code.google.com/p/dbmigrate/">dbmigrate</a> utility and in fact I recommend you use them together for the most leverage.  It is great to be able to add a new migration, execute the migration, generate new classes and see exactly the effect that your database change has on the domain model.</p><p>The default functionality is also available directly from <a
href="http://grails.codehaus.org/">Grails</a>. On the command-line simply type:</p><pre>grails install-plugin dbmapper</pre><p>This will contact the plugin repository and install the latest dbmapper plugin directly into your Grails application.  Assuming that you have configured your database in the normal fashion for Grails you can then generate domain classes directly from that connection with a single command:</p><pre>grails generate-domain-classes</pre><p>Assuming that is successful you will find all of your domain classes in the grails-app/domain directory and also a hibernate configuration file in your grails-app/conf/hibernate directory.  You should then be able to use tasks likes generate-all to create views and controllers for each of your domain classes.</p><p>There is also experimental support for creating <a
href="http://grails.codehaus.org/GORM">GORM</a> classes instead of JPA classes, however this really is experimental at this time and I suggest that you only try it if you are interested in fixing it.  GORM doesn&#8217;t seem to have the flexibility dbmapper needs quite yet.</p><p>Another feature of dbmapper is the ability to create <a
href="http://java.sun.com/webservices/jaxb/about.html">JAXB</a> annotations on the JPA classes so the objects can be read from and written to XML in addition to the database. The dbmapper framework itself is designed to be reasonably extensible.  By adding another template you can extend it to generate mappings to other persistence frameworks.</p> ]]></content:encoded> <wfw:commentRss>http://www.javarants.com/2007/10/14/generate-jpa-or-gorm-classes-from-your-database-for-java-and-grails/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Agile database schema migration tool for Java</title><link>http://www.javarants.com/2007/09/09/agile-database-schema-migration-tool-for-java/</link> <comments>http://www.javarants.com/2007/09/09/agile-database-schema-migration-tool-for-java/#comments</comments> <pubDate>Sun, 09 Sep 2007 18:49:03 +0000</pubDate> <dc:creator>Sam Pullara</dc:creator> <category><![CDATA[Java]]></category> <category><![CDATA[database]]></category> <category><![CDATA[migration]]></category> <category><![CDATA[schema]]></category> <category><![CDATA[upgrade]]></category> <guid
isPermaLink="false">http://javarants.com/wordpress/?p=854</guid> <description><![CDATA[Update: Grails Migration Plugin Forum About a month into building Gauntlet we found ourselves in a situation where it was impossible for us to keep our development databases up to date with the latest changes to the schema. We were &#8230; <a
href="http://www.javarants.com/2007/09/09/agile-database-schema-migration-tool-for-java/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p><font
color="#ff0000"><strong>Update</strong></font>: <a
href="http://www.javarants.com/sf-forum/?forum=1&amp;page=1">Grails Migration Plugin Forum </a></p><p>About a month into building <a
href="http://www.borland.com/us/products/silk/gauntlet/index.html" title="Borland Gauntlet" target="_blank">Gauntlet</a> we found ourselves in a situation where it was impossible for us to keep our development databases up to date with the latest changes to the schema.  We were sending around emails telling each other what changes need to be made alongside our check-ins.  In order to get around this problem I spent a few hours building a rudimentary database schema migration tool.  When you made a change to the database schema you would have to build a DDL file that would make the change and then update the version numbers for the Gauntlet software and within the database.  A few short months later and I discovered that we had built something very much like <a
href="http://garrettsnider.backpackit.com/pub/367902" title="rake migrate">&#8216;rake migrate&#8217; from Ruby on Rails</a> &#8212; in fact it was almost exactly the same except that ours worked at runtime rather than only from the command-line.  Fast forward a couple years later and I no longer own the Gauntlet source code, so yesterday I set out to <a
href="http://code.google.com/p/dbmigrate/" title="dbmigrate project" target="_blank">rebuild the schema migration tool from scratch</a> <a
href="http://svnfeed.com/convert?url=http%3A%2F%2Fdbmigrate.googlecode.com%2Fsvn%2F" title="RSS feed of dbmigrate" target="_blank"><img
src="http://www.javarants.com/feed-icon-14x14.png" border="0" height="14" width="14" /></a>.</p><p>The basic concept is very simple.  The first time your program connects to its database it calls the schema migration code to make sure that the code and the database are at the same version so that you are always using data objects and queries that match the schema that is present in the database.  When you make the call you need to pass the tool all the details about the database that you are connecting to, the place to find and classes or scripts to do the migration, and the current version of the client.  Then, if the database version is less than the client version, the migration tool systematically searches for first database type specific DDL classes/scripts then generic versions, executing them in turn to migrate the schema forward until the database version and the client version match.  If it encounters a case where the client version is less than the database version it has no recourse but to fail.  As a bonus, it also offers a version 0 transition where it will bootstrap you from a completely empty database to your initial schema.</p><p>For instance, lets say in version 1 of your database you have the following table:</p><pre>mysql&gt; describe event;
+---------------+---------------+------+-----+-------------------+----------------+
| Field         | Type          | Null | Key | Default           | Extra          |
+---------------+---------------+------+-----+-------------------+----------------+
| id            | bigint(20)    | NO   | PRI | NULL              | auto_increment |
| time          | timestamp     | NO   |     | CURRENT_TIMESTAMP |                |
| z             | bigint(20)    | NO   | MUL |                   |                |
| ip_address    | int(11)       | YES  |     | NULL              |                |
| user_agent_id | int(11)       | YES  |     | NULL              |                |
| referrer      | varchar(256)  | YES  |     | NULL              |                |
+---------------+---------------+------+-----+-------------------+----------------+</pre><p>Then you decide that you want to change the name of the referrer field to url.  In order to do that you would create a new migration script that updates the field name and the database version:</p><pre>
ALTER TABLE event CHANGE referrer (url varchar(256));
UPDATE db_version SET version = 2;</pre><p>You would name that script migrate1.sql and put it in the mysql specific database migration scripts.  You would also then update the client version to 2 as well.  Once that was done anyone who uses the new client code against their database will automatically get the schema changes required for the client to work with the database.  This drastically cuts down on the amount of communication that needs to occur in typical database development situations.  You can find the project that implements this db schema migration <a
href="http://code.google.com/p/dbmigrate">here</a>.  It has one dependency that is included with the project, my <a
href="http://code.google.com/p/cli-parser/" title="cli-parser project" target="_blank">cli-parser</a> <a
href="http://svnfeed.com/convert?url=http%3A%2F%2Fcli-parser.googlecode.com%2Fsvn%2F" title="RSS feed for cli-parser changes"><img
src="http://www.javarants.com/feed-icon-14x14.png" border="0" height="14" width="14" /></a>.</p> ]]></content:encoded> <wfw:commentRss>http://www.javarants.com/2007/09/09/agile-database-schema-migration-tool-for-java/feed/</wfw:commentRss> <slash:comments>23</slash:comments> </item> <item><title>PostgreSQL now has a native Windows port</title><link>http://www.javarants.com/2005/01/19/postgresql-now-has-a-native-windows-port/</link> <comments>http://www.javarants.com/2005/01/19/postgresql-now-has-a-native-windows-port/#comments</comments> <pubDate>Wed, 19 Jan 2005 18:37:56 +0000</pubDate> <dc:creator>Sam Pullara</dc:creator> <category><![CDATA[database]]></category> <category><![CDATA[postgresql]]></category> <guid
isPermaLink="false">http://www.javarants.com/?p=1016</guid> <description><![CDATA[PostgreSQL now has a native Windows port  <a
href="http://www.javarants.com/2005/01/19/postgresql-now-has-a-native-windows-port/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<div><font
face="Helvetica">PostgreSQL 8.0.0 was released to do and with it a native installer for Windows.  This closes one of the big barriers to adoption of the database and because of its superiority in all other areas may actually turn the tide against MySQL.</font></div><p><div><font
face="Helvetica"><a
href="http://www.postgresql.org/">PostgreSQL</a> should really be compared to <a
href="http://www.oracle.com">Oracle</a> rather than <a
href="http://www.mysql.com/">MySQL</a> but because it is open source it is often tossed in with MySQL in comparisons.  I don&#8217;t think there is much of a comparison though.  PostgreSQL, for me, is clearly a better enterprise database than MySQL will ever be because the focus of the two products are on such wildly different users.  Where MySQL has always focused on quick-and-dirty, PostgreSQL has always focused on doing things correctly.  Things like &#8220;transactions&#8221;, often used in real database applications, are not <a
href="http://www.innodb.com/index.php">bolted on with a different table type a la MySQL</a>, instead they are native to the system in PostgreSQL.  Conformance to the SQL standard has also been a focus for the PostgreSQL contributers and seemingly an afterthought for MySQL.  Another advantage is that <a
href="http://www.postgresql.org/docs/8.0/interactive/plpgsql.html">PostgreSQL&#8217;s stored procedure language</a> is very similar to Oracle&#8217;s whereas <a
href="http://dev.mysql.com/doc/mysql/en/Stored_Procedures.html">MySQL&#8217;s recently added stored procedure support is based on DB/2</a>.  Probably the most important difference to many may be that the <a
href="http://www.postgresql.org/about/licence">license for PostgreSQL</a> is the BSD license rather than <a
href="http://www.mysql.com/company/legal/licensing/opensource-license.html">MySQL&#8217;s mixed GPL/commercial license</a>.  PostgreSQL is as free as it gets.  Starting from that solid base PostgreSQL has also increased its performance to be on par with or better than MySQL in many benchmarks though in recent times it appears that people have decided that performance for databases is now &#8220;good-enough&#8221; and you don&#8217;t see that many direct comparisons.</font></p><p><font
face="Helvetica">My contention for a long time was that PostgreSQL doesn&#8217;t get nearly the adoption that MySQL gets was twofold. 1) PHP uses MySQL by default, therefore PHP users use MySQL by default and 2) MySQL was easy to install on Windows.  Now we can at least get rid of #2 with version 8.0.0 since there is now a standard distribution from the source for that platform.  If you are doing enterprise software development you should definitely <a
href="http://www.postgresql.org/download/">try out PostgreSQL</a> ASAP and you might save yourself either a big headache or a ton of dough.  As a side note, it blows my mind that the the <a
href="http://wwwmaster.postgresql.org/download/mirrors-ftp?file=latest%2Fpostgresql-8.0.0.tar.bz2">full source distribution</a> for the database is only 10MB compressed and the <a
href="ftp://ftp10.us.postgresql.org/pub/postgresql/win32/postgresql-8.0.zip">binary distribution for Windows</a> a mere 17.5MB and took about 2 minutes to install.  It includes a graphical installer and a graphical admin tool out of the box that really make it easy.</font></p><p><font
face="Helvetica">P.S.: pgAdmin III, the GUI utility doesn&#8217;t run on the Mac because it uses Tk, however you can use <a
href="http://phppgadmin.sourceforge.net/">phpPgAdmin</a> which runs fine and does about the same things.  You just have to <a
href="http://www.entropy.ch/software/macosx/php/">install PHP on your built-in Apache server</a> and then drop phpPgAdmin into your ~/Sites directory.  You can then access it with http://localhost/~user/phpPgAdmin.</font></div> ]]></content:encoded> <wfw:commentRss>http://www.javarants.com/2005/01/19/postgresql-now-has-a-native-windows-port/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
