Monday, March 23, 2009

Hibernate optimistic locking

@Column(name = "VERSION", nullable = false, columnDefinition = "bigint default 0")
@Version()
private Long version;
try {
spaceShipManager.saveSpaceShip(ship);
} catch (HibernateOptimisticLockingFailureException e) {
return mapping.findForward("error");
}

Hibernate annotation default column value

@Column(name = "VERSION", nullable = false, columnDefinition = "bigint default 0")
private Long version;

Friday, March 13, 2009

Configure Interactive mode for QuickBooks Web Connector

The name of my computer is "b04".

1) generate SSL certificate for Tomcat (see tomcat-docs/ssl-howto.html from your Tomcat for details).
During generating certificate the answer on question "What is your first and last name" must be the name of your host (b04 in my case).

2) specify CertURL in your .qwc file:

...
https://b04:8443/services/MySOAPService
...
https://b04:8443/somepage.htm
...


3) return "" from sendRequestXML()
return "Interactive mode" from getLastError()
return "https://b04:8443/somepage.htm" from getInteractiveURL()

Terminate Java process

taskkill /IM java.exe /F
pause

Thursday, March 12, 2009

Hibernate bytecode instrumentation (enhance persistent classes) with help of Maven

Is used to enable Hibernate lazy property fetching. "**/model/*" are your persistent classes.

pom.xml:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>Instrument domain classes</id>
<configuration>
<tasks>
<taskdef name="instrument"
classname="org.hibernate.tool.instrument.cglib.InstrumentTask">
<classpath>
<path refid="maven.dependency.classpath"/>
<path refid="maven.plugin.classpath"/>
</classpath>
</taskdef>
<instrument verbose="true">
<fileset dir="${project.build.outputDirectory}">
<include name="**/model/*.class"/>
</fileset>
</instrument>
</tasks>
</configuration>
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
</dependency>
</dependencies>
</plugin>

Hibernate ddl (database schema) generation with help of Maven

pom.xml:
<plugin>
<!-- hibernate ddl generation -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.0-alpha-2</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<outputDirectory>.</outputDirectory>
</component>
</components>
<componentProperties>
<configurationfile>src/main/db/hibernate.cfg.xml</configurationfile>
<drop>false</drop>
<create>true</create>
<export>false</export>
<jdk5>true</jdk5>
<format>true</format>
</componentProperties>
</configuration>
<executions>
<execution>
<id>export-mysql</id>
<phase>process-classes</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<componentProperties>
<propertyfile>src/main/db/hibernate-mysql.properties</propertyfile>
<outputfilename>target/mysql-ddl.sql</outputfilename>
</componentProperties>
</configuration>
</execution>
</executions>
</plugin>

hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!--Annotated classes-->
<mapping class="com.etymgiko.lyricscollection.model.Artist" />
<mapping class="com.etymgiko.lyricscollection.model.Song" />
</session-factory>
</hibernate-configuration>

hibernate-mysql.properties:
# This properties file defines the dialect for the MYSQL database
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

Tuesday, March 10, 2009

Java System properties

import java.util.Arrays;

public class SystemProperties {

public static void main(String [] args) {
String [] keys = System.getProperties().keySet()
.toArray(new String [] {});
Arrays.sort(keys);
for (String key: keys) {
String value = System.getProperty(key);
System.out.println(key + ": " + value);
}
}

}

Monday, March 2, 2009

Maven compile sources version 1.5

Add following to pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>

Sunday, March 1, 2009

Maven artifact sources

Download sources of artifacts (from pom.xml) to local repository.

set JAVA_HOME=C:\jdk1.6.0
set MAVEN_HOME=D:\java\apache-maven-2.0.9
%MAVEN_HOME%\bin\mvn dependency:sources

Thursday, February 26, 2009

Hibernate Spring where clause

public List getSongs(Long artistId) {
return getHibernateTemplate().find("from Song as song where song.artist.id = ?", new Object [] {artistId});
}

Wednesday, February 25, 2009

Use regexp in Digester

How to configure Digester to use reg exp pattern like *
<pattern value="*AddRs">
...
<pattern>

URL rulesXml = getClass().getClassLoader().getResource(path);
RuleSet ruleSet = new FromXmlRuleSet(rulesXml);
Digester digester = new Digester();
digester.setRules(new RegexRules(new SimpleRegexMatcher()));
digester.addRuleSet(ruleSet);
return digester;

Maven dependency tree

set JAVA_HOME=C:\jdk1.6.0
set MAVEN_HOME=D:\java\apache-maven-2.0.9
%MAVEN_HOME%\bin\mvn dependency:tree > dep.txt

Followers