Monday, March 23, 2009

Importing Blog for Facebook Note

I recently new that we can show our posts from blog into notes application in facebook. So I donot need to copy my note into my blog. This post is for testing how my facebook looks after I create new post.

But I should tell you about something, I don't want to post just for trying that facility only. But to be honest it's very hard for me to write something, writing is a hard job, sometimes suddenly we get idea but and then we loose it or even when we write something we then blank, and loosing words, and it happen to me often.

Anyway now Im listening marz music again and again, I do it in here in office, I do it again at home, again and again, but sometimes I change it into murottil mp3 or mp3 of someone read quran without tartil when I feel miss my home or feel very religious atmosphere.

I love the lyrics of jason mraz songs. "Please Don't Tell Her", "The Remedy", "Im yours", "Geek in the Pink", or "Clockwatching", or some other lyrics. I think he write his songs by himself, in case it shows his conditions. he is still single like my, old as single like me, he was born in 1979 or 1977 I forget the detail, I think he is introvert just like me, he is not quite confidence for doing relationship just in lyrics in above songs, he said that "she is taller than I am", and he said that he is a geek just like as the title.

Friday, March 20, 2009

Getting Limit Query from Hibernate

This is a short note continuing older note about creating google wannabe paging, in case I want to write a note but Im not telling you yet how I create my own paging completely.

There are many ways how to get limited query in hibernate, there are HQL (Hibernate Query Language), Criterion, or native sql. I will tell you with the first way the HQL way. For me HQL is simply SQL using hibernate POJO (Plain Old Java Object), the object representative of tables. For example if the table named LOG_ACTIVITY the POJO could be named LogActivity. if the SQL looks like: "SELECT * FROM LOG_ACTIVITY", the HQL could simply looks like: "FROM LogActivity", and it has more functions.

In this note Im not only telling you about getting limitation records from 1 to 100, but also parameterized, such as getting records from yesterday to now only the first 100 records.
1. Get the searching criteria. The default value is "*". For example field username, if there is a value from the input such as "imam" then the username="imam", otherwise username="*"
2. Count the total record,
3. Have a constant of how many records shown in every page, for example 10, and it can parameterized also.
4. I divide total record with that constant so I get the total of pages
5. I do query with the same syntax when I search the count of the total records (the syntax I move into an own method), but this time is for getting the records not the count.
6. I pass all of the variables (page, totalPages, listPages, perPage, totRecord,
recordList, qName, qDate, etc etc)
- which page =page requested, foe example page 13
- totalPage for example 5
- listPages, so the values are: 11, 12, 13, 14, 15
- perPage, how many records shown in every page
- totRecord, because it will be shown in my application
- recordList
- qName, qDate, and other question as search parameter that saved in a session.

Anyway this is the code snipped, the first method to get the count of the record, the second is to get the actual records, while buildQueryString is method that resulting hql syntax with parameter criteria=names of the searching fields such as username, dateForm, dateTo, and the second parameter is question the values of the searching fields, I set "*" if null or empty.

public Long getLogActivitiesSearchingPagingCount(String criteria, String
question) {
String queryString = "select count(*) " + buildQueryString(criteria, question);
Long total = (Long) getSession().createQuery(queryString).uniqueResult();

return total;
}

public List getLogActivitiesSearchingPaging(int start, int length, String
criteria, String question) {
List logActivities = getSession().createQuery(buildQueryString(criteria, question))
.setFirstResult(start)
.setMaxResults(length).list();
return logActivities;
}

Monday, March 16, 2009

Creating google wannabe paging

As my several notes that copied to my blog, I will write a note again and then Ill copy to blog again although its a java theme, in case I think there are reader from facebook rather than from blogspot. And especially my blog is already long time don't have a java post.

Yesterday in milist Java User Group-Indonesia, there is a member asked about how to create paging list in java-application. I face the same problem in my first project in balicamp. I cannot find component that fetch query with limitation. Displaytag component select all records and then view it page by page as user needed. While valulist donot use hibernate, data framework that shoud be standard as java application. I will make the select in other post, but now I want to show you ho to make google paging mine version.

