27 Nov 2008

Insert big data chunk into MySQL

Inserting 370 000 records in a mysql table was taking ages!
Found this little trick:
LOAD DATA CONCURRENT LOCAL INFILE 'C:\\my\\path\\to\\folder\\records.sql' INTO TABLE FOO;

Useful under Windows and MySQLQueryBrowser ;)

MySQL funny command line option

While searching for help for mysql ubuntu command line tool:

$ mysql --help
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
...
-U, --i-am-a-dummy Synonym for option --safe-updates, -U.
...

19 Nov 2008

Flag a blog post as deprecated

While looking for some info on capistrano I stumbled on this post: "Ant sucks for FTP deployment - What alternatives do we have?".

The funny thing is the deprecated notice:


I often use @deprecated for the code but I never though of using it for my old blog posts... good idea :)

And it's also a good way to always keep url even if they display wrong or inaccurate info, just like describe in this w3c document "Cool URIs don't change."

Simple Jdbc

I wanted to use spring JdbcTemplate to simplify my jdbc code but I had to add 3 jars just to use it !
  • spring-jdbc.jar
  • spring-tx.jar
  • spring-core.jar


spring-tx.jar because I got this error:
The type org.springframework.dao.DataAccessException cannot be resolved. 
It is indirectly referenced from required .class files
TestSpring.java

spring-core.jar because I got this error:
The type org.springframework.core.NestedRuntimeException 
cannot be resolved. It is indirectly referenced from required .class files
TestSpring.java

And I wasn't even sure about the transaction part, did I need to include spring-beans.jar and spring-context.jar; start to use a TransactionTemplate and configure a PlatformTransactionManager with tons of xml configuration, services and dao(s) :(

So I decided to make a small but simple project doing exactly what I wanted: jdbcTemplate and I made it public on sourceforge.

Don't expect any documentation or support for this, it's just that I don't want to redo this code on my next jdbc project (if that ever happens).




You can also take a look at DbUtils at http://commons.apache.org that does just the same ;)


 

12 Nov 2008

Why you should use JUnit4

I've been using JUnit 4 from time to time but never really understood the benefit moving from version 3 to version 4.

That's because I never took time to take a look at new features :o

Don't be like me ;) Just take a look at this article: "Junit 4 in 60 seconds"

You will discover annotations like:
  • Better Exception Handling with @Test(expected = ArithmeticException.class)
  • @Ignore("Not Ready to Run")
  • @Test(timeout = 1000)

Small enhancements making testing easier and clearer!

5 Nov 2008

New Java Date Time Api

This is a good news: Date and Time API: Round 3. Date and Time parsing is always a mess... if they could just remove the old api (and not be backward compatible) that would be even better but it takes courage.

Come on almost all java.util.Date methods are deprecated since Jdk version 1.1... It's time to change!

27 Oct 2008

Fixing log4j email notification under ubuntu

I had a problem under ubuntu to use log4j email notification through SMTPAppender.

The problem:

java.lang.NoClassDefFoundError: gnu/inet/util/GetSystemPropertyAction
at javax.mail.internet.ParameterList.(ParameterList.java:72)
at javax.mail.internet.ContentType.(ContentType.java:104)
at gnu.mail.handler.Text.getJavaCharset(Text.java:160)
at gnu.mail.handler.Text.writeTo(Text.java:140)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:868)
...


Solution:

I think :
apt-get remove libgnuinet-java

is enough but this is the exact command I had to run:
apt-get remove libgnuinet-java libgnujaf-java libgnumail-java-doc


Env:
Jetty 6, java 6, log4j 1.2.15 + commons-logging 1.1

Log4j conf:

log4j.rootLogger=INFO, CONSOLE, FILE, EMAIL
# EMAIL
log4j.appender.EMAIL=org.apache.log4j.net.SMTPAppender
log4j.appender.EMAIL.SMTPHost=xxx
log4j.appender.EMAIL.From=xxx@xx.com
log4j.appender.EMAIL.To=xxx@xx.com
# log4j.appender.EMAIL.SMTPUsername=xxx
# log4j.appender.EMAIL.SMTPPassword=xxx
log4j.appender.EMAIL.Subject=[MyApp] Application Error
log4j.appender.EMAIL.layout=org.apache.log4j.PatternLayout
log4j.appender.EMAIL.layout.ConversionPattern=[%d] [%t] %-5p %c %x - %m%n
log4j.appender.EMAIL.Threshold=ERROR
log4j.appender.EMAIL.BufferSize=1
# log4j.appender.EMAIL.SMTPDebug=true


I'm also using sun jvm using this command:
update-java-alternatives --set java-6-sun

29 Sept 2008

Gmail Ads doesn't filter content

While reading a mail in gmail about technical webapp stuff, I find this sponsored link quite surprising ?!



Translated in english, it says:
Fed up with GWT? Try ZK
Understand why GWT is the root of all evil for your project

Gmail doesn't filter the content of it's ads ;)

Technorati tags:

12 Sept 2008

Is node order important in xml ?

"Is node order important in xml ?"

This has always been a pending question, I wanted to answer.

The quick answer:
  • No dtd, xml schema(xsd) validation, node order doesn't matter
  • Any type of xml validation, order does matter (unless using a special notation in the schema)
The long answer:

For a long time I was pretty sure the order wasn't important, you could write:

<root>
<node1/>
<node2/>
</root>

and

<root>
<node2/>
<node1/>
</root>

It was the same...

But when using eclipse and validating an xml document, the validator kept complaning if the node were not in the same order as describe in the xsd.

I didn't know if it was an eclipse validator limitation (the validator wasn't able to cop with node order) or a w3c xml requirement.

Untill I found this IBM page describing the same exact issue ;)
Principles of XML design: When the order of XML elements matters

Apparently you can specify in an relax ng schema that order doesn't matter (using ampersand "&") (see: chapter "Schema constraints of element order") but I suspect many people (me included) to use the easiest path and use the comma notation.
As a side effect that means the order does matter, but people writing schema usually don't do this on purpose...


Technorati tags:

[Eclipse] No more Ctrl+O Ctrl+F

I'm pretty sure many eclipse "guru" already noticed it but in eclipse ganymede you can now auto-format and auto-organize import on save.

But now it's available by default in eclipse :)

Just go to "Windows > Preferences" and find the "Save Actions" menu:



Technorati tags: