2/12/2012

Getting Started with mirage-scala

mirage-scala is the simple and powerful library to access RDBMS from Scala. I introduce how to use mirage-scala with sbt.

At first, add the following dependency into your build.sbt:

And create the jdbc.properties and put it on the root of classpath.

Next, you have to create the entity class. mirage-scala supports both of mutable and immutable style as entity class. This is the example of immutable style entity class:

Ready for mirage-scala. Let's try to use it!

You can insert, update and delete a record using SqlManager and entity classes. And also you can select a record by the primary key.

When you must select records by the more complex query, you can do it using 2way-SQL which is the powerful feature of mirage-scala. I would like to write about it in the next entiry.

mirage-scala 0.0.3 is now available!

mirage-scala is the wrapper of Mirage for Scala. It provides the best solution to access RDBMS from Scala.

New features in mirage-scala 0.0.3:

  • Case class (immutable model) is available as entity.
  • Option[T] is available as property type.

By these new features, mirage-scala became the more suitable library for Scala to access RDBMS.

mirage-scala is still under preview release. So any request or feedback welcome!

Mirage 1.1.4 is now available!

Mirage is a simple SQL centric database access library. See the following URL to know about Mirage:

New features in Mirage 1.1.4:

  • Added RailsLikeNameConverter as an optional NameConverter.
  • Added FieldPropertyExtractor as an optional implementation of PropertyExtractor.
  • BugFix: Avoid depending on JDBC 4.0 (Java6) API in DefaultValueType
  • Chopping semicolon from the end of the SQL file.
  • Improve: Avoid using type Exception/RuntimeException to make interfaces intension revealing
  • Added SqlManagerImpl#setValueTypes to make it easier to configure valueTypes using Spring framework
  • BugFix: PropertyExtractor extracts static or final field
  • Improvement: DefaultResultEntityCreator just reqires no-argument constructor. It really doesn't matter if the constructor is public.
  • Improvement: Make ValueType parameterized. If you implement custom ValueTypes, these is not compatible in this version.
  • Added BreakIterationException to discontinue iteration search.
  • BugFix: @Column is available for the select query.

Since this version, we provide a source code cross reference generated by Sorcerer. It generates so rich HTML based cross reference which provide references search like Eclipse. See the follwing URL:

I hope Mirage helps your development. Enjoy!

11/03/2011

Simple HTTP Client for Scala

I'm writing a Simple HTTP Client for Scala. This is a simple example of GET request:

using (new SimpleHttpClient()){ client =>
  val content: Option[String] = client.get(
    url = "http://localhost:8080/"
  )
  content match {
    case Some(s) => println(s)
    case None => println("Request Failed.")
  }
}

You can give request parameters to get() method. And it's possible to send POST request to use post() method instead of get() method. The second example shows how to give request parameters with the POST request:

using (new SimpleHttpClient()){ client =>
  val content: Option[String] = client.post(
    url = "http://localhost:8080/",
    params = Map("q" -> "Scala"),
    encode = "UTF-8"
  )
  ...
}

In default SimpleHttpClient returns the response body as Option[String]. You can handle the response to give the your own response handler. The response handler has to be a function has a signature (HttpResponse => T).

using (new SimpleHttpClient()){ client =>
  val content: Array[Byte] = client.post(
    url = "http://localhost:8080/",
    handler = { r: HttpResponse =>
      r.getStatusLine.getStatusCode match {
        case HttpStatus.SC_OK => 
          EntityUtils.toByteArray(r.getEntity())
        case _ => 
          throw new RuntimeException("Request Failed.")
      }
    }
  )
  ...
}

SimpleHttpClient also supports http proxy. You can give proxy settings to the constructor.

using(new SimpleHttpClient(
    "proxy.example.com:8080")){ client =>
  ...
}

I'm making useful utilities like this HTTP Client for development of general Scala based applications at scala-utils.

10/31/2011

xsbt-scalate-precompile-plugin 1.6

xsbt-scalate-precompile-plugin is a sbt plug-in which makes precompilation Scalate templates in the sbt build process (Scalate is a template engine for Scala).

However xsbt-scalate-precompile-plugin 1.5 had one serious problem which does not process templates in the nested directory. For example, it could't handle the layout template (which have to be placed into WEB-INF/scalate/layouts) correctly.

I made a patch to fix this problem and send it. It's taken in xsbt-scalate-precompile-plugin 1.6.

The fixed version of xsbt-scalate-precompile-plugin 1.6 is already available! Now it can process templates in the nested directory correctly.

9/23/2011

Introduction of CookieSessionFilter

CookieSessionFilter is a servlet filter which stores session data into the client cookie for Java based web applications.

In using CookieSessionFilter, session replication becomes unnecessary for multiplexing of application servers. You'll be able to make and manage multiplexing environment more easily.

It provides HttpSession interface. So any modification in your application is not necessary. Probably, you'll be able to use it with not so large cost.

See details about CookieSessionFilter at:
http://amateras.sourceforge.jp/site/cookie-session-filter/usage.html

8/20/2011

eclipse-scala-tools 0.0.2 is now available!

eclipse-scala-tools provides some small Eclipse plug-ins for Scala. It supplements ScalaIDE for Eclipse. The current version of eclipse-scala-tools provides features that support SBT.

See details about eclipse-scala-tools at the following URL:

New features in eclipse-scala-tools 0.0.2:

  • SBT 0.10 Support
  • Proxy Settings
  • SBT Console (SBT > Open SBT Shell)
  • Built-In SBT Runtime
Context menu of the SBT project Project property page of the SBT project

I hope it helps your Scala development!