This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Spring, Fly and MyBatis

Familiar tools and Libraries from the Java world are steadily being made available to Scala programmers by means of wrappers, Scala specific API's or how-to-use guides. Here are three that you may find useful. Spring, a popular framework is described by Urs Peter. Nigel Warren and Channing Walton explain how the new Scala API was created for Fly Object Spaces, giving a valuable insight into how a Java application can be easily converted to a Scala one. Vasil Remeniuk blogs on how to use IBatis 3.0, (now MyBatis 3.0) with Scala.


Spring

Urs Peter shows you in his Infoq article, how to leverage Spring, one of the most popular frameworks, with Scala. Spring not only offers effective programming paradigms such as Dependency Injection (DI) and Aspect Oriented Programming (AOP) but also provides lots of handy glue code to interface with popular frameworks such as Hibernate, Toplink and the like, as well as the JEE environment.

He says "Scala is a great programming language combining a concise and legible syntax with a seamless fusion of the object-oriented and functional programming paradigm that is fully compatible with Java. The latter makes it possible to combine Scala with Java APIs and frameworks that Java developers are familiar with. By doing so, the usage of existing Java frameworks can be improved and simplified. In addition to that, the threshold to learn Scala is also lowered because it can easily easily be integrated with the well-known world of Java”.
 

Fly Object Space

Nigel Warren and Channing Walton gave a talk at the Skills Matter, about using the Fly Object Space with Scala and demonstrated how a pragmatic conversion methodology made moving from Java to Scala an easy, low risk task.

Slides of the presentation are available and a shorter paper presentation at ScalaDays 2010.

Nigel talks about Fly, a recently developed, lightweight Object Space that can distribute and coordinate information on clusters of computers in the form of Objects. It follows the form of Tuple Spaces in Linda and Java Spaces in Jini. Fly is language independent and hence can be bound into various programming languages via the development of specific language stubs that expose the interface to the Space to client programs.

Channing, gives a detailed explanation how he set about converting the Java code base to add the Scala bindings for Fly. He started with a "syntactic" conversion of the Java code to Scala using the standard edit and find-replace features of his IDE. At this stage he was pleasantly surprised to find the Scala code just worked. Then as a second pass he replaced Java like code with more idiomatic Scala code introducing comprehensions, functional techniques, option and Actors to achieve between 40% and 50% reduction in LOC as well as a more elegant solution.
 

MyBatis 3.0 (previously called IBatis 3.0)

Vasil Remeniuk explains in his blog how to use IBatis 3.0 with Scala.

The MyBatis data mapper framework makes it easier to use a relational database with object-oriented applications. MyBatis couples objects with stored procedures or SQL statements using a XML descriptor. Simplicity is the biggest advantage of the MyBatis data mapper over object relational mapping tools.

To use the MyBatis data mapper, you rely on your own objects, XML, and SQL. There is little to learn that you don't already know. With the MyBatis Data Mapper, you have the full power of both SQL and stored procedures at your fingertips. MyBatis home and Wiki.

Re: Spring, Fly and MyBatis

I would recommend anyone considering MyBatis to look at www.orbroker.org, which accomplishes some of the same goals as MyBatis, but with no XML and written natively for Scala.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland