Tuesday, November 25, 2008

Calendar and date ranges

I hate Java's Calendar and Date apis.  Hopefully JSR 310 will improve things.  

In the meantime, here's a trick for selecting based on a date range :

Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR, (cal.get(Calendar.HOUR) - 1));
beforeDate = cal.getTime();
cal.set(Calendar.DATE, (cal.get(Calendar.DATE) - 1));
cal.set(Calendar.HOUR_OF_DAY, 00);
cal.set(Calendar.MINUTE, 00);
cal.set(Calendar.SECOND, 00);
afterDate = cal.getTime();
The beforeDate member variable is set to the current date minus one hour.  Then the cal Calendar instance is set to 12:00 AM the day before.

Friday, November 21, 2008

Dashboard wouldn't start

I got a new MacBook Pro at work.  I'm completely happy about that!

Dashboard quit working.  It might not have ever worked, but I think it did.  After installing a new widget it wouldn't start.

I typed :   defaults write com.apple.dashboard mcx-disabled -boolean NO
Followed by : killall Dock

Dashboard worked fine after that.

I found the answer here.

Wednesday, November 12, 2008

Seam-gen and Oracle Express

I installed Oracle Express.  I created a user, "local," with the creative password, "local."  I created a project with seam-gen.  I created an entity object and annotated the id column with :
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id", unique = true, nullable = false)
private Long id;
On deploy I saw in the logs :
09:42:14,281 INFO  [SchemaExport] exporting generated schema to database
09:42:14,609 ERROR [SchemaExport] Unsuccessful: create table TABLE_NAME (id number(19,0) not null unique, name varchar2(30) not null, description varchar2(200) not null, inputChannel varchar2(100) not null, outputChannel varchar2(100) not null, parser varchar2(100), primary key (id))
09:42:14,609 ERROR [SchemaExport] ORA-02261: such unique or primary key already exists in the table
The message, "such unique or primary key already exists in the table," led me to believe that the table existed.  However, I couldn't see it using the Oracle web interface.  Or SQL Developer.  Or MyEclipse. 

So I ran the statement in the web interface.  Same error. 

The problem turned out to be that the statement was creating the id twice.  First with, "id number(19,0) not null unique," and second with, "primary key (id)."

I changed the syntax, and it worked.  As for the annotations, I removed the "Column" annotation :
@Column(name = "id", unique = true, nullable = false)
When I redeployed it worked fine.

The working annotation was :
@Id
@SequenceGenerator(name = "TABLE_NAME_SEQUENCE_GENERATOR", sequenceName = "TABLE_NAME_SEQUENCE")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TABLE_NAME_SEQUENCE_GENERATOR")
private Long id;

Tuesday, October 21, 2008

JBossWS Eclipse JUnit Error

I played with JBossWS for the first time this evening. I'm runningEclipse with JBossTools installed. It was easy enough to compile (Ant task) and import the project into Eclipse.

However, when I ran the tests I got a "Java Virtual Machine Error." The popup read "Could not find the main class. Program will exit." There's an post about this in the JBoss forums but no answer.

The tests run from Ant (even within Eclipse.) While running the tests from the command line a second time I noticed the following message :

tests-prepare: [echo] [echo] ----------------------------------------------- [echo] jboss.home = C:/tools/servers/jboss/jboss-4.2.3.GA [echo] excludesfile = C:\tools\jbossws\jbossws-native-3.0.4.GA\jbossws-native-bin-dist/tests/resources/test-exclude s-jboss423.txt [echo] java.home = C:\tools\java\j2se5.0u16\jre

It's pointing to the jre of my java home for some reason. I check the environment variable by running, echo %JAVA_HOME%, but it is pointing to the base install not just the jre.

Searching through the project for "jre" doesn't return anything. I hate to give up before I find a solution, but I had stuff to get done.

I ran the "ant eclipse" task again and imported into a fresh Eclipse install. No problem running the tests.

I'll try to reproduce and file a Jira issue. I thought I'd post this just in case anyone else is banging their head against the same wall.



Thursday, October 16, 2008

Running Eclipse in a full JDK

After installing the Maven plugin I got a warning that Eclipse should run in a full jdk.  The solution is really simple (and on the Eclipse wiki), and I was kind of surprised I hadn't run into this before.

Simply add the following to eclipse.ini (found in the Eclipse install folder) :
-vm
path-to-your-jdk (C:\tools\java\j2se5.0u16\bin\javaw.exe for example)

 
Blogged with the Flock Browser

Thursday, September 25, 2008

gVim

Want to change your font in gVim?  Here's how.  I love the title of that page, "Troubleshooters.com and T.C Linux Library Present Permananetly Changing Your Graphical Vim Font"

If you want to change the color scheme, edit your _vimrc file on Windows, which is located in :  C:\Program Files\Vim.  Simply add "colors [name of the color theme you want to use]."  The themes themselves can be found in C:\Program Files\Vim\vim72\colors.  I like "darkblue."
Blogged with the Flock Browser

Seam-gen, HSQLDB and development schemas

I like using HSQLDB's in memory db for early development.  Changes the annotations on my entities and letting hbm2ddl create the schema (tables actually which is what this post is about) for me is way useful.  One of the best things about Seam IMHO.

I ran into an error in my curent project which I set up using seam-gen and giving it a schema name of "PROJECTDEV."  After creating an entity class, "Job" I ran "seam generate-ui" from my project directory.  I deployed expecting to see the default crud screens that seam generates.  However, when I clicked on the "Job List" link I got an error.  The console told me something was wrong with my schema :

Caused by: java.sql.SQLException: invalid schema name in statement

And looking further back in the logs I found error messages from Seam while the schema export was running:

[SchemaExport] invalid schema name: PROJECTDEV in statement

Poking around the web I found some references to this problem on the Hibernate forums, JBoss forums and JBoss Jira. 

I tried putting :

CREATE SCHEMA PROJECTDEV AUTHORIZATION DBA;

in my import.sql file, but that didn't work.  Same errors.

I had to create the schema manually in the HSQLDB database manager (I have a post on how to use this if you don't already know how.)  After that everything worked fine.
Blogged with the Flock Browser