Scala

Easiest Way To Insert Scala Collection into PostgreSQL using Slick

Reading Time: 2 minutes Few days ago, I had a scenario, in which I had to insert scala collection into postgreSQL using Slick. My postgreSQL table has some columns with data types such as Arrays, hstore  etc.. I tried to do this using slick, but didn’t get success. After beating my head whole day, I found a solution. I found a slick extension slick-pg, which supports following postgreSQL types:- Continue Reading

Scala in Business | Knoldus Newsletter – January 2015

Reading Time: < 1 minute Hello Folks We are back again with January 2015, Newsletter. Here is this Scala in Business | Knoldus Newsletter – January 2015 In this news letter, you will see how functional programming is getting much attention, why should Akka be used in production, how Scala is getting popularity in Italy and many more. So, if you haven’t subscribed to the newsletter yet then make it Continue Reading

Working Effortlessly with Java null in Scala

Reading Time: 2 minutes We would not repeat why null is a billion dollar mistake of Java. In our earlier post, we have already discussed how to handle nulls of Java. In this post we would take it a step further, but first a bit of recap. Say that you have a function in Java which can potentially throw a null. def getUser:User = null Now, the way we Continue Reading

How to Implement Cross Cutting Concern using AOP in Scala

Reading Time: < 1 minute In this blog, I have explained that how easily we can implement Cross Cutting Concern such as logging using Aspect Oriented Programming in Scala. These concerns have nothing to do with core business logic. Aspect Oriented Programming is used for encapsulating cross-cutting concerns into re-usable modules. Here we used AspectJ weaver to weave precompiled aspects into project output First we defined an annotation style aspect Continue Reading

Spray authenticate directive : A decoupled way to authenticate your API

Reading Time: 3 minutes Organization exposes critical business data or user’s private data through API. It is required to protect API against any unauthorized access, attack or security breach. In this blog I am not going to discuss API security mechanism. Here I want to detailed out the separation of API authentication from underlying RESTful Api. Authentication / Authorization is cross cutting concern and it must be decoupled from Continue Reading

How To Implement logRequestResponse in Spray

Reading Time: < 1 minute Spray has the feature to log request and response of every route through logRequestResponse. We needn’t to add log in each route because it could be done from a single place. This also helps to maintain clean code. Please see below example:- class HubServices extends Actor with HubRoutes { def actorRefFactory: ActorContext = context // logs just the request method and response status at info Continue Reading

FunHop: Working with Exceptions in Scala – Problem Statement

Reading Time: 2 minutes If you look at the earlier posts in the FunHop series, you would notice that Exceptions are side effects. Exceptions by their very nature also break referential transparency and are context dependent. You would have got an idea about referential transparency from our earlier post. If not, it might be a good idea to review it once. Let us consider the code sequence below def Continue Reading

Scala in Business | Knoldus Christmas Newsletter – December 2014

Reading Time: < 1 minute Hello Folks We are back again with December 2014, Newsletter. Here is this Scala in Business | Knoldus Newsletter – December 2014 In this news letter, you will see that how fast organisations are adopting Typesafe Reactive Platform to get best solution, how functional programming is getting into mainstream and how functional programming is becoming popular choice among the developers. So, if you haven’t subscribed Continue Reading

SCALA : Handling visibility of constructor fields

Reading Time: < 1 minute Constructor fields are parameters of class . In scala , we can define the visibility of parameters , visibility of parameters can be defined by “val” or “var” or without “val” or “var” . For example : class Knoldus(val name:String) Here, “val” defines the visibility of constructor field. With val field scala> class Knoldus(val name:String) defined class Knoldus scala> val knolObj=new Knoldus("Malti Yadav") knolObj: Knoldus Continue Reading

Scala in Business | Knoldus Newsletter – November 2014

Reading Time: < 1 minute Hello Folks We are back again with November 2014, Newsletter. Here is this Scala in Business | Knoldus Newsletter – November 2014 In this newsletter, you will get to know the popularity of Spark in big data. Spark is getting more attention in all over the world for fast data processing. People are getting much faster data processing speed with Spark. You will get to Continue Reading

Building Reactive applications with Akka

Reading Time: < 1 minute Knoldus organized a Meetp up on Wednesday, 29 Oct 2014 at 5:00PM. Mr. Nilanjan Raychaudhuri from Typesafe presented this session on “Building Reactive applications with Akka”. He did the session remotely from Germany and it was very well accepted by the audience at the meetup. Nilanjan is a consultant/trainer and member of Play framework team. He works for Typesafe. He has more than 14 years Continue Reading

Easiest Way To Map Optional Nested Case Class with Slick in Scala

Reading Time: 2 minutes Few days ago, I had a scenario, in which I was supposed to map optional nested case class in slick using Scala. case class Employee(emdId:String,name: String, record: Option[Record]) case class Record(subject: String, mark: Int) I was trying to do this mapping the way, I have explained below. class EmployeeSlickMapping(tag: Tag) extends Table[Employee](tag, “Employee”) { def emdId = column[String](“emdId”) def name = column[String](“name”) def subject = Continue Reading