If you were googling, there will be list of paging if the result is a lot, such as: Previous 1 2 3 4 5 6 7 8 9 10 Next. It's easy not as scared as we saw it in google. it's only playing with some if and else in jsp with some of parameters.

Im a spring guy, spring is one kind of a framework that needed in building java application, and it playing class called controller, in easy word, we have a controller for each page we make. we need 3 parameters (information) for a controller for our paging:
1. page, the page that user request, for example is 5
2. totalPages, total of the pages, get from select count / perPage, which is perPage is total record every page.
for example total record = 100, perPage 10 record, so totalPages = 10
3. listPages, list pages that shown.
for example we viewing 5 pages, ther listPages is 3 4 5 6 7,

Meanwhile in the jsp the algorithm such as below:
1. if page != 1 then print First, anchor to page=1
2. print every value of listPages, if equals with the requested page, then no anchor needed, otherwise anchor to the page
3. if totalPage != 0 and requested page != total
3. jika totalPage != 0 dan page yg direquest != totalPages then print Last, anchor to the last page.
the result for our example is First 3 4 5 6 7 Last.

write all of that step into separated jsp file, we only need to include as we need it, we put it above our table.

As compare with google, google used 20 list of pages if the record is a lot. we already have the similar with google, unless if also set listPages size 20 same as google, and the page is 5 for example we print 20 pages from 1 to 20, while google only print 10 page. As far the page is below 10 google show only 10 page.

The other different is google print Previous and Next, while mine prints First and Last, and FYI, I prefer mine ^_^, I think it also applicable for other than java, because it's an algorithm not language-based, thank you for reading & have a nice try!!

Monday, March 9, 2009

Spent holiday as usual

Today is the third day of me being idle at home in jakarta, same as usual workers from other town, I rent a room near office in a house, big house in case it contains twenty rooms for rent beside rooms for the owner, the owner contains parents and three children. It quit expensive for me for the room, but in case many of my office friends living in the same house, so I never search other place for moving.

Last two days I spent times with sleeping a lot and watching tv a bit. I watch tv in a kind of living room, with friends, I watch the program that choosen by them. Last night I watch serie A between Milan and Atalanta. only the second half, in case I went to the tv room in 10pm because I cannot sleep. It's been so long time for me for wathing footbal again. and watch tv also, I so rarely watch it since working here.

the last score was 3 - 0 for milan, all of the goals made by philippo inzaghi, the first goal made in the first half, wich is Im not watch yet. the others is ofcourse made in the last half, with normally without diving in case he is fame of with doing unfair action AFAIK.

Nowadays milan is full of a stars, many of them are old but still great players, beside philippo inzaghi, milan has andrey shevchenco which is not quite showing good performance in his only for about ten minuites play. and the it has david beckham which still give precission ball passing, and then andrea pirlo with his energic stamina as usual, and also abiatti as goal keeper. and as the young gun it has pato which is sometimes try to make a goal but fails again and again. And also I saw kaka as supporter, which is not played perhaps his still injured. Nice personality of kaka with his formal dress, I think he has potentiality to be a celebrity same as beckam. And also I saw victoria, becham's wife supporting milan.

One thing I want to say is, in the last minuite, very very last minuite beckham was changed by new young innocent player which if Im not wrong heard is from uruguay. and the funny thing is after he entered the field the game is over, then he turn out the field as other player did, he only smiling. I think that just the scenario, how to sell beckham, footbal, and the country of that young player, the beckham replacer. yes, that is my opinion, they want to sell and shows to us the mega-shining the world of celebrity-football so we want to be in there also, at least dream of it.

rrrggh.. btw after finishing the serie a match, I saw metro tv, it's the "zona 80an", only for perhaps ten minuites, because the show already started on 10 pm in which I still watch for milan, the show as the title is about the 80 stuff, in last night episode, it invite the indonesian 80s movie stars. There is Rano karno, Paramitha Rusadie, Yessie Gusman, Rico Tampati, Ita Mustafa, and one again that I don remember.

