WP-Syntax plugin styles
I’m using the wp-syntax plugin to get these nicely formatted code boxes for a variety of programming languages. These are the CSS definitions that must be included in a theme:
.wp_syntax {
color: #100;
background-color: #f9f9f9;
border: 1px solid silver;
margin: 0 0 1.5em 0;
overflow: auto;
}
/* IE FIX */
.wp_syntax {
overflow-x: auto;
overflow-y: hidden;
padding-bottom: expression(this.scrollWidth > this.offsetWidth ? 15 : 0);
width: 100%;
}
.wp_syntax table {
border-collapse: collapse;
}
.wp_syntax div, .wp_syntax td {
vertical-align: top;
padding: 2px 4px;
}
.wp_syntax .line_numbers {
text-align: right;
background-color: #def;
color: gray;
overflow: visible;
}
/* potential overrides for other styles */
.wp_syntax pre {
margin: 0;
width: auto;
float: none;
clear: none;
overflow: visible;
}
IBM and SAP Open Source their JVM Diagnostics Tools
A few weeks ago already I came across a InfoQ article which discusses plenty of tools for hunting down memory problems.
SwingLabs PDF Renderer
In 2003, developers at Sun Labs developed a PDF Renderer which in december has been released under the LGPL as part of SwingLabs. So now it should be much easier to integrate PDF solutions into rich client apps.
Oracle 9.2+ JDBC Driver DATE type problem
With Oracle 9.2 some changes regarding the DATE type and the new TIMESTAMP type were introduced. These are causing problems with the JDBC driver when an application is expecting a DATE column to contain time information. These issues and a workaround are discussed in this article from Oracle.
This article proposes a few workarounds that you might be able to apply or not. Today I encountered a case that was troubling me for a while.
I’m using Hibernate 3.2.5.ga to map a class to some legacy table containing a DATE column holding date + time information. The property mapping looks as simple as <property name="timestamp" column= "MESSAGE_TIMESTAMP"/ >.
I have configured Hibernate with hibernate.hbm2ddl.auto=validate so my mapping files are checked against database metadata. As a result Hibernate would throw an exception at me telling that it can’t match the column type with the POJO property type.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/context-web.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Wrong column type: COMM_MSGDT, expected: timestamp
Caused by: org.hibernate.HibernateException: Wrong column type: COMM_MSGDT, expected: timestamp
at org.hibernate.mapping.Table.validateColumns(Table.java:261)
...
If you don’t need time information you can get around this execption by tweaking the type information for the property mapping (<property name="timestamp" column="MESSAGE_TIMESTAMP" type="date"/>) otherwise if time is required then you are in trouble!
The Oracle article above is suggesting to set a system property (as a JVM start parameter) which is kind of difficult to handle during deployment. So I was investigating the other option which is to set the connection property (oracle.jdbc.V8Compatible=true) for the Oracle JDBC driver, this option would allow a deployment configuration that is working “out-of-the-box”. Reading the Tomcat documentation on how to configure a JNDI DataSource led me to the DBCP documentation that is explaining this thoroughly.
I’m using a Tomcat managed DataSource. So I’m having a META-INF/context.xml file to set up the DataSource. To fix the type problem just add the property connectionProperties.
Mock Testing
A few weeks ago I have switched my favourite mock testing framework from Easymock to jMock. Not that I would say that Easymock is bad or has problems (I haven’t encountered any), I just found jMock more intuitive and it seems that it heavily relies on equals() to check test behaviour. After I started using jMock I had put my eyes on properly implementing equals() and hashCode() methods (utilizing the commons-lang library). So in general, I feel this also helps improving code quality!
Create reusable hibernate mappings
Complex mappings very often tend to result in repetitive mapping definitions especially when trying to apply concepts from Domain Driven Design. Value objects (value types as they are called by Hibernate) are a typical example for those kind of repetitive tasks.
Let us assume that you want to keep track of user and time a set of entity types has been updated. So you would add a component mapping to all of the entity mappings where this feature is required.
This can get really tedious, so you might want to look for a more elegant solution that allows re-using this component mapping. Hibernate does not offer a mapping element that allows to include some externalized mapping fragment. But XML supports including XML documents through it’s DTD entity facility.
So you first start by moving the XML fragment that should be reusable to a file (e.g. domain/model/LastUpdate.xml)
For mapping file that requires the lastUpdate component an external ENTITY declaration must be added, the entity reference (&lastUpdate;) is a place holder that is replaced by the entity.
]>
&lastUpdate;
Upgrade to ShareThis 2.0
I had used ShareThis 1.4 for a while in my blog but had problems with displaying the icon next to the SharThis link. Today I upgraded to version 2.0 and everything is working fine now.
Hibernate and Generics
Wherever possible I try to apply some principles from Domain Driven Design. So I also use Value Objects – some of them implemented based on Java5 Generics
Example:
public class Range {
private T start;
private T end;
public Range() {
super();
}
public Range(T start, T end) {
super();
this.start = start;
this.end = end;
}
public T getStart() {
return start;
}
public void setStart(T start) {
this.start = start;
}
public T getEnd() {
return end;
}
public void setEnd(T end) {
this.end = end;
}
}
Hibernate is not able to determine the proper type (org.hibernate.MappingException: property mapping has wrong number of columns …) for the properties of the value object unless they are explicitely described in the class mapping.
For a Range with Date as template parameter you would map:
