Tuesday 15 November 2011

Config & code snippets

This is my notepad post containing some config and code snippets.

Enabling JRebel in the Eclipse run configuration


Select the JRE tab and paste the following (replace path with your local jrebel.jar location) in the VM arguments field:

-noverify -javaagent:/Applications/ZeroTurnaround/JRebel/jrebel.jar -Drebel.lift_plugin=true


Set Java maximum Java heap size when starting Eclipse (windows)


Drag "eclipse.exe" into the task bar to create an icon -> right click the icon and select "properties" -> choose "Shortcut" tab and paste the following (replace with local Eclipse path) into the target field:

"C:\Program Files (x86)\eclipse-jee-indigo-SR1-scala\eclipse Scala.exe" -vm "C:\Program Files (x86)\Java\jdk1.7.0_01\bin\javaw.exe" -vmargs -Xmx1152m


Fixing Pentaho data integration app on Mac OSX


Starting the data integration app results in:


LSOpenURLsWithRole() failed with error -10810 for the file /Applications/pentaho/data-integration/Data Integration 32-bit.app.


Can be resolved by:


chmod +x ~/Downloads/data-integration/Data\ Integration\ 32-bit.app/Contents/MacOS/JavaApplicationStub


Same fix works for 64-bit version.

Wednesday 21 September 2011

Scala case classes and DDD value objects

I was looking for a neat way to use the Scala case class construct when implementing value objects as advertised by the domain driven design approach.

The only problem with using case classes, which come with all the convenience features like "unapply" and "copy", was that I wanted to operate on arguments before the class constructor assigns them to the immutable class members.

In case of the example below I simply wanted to trim the given postcode. Similar use cases, where I want to bring value object arguments into a particular format, pop up all the time.

The best pointer to a suitable solution was this Stackoverflow post: http://stackoverflow.com/questions/5827510/how-to-override-apply-in-a-case-class-companion

Since we cannot override the default "apply" method of case class companion objects I changed the method to be called "parse" which is not as concise as using the "apply" approach but with time I actually started to appreciate the more explicit naming.

Following code shows the way I'm currently implementing DDD value objects in Scala:


Making the case class constructor private ensures that the factory method "parse" of the companion object must be used to instantiate a new postcode object.

In addition to the version above I just recently found another way of tackling the problem.

There is a related discussion happening here:
https://issues.scala-lang.org/browse/SI-844?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel

According to the Scala specs the definition of apply is omitted if class c is abstract. Unfortunately this also prevents the compiler from generating the copy method which will have to be implemented manually.

Sample case class with companion object that sanitizes parameters before instantiating a new case class instance:

Wednesday 14 September 2011

Scala 2.9.1 Circumflex ORM 2.0.3

I just upgraded my Scala Eclipse plugin to Scala IDE 2.0.0-beta10 which ships with Scala 2.9.1.final.

When running my sample Circumflex ORM project I received this exception:
Exception
java.lang.NoSuchMethodError: scala.collection.mutable.Stack$.apply(Lscala/collection/Seq;)Lscala/collection/mutable/Stack;

Fixing it required me to recompile Circumflex against Scala 2.9.1.

I forked the project on GitHub and made the necessary amendments. I'm currently using the unstable 2.1 version. 

Clone and install the forked Circumflex version 2.1 to the local Maven repository
git clone git@github.com:tinoadams/circumflex.git
cd circumflex
git checkout master
mvn clean install

With the newly compiled Circumflex version in place you should now be able to build and run the sample application using the version 2.1 dependency:
		
<dependency>
	<groupId>ru.circumflex</groupId>
	<artifactId>circumflex-orm</artifactId>
	<version>2.1</version>
	<scope>provided</scope>
</dependency>