<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Without the bitter, the sweet ain't as sweet</title>
	<atom:link href="http://i2b0.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://i2b0.wordpress.com</link>
	<description></description>
	<lastBuildDate>Tue, 21 Apr 2009 04:09:44 +0000</lastBuildDate>
	<language>th</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='i2b0.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Without the bitter, the sweet ain't as sweet</title>
		<link>http://i2b0.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://i2b0.wordpress.com/osd.xml" title="Without the bitter, the sweet ain&#039;t as sweet" />
	<atom:link rel='hub' href='http://i2b0.wordpress.com/?pushpress=hub'/>
		<item>
		<title>ของฟรี vs. ของเสียเงิน</title>
		<link>http://i2b0.wordpress.com/2009/04/21/%e0%b8%82%e0%b8%ad%e0%b8%87%e0%b8%9f%e0%b8%a3%e0%b8%b5-vs-%e0%b8%82%e0%b8%ad%e0%b8%87%e0%b9%80%e0%b8%aa%e0%b8%b5%e0%b8%a2%e0%b9%80%e0%b8%87%e0%b8%b4%e0%b8%99/</link>
		<comments>http://i2b0.wordpress.com/2009/04/21/%e0%b8%82%e0%b8%ad%e0%b8%87%e0%b8%9f%e0%b8%a3%e0%b8%b5-vs-%e0%b8%82%e0%b8%ad%e0%b8%87%e0%b9%80%e0%b8%aa%e0%b8%b5%e0%b8%a2%e0%b9%80%e0%b8%87%e0%b8%b4%e0%b8%99/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 04:09:44 +0000</pubDate>
		<dc:creator>i2b0</dc:creator>
				<category><![CDATA[nothing]]></category>

		<guid isPermaLink="false">http://i2b0.wordpress.com/?p=20</guid>
		<description><![CDATA[ไม่ได้ update blog ซะนานเลย  วันนี้ำพอมีเวลาว่างเปิด web ดูนู่นดูนี่  ก็ไปเจอเรื่องน่าสนใจ เมื่อหลายเดือนก่อนมีคนมาถามผมว่า ถ้าจะทำพวกให้บริการ ads คล้ายๆ google adsense จะต้องใ ช้เครื่อง spec อะไร ใช้ software อะไรเป็น DBMS โดยให้ตัวเลขประมาณ transaction ต่อวันมาคร่าวๆ ผมก็ตอบไ ปว่าแค่ MySQL ก็เหลือเฟือ ไม่ถึงกับต้องเสียเงินไปซื้อ DBMS ราคาแพงมาใช้ คนถามก็งงๆ ว่าจะสามารถรองรับได้เหรอ จนถึงตอนนี้ก็ไ ม่ทราบว่าโครงการนั้นไปถึงไหนแล้ว มาวันนี้ผมเ องก็เพิ่งรู้ว่า facebook เจ้าของ social networking ชื่อก้องโ ลกเอง ที่เมื่อปีที่แล้วมี hit rate มากกว่า 80,000 hit ต่อนาที ก็ยังคงใ ช้ php/mysql อยู่ อย่าง [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=i2b0.wordpress.com&amp;blog=6232190&amp;post=20&amp;subd=i2b0&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>ไม่ได้ update blog ซะนานเลย <br />
วันนี้ำพอมีเวลาว่างเปิด web ดูนู่นดูนี่  ก็ไปเจอเรื่องน่าสนใจ</p>
<p>เมื่อหลายเดือนก่อนมีคนมาถามผมว่า ถ้าจะทำพวกให้บริการ ads คล้ายๆ google adsense<br />
จะต้องใ ช้เครื่อง spec อะไร ใช้ software อะไรเป็น DBMS โดยให้ตัวเลขประมาณ transaction ต่อวันมาคร่าวๆ<br />
ผมก็ตอบไ ปว่าแค่ MySQL ก็เหลือเฟือ ไม่ถึงกับต้องเสียเงินไปซื้อ DBMS ราคาแพงมาใช้<br />
คนถามก็งงๆ ว่าจะสามารถรองรับได้เหรอ<br />
จนถึงตอนนี้ก็ไ ม่ทราบว่าโครงการนั้นไปถึงไหนแล้ว</p>
<p>มาวันนี้ผมเ องก็เพิ่งรู้ว่า facebook เจ้าของ social networking ชื่อก้องโ ลกเอง<br />
ที่เมื่อปีที่แล้วมี hit rate มากกว่า 80,000 hit ต่อนาที ก็ยังคงใ ช้ php/mysql อยู่</p>
<p>อย่าง google เองก็ยังคงใช้ linux เป็น os สำหรับ server<br />
และในหลายๆ project ของ google เองก็ใช้ opensource อย่างแพร่หลาย และมีประสิทธิภาพ</p>
<p>จะเห็นได้ว่าบ่อยครั้งที่ free opensource/software ก็ knock out licensed software ด้วยความสามารถของ architecture และ engineer<br />
ทำไ มคนไทยไม่เอาเป็นแบบอย่างบ้าง<br />
หรือกลัวว่าจะไม่ได้ commission นอกระบบกันนะ <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/i2b0.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/i2b0.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/i2b0.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/i2b0.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/i2b0.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/i2b0.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/i2b0.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/i2b0.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/i2b0.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/i2b0.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/i2b0.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/i2b0.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/i2b0.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/i2b0.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=i2b0.wordpress.com&amp;blog=6232190&amp;post=20&amp;subd=i2b0&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://i2b0.wordpress.com/2009/04/21/%e0%b8%82%e0%b8%ad%e0%b8%87%e0%b8%9f%e0%b8%a3%e0%b8%b5-vs-%e0%b8%82%e0%b8%ad%e0%b8%87%e0%b9%80%e0%b8%aa%e0%b8%b5%e0%b8%a2%e0%b9%80%e0%b8%87%e0%b8%b4%e0%b8%99/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4a7645bd6088a4e28f31fbb618f1567a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">i2b0</media:title>
		</media:content>
	</item>
		<item>
		<title>ทำไม !!?!?!?</title>
		<link>http://i2b0.wordpress.com/2009/01/30/%e0%b8%97%e0%b8%b3%e0%b9%84%e0%b8%a1/</link>
		<comments>http://i2b0.wordpress.com/2009/01/30/%e0%b8%97%e0%b8%b3%e0%b9%84%e0%b8%a1/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 18:20:32 +0000</pubDate>
		<dc:creator>i2b0</dc:creator>
				<category><![CDATA[nothing]]></category>

		<guid isPermaLink="false">http://i2b0.wordpress.com/?p=18</guid>
		<description><![CDATA[ทำไมงาน sw development ที่ใช้ OOP เป็นหลัก ถึงได้มีแต่คนที่ทำงานโดยยังคิดเป็น procedural programming อยู่นะ ทั้งที่ OOP ในไทยก็เริ่มใช้กันแพร่หลายมาเกือบสิบปีแล้ว แต่ knowledge และความเข้าใจของคนที่ทำงานด้วยกัน เหมือนมันเป็นเรื่องใหม่เลย แค่ developer เองยังหาน้อยมากที่เข้าใจ concept และนำมาใช้งานให้ได้ประสิทธิภาพ ซ้ำร้าย sa ที่เ ข้าใจยิ่งหายากกว่า ปล1: โดยทั่วไปประมาณ 90% ของ developer ที่ใช้ microsoft ใช้งาน OOP ให้เกิดประโยชน์ไม่เป็น ปล2: ส่วนใหญ่ developer ชอบการ copy+paste ทั้งที่รู้ว่างาน sw development มักจะเจอแบบแก้แล้วแก้อีก ทั้งแก็ก้ bug ทั้ง change requirement แต่ก็ยังคงเพิ่มงานให้ตัวเองโดยการ copy+paste ปล3: คนที่ทำงาน sw [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=i2b0.wordpress.com&amp;blog=6232190&amp;post=18&amp;subd=i2b0&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>ทำไมงาน sw development ที่ใช้ OOP เป็นหลัก ถึงได้มีแต่คนที่ทำงานโดยยังคิดเป็น procedural programming อยู่นะ<br />
ทั้งที่ OOP ในไทยก็เริ่มใช้กันแพร่หลายมาเกือบสิบปีแล้ว แต่ knowledge และความเข้าใจของคนที่ทำงานด้วยกัน เหมือนมันเป็นเรื่องใหม่เลย<br />
แค่ developer เองยังหาน้อยมากที่เข้าใจ concept และนำมาใช้งานให้ได้ประสิทธิภาพ<br />
ซ้ำร้าย sa ที่เ ข้าใจยิ่งหายากกว่า</p>
<p>ปล1: โดยทั่วไปประมาณ 90% ของ developer ที่ใช้ microsoft ใช้งาน OOP ให้เกิดประโยชน์ไม่เป็น<br />
ปล2: ส่วนใหญ่ developer ชอบการ copy+paste ทั้งที่รู้ว่างาน sw development มักจะเจอแบบแก้แล้วแก้อีก ทั้งแก็ก้ bug ทั้ง change requirement แต่ก็ยังคงเพิ่มงานให้ตัวเองโดยการ copy+paste<br />
ปล3: คนที่ทำงาน sw development โดยทั่วไป (โดยเฉพาะ sa) เข้าใจว่าการ re-use ในมุมของ oop คือการ enhancement บางสิ่งบางอย่าง ให้ใช้งานได้หลายๆ ที่ ผลที่ตามมาคือ dependency มหาศาล ทำให้ยากต่อการ debug และการแก้ไข<br />
ปล4: เท่าที่เจอมา 80% ของ developer ใช้ spring เพียงแค่การใช้แทนการสร้าง object และการเรียก set method<br />
ปล5: ทั้งหมดมาจากประสบการณ์ส่วนตัวทีเ จอมาทั้ง organization ขนาดใหญ่บางที่ จนถึงขนาดเล็ก<br />
ปล6: จากทั้งหมดข้างบนอาจบอกได้ว่าคนที่ทำงานจริงจังไม่ได้รับการ encourage/motivate ในการเรียนรู้ ทั้งจากที่เกี่ยวกับงาน และเกี่ยวกับ technology จริงจังจากองค์กร เท่าที่เห็นส่วนมาก คนที่ทำงานดีทำงานเก่ง งานจะมากองโดยที่เงินเดือนเท่าเดิม จะได้เงินดือนขึ้นก็ต่อเมื่อตอนที่บอกว่าจะลาออก ซึ่งคนส่วนมากเมื่อบอกว่าจะลาออกก็คือได้งานใหม่แล้วนั่นเอง</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/i2b0.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/i2b0.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/i2b0.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/i2b0.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/i2b0.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/i2b0.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/i2b0.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/i2b0.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/i2b0.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/i2b0.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/i2b0.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/i2b0.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/i2b0.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/i2b0.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=i2b0.wordpress.com&amp;blog=6232190&amp;post=18&amp;subd=i2b0&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://i2b0.wordpress.com/2009/01/30/%e0%b8%97%e0%b8%b3%e0%b9%84%e0%b8%a1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4a7645bd6088a4e28f31fbb618f1567a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">i2b0</media:title>
		</media:content>
	</item>
		<item>
		<title>สร้าง generic type-safe DAO ด้วย Hibernate และ JDK5</title>
		<link>http://i2b0.wordpress.com/2009/01/19/%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87-generic-type-safe-dao-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-hibernate-%e0%b9%81%e0%b8%a5%e0%b8%b0-jdk5/</link>
		<comments>http://i2b0.wordpress.com/2009/01/19/%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87-generic-type-safe-dao-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-hibernate-%e0%b9%81%e0%b8%a5%e0%b8%b0-jdk5/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 13:36:16 +0000</pubDate>
		<dc:creator>i2b0</dc:creator>
				<category><![CDATA[Object-Oriented]]></category>
		<category><![CDATA[DAO]]></category>
		<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://i2b0.wordpress.com/?p=3</guid>
		<description><![CDATA[การใช้ hibernate สำหรับทำ ORM นั้น ยังมีข้อดีอีกอย่างนึงคือ สามารถสร้าง generic dao ได้ โดยสามารถนำ operation ที่ใช้ทั่วไปคือ CRUD (Create, Read, Update, Delete) มาไว้ที่ base-class โดยที่ไม่ต้องเขียน operation เหล่านี้ที่ sub-class อีก  แต่การทำแบบนี้เป็น type-unsafe operation คือ ใน base-class สามารถรับ parameter เป็น Object หรือ base-class ของ data class เท่านั้น ซึ่งในการเรียกใช้งาน operation เหล่านี้เราต้องทำ explicit casting และ error บางอย่าง สามารถตรวจสอบได้ที่ runtime เท่านั้น ที่นี้เรามาดูการใช้ hibernate และ jdk5 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=i2b0.wordpress.com&amp;blog=6232190&amp;post=3&amp;subd=i2b0&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>การใช้ hibernate สำหรับทำ ORM นั้น ยังมีข้อดีอีกอย่างนึงคือ<br />
สามารถสร้าง generic dao ได้ โดยสามารถนำ operation ที่ใช้ทั่วไปคือ CRUD (Create, Read, Update, Delete)<br />
มาไว้ที่ base-class โดยที่ไม่ต้องเขียน operation เหล่านี้ที่ sub-class อีก <br />
แต่การทำแบบนี้เป็น type-unsafe operation คือ ใน base-class สามารถรับ parameter เป็น Object<br />
หรือ base-class ของ data class เท่านั้น ซึ่งในการเรียกใช้งาน operation เหล่านี้เราต้องทำ explicit casting และ error บางอย่าง<br />
สามารถตรวจสอบได้ที่ runtime เท่านั้น<br />
<span id="more-3"></span>ที่นี้เรามาดูการใช้ hibernate และ jdk5 ในการสร้าง generic type-safe dao กัน <br />
ขั้นตอนแรกคือการกำหนด interface สำหรับ generic dao และ implementation class</p>
<pre>public interface GenericDao &lt;T, PK extends Serializable&gt; {
  public PK create(T object);
  public T read(PK pk);
  public void update(T object);
  public void delete(T object);
}

public class GenericDaoImpl &lt;T, PK extends Serializable&gt;
    implements GenericDao&lt;T,PK&gt; {
  private Class&lt;T&gt; type;
  public GenericDaoImpl(Class&lt;T&gt; type) {
    this.type = type;
  }
  public PK create(T object) {
    return (PK) getSession().save(object);
  }
  public T read(PK pk) {
    return (T) getSession().get(type, pk);
  }
  public void update(T object) {
    getSession().update(object);
  }
  public void delete(T object) {
    getSession().delete(object);
  }
} </pre>
<p>ในการนำ GenericDao นี้ไปใช้งานต่างๆ ก็เพียงแค่สร้าง sub-class ขึ้นมาเท่านั้น<br />
และยังสามารถเพิ่มเติม method ต่างๆ ตามที่ต้องการได้</p>
<pre>public class PersonDao extends GenericDaoImpl&lt;Person, Integer&gt; {
  public PersonDao() {
    super(Person.class);
  }

  public List&lt;Person&gt; findByName(String name) {
    return (List&lt;Person&gt;) getSession().createQuery("from packagename.Person p where p.name = ?").setString(1,name).list();
  }
  // additional finder methods if need
} 

 </pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/i2b0.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/i2b0.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/i2b0.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/i2b0.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/i2b0.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/i2b0.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/i2b0.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/i2b0.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/i2b0.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/i2b0.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/i2b0.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/i2b0.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/i2b0.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/i2b0.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=i2b0.wordpress.com&amp;blog=6232190&amp;post=3&amp;subd=i2b0&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://i2b0.wordpress.com/2009/01/19/%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87-generic-type-safe-dao-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-hibernate-%e0%b9%81%e0%b8%a5%e0%b8%b0-jdk5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4a7645bd6088a4e28f31fbb618f1567a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">i2b0</media:title>
		</media:content>
	</item>
		<item>
		<title>DAO คืออะไร?</title>
		<link>http://i2b0.wordpress.com/2009/01/19/dao-%e0%b8%84%e0%b8%b7%e0%b8%ad%e0%b8%ad%e0%b8%b0%e0%b9%84%e0%b8%a3/</link>
		<comments>http://i2b0.wordpress.com/2009/01/19/dao-%e0%b8%84%e0%b8%b7%e0%b8%ad%e0%b8%ad%e0%b8%b0%e0%b9%84%e0%b8%a3/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 12:22:16 +0000</pubDate>
		<dc:creator>i2b0</dc:creator>
				<category><![CDATA[Object-Oriented]]></category>
		<category><![CDATA[DAO]]></category>

		<guid isPermaLink="false">http://i2b0.wordpress.com/?p=5</guid>
		<description><![CDATA[DAO ย่อมาจาก Data Access Objects แนวความคิดนี้เกิดขึ้นมาจาก Microsoft เพื่อให้ programmer สามารถเข้าใช้งาน database ประเภทต่างๆ ได้โดยง่าย ใน OOP เราใช้ DAO เพื่อแยก data layer ออกจาก business layer ให้ชัดเจน ใน business layer เราไม่จำเป็นต้องรู้เกี่ยวกับ sql statement หรือการเข้าถึงข้อมูลในฐานข้อมูล ดังนั้นในส่วนที่เป็นการเข้าถึงข้อมูลในฐานข้อมูลจึงถูกแยกออกมาเป็น data access layer   ข้อดีและข้อเสีย ข้อดีของการแยก data access code ออกจาก business code ก็คือ ผู้ที่เขียน business code ไม่จำเป็นต้องรู้เกี่ยวกับฐานข้อมูล หรือการเขียน sql statement ทั้งนี้ใน medium-scale และ [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=i2b0.wordpress.com&amp;blog=6232190&amp;post=5&amp;subd=i2b0&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>DAO ย่อมาจาก Data Access Objects แนวความคิดนี้เกิดขึ้นมาจาก Microsoft เพื่อให้ programmer สามารถเข้าใช้งาน database ประเภทต่างๆ ได้โดยง่าย<br />
ใน OOP เราใช้ DAO เพื่อแยก data layer ออกจาก business layer ให้ชัดเจน<br />
ใน business layer เราไม่จำเป็นต้องรู้เกี่ยวกับ sql statement หรือการเข้าถึงข้อมูลในฐานข้อมูล<br />
ดังนั้นในส่วนที่เป็นการเข้าถึงข้อมูลในฐานข้อมูลจึงถูกแยกออกมาเป็น data access layer<br />
<span id="more-5"></span> </p>
<h2>ข้อดีและข้อเสีย</h2>
<p>ข้อดีของการแยก data access code ออกจาก business code ก็คือ ผู้ที่เขียน business code ไม่จำเป็นต้องรู้เกี่ยวกับฐานข้อมูล หรือการเขียน sql statement<br />
ทั้งนี้ใน medium-scale และ large-scale application มีโอกาสมากที่จะมีการ query หรือ update ข้อมูลเดียวกันมากกว่า 1 function<br />
การแยก data access layer ออกมาก ก็ทำให้ไม่ต้องเขียน code ซ้ำๆ หรือ copy + paste และทำให้ความซับซ้อนของ code ลดลงอย่างมาก</p>
<h2>วิธีการ</h2>
<p> โดยมากแล้ว วิธีการพัฒนา software ในไทย เริ่มจากการ design database/table ซึ่งในการใช้ OOP นั้นเป็นวิธีการที่ไม่ค่อยจะถูกต้องนัก<br />
ในเมื่อ table ถูกออกแบบมา ดังนั้นโดยทั่วไป data object และ dao จะถูกสร้างขึ้นที่จุดนี้<br />
 โดยทำการสร้าง 1 data class และ 1 dao class ต่อ 1 table ตัวอย่างเช่น<br />
เรามีตารางลูกค้า</p>
<pre>create table customer {
  customer_id int primary key,
  name varchar(50),
  addr_line1 varchar(200),
  addr_line2 varchar(200),
  addr_line3 varchar(200),
  tel varchar(100),
  fax varchar(100)
} </pre>
<p>เราจะสร้าง class เพื่อเป็นตัวแทนของข้อมูลลูกค้าโดยมี property ต่างๆ ตามตาราง customer</p>
<pre>public class Customer {
  private Integer customer_id;
  private String name;
  private String addrLine1;
  private String addrLine2;
  private String addrLine3;
  private String tel;
  private String fax;
} </pre>
<p>หลังจากนั้นจึงสร้าง interface สำหรับ DAO และ implementation class ในการ select/insert/update/delete ข้อมูลลูกค้า ดังนี้</p>
<pre>public interface ICustomerDao {
  public Customer read(Integer customerId) throws Exception; 
  public void create(Customer c) throws Exception;
  public void update(Customer c) throws Exception;
  public void delete(Customer c) throws Exception;
  public void delete(Integer customerId) throws Exception;
  public List&lt;Customer&gt; findByName(String name) throws Exception;
  // .. additional methods if need
} 

public class CustomerDao implements ICustomerDao {
  public Customer read(Integer customerId) throws Exception {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Customer c = null;

    try {
      pstmt = connection.prepareStatement("select * from customer where customer_id=?");
      pstmt.setInt(1, customerId);
      rs = pstmt.executeQuery();
      if (rs.next()) {
        c = new Customer();
        c.setCustomerId(rs.getInt(1));
        c.setName(rs.getString(2));
        // map other properties
      }
    } finally {
       try {
         if (rs != null) rs.close();
         if (pstmt != null) pstmt.close();
       } catch (Exception e) {}
    }
    return c;
  }
  // other method implementation code
} </pre>
<p>ในการใช้งาน dao ภายใน business layer ก็ใช้เพียงแค่</p>
<pre>Customer customer = customerDao.read(customerId);
customer.setName(newName);
customerDao.update(customer); </pre>
<p>โดยไม่ต้องสนใจการเขียน sql statement และยังสามารถนำไปใช้ได้หลายที่โดยไม่ต้อง copy+paste อีกด้วย</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/i2b0.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/i2b0.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/i2b0.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/i2b0.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/i2b0.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/i2b0.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/i2b0.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/i2b0.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/i2b0.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/i2b0.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/i2b0.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/i2b0.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/i2b0.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/i2b0.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=i2b0.wordpress.com&amp;blog=6232190&amp;post=5&amp;subd=i2b0&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://i2b0.wordpress.com/2009/01/19/dao-%e0%b8%84%e0%b8%b7%e0%b8%ad%e0%b8%ad%e0%b8%b0%e0%b9%84%e0%b8%a3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4a7645bd6088a4e28f31fbb618f1567a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">i2b0</media:title>
		</media:content>
	</item>
		<item>
		<title>สวัสดี ชาวโลก!</title>
		<link>http://i2b0.wordpress.com/2009/01/19/สวัสดี-ชาวโลก/</link>
		<comments>http://i2b0.wordpress.com/2009/01/19/สวัสดี-ชาวโลก/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 10:18:31 +0000</pubDate>
		<dc:creator>i2b0</dc:creator>
				<category><![CDATA[ไม่มีหมวดหมู่]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=i2b0.wordpress.com&amp;blog=6232190&amp;post=1&amp;subd=i2b0&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Welcome to <a href="http://wordpress.com/">WordPress.com</a>. This is your first post. Edit or delete it and start blogging!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/i2b0.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/i2b0.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/i2b0.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/i2b0.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/i2b0.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/i2b0.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/i2b0.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/i2b0.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/i2b0.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/i2b0.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/i2b0.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/i2b0.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/i2b0.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/i2b0.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=i2b0.wordpress.com&amp;blog=6232190&amp;post=1&amp;subd=i2b0&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://i2b0.wordpress.com/2009/01/19/สวัสดี-ชาวโลก/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4a7645bd6088a4e28f31fbb618f1567a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">i2b0</media:title>
		</media:content>
	</item>
	</channel>
</rss>
