Joine Music

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Wednesday, 26 July 2006

My Current Firefox Extensions

Posted on 09:56 by Unknown

Here's a snap of my current firefox extensions. Not too few, not too many, but just enough...


Read More
Posted in | No comments

Tuesday, 11 July 2006

EJB 3.0: One Model Inside and Out (Pt. 2) - The POJO Model Itself – Annotations and Relationships

Posted on 03:26 by Unknown
Please note, this blog entry is based heavily on many other things out there on the web at the moment, most particularly this tutorial on netbeans.org. I've taken this liberty, as I thought I needed to provide a firm bedrock upon which to build my later entries in this series where I do go into uncharted territory. If I have infringed any copyright, please do tell me and I will take appropriate action.

I hate databases. We don't get on. They don't respect me, and as a result I don't respect them. Therefore I always like to start my OO apps. by encapsulating the domain model in a class model. For the Loads-A-Movies project mine was very simple:

If it looks simple, it's supposed to. Lets create the classes.

Creating the Movie Entity Class

This will represent the table “MOVIE” in the database. We first need to generate a simple, serializable java POJO class with the attributes shown above encapsulated as appropriate (you can do this automatically with your chosen GUI). This now needs to be annotated to let the compiler know how to treat it. (Note: This requires JDK annotation support which you'll get if you use Java 5)

 ...
public class Movie implents Serializable {
private Long id;
private String title;
private int runningTime;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}
...

First up we need to let on this is an Entity Class. We do this simply by using the “@Entity” annotation before the “public class Movie implements Serializable” line. The compiler is now clever enough to know that, unless told otherwise, the attributes on this class will be represented as columns in our table. That's how EJB 3.0 works. It assumes the default, unless you tell it different. Very handy.

 ...
import javax.persistence.Entity;
...
@Entity
public class Movie implents Serializable {
...

The observant amongst you will realise that we most likely need a primary key. Correct, each entity class must have a primary key. When you create the entity class, we must add an @Id annotation to the “id” attribute to declare we plan to use it as the primary key. We also add the @Generated... annotation to specify the key generation strategy for the primary Id. In our case:

 ...
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
...
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
...

Finally for Movie, there is the interesting case of the relationship with the Actor Entity class. Firstly we need to add the collection attribute, “Collection actors;” and encapsulate it (again you can do this automatically with your GUI if you so desire). Now you need to provide some information about the relationship. Add the following annotation above the actors collection to specify a One-to-Many relationship for the entity:

  import javax.persistence.OneToMany;
...
@OneToMany(mappedBy="movie")
private Collection actors;
...

And that's the Movie Entity class coded. We now need to do the same for the Actors. As before, create a POJO class (ensuring you “implement Serializable”) with the required attributes encapsulated. This will represent the "ACTOR" table in the database. Again define it as an Entity with the @Entity annotation and mark the “id” attribute as the primary key and set it to
be auto generated with the @Id and @Generated tags.

Again we need to add the new attribute. in this case it's the Actior nowing about the film he has appeared in:

 private Movie movie;

Again, encapsulate this attribute. Finally we need to add the annotation to let on that this is the reverse direction of the previous relationship. We do this by putting the following annotation above the new movie declaration:

  import javax.persistence.ManyToOne;
...
@ManyToOne

private Movie movie;

Note: You'll have noticed that you require imports for these annotations. These are contained in the “javaee.jar” package which I needed to declare as a dependency in my maven project.xml file. I found the one I used in my GlassFish server's /lib directory. If you're doing it differently maybe your IDE has suggested one for you.


That's all for this entry. There is far more information on the possibilities of EJB 3.0 persistence which I haven't gone into. The best sources for more information I have found are as follows:
  • Java Persistence in the Java EE Platform - tutorial at netbeans.org
  • Standardizing Java Persistence with the EJB3 Java Persistence API - Article at OnJava.com
  • The Java Persistence API - A Simpler Programming Model for Entity Persistence - Article at java.sun.com
Read More
Posted in | No comments

EJB 3.0 - One Model Inside and Outside the Container (Pt. 1)

Posted on 02:44 by Unknown
I'm writing a suite of (i.e. two) applications which share an object model. I'm a trained J2EE architect and consequently I love the idea of maximum code reuse. I'm also lazy. In the following series of blog entries I'm going to explain how I managed to achieve this using Java 5, EJB 3.0 (including persistence) and Maven.

First up, lets have a quick overview of what I'm trying to achieve. The plan is to create a website to store information about my film collection. I want to be able to do all kinds of fancy things but really it's an excuse to fiddle around with Java 5, generics, annotations, JSF, EJB 3.0 and Maven. I have a cunning plan however. I love the idea of the Flickr uploader but I want to take it further. What if I could have a local, thick Swing app. which I could keep in sync. with my web app. and use to upload and maintain info on my public website? It could use the same model code... That would be cool. It would also let me fiddle with the Matisse GUI builder, Derby and most importantly the Napkin look and feel...

So how am I going to approach this? Well, the plan is to have three separate maven projects, with all the common stuff factored out into a code-less master project (I won't go into this any further, that's a separate blog entry). The first is to be the model project; “loadsamovies-model” which we will discuss in the next blog, the second the web presentation layer; “loadsamovies-presentation” which I don't plan to go into as the techs and methods is covered in great detail elsewhere. The last is the uploader Swing app; “loadsamovies-thickclient”

See the next entry for how I coded up the model.
Read More
Posted in | No comments

Sunday, 9 July 2006

Booting Apache Derby ("JavaDB") with your Java App's Startup

Posted on 09:58 by Unknown
If you're embedding the Derby RDBMS with your java desktop application and want it to start when you start your app, you need to make the following call somewhere in your code (i.e. in main() or an init() method):
        // Start the Derby Database
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver")
.newInstance();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (InstantiationException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
}

// Set the connection to the database
Connection conn = null;
try {
conn = DriverManager
.getConnection("jdbc:derby:sample;create=true");
} catch (SQLException ex) {
ex.printStackTrace();
}

It's important to notice (as I didn't to begin with) that you need the local version of the URL as you are doing this using the embedded driver. If you use the URL version you'll get a "java.sql.SQLException: No suitable driver" error.


You'll also notice that this creates the database with the name provided in a directory with the name provided, (e.g. "sample"). This directory will be in the same place as the main class you are running.

One final thing, this is dead easy to use with EJB 3.0 too. All you need to do is set up your persistence manager to run outside a container and as soon as you have started your embedded database, you can connect to it with something like TopLink. Beautiful....
Read More
Posted in | No comments

Saturday, 8 July 2006

Ubuntu Superusers

Posted on 03:31 by Unknown
I came to Ubuntu (Dapper Drake) from Solaris. I thought I'd be able to log in as the root user or su from the command line to my heart's content. It's not that simple. By default you can't log in or su to the root user as I expected. To perform admin tasks as a non root user you need to use the sudo command (this was in fact running for me withjout my knowledge as I ran the various admin tasks to set things up after install. For info on the sudo command, look at the Dapper documentation wiki.
Read More
Posted in | No comments
Newer Posts Older Posts Home
Subscribe to: Comments (Atom)

Popular Posts

  • (no title)
    The Significance and Importance of Quotes in JSTL EL I just spent a few hours debuggung a null pointer in a Portlet JSP I'm writing. It...
  • (no title)
    Agile Development Ramblings: Part I Introduction I've just completed my first Agile development project. We developed a fully functiona...
  • EJB 3.0 Outside the Container, Inside the JVM - Part 2: Configuring JPA Declaratively
    Welcome to part two of this blog entry introducing using EJB3.0 inside the JVM. Click here to view the first part. As we've seen, JPA ...
  • Reuse (ii): Definition of Done
    As I said in my previous post , our project has suddenly taken a new path. There are two bits of collateral which I'd recently produced...
  • Notes from the FindBugs BOF9231 at JavaOne 2007
    NOTE: These are my incomplete notes from the FindBugs BOF at JavaOne 2007. I got in late due to the crush outside so missed the start of th...
  • Writing Unit Tests to Ensure Your "@Transactional ... rollbackFor" Annotations are Honoured
    Thanks to Russ Hart for providing the info on how to get this to work.  I just cut and paste, and then blogged it. It's nice to write un...
  • (no title)
    Can Your Own Demo I found something great on t'internet the other day. I had been asked to do a demo of our new ystem to some users but...
  • JavaOne Bred Over-Enthusiasm...
    I want to build and fiddle with Wonderland , and my own JDK ! The problem is my graphics card sucks (I need acceleration) and I'm runnin...
  • Booting Apache Derby ("JavaDB") with your Java App's Startup
    If you're embedding the Derby RDBMS with your java desktop application and want it to start when you start your app, you need to make th...
  • STS and RTC – Getting them to Play Nice
    We’re developing our new app using Spring 3.0 RC1 and we want the best tools available. We’ve picked the following: SpringSource Tools ...

Categories

  • 0
  • 2008
  • ant maven pimp build javaone 2008
  • apple ipod touch
  • asm
  • blog new ruby
  • blogtag list
  • bond casinoroyale mashup mi6 film movie
  • build
  • bytecode
  • CI
  • cobertura
  • communityone 2008 nutter jvm scala jruby groovy davinci
  • communityone 2008 opensocial socialsite
  • communityone javaone keynote oreilly
  • configuration
  • cowley
  • css div layout column ie firefox safari example
  • custom
  • darkstar mpk20 wonderland java3d commaboration SL
  • dashboard rss communication news development
  • db2 database SQL max min howto tip
  • db2 database ibm lessons tips
  • db2 database load batch howto example
  • db2 import upload data howto command
  • debt technical java annotation
  • debugging tips javaone 2008
  • development web2.0
  • findbugs JavaOne 2008 pugh
  • findbugs JavaOne BOF notes
  • gafter closures java javaone notes
  • google trouble patriarchal patriarchy
  • groovy metaprogramming javaone 2008
  • grubby oss data generation project announce
  • guice javaone 2008
  • gwt maven howto example simple
  • howto
  • hudson
  • hudson CI javaone 2008
  • ibm
  • invokeDynamic jvm dynamic ruby javaone
  • itinerant web2.0 portable desktop
  • jacl was websphere wsadmin trace logging
  • james gosling sun java open source tech days second life SL
  • jar java manifest properties config howto tip
  • java
  • java applet javaone 2008 reloaded jnlp
  • java javafxscript javaone 2008 fxscript
  • java javaone 2007 07
  • java javaone 2008 bytecode cobertura asm singleton testability
  • javaone
  • javaone keynote gage schwarz javafx
  • javaone semantic web bof notes web3
  • jazz
  • jruby rails javaone charlesnutter thomasenebo
  • jruby ruby netbeans development
  • kill dead laptop computer rebuild restore
  • lessonslearned
  • mac osx java gui shellscript classpath problem solution
  • maven plugin unittest test packager
  • mylin mylar javaone eclipse 2008
  • netbeans development ide
  • netbeans development ide RC
  • netbeans maven2 profiling
  • netbeans ruby sun tech days visual web pack roman strobl
  • ola bini java javaone 2008 thoughtworks ruby jruby
  • openjdk java javaone javafx wonderland
  • overheard
  • pojo ejb3.0 jpa orm java example howto
  • rant
  • rest restful jsr311 java web2.0 javaone ts-6411
  • rome rss feed blog rss atom propono java javaone
  • rsa uml profile plugin howto
  • ruby inheritance example
  • ruby jruby rss xml hpricot
  • ruby unless example
  • scm
  • setup
  • subversion svn xp windows cleanup
  • sun java soa web2.0 netbeans opensource javacaps
  • sun tech days java derby database rdbms london
  • sun tech days london impressions
  • terracotta java javaone 2008 android gwt
  • tip
  • tips
  • vwp netbeans JPA howto
  • was jython scripting nfr ibm pmi jvm
  • was tpv jython scripting nfr ibm pmi
  • webrick ruby jruby actadiurna investigation code howto
  • workitem

Blog Archive

  • ►  2012 (1)
    • ►  October (1)
  • ►  2010 (8)
    • ►  November (1)
    • ►  October (3)
    • ►  June (1)
    • ►  May (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2009 (9)
    • ►  December (1)
    • ►  November (5)
    • ►  March (2)
    • ►  February (1)
  • ►  2008 (22)
    • ►  December (1)
    • ►  November (3)
    • ►  May (15)
    • ►  March (1)
    • ►  January (2)
  • ►  2007 (53)
    • ►  December (1)
    • ►  November (3)
    • ►  September (3)
    • ►  August (2)
    • ►  July (3)
    • ►  June (1)
    • ►  May (12)
    • ►  April (5)
    • ►  March (13)
    • ►  February (7)
    • ►  January (3)
  • ▼  2006 (35)
    • ►  December (8)
    • ►  October (1)
    • ►  August (1)
    • ▼  July (5)
      • My Current Firefox Extensions
      • EJB 3.0: One Model Inside and Out (Pt. 2) - The P...
      • EJB 3.0 - One Model Inside and Outside the Contain...
      • Booting Apache Derby ("JavaDB") with your Java App...
      • Ubuntu Superusers
    • ►  June (8)
    • ►  May (3)
    • ►  April (7)
    • ►  March (2)
Powered by Blogger.

About Me

Unknown
View my complete profile