Beginning Grails 2.0 with MongoDB

This is the quick step-by-step tutorial about beginning Grails 2.0 with mongoDB(Quickstart) for newbies who have read the manual but got nothing.
First thing first, you must install mongoDB in your machine by following Qucikstart Guide. if you done, let’s go.

1. Create your Grails application as you like.

$ grails create-app sample

2. Install mongodb plugin.

$ grails install-plugin mongodb

You don’t have to worry about configuring plugin, that all be done by default.

3. Remove hibernate plugin if you need to use only mongodb to store all of data in your application, or not? skip this step.

$ grails uninstall-plugin hibernate

or just remove or comment this line of code

runtime ":hibernate:$grailsVersion"

in yourapp/grails-app/conf/BuildConfig.groovy

4. Create Domain class as you like.

$ grails create-domain-class sample.Person

Then edit your domain class by adding some properties to Person class like.

String firstname
String lastName

if you still have the hibernate plugin, you will need to add this line to your domain class.

static mapWith="mongo"

5. Generate controller with scaffolding.

$ grails generate-controller sample.Person

and edit controller class by adding def scaffold = Person and controller will look like this.

package sample
import org.springframework.dao.DataIntegrityViolationException
class PersonController {
def scaffold = Person
}

6. Run application, be for run application you have to be sure that mogod is running by

$ mongostat

if you got this message “couldn’t connect to [127.0.0.1] couldn’t connect to server 127.0.0.1″ you must start the mongod, see how to start mongod  but if the mongo is already running you will see the result of that command like this

After everything goes OK It’s time to run-app
$ grails run-app
and hit the browser by localhost:8080/yourapp you will see

7. Test insert and query data

8. Use mongoDB shell to see data.
$ mongo
MongoDB shell version: 2.0.2
connecting to: test
> show dbs;
local (empty)
sample 0.203125GB
> use sample;
switched to db sample
> show collections;
person
person.next_id
system.indexes
> db.person.find();
{ “_id” : NumberLong(1), “firstName” : “Suriya”, “lastName” : “Sripalang”, “version” : 0 }
{ “_id” : NumberLong(3), “firstName” : “Isaac”, “lastName” : “Newton”, “version” : 0 }
{ “_id” : NumberLong(4), “firstName” : “Mark”, “lastName” : “Viduka”, “version” : 0 }
{ “_id” : NumberLong(5), “firstName” : “Homer”, “lastName” : “Simpson”, “version” : 0 }
>

Yes! we did it. It’s so really easy to connect mongoDB with Grails 2.0
Need more? see Grails mongoDB manual. Talk to me @etcpe9 

Extending domain classes with inheritant in Grails, การสืบทอดโดเมนคลาสใน Grails

สมมุติเรามีคลาสดังนี้
class Person {
String name
}

class Employee extends Person {
String employeeID
}

class Student extends Person {
String studentID
String faculty
}

ในฐานข้อมูลจะเป็นอย่างไร? จะมีตารางแยกจากกันหรือจะมีแค่ตารางเดียว คำตอบคือ ใน grails ทำได้ทั้งสองอย่าง

แบบแรก table per hierarchy mapping
โดยปกติแล้วเราจะได้ตาราง person ในฐานข้อมูลที่มีคุณสมบัติ ของทั้งคลาสแม่และคลาสลูกอยู่ด้วยกันไม่ว่า Person จะถูกสืบทอดมากน้อยแค่ไหน เราก็จะได้แค่ตารางในฐานข้อมูลเพียงตาราง Person ตารางเดียว โดยเวลาที่เราสร้าง instance ของคลาส ใด ๆ ที่อยู่ในลำดับของการสืบทอดก็ตาม คุณสมบัติที่ไม่มีในคลาสอื่นก็จะมีค่าเป็น null ในคอลัมน์ ซึ่งมันก็ไม่มีปัญหาใด ๆ เพราะ grails มันจะสร้าง ตารางที่มีคอลัมที่สามารถมีค่าเป็น null ได้ ลองคิดดูว่าหากมีการสือบทอดกันยาว ๆ แล้วละก็ ตาราง Person จะวุ่นวายขนาดไหน

แบบที่สอง table per subclass mapping
คือ ทำให้ตารางแยกออกจากกัน โดยเราต้องระบุลงไปในคลาสแม่ ดังนี้

static mapping = {
tablePerHierarchy false
}

