GeeCON Prague 2014*
The moose likes Java in General and the fly likes Need help constructing this project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Need help constructing this project" Watch "Need help constructing this project" New topic
Author

Need help constructing this project

Tanya Ruttenberg
Ranch Hand

Joined: Jun 22, 2009
Posts: 40
In the past I've created more-or-less boilerplate web apps using seam-gen and then did some basic enhancement. I did not have to figure out how to structure the project. I am not a well-eduated developer (former sys admin and mostly self-taught) and there are some gaps in my knowledge.

I now want to create a simple batch job in java that would use a specific vendor API to get data from a proprietary database and plop it into mysql so the general public has access to it. How do I structure and run it? I have this idea to use EJB3 entity beans as an interface to the database, but I have no idea how to incorporate it into a simple project like this or even if it is possible to use it in this context.

Hope I've provided enough information. I can't figure out how to get started.

Thanks
TDR
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
I think for an application as simple as this you might want to avoid any frameworks. It seems to me you need the following small code areas:

1. MySQL Connectivity.
2. Proprietary API Connectivity.
3. Central Logic.

In number 1 you implement code (could be just a class) which configures access to the MySQL database and provides the ability to interact with it (you'll need a JDBC Driver and some SQL).
Number 2 will provide connectivity to the proprietary API and the ability to interact with it to extract the data (you'll need whatever the API is and write some methods which invoke its methods to get what you need).
Number 3 will provide the intermediary logic, calling number 2 to get the data and number 1 to store it in MySQL.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61311
    
  66

For a batch job you'd just write a simple Java application. No EJB or other such overhead as this will not be a web application.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tanya Ruttenberg
Ranch Hand

Joined: Jun 22, 2009
Posts: 40
Thanks for replies --

The reason why I think "EJB" is that I want to use an ORM framework to interface with database tables.

I was originally going write this script in perl and using the RoseDB ORM framework makes putting the data into the database SO much easier than using SQL queries. Is that not also true in Java? I assumed it would be, but maybe not. I think my head is stuck in the perl paradigm and I'm missing something fundamental about the java paradigm. I don't know.

I don't understand why EJB is more appropriate for a web application than a batch job. Isn't the bottom line that you use EJB when you want to solve the problem of classes interfacing with database tables?

Hope someone has more to add, because I'm still confused.
TDR
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14194
    
  20

Tanya Ruttenberg wrote:The reason why I think "EJB" is that I want to use an ORM framework to interface with database tables.

You don't need EJB for that. Java ORM frameworks such as Hibernate can map regular Java classes (often referred to as "POJO" = Plain Old Java Object) to and from database tables.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Tanya Ruttenberg
Ranch Hand

Joined: Jun 22, 2009
Posts: 40
Oh got it. Just plain POJOs with Hibernate.
That makes sense.

(I think I was conflating hibernate with ejb)
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
ORM is not a silver bullet - it does have cost - complexity, understanding its implications and nuances, creating all the mappings, etc. It is definitely worth the while if it helps reduce the complexity elsewhere. But for a small project, especially what sounds like a one-of type of thing (I assume you will port the data once from the proprietary database into MySQL and that's it), you will end up creating a lot of unnecessary classes, annotations and/or xml files, deal with all kinds of ORM related issues, etc. just to avoid writing some INSERT statements.

In fact, I think your original sentiment about using PERL may well be correct. If you're not going to reuse this thing much, and want just a straight data port, you're probably better off with a script than using Java.
Tanya Ruttenberg
Ranch Hand

Joined: Jun 22, 2009
Posts: 40
Once this script is written it will be run daily, but a script _like it_ will not have to written again.

The thought of writing those mapping files is a bit daunting as there are relationships that have to be maintained etc.

Still trying to figure out what to do -- I may use hibernate anyway just for the experience.

Thanks again.
TDR
Tanya Ruttenberg
Ranch Hand

Joined: Jun 22, 2009
Posts: 40
Here's what I ended up learning and doing.

1) I learned that you don't need hbm.xml files to use hibernate -- that was a relief. You can use the hibernate annotations on a pojo to map a class and its attributes to a table and its columns. Because I had never used plain hibernate before, I had confused hibernate with EJB. (I guess I'm still mystified as to what EJB adds or even is, but that's another discussion).

2) This is a good resource http://www.mkyong.com/tutorials/hibernate-tutorials/ Very easy to follow (if a bit outdated) tutorials/examples.

3) I created a maven/hibernate project using maven-archetype-quickstart and then more or less followed this tutorial http://www.mkyong.com/hibernate/maven-3-hibernate-3-6-oracle-11g-example-annotation/ substituting mysql for oracle.

It turned out to be so simple and now I can use this as a boilerplate for other small tasks that I used to accomplish in perl.

Thanks,
TDR
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help constructing this project