Basic CRUD operations using Jaggery

Screenshot from 2014-01-18 13:10:58WSO2 has released Jaggery.js, a framework to compose web apps and HTTP-focused web services in pure JavaScript for all aspects of the application: front-end, communication, Server-side logic and persistence. The framework will reduce the gap between writing client-side web application pages and back-end web services.

In this series of Jaggery.js tutorials, I’m going to talk about how to perform basic CRUD operations using Jaggery.js.Jaggeryjs

If you want to know what and how Jaggery.js works, please refer my previous post for further clarifications.

Technologies and Tools used in this article:

1. Setting up  

I hope you have downloaded all the necessary tools which are mentioned above.

  • Download and unzip jaggary then go to {Jaggery_home}/bin and execute following commands on the terminal. If you are a Linux user sh or windows user server.bat to start the serverScreenshot from 2014-01-18 13:07:32
  • Create a folder called crud inside {Jaggery_home}/apps/ folder path
  • Make sure your MySQL up and running, create a DB called tasks
  • Copy MySQL connector jar file ( mysql-connector-java-5.*-bin.jar ) in to  {Jaggery_home}/carbon/repository/components/lib

2. Standard web project 

follow the instruction as it is.

  • Create a Jaggery configuration file called jaggery.conf which specifies the application specific configurations.for this example it contains application URL mappings. application context as follows.
  • Now we are going to create our first jaggery file. In-order to isolate the server-side logic create serverReq.jag jaggery file inside modules directory.
  • Basic CRUD operations as follows.
 var query1 ="CREATE TABLE example(
             id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), val VARCHAR(200));";
 var query3 ="SELECT * FROM example;";
 var query4 ="SHOW TABLES LIKE 'example';";
 config = {};
 var dataSource = new Database("
             jdbc:mysql://localhost:3306/tasks", "root", "root", config);
  • Let’s move on to client side logic. for that create a javascript file called crud.js
CRUD = new function() {
   console.log("CRUD operations protocol has been initiated ");
   this.getValues = function(){
   var id = Math.floor(Math.random()*100000);
   var d = new Date().toString();
   var dateStr = d.substring(0, d.indexOf(":",20));

   var textFName = document.task.fName.value;
   var textLName = document.task.lName.value;
   var textConNo = document.task.conNo.value;

   first: textFName, 
   last: textLName, 
   contact: textConNo, 
   time: dateStr, 
   action: "add", 
  console.log("fadein executed");
 } ); 
  • Create your index.jag file and paste the following code
  <div class="row">
   <div class="col-lg-4">
   <form id="task" name="task">
     <div class="input-group">
     <span class="input-group-addon">First Name</span>
     <input type="text" class="form-control" id="fName" placeholder="Employee First Name">
     <div class="input-group">
     <span class="input-group-addon">Last Name</span>
     <input type="text" class="form-control" id="lName" placeholder="Employee Last Name">
     <div class="input-group">
     <span class="input-group-addon">Contact No</span>
     <input type="text" class="form-control" id="conNo" placeholder="Employee Contact #">
     <button class="btn btn-default " onclick="CRUD.getValues();">Save changes</button>
  • So that’s all folks, then after you execute the code correctly you will be getting inputs as follows

Screenshot from 2014-01-18 13:10:47

Download the source files and try it out , Next post will be about, how to deal with POJO using jaggery.js till then , Happy coding 🙂



Jaggery.js – The delicious Javascript framework

Why JavaScript ?

There is no denying that since its inception in the mid 90’s, JavaScript has become one of the most popular Web development languages. So it has become the top language due to its ability to deliver rich, dynamic web content, its relatively lightweight and its high ease of use. In recent years, we’ve seen its continued evolution beyond the desktop to areas such as mobility and server-side web applications. There are strong odds in favor of JavaScript becoming the dominant language of the enterprise.This isn’t to say every other language will atrophy overnight (They won’t !) but legacy systems count on them for sure. So yet a revolutionary,a simple, open language, equally adapted to building both client and server-side apps? There’s no such thing as technology perfection, but JavaScript looks like the next best thing.

A modern web application invariably includes a significant client-side Javascript component.Why then are we using a completely separate language for server-side programming? You don’t have to switch our brain here and there, now we can use Javascript for server-side-programming for an example Node.js which is based on Google’s V8 JavaScript engine, that makes wonders. I’m directing this post towards another revolutionary server-side Javascript framework called.” jaggery.js “. Jaggery uses Javascript as the server-side programming language, the obvious choice for simplification. let’s get on with it. shall we ?


Jaggery is a framework to write webapps and HTTP-focused web services for all aspects of the application: front-end, communication, Server-side logic and persistence in pure Javascript. One of the intents of this framework is to reduce the gap between writing web apps and web services. Importantly, Jaggery is open-source and released under Apache 2.0. if you interested to read the full manifesto read it from here [5] .

Enough said, here’s a simple example, a step beyond the basic hello world to help you get a sample of Jaggery’s core implementations. enjoy 🙂

var jsonString = '{"name":"Pubudu","company":"WSO2"}';

You can try above code on Jaggery-Tryit . Download jaggery framework form the parent site [2] and do your experiments, here few sample implementations which helps you to learn in depth about what jaggery can do.

My next blog post will be about Basic CRUD operations using Jaggery, till then happy coding 🙂







QUESTION: Is David Moyes under-performing as manager of Manchester United, or was SAF over-achieving in the last few seasons?


Classy! Only fair that I give this city fan gold for the golden words. From one fan to another.If you have the time please do go through this [1] it’s worth every bit of your valuable time. The opinion of a City fan about Moyes and the current (2013/2014) situation of the United team. it was an absolutely brilliant and beautiful, great post. answer as follows

” Neither.

This is one of those times where the modern media really fails us as football fans in explaining exactly what has happened at Manchester United. I often complain that they focus too much on irrelevance and not enough on the actual business of football behind the scenes and this is an example of where it could have helped.

I’m not sure what anybody else was expecting here but Man United are right about where I thought they would be. I think they’ll finish higher than this but their form is somewhat predictable.

United as a Club has completely fell apart and it is the job of David Moyes to rebuild it. It has fell apart because the Club in the modern era was built entirely to Ferguson’s exacting standards and methods. Every single person in every department of the Club knew what they were doing every day and what the ultimate point was.

Clubs falling apart after the movement of a Czar isn’t new. United fell apart after Busby left, Liverpool got worse the more contrived the boot room system became. It’s natural.

I think United fans should remember the words of Ferguson before he left. He’s a proper football man, as is David Moyes, and they both know the scale of the task Moyes has undertaken and the time it will take to bear fruit. United can either studiously water their crops over time to create a vast sustainable empire once again that will provide riches for generations or they can dump nuclear waste on their land and grow tomacco.

For me, the real test of the Glazers as owners starts today. You can talk about money and whatever but to most people it’s an irrelevance, United have been ultra successful and the manager has been given what he wanted. So far so good for the Glazers. The test starts right now because we discover whether they are the seasoned and patient businessmen that the Edwards family were or just another kneejerk bunch of twats who are sacking managers on ridiculous timescales.

I think Moyes has certainly made mistakes, or rather a single mistake. I think he tried to transition too quickly from Ferguson’s staff to his own staff in the first team which created unneccesary pressure on himself. This can be forgiven however as I see what he was trying to accomplish. He knew that this would be a difficult period of transition and he wants to snap it as quickly as possible rather than do it piece by piece. Managers often do lack patience in transition, AVB had the same problem at Chelsea. Funnily, Ferguson did the same mistake when he first joined too.

I see people who have called Moyes unambitious because he has said that United played well when they didn’t. This is a man who had a job for life in a stable Premier League team where he was beloved and he decided to pack that in and move to the most famous Club in the world and succeed the best ever manager in the game, to take on a rebuilding job the like of which has never been done in the modern era of football. Unambitious? Do me a favour.

You see, Manchester United was a club built in Ferguson’s own image and everybody took their lead from him. He was an imposing figure yet if you meet him he had this working class charm that made you want to fight for him. David Moyes is a similar figure but doesn’t yet covet the same respect and loyalty from everybody at Manchester United. There’s no possible way that he could, that anybody could, most of the people at United were directly employed by Ferguson or employed whilst he was the manager. In time, Moyes will have the same respect bestowed on him, that’s all that it needs at the minute, just some time for him to get his feet under the table.

Some fans believe that David Moyes isn’t the man for United. I challenge the idea that they even understand what United is as a Club. David Moyes is pretty much the prototypical Manchester United manager, if you had to walk away and design a man who would manage them, it is him. He’s fierce, he’s tactically well versed, he has a superhuman work ethic, he believes in youth promotion, he plays with wingers, he inspires loyalty and fight from everybody around him. Those who don’t see this have never been to Everton away under his tenure there. Moyes managed to turn that place into a lion’s den in how ferocious the atmosphere was and how the team played, and make no mistake this developed under him and will wane without him, managers have a major effect on atmospheres as any United fan will tell you (or City fan for that matter), he will do the same to Old Trafford given time.

So I suppose the problem here is that fans have underestimated the mammoth of a task that Moyes has to accomplish and pundits have over-simplified it. It will take Moyes several years to get United built in his own image and it will be better off for it rather than start some roundabout of managerial changes. And I warn United fans, I’m a fan of a Club that has had probably 30 managers in the past 30 years. Once you start down this path of swapping in and out managers, you can never come back from it.

One last thing to note. I find it interesting how many people when this was announced said things like “Moyes will need a transition time” but have now decided that he should be gone in January. Transition time is a term used to denote the time it takes to sweep away the mentality of the old regime and bring in your own mentality. Essentially, how long it takes to forget the old manager and buy into the thoughts of the new even if it conflicts with what the old manager would say. For a manager who casts the shadow of Ferguson, this will take 3 or 4 years, not 3 or 4 months. Bobby Charlton, Alex Ferguson and others at United understand this so appointed a manager who can rebuild United and have the wide shoulders it requires to bear the load of expectation from the fans and media. They think they found their right man in David Moyes and all piss taking aside, so do I. I hope that they both fight his corner in the boardroom and I’m sure they will. These people understand United as a Club, understand what makes it successful and understand what makes it special.

Moyes will be fine if the fans just shut up and let him do his job. ”  So I quote and unquote

Believe !!!! Best is always yet to come 🙂

[1] Original post : on Reddit

Top Sri Lankan Asshole moments

I found this very interesting and if you find anything offensive, its your problem not mine ..!!

  • Ol)EL Is the only place which has clothes in SL
  • My real name is “SAMANWATHI PETERAARACHCHIGE” but I just use “SAM PETERS” on Facebook
  • you tell me that price in dollars and i don’t mind spending it, tell it to me in Rupees and I’ll get a heart attack
  • Please judge me by my car!! And if it’s a diesel, note that it’s more expensive than a petrol model.
  • If my ride has a higher seating position, that is supposed to represent my higher status than others.
  • More than the chemical effect I get from an alcohol bottle, I prefer to open it in front of hundreds of fellow fools. This would display that I have the capacity to pay extra for the same bottle and I expect you to judge me by this.
  • Please look at my number plates If they are red or someshit, my father must be losing his dignity in front of somebody just to show the rest of the world that we are “powerful” people
  • If I wear sarong to an event, that means I’m so posh that I passed the level of pants and then wanted to get highlighted with something splashy like this
  • I paid so much for these shades, so I deserve to wear it in the dark
  • If I display a politician’s photo or a poster on my car, I expect you to think that I’m pretty close to them so don’t mess with me.
  • Whenever I get a time I go to “hikkaduwa” because you know!! It’s the cool place to go, and u know what I do there right?? (I also don’t mind paying like 250/= for a cheese rotti)
  • Whatever I do, I need to end up in pillawoos with ice-milo and koththu, and I promise I’ll act like I have never seen koththu in my life before
  • I just want a small transit in a western country and I swear I’ll get a new accent and start laughing back at my own culture cause its cool like that
  • Please note what’s in my profile picture, if it’s a car its mine, if its people, those are the people I hang out with. It’s not what describes me the best, it’s what I need to be described as
  • It’s a shame to listen to Sinhalese music regardless of what it is, so I listen to it when others are not around, never play it in my ride
  • British fucked my great-grandparents in many ways, so whatever they do now, I need to grasp it before the others do
  • If I carry a DSLR with a long lens, I’m a professional. And the longest lens wins
  • Person who can drink the most isn’t the person with the most messed up body, it is the “pora”
  • Drinking is the only leisure activity that needs to be done in this world
  • ARUGAMBAY replaces last generations bata/SHOES and any other footwear
  • Beach shorts would replace sarong and everything else
  • Why won’t the rest of the world wear sports shoes for anything between dinners to a little below a wedding?? Ehhh that bugger has  splashier shoes L
  • Success is where you don’t let anybody overtake you in the street; I could bloody sacrifice my life for it. Fastest driver is the most productive in life
  • Cricket is the only sport in Sri Lanka, it is also the national sport* doing any other sport is just stupid
  • Inching into the intersection while the lights are red gets me closer to the destination right??
  • Thank you parents for putting me to a big school, now people will judge me by my school
  • Hey look!! I have an HP laptop bag!! But my laptop is some other brand
  • Got to spend all my money on a mobile phone, it’s alright if I don’t put credit on it. I can’t pull out credits out of my pocket in awkward moments and pay my attention to it right??
  • You can also judge me by who my father is
  • I feel so insecure with my personality, I’m going to hire some bodyguards
  • Got up!!…Let me update my status saying “I had a good night last night” and that I’ve got a hangover.
  • Wait now….so we have different political views?? Why aren’t we fighting on it?? Rest of the world will give a shit about our fight and I expect you’r leader to convert to my side in the end of the conversation.
  • Ahh…!!A posh place!! Let’s take a photo with all the booze and do a check-in on Facebook
  • I don’t exactly know Sinhalese, but let me borrow some filth from its vocabulary cause it’ll sound nice
  • Let’s go to that horse or rice and drink, kids can stay out and drink until the police come.
  • alright..!! drunk now, lets pull a fight.
  • I need to support Manchester united or some team of that sort, no need to think of how I could help my country to get there
  • So does your car have heated seats,cruise control and day running lights?? I’ll be needing it in Galle Road noh meya!!
  • Look!! I got this new Japanese tattoo, don’t know what it means though
  • So u think I can’t drive?? let’s sacrifice our lives just to impress you
  • The horn in the vehicle is to let know my presence, not to indicate a danger
  • Cars with stickers,2 doors, some extra fiberglass and the loudest beat is a “SPORTS car”
  • I only drive my jeep to work, but I need two spare wheels and and a shovel at the back just in case it gets stuck in duplication road
  • looking at a quote on a three wheeler and laughing at that tiny grammatical error. he should’ve done an English degree before he chose to be a three wheel driver.
  • carrying a million rupees around your neck and complaining you got raped and the necklace got stolen in “PETTAH”
  • I just need a spare moment to go to a corner in the street and start looking for a lighter
  • Somehow I need to pop my face in to that weekly  l<ama colombo=”” photo=”” album=”” on=”” facebook=””></ama>
  • I’m going to spend a hundred thousand rupees on a air-ticket because I can shop for cheaper there…!!
  • I’ve got enough oil in my hair to risk an American invasion. Deal with it.

{At Some Random Blog}