เราก็จะได้ตารางที่ถูกแยกออกจากัน เวลาเราจะรับข้อมูลของคลาสลูกมันจะรวบรวมคุณสมบัติทั้งหมดที่เกี่ยวข้อง ซึ่งจะทำให้เกิดการ join ตารางเกิดขึ้น ถ้าหากเรามองในเรื่องประสิทธิภาพแล้วการไม่มีการ join ตารางนั้นเวลาเรา query ข้อมูลก็จะมีประสิทธิภาพมากกว่าพูดง่าย ๆ คือเร็วกว่า

สรุปแล้วจะเลือกใช้แบบไหนอันนี้ก็ขึ้นอยู่กับหลายอย่างรวมทั้ง business logic ด้วย ก็พิจารณาเลือกใช้ตามความเหมาะสมของแต่ละ Application

วิธี ลง driver webcam Sony Vaio CR35S บน Ubuntu

หลายคนคงมีปัญหาในการเข้าใช้งาน webcam บน linux ไม่ได้ ผมเองก็เป็นหนึ่งในนั้น เพราะ Google Plus มี Hangout แต่เผอิญ ใช้งานไม่ได้ ก็เลยลองค้นในเน็ตดูก็พบวิธีแนะนำการติดตั้ง ไดร์วเวอร์ webcam ของ Vaio รุ่น VGN-CR35S บน Ubuntu ดังนี้

$ sudo apt-get install libglib2.0-dev libusb-dev build-essential gcc automake mercurial
$ hg clone http://bitbucket.org/ahixon/r5u87x/
$ cd r5u87x
$ make
$ sudo make install
$ sudo r5u87x-loader –reload

ลอง lsusb ดูว่า มี webcam เป็นรุ่นอะไร ในที่นี้เป็น
Ricoh Co., Ltd Visual Communication Camera VGP-VCC6 [R5U870]

หมายเหตุ: การติดตั้งสามารถใช้ได้กับ Sony Vaio VGN-CR35S หรือรุ่นใกล้เคียงที่ใช้webcam รหัส R5U870

ระบบที่ใช้ Ubuntu 11.04 Natty AMD64
ที่มา https://bitbucket.org/ahixon/r5u87x/overview

Setting Time on Debian, ตั้งเวลาบน debian

following step to change date and time on your debian system by using terminal.
1. Open terminal and log in into root by type “su” without quote then enter and input your root password to change date and time you must login as root.
2. If you enter “date” without quot in terminal you will get date like this “Thu Oct 29 21:10:09 ICT 2009″
3. Change date and time by using

date nnddhhmm[[cc]yy][.ss]

where

  • nn = month of the year (01 to 12)
  • dd = day of the month (01 to 31)
  • hh = hour of the day (00 to 23)
  • mm = minute of the hour (00 to 59>
  • cc = The first to digits of the year
  • yy = The last two digits of the year
  • .ss = The seconds

Example:  date 10292120[[20]09][.00]

Reference: http://www.go2linux.org/how-to-set-the-date-and-time-in-linux

Lamborghini Gallardo LP550-2 Valentino Balboni

ผมเป็นคนนึงซึ่งชอบ Lamborghini เอามาก ๆ ก็เลยอยากนำเสนอข้อมูลรถรุ่นต่าง ๆ ของ Lamborghini มาให้อ่านกัน

gallardolp550-2_and_valentino_rgb_large

คงไม่สายไปที่จะนำเอารถรุ่นนี้มาพูดถึงกันสักหน่อย Lamborghini Gallardo LP 550-2 Valentino Balboni เป็นรถรุ่นที่ทำมาพิเศษเพื่อเป็นเกียรติแก่ Test Driver ของ Lamborghini ที่ได้รับความไว้วางใจจาก Ferruccio Lamborghini ผู้ก่อตั้งบริษัท ให้เป็นผู้ขับทดสอบที่ยิ่งใหญ่ ซึ่งเขาก็คือ Valentino Balboni นั่นเอง. Balboni เข้ามาทำงานที่นี่ตั้งแต่ปี 1968 Continue reading

Hello world

Hello everyone. Welcome to my new blog from the old retard blog etcpe9.blogspot.com to the new wordpress blog. What about the topic to say and share in this blog. The topic is all about internet technology, computer technology, robot, super car, business, social marketing, gadget, e-commerce, opensouce, the universe, all kind of technology, and myself. Enjoy my post and surfing the information.
Bye ^_^