Thursday, June 5, 2014

RELOCATION AND JOB HUNTING...

After a recent shift to UAE more specifically Dubai, I have been job hunting for the past two months.. and has it been unfruitful or what...

Apparently Dubai has a vast requirement for Salespersons and Managers but poor souls like me who are still at entry level are not needed. I wonder who does their odd jobs...

Anyway, this is just in case some one decides they are looking to hire and bumps into this blog... well I'm up for grabs...

So here is my profile LinkedIn Profile.


Tuesday, June 25, 2013

Single Quotes Is All It Takes

So after playing with Play 2.1.x and scala for a good 2 months, and working out how to get and retrieve data from a relational database like mysql, i was asked to do the same with a NoSQL DB.
I initially started working through it with the attitude of "how different can it really be?"
Cassandra taught me in the first week how stupid i was to think that.. and after weeks of reading through texts like Making Sense of NoSQL,etc I finally understood a little bit. Anyway, let me just get to what i learnt.
So, after connecting my play app to cassandra, I got to inserting values into the DB, getting the syntax right was easy. Inserting values directly was easy too..

but in the real world, you need to input value from some variable and not directly and  that's where i got stuck.

And the error i got looked like this

Doesn't say much, that was my first thought.. anyway, i kept trying to figure out what i was doing wrong.. and here is the mistake ...

 "  VALUES (" + id1.toLong + ", " + name1 + ", " + age1 + ", " + add1 + ");"

The values of name1 and add1 were both strings and when i was passing the query inside a String, any string inside the query needs to be inside SINGLE QUOTES. Do they say that in any of the documents and help files i poured through.. Nope.. its its supposed to be understood.. But I dint understand it.. Anyway , so here is the correct way of doing it. Hope it helps..

For someone who is an expert or even someone who has a little experience in the field, this might seems like a very small and inconsequential lesson. You might even brush it off as common sense.
But for a new comer like me,  was it small? - yes, was it stupid? - maybe, but a lot of them out there might be looking for this simple answer. I know I looked in a lot of places and all I got was the Syntax which was passing values directly...  

Wednesday, May 8, 2013

Play 2.1.x Writes Troubles

SO, This week's assignment was to learn how to use Reads/Writes Combinators. I started off with the play documentation on the same( http://www.playframework.com/documentation/2.1.1/ScalaJsonCombinators ) ,I wrote the functions for reads and writes which is given below.
But what I actually need to do was make an implicit call to the Reads and Writes. So i rewrote my function and this is the modified code is:
This code gave me no explicit error, but when i ran the code the:


The error in this output was that it should show me the id, name, age and address. Not just the address.
After doing a lot of checking, I realized there was no error from the db or any other functions. The only error was somewhere in the detailsWrite(), and no matter what i did it only printed the last value from the json.

So, with a little help, this is what i learnt:
The detailsWrite() function was giving an error because of the 2- level path that i was using
( __ \ "user" \ "id" )

Once I changed that into a simple path, it worked perfectly.
So the final code is here:

And the correct output.



Friday, May 3, 2013

BigDecimal And Anorm

Today i came across a new Data Type.. Its called BigDecimal/BigInteger,etc.... I actually did not use this in my program but chanced on it because of an error i got while i tried to run my simple code for user details.


case class UserInfo (
  id: Int,
name: String,
age: Int,
address: String
)

object UserInfo{

 val ds = DB.getDataSource()

 val data = {
  get[Pk[Int]]("id") ~
  get[String] ("name") ~
  get[Int]("age") ~
  get[String]("address") map {
  case id~name~age~address => UserInfo(id, name, age, address)
  }                                        
 }

This was a simple code and should've run without any errors. I had no errors on my eclipse window... But on executing the code i got the following error for output.

[RuntimeException: TypeDoesNotMatch(Cannot convert 1:class java.math.BigInteger to Int for column ColumnName(userinfo.id,Some(id)))]

So i did what every newbie does... I googled the error.... To my surprise I wasn't the only one who came across this error. And after fiddling around with the code i figured out the following :

- The Database returns BigDecimal values that are part of the java.math.BigDecimal package, which is not a scala package. So we need to explicitly import this package.
import java.math.BigDecimal

So, this is my finally working code,

import java.math.BigInteger

case class UserInfo (
       id: Int,
name: String,
age: Int,
address: String
)

object UserInfo{

 val ds = DB.getDataSource()

 val data = {
  get[BigInteger]("id") ~
  get[String] ("name") ~
  get[Int]("age") ~
  get[String]("address") map {
  case id~name~age~address => UserInfo(id.intValue, name, age, address)
  }                                         //> data  : anorm.RowParser[models.UserInfo] = <function1>
 }

Yep, I made a few changes.. Well, thats what I'm coming to next... Here's what i couldn't figure out...

I couldn't figure out how to get Pk[Int] to be compatible with BigInteger. So even after importing the java package and changing my id type to Pk[BigInteger] i couldn't return a compatible id value.

If anyone has the answer to that, please let me know. Else whenever I figure it out I will update it.







One month later...

So I've been at this job for a month now, and i can finally say that i have managed to learn bits of everything thrown my way... Before i go further i should mention that i was out of the loop for almost two years so what might seem silly were actually genuine doubts and problems for me...

So far, I have managed to understand the concepts of Scala and Play. I have learnt how to use Json, XML and Forms with my Play Applications. Just today I finally worked through how to use Anorm to have persistent data... And I came across a data type know as BigDecimal. So that's what my next post is about.