They were adorable, rano is sometimes told a joke to the audience or the yessie gusman, when they were asked by audience in the ask-answer session about how far they'we near in relation between in the 80 era in case both of them involved in many movies such as galih and ratna ? hwehehe, i think everybody loves the movie. Rano said that Yesy should answer that question because the question is too hard for him because it ask about two think that different, far and near, and then yessy said that both of them are far from eye near in heart.

today is maulud nabi holiday, im not working now, but after saturday and sunday I spent in home, I go to office today for internet. Actually last night I told by my mother to read solawat a hundred times for maulud and already did it last night. Anyway thanks for reading if you're still read this note ^_^

Monday, March 2, 2009

Okay... Im a book reader right now

in case a buddy of mine commenting about my older profile that Im not reading book for long time and never finished when reading, last week I bought a book from book store, there's only few book stores in this town, I think there are three only, two of them Gramedia, in WTC and SMS, the other is Gunung Agung in Melati Mas, I went to Gramedia WTC. Im in BSD FYI, small town Jakarta nearby.

First, there are a couple of books interest me, "the lenovo gate" or something and biography mr. Habibie, the first book is story about how the chinese IT company named lenovo buy IBM or IBM products or something, I newly known that lenovo is the company name from China, I thought before that it was one of the IBM product. the second book is ordinary biography of someone, but it make special because it tell me about someone I admire.

I opened the lenove gate pages by pages, I read the comments from some people in the back of the book, I open the page that have photos, it's about four pages, the first photo is an old photo, it says that it was the first building of lenovo, it very small building, square of walls and I think it has no roof or something as change of roof. it just pathetic building, and perhaps it just a hiperbolic from the writer. and then the other picture is also old picture that capture the lenovo employees standing up in front of newly build apartment. the caption of the photo said that they were very happy because they will get apartment, and that the first time n Chine history that a company give his employee an apartment. I forgot the year, I think both of those pictures happened in eighties. the second book I cannot open because it sealed, but there are a lot of photos which is I like.

Beside the price of those books are expensive for me, it's abouot 85 rupiahs. and it is too thick for me to read, I will never finished it I think. and the first book is too heavy reading for me, it is a business book which is I will need extra concentration for it.

I told to myself that I need light book, easy reading, such a stury or novels. So I went to the novel area. I saw some names that familiar to me, such as Agatha Cristie, Jon Grisham, and one again but sorry I forget. And then the titlle of the books are much of them is movie title, such as the firm with tom cruise, to die for with nicole kidman, and pelican brief with julia robert. near of them are newly heard book something that 1001 nights story, and some again about taj mahal and some related love story of taj mahal. and then near them again are indonesian novels such as Marga T, NH Dini, Dewi Lestari, and more cicklit and teenlit that the title are so catchy.

I read the write back of some books, I think and think again so I chose one of the John Grisham (is the name is right?) titled "Runaway Jury". I think all of his novels are law related, It about the court of the cigarette company versus people that disagree of cigarette that representatived by an old man that already died because of cancer in case of he already consume cigarette for years.

I still read until chapter 8 I guess from 44 chapters, The first part of the story is the recruiting jury, it happened in small town in america, I forgot the name, but the fact is the writer did live in that town when he write the story, and in many place of the parts there are a lot of detailed description of places such as apartments, roads, and specially the court.

In the first page I only found so few of thank you statements, for people in that town and for corrector of the novel, one of them is from oxford, no surprise the novel is famous and received by international public. and I think you guys already heard or even watch one of his movie from the novel.

The first part of the novel mainly tells about of one of the jury Nicholas "something" I forget, he is misterious, smart person, 27 years old same as me, he work in computer store, and confess as a student and ever study law for couple of semesters. he live in small unexpected apartment because he moved because need to hide his identity and history.

In that novel also tell the both side of the plaintiff and defendant are work hard to get the list of the jury. they spy their live, take pictures from them, entering their home without their permission, they have all the jury data so from almost 200 candidates there are I think twelve selected jury and three for backups I guess.

I forgot the details, I don't know exactly if I like the story or not, but it friend me while Im waiting the train when I went home last thursday, and I loose 50 grants for it.