Wednesday, February 9, 2011

About Hibernate 3 plugin for Maven

In one of my previous entries, I had something really cool on my POM, which basically generated the DataBase based on my Entyties (or Domain objects), and that was the Hibernate 3 plugin for Maven
As you will see on the official documentation for that plugin, you can do a bunch of things, but it doesn't says anything about, generating Java classes based on the Tables, right? In other words, if I want my model java files (obtained by reveng) compiled, you don't need to run hbm2hbmxml.
I found the solution to this issue (unfortunately is not documented, and that's why you see it here):

Plugin configuration
hibernate.properties
hibernate.connection.username=root
hibernate.connection.password=secretit0
hibernate.connection.url=jdbc:mysql://127.0.0.1:3306/little_store
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.default_schema=little_store

model_reveng.xml
Then the last step is executing Maven:
mvn hibernate3:hbm2java

And we're ready to roll! :)

Is your Computer boy or girl?

If you want to hear the voice of your Computer, what you can do is write this simple code into a notepad and save it with extension *.vbs

And you'll hear your computer speaking :P

Tuesday, February 8, 2011

Reading text files on MS-DOS

In my previous entry, I was trying to process a text files (a CSV), using each line of that file as input for my SQL*Plus call.
But, what happens if you don't have a UNIX box where you can execute it??? :(
Let's write my shell script into a batch file (oh man!), and this is the result: Where %%a is the first token, %%b the second one, and so on (until we'd reached the fourth token - as specified on tokens=1,2,3,4)
At the end, it was simple :D

Friday, February 4, 2011

Report in SQLPlus using spool to write a file

On my previous entry I'm reading a file and using each line as input to make an external call (call SQL*Plus for example) Well, this is my SQL (script) to be executed using SQL*Plus, in other words, I will execute this query for each line of a given file (shell script), each time that I call SQLPlus I'll append to the spool (output file) the result of my query (I'll pass as parameter to my query the parameter given on command call)
sqlplus CIDB/CIDB1234@CIDB @input_file.sql PRE11221000001

And this is my Query (my report, because I'm adding more stuff)
&&1
is the first parameter after the script namde in command line, then the second param will be &&2 then the third one &&3 and so on

My output will be a file named: output_file_2011-02-04.LST

For more information and references please see the official Oracle web site for SQL*Plus:
Ref 1
Ref 2
Ref 3
Ref 4

Read File using Unix Shell

This is something really small which could be useful in case you want to read a comma separated file and use each line (on this case to call an external program passing as parameter each field value)

Run a SQLPlus script and pass a parameter as input

Simple:

Then your script:
begin dbms_output.put_line(&&1);
dbms_output.put_line(&&2);
end;
/