Beiträge getagged mit Scala

Wrapping JPA Queries

I love the “pattern” used in this post (which I got from here). Working with JPA queries I tried to follow the same pattern. In a REST resource I needed to query for one entity and change the location attribute. [UPDATE] This is mostly realized here [UPDATE] The code that visually separates the query from [...]

,

Keine Kommentare

REST Client calls with Scala and Jersey (JAX-RS)

[UPDATE] this post is really old. I’ve written a new one: klick [/UPDATE] Usually client calls to Jersey (see API) are looking like this: ?View Code SCALA1 2 3 4 5 6 … WebResource resource = client.resource(baseURI); Units units = resource.path("units/" + id).accept(MediaType.APPLICATION_XML). get(Units.class); … Using many different HTTP method calls with changing paths is [...]

, ,

Keine Kommentare

Reflection Read-Access to Scala Vars

Scala does not provide a special reflection API so we have to use the usual java reflection. Scala provides the @BeanProperty annotation to automatically create setter and getter (although these are not usable by Scala code). In this case Scala and Java makes no difference. If I want to access simple property fields directly I [...]

,

Keine Kommentare

withService(myService) {…}

If we are using e.g. Service objects (and a method called “create” on it), it is a common case that we have to create the object and do some open and close operations on it like this: { val s:Service = new Service() s.open s.create(“test”) s.close } In Scala we can use closures as a [...]

Keine Kommentare

JSONContextResolver

Playing around with CouchDB (which is a great JSON document based database with REST access), Jersey (JAX-RS/JSR-311 implementation) and Scala I had to implement a custom ContextResolver to use JSON objects instead of XML. The Context Resolver Interface in Java is: package javax.ws.rs.ext; public interface ContextResolver<T> { T getContext(java.lang.Class<?> aClass); } I needed some time [...]

, ,

Keine Kommentare

Caching XML access in Scala (example)

I want to create a hashed map for fast access to specific XML tags and attributes. I used a config xml file of JDBCluster and its attribute name of the tag property. At the end of execution ht contains the following: Map(Car -> List(longitude, latitude), Car2 -> List(longitude2, latitude2)) Here is the code: object XmlTest [...]

,

Keine Kommentare