<?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/"
	>

<channel>
	<title>Pakzilla</title>
	<atom:link href="http://www.pakzilla.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pakzilla.com</link>
	<description>A blog on Programming, Web and Technology</description>
	<lastBuildDate>Fri, 05 Mar 2010 11:37:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to use and retain Twitter4J OAuth access token</title>
		<link>http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/</link>
		<comments>http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 20:41:34 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[Twitter4J]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=831</guid>
		<description><![CDATA[I  stuck in a problem that how to re use access token, once user has authenticated by Twitter (on call back URL). I got it working. There was problem in my understanding about request token vs access token. When user first time comes on call backed URL. I take request token and token secret from [...]]]></description>
			<content:encoded><![CDATA[<p>I  stuck in a problem that how to re use access token, once user has authenticated by Twitter (on call back URL). I got it working. There was problem in my understanding about request token vs access token. When user first time comes on call backed URL. I take request token and token secret from session and prepare the access token. Here the place where I was confused.</p>
<p>Now if user presses the refresh button or you want to get user information again from twitter any where in your application. You need to use the access token and this method<strong> twitter.setOAuthAccessToken(String1, String2)</strong>. Because user has already been authenticated by Twitter. You can save this information in session.</p>
<pre class="brush: java;">
HttpSession session = request.getSession();

twitter.setOAuthConsumer(Constants.CONSUMER_KEY,Constants.CONSUMER_SECRET);

if (session.getAttribute(&quot;aToken&quot;) == null){
	// request token
	String token = (String) session.getAttribute(&quot;token&quot;);
	String tokenSecret = (String)session.getAttribute(&quot;tokenSecret&quot;);
	AccessToken accessToken =
		twitter.getOAuthAccessToken(token, tokenSecret);
	twitter.setOAuthAccessToken(accessToken);

	// save the access token, that are different from request token
	session.setAttribute(&quot;aToken&quot;, accessToken.getToken());
	session.setAttribute(&quot;aTokenSecret&quot;, accessToken.getTokenSecret());

}else{
	// use the access token to authenticate user whenever you want
	twitter.setOAuthAccessToken((String)session.getAttribute(&quot;aToken&quot;),
		(String)session.getAttribute(&quot;aTokenSecret&quot;));
}
User user = twitter.verifyCredentials();
</pre>
<p>If you are also developing some app by using Twitter4J API on Google App Engine. Please give feedback on it.</p>
<p><strong>Twitter4J Quick Tutorial:</strong> <a href="http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/">A quick tutorial on how to develop Twitter app by using Twitter4J on Google App Engine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2010/03/01/how-to-use-and-retain-twitter4j-oauth-access-token/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Get Google Wave invitation</title>
		<link>http://www.pakzilla.com/2010/02/26/get-google-wave-invitation/</link>
		<comments>http://www.pakzilla.com/2010/02/26/get-google-wave-invitation/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 09:49:05 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[Giveaway]]></category>
		<category><![CDATA[Google Wave]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=812</guid>
		<description><![CDATA[I got 28 Google Wave invitations. I am inviting my friends. I want to bring people in so that they can try it out. If they find it useful. So if you guys didn&#8217;t tried it yet. Just leave a comment by filling your correct email address. And I will bring you in.
Google guys take [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pakzilla.com/wp-content/upload/google-wave-logo.gif"><img class="size-full wp-image-813  alignright" title="google-wave-logo" src="http://www.pakzilla.com/wp-content/upload/google-wave-logo.gif" alt="" width="227" height="41" /></a>I got 28 Google Wave invitations. I am inviting my friends. I want to bring people in so that they can try it out. If they find it useful. So if you guys didn&#8217;t tried it yet. Just leave a comment by filling your correct email address. And I will bring you in.</p>
<p>Google guys take some days to deliver the invitation. So be patience. <img src='http://www.pakzilla.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Wave is in development phase so not available to every one, except invitations. You can also <a href="https://services.google.com/fb/forms/wavesignup/">request</a> Google to deliver you. Read more about <a href="http://wave.google.com/help/wave/about.html">Google Wave</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2010/02/26/get-google-wave-invitation/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Sun CEO&#8217;s internal memo to employees, before his resignation</title>
		<link>http://www.pakzilla.com/2010/02/06/sun-ceos-internal-memo-to-employees-before-his-resignation/</link>
		<comments>http://www.pakzilla.com/2010/02/06/sun-ceos-internal-memo-to-employees-before-his-resignation/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 14:07:29 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Software Industry]]></category>
		<category><![CDATA[Sun Microsystems]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Sun]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=800</guid>
		<description><![CDATA[Today I found that Jonathan Schwartz has tweeted about his resignation as Sun CEO. Due to the new control to Oracle. Schwartz sent following memo to his employees. Jonathan is an avid blogger used to blog on blogs.sun.com/jonathan.

He also tweeted about his last blog post on Sun.com, saying &#8220;Where Life Takes Me Next&#8220;.
Read the memo [...]]]></description>
			<content:encoded><![CDATA[<p>Today I found that Jonathan Schwartz has tweeted about his resignation as Sun CEO. Due to the new control to Oracle. Schwartz sent following memo to his employees. Jonathan is an avid blogger used to blog on <a href="http://blogs.sun.com/jonathan">blogs.sun.com/jonathan</a>.</p>
<p><a href="http://twitter.com/OpenJonathan/status/8620937722"><img class="aligncenter size-full wp-image-801" title="jonathan_tweets_resignation" src="http://www.pakzilla.com/wp-content/upload/jonathan_tweet.png" alt="" width="396" height="179" /></a></p>
<p>He also tweeted about his last blog post on Sun.com, saying &#8220;<a href="http://blogs.sun.com/jonathan/entry/where_life_takes_me_next">Where Life Takes Me Next</a>&#8220;.</p>
<p>Read the memo on <a href="http://digitaldaily.allthingsd.com/20100121/sun-ceo-go-oracle-internal-memo/">AllThingsDigital</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2010/02/06/sun-ceos-internal-memo-to-employees-before-his-resignation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sun.com is dead now</title>
		<link>http://www.pakzilla.com/2010/01/31/sun-com-is-dead-now/</link>
		<comments>http://www.pakzilla.com/2010/01/31/sun-com-is-dead-now/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 15:35:29 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Sun Microsystems]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Sun]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=793</guid>
		<description><![CDATA[Just found that sun.com is now redirecting to oracle.com. Some days back I visited Sun&#8217;s original website. But it didn&#8217;t took long by Oracle to make it red. Well I am a regular visitor of Sun forums. And with this change, I am trying to adjust myself with this transition. As I am having some [...]]]></description>
			<content:encoded><![CDATA[<p>Just found that <a href="http://sun.com">sun.com</a> is now redirecting to oracle.com. Some days back I visited Sun&#8217;s original website. But it didn&#8217;t took long by Oracle to make it red. Well I am a regular visitor of Sun forums. And with this change, I am trying to adjust myself with this transition. As I am having some issue in finding contents.</p>
<p>After some browsing Oracle&#8217;s website I found they were some thing to say to Java developers community about continuing Sun Developer Network.</p>
<div id="attachment_796" class="wp-caption aligncenter" style="width: 368px"><a href="http://www.pakzilla.com/wp-content/upload/oracle-sun-website.jpg"><img class="size-full wp-image-796" title="oracle-sun-website" src="http://www.pakzilla.com/wp-content/upload/oracle-sun-website.jpg" alt="" width="358" height="263" /></a><p class="wp-caption-text">Sun.com now redirects to Oracle.com</p></div>
<p><a href="http://www.oracle.com/technology/community/sun-oracle-community-continuity.html">FAQs for Sun Java developer community:</a></p>
<blockquote><p><strong>What will happen to Sun Developer Network, java.sun.com, and BigAdmin?</strong></p>
<p>For the near future, all these sites will remain in their current form. We know that these resources are important, so you can continue to access them just as you always have at the same URLs and bookmarks. At some time, we foresee an integration of these sites into a newly redesigned and re-architected Oracle Technology Network, and we welcome your feedback about this process. We will make sure that any changes are communicated well in advance so that you will continue to have access to the tools and resources that you need.</p></blockquote>
<p>And there are some other promises too about continuing Sun things.</p>
<p>I also found a Sun blogger saying good bye to <strong>blog.sun.com</strong>. Due to some Oracle policies that they can host only those blogs that targets to their products only not personal topics. You can read that blog post <a href="http://blogs.sun.com/christophersaul/entry/goodbye_blogs_sun_com">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2010/01/31/sun-com-is-dead-now/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>I have started preparing for SCJP</title>
		<link>http://www.pakzilla.com/2010/01/27/i-have-started-preparing-for-scjp/</link>
		<comments>http://www.pakzilla.com/2010/01/27/i-have-started-preparing-for-scjp/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 12:01:03 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Sun Microsystems]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SCJP]]></category>
		<category><![CDATA[Sun]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=790</guid>
		<description><![CDATA[Its been a year since I purchased the voucher for SCJP 5.0. But I cant concentrate to have time to prepare it. From last night I have taken the oath to finally make it done. I have started with the book SCJP Sun Certified Programmer for Java 5 Study Guide (Exam 310-055) by Kathy Sierra [...]]]></description>
			<content:encoded><![CDATA[<p>Its been a year since I purchased the voucher for SCJP 5.0. But I cant concentrate to have time to prepare it. From last night I have taken the oath to finally make it done. I have started with the book SCJP Sun Certified Programmer for Java 5 Study Guide (Exam 310-055) by Kathy Sierra and Bert Bates.</p>
<p>A remarkable thing is I purchased the free retake voucher which is going to expire on June 2010. But I still didnt make even a single attempt. Ok thats all right. I am going to do it. I hope to appear for the successful first attempt in good marks.</p>
<p>I am not using any IDE for coding practice. I am using Notepad++ editor and command line Javac compilation. I want to get maximum of language fundamentals and want to think out of code completion feature.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2010/01/27/i-have-started-preparing-for-scjp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Useful cheat sheets on Cloud Computing and Google App Engine for Java</title>
		<link>http://www.pakzilla.com/2010/01/12/useful-cheat-sheets-on-cloud-computing-and-google-app-engine-for-java/</link>
		<comments>http://www.pakzilla.com/2010/01/12/useful-cheat-sheets-on-cloud-computing-and-google-app-engine-for-java/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 09:49:13 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Google App Engine]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=755</guid>
		<description><![CDATA[Just read cheat sheets (Refcard) by Dzone on Cloud Computing and Google App Engine for Java. They contain a very jumped to the point and quick reference on these things. You can read to have a quick overview.
Read them here:

Cloud Computing
Google App Engine for Java

]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-705 alignright" title="google_app_engine_java" src="http://www.pakzilla.com/wp-content/upload/google_app_engine_java.png" alt="google_app_engine_java" width="117" height="106" />Just read cheat sheets (<a href="http://refcardz.dzone.com/">Refcard</a>) by Dzone on Cloud Computing and <a href="http://www.pakzilla.com/tag/google-app-engine/">Google App Engine</a> for <a href="http://www.pakzilla.com/tag/java/">Java</a>. They contain a very jumped to the point and quick reference on these things. You can read to have a quick overview.</p>
<p>Read them here:</p>
<ul>
<li><a href="http://library.dzone.com/sites/all/files/refcardz/rc082-010d-cloud-computing.pdf">Cloud Computing</a></li>
<li><a href="http://library.dzone.com/sites/all/files/refcardz/rc079-010d-google-app-engine-4.pdf">Google App Engine for Java</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2010/01/12/useful-cheat-sheets-on-cloud-computing-and-google-app-engine-for-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>010110 &#8211; The first day of 2010 is a binary friendly day</title>
		<link>http://www.pakzilla.com/2010/01/01/010110-the-first-day-of-2010-is-a-binary-friendly-day/</link>
		<comments>http://www.pakzilla.com/2010/01/01/010110-the-first-day-of-2010-is-a-binary-friendly-day/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 07:30:55 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=748</guid>
		<description><![CDATA[010110
You see todays date. OK, lets format it. 01/01/10
The combination of 0s and 1s.
So lets call the first day of 2010 is a binary friendly day. If we calculate the decimal of this binary we get 22. And we know binary has base 2.
Add these digits divide them with binary base and again you will get 2. [...]]]></description>
			<content:encoded><![CDATA[<h2>010110</h2>
<p>You see todays date. OK, lets format it. 01/01/10</p>
<p>The combination of 0s and 1s.</p>
<p>So lets call <strong>the first day of 2010 is a binary friendly day</strong>. If we calculate the decimal of this binary we get 22. And we know binary has base 2.</p>
<p>Add these digits divide them with binary base and again you will get 2. ((2+2)/2)=2. <img src='http://www.pakzilla.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2010/01/01/010110-the-first-day-of-2010-is-a-binary-friendly-day/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Got two books on Google App Engine for Java</title>
		<link>http://www.pakzilla.com/2009/12/28/got-two-books-on-google-app-engine-for-java/</link>
		<comments>http://www.pakzilla.com/2009/12/28/got-two-books-on-google-app-engine-for-java/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 18:52:40 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Google App Engine]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=733</guid>
		<description><![CDATA[Recently I got two books on Google App Engine for Java. Programming Google App Engine by Oreilly and Beginning Google App Engine by Apress. There is less material and comprehensive online tutorials available on this. So its better that you read book on it. I started reading Oreilly&#8217;s book. I completed some of the basic [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I got two books on Google App Engine for Java. <a href="http://oreilly.com/catalog/9780596522735/">Programming Google App Engine by Oreilly</a> and <a href="http://www.apress.com/book/view/9781430225539">Beginning Google App Engine by Apress</a>. There is less material and comprehensive online tutorials available on this. So its better that you read book on it. I started reading Oreilly&#8217;s book. I completed some of the basic components so quickly by given code examples in the book. Its always a good start on some new technology, if you have books in your pocket.</p>
<p>You guys can share your feedback if you read any book or any material on it.</p>
<table border = '0'>
<tr>
<td>
<img title="Apress_Beginning_Google_App_Engine" src="http://www.pakzilla.com/wp-content/upload/Apress_Beginning_Google_App_Engine.gif" alt="Apress_Beginning_Google_App_Engine" width="125" height="165" /></p>
<td>
<td>
<img title="Oreilly_GoogleAppEngin" src="http://www.pakzilla.com/wp-content/upload/Oreilly_GoogleAppEngin.gif" alt="Oreilly_GoogleAppEngin" width="128" height="166" /></p>
<td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2009/12/28/got-two-books-on-google-app-engine-for-java/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Spoken on Google App Engine at a conference in UET</title>
		<link>http://www.pakzilla.com/2009/12/19/spoken-on-google-app-engine-at-a-conference-in-uet/</link>
		<comments>http://www.pakzilla.com/2009/12/19/spoken-on-google-app-engine-at-a-conference-in-uet/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 13:31:34 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Pakistan]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[UET]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=728</guid>
		<description><![CDATA[Today I had delivered a workshop on Developing Java Web Applications In Google App Engine. This workshop was the part of events of 3rd International Conference on Open Source Systems and Technologies. It was organized by Al-Khawarizmi Institute of Computer Science , University of Engineering and Technology, Lahore.
I have presented following slides there. Also coded [...]]]></description>
			<content:encoded><![CDATA[<p>Today I had delivered a workshop on <a title="Developing Java Web Applications In Google App Engine" href="http://www.slideshare.net/tahirakram/developing-java-web-applications-in-google-app-engine-2749092">Developing Java Web Applications In Google App Engine</a>. This workshop was the part of events of <a href="http://www.uet.edu.pk/Conferences/icosst2009/_workshop.html">3rd International Conference on Open Source Systems and Technologies</a>. It was organized by <a href="http://www.kics.edu.pk/">Al-Khawarizmi Institute of Computer Science</a> , <a href="http://www.uet.edu.pk">University of Engineering and Technology</a>, Lahore.</p>
<p>I have presented following slides there. Also coded a basic sample application to show how to create and deploy new Java project on GAE. Which can send emails, how to use authentication by Google, and how to do database interaction. It was a very intresting topic for me to present. Participants also liked it.</p>
<div id="__ss_2749092" style="width: 425px; text-align: left;"><object style="margin:0px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=developingjavabasedwebapplicationsingoogleapp-091219065103-phpapp01&amp;stripped_title=developing-java-web-applications-in-google-app-engine-2749092" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=developingjavabasedwebapplicationsingoogleapp-091219065103-phpapp01&amp;stripped_title=developing-java-web-applications-in-google-app-engine-2749092" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
</div>
<p>Comments and feedback is welcomed on the presentation material from you guys.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2009/12/19/spoken-on-google-app-engine-at-a-conference-in-uet/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Tutorial: JPA on Google App Engine</title>
		<link>http://www.pakzilla.com/2009/12/13/tutorial-jpa-on-google-app-engine/</link>
		<comments>http://www.pakzilla.com/2009/12/13/tutorial-jpa-on-google-app-engine/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 15:05:58 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[JPA]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=723</guid>
		<description><![CDATA[This project will create and delete an entity record. I have chosen JPA for datastore in app engine. You can also look JDO for this purpose. But my choice to go for JPA is due to Sun standardization on it.
I am using App Engine SDK version 1.2.18
Project name: engineplay
URL: http://engineplay.appspot.com
Project structure:
UserPrefs.java: The entity class

package com.engineplay.datastore.pojos;
import [...]]]></description>
			<content:encoded><![CDATA[<p>This project will create and delete an entity record. I have chosen JPA for datastore in app engine. You can also look JDO for this purpose. But my choice to go for JPA is due to Sun standardization on it.</p>
<p>I am using App Engine SDK version 1.2.18</p>
<p>Project name: engineplay<br />
URL: http://engineplay.appspot.com</p>
<p><strong>Project structure:</strong></p>
<p><img class="aligncenter size-full wp-image-717" title="jpa_gae_project_structure" src="http://www.pakzilla.com/wp-content/upload/jpa_gae_project_structure.png" alt="jpa_gae_project_structure" width="279" height="530" /><strong>UserPrefs.java:</strong> The entity class</p>
<pre class="brush: java;">
package com.engineplay.datastore.pojos;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.Id;
import com.engineplay.datastore.EMFService;
import com.google.appengine.api.users.User;

@Entity(name = &quot;UserPrefs&quot;)
public class UserPrefs {
 @Id
 private String userId;
 private int donuts;
 @Basic
 private User user;

 public UserPrefs(String userId) {
 this.userId = userId;
 }

 /* TODO create getter and setters for above properties yourself */

 public static UserPrefs getPrefsForUser(User user) {
 UserPrefs userPrefs = null;
 EntityManager em = EMFService.get().createEntityManager();
 try {
 if (em.find(UserPrefs.class, user.getEmail()) == null) {

 userPrefs = new UserPrefs(user.getEmail());
 userPrefs.setUser(user);

 } else {
 userPrefs = em.find(UserPrefs.class, user.getEmail());
 }
 } finally {
 em.close();
 }
 return userPrefs;
 }

 public void save() {
 EntityManager em = EMFService.get().createEntityManager();
 try {
 em.persist(this);
 } finally {
 em.close();
 }
 }

 public void remove() {
 EntityManager em = EMFService.get().createEntityManager();
 try {
 UserPrefs userPrefs = em.find(UserPrefs.class, user.getEmail());
 em.remove(userPrefs);
 } finally {
 em.close();
 }
 }
}
</pre>
<p><strong>EMFService.java: </strong>The class to create EntityManagerFactory instance.</p>
<pre class="brush: java;">
package com.engineplay.datastore;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class EMFService {
 private static final EntityManagerFactory emfInstance = Persistence
 .createEntityManagerFactory(&quot;transactions-optional&quot;);

 private EMFService() {
 }

 public static EntityManagerFactory get() {
 return emfInstance;
 }
}
</pre>
<p><strong>LoginServlet.java</strong></p>
<pre class="brush: java;">
package com.engineplay.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.engineplay.datastore.pojos.UserPrefs;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class LoginServlet extends HttpServlet {

 public void doGet(HttpServletRequest req, HttpServletResponse resp)
 throws IOException {

 UserService userService = UserServiceFactory.getUserService();
 User user = userService.getCurrentUser();
 String navBar, form = null;
 int donuts = 0;
 if (user == null) {
 navBar = &quot;&lt;p&gt;Welcome! &lt;a href=\&quot;&quot; + userService.createLoginURL(&quot;/&quot;) +
 &quot;\&quot;&gt;Sign in or register&lt;/a&gt; to customize.&lt;/p&gt;&quot;;
 form = &quot;&quot;;
 } else {
 UserPrefs userPrefs = UserPrefs.getPrefsForUser(user);

 if (userPrefs != null) {
 donuts = userPrefs.getDonuts();
 }
 navBar = &quot;&lt;p&gt;Welcome, &quot; + user.getEmail() + &quot;! You can &lt;a href=\&quot;&quot; +
 userService.createLogoutURL(&quot;/&quot;) +
 &quot;\&quot;&gt;sign out&lt;/a&gt;.&lt;/p&gt;&quot;;
 form = &quot;&lt;form action=\&quot;/donuts\&quot; method=\&quot;post\&quot;&gt;&quot; +
 &quot;&lt;label for=\&quot;donuts\&quot;&gt;&quot; +
 &quot;Need more donuts?:&quot; +
 &quot;&lt;/label&gt;&quot; +
 &quot;&lt;input name=\&quot;donuts\&quot; id=\&quot;donuts\&quot; type=\&quot;text\&quot; size=\&quot;4\&quot; /&gt;&quot; +
 &quot; &lt;input name=\&quot;olddonuts\&quot;  type=\&quot;hidden\&quot; value=\&quot;&quot; + donuts + &quot;\&quot; /&gt; &quot; +
 &quot; &lt;input name=\&quot;userId\&quot;  type=\&quot;hidden\&quot; value=\&quot;&quot; +user.getEmail()+ &quot;\&quot; /&gt; &quot; +
 &quot;   &lt;input type=\&quot;submit\&quot; value=\&quot;  ADD  \&quot; /&gt;&lt;br&gt;&lt;input type=\&quot;submit\&quot;  name =\&quot;deleteBtn\&quot; value=\&quot;  DELETE ME!  \&quot; /&gt;&quot; +
 &quot;&lt;/form&gt;&quot;;

 }
 resp.setContentType(&quot;text/html&quot;);
 PrintWriter out = resp.getWriter();
 out.print(&quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Engine Play - Donuts&lt;/title&lt;/head&gt;&lt;body&gt;&quot;);
 out.println(navBar);
 if (donuts != 0)
 out.println(&quot;&lt;p&gt;Donuts you have: &quot; + donuts + &quot;&lt;/p&gt;&quot;);
 else
 out.println(&quot;&lt;p&gt; No donuts you have <img src='http://www.pakzilla.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  &lt;/p&gt;&quot;);
 out.println(form);
 out.print(&quot;&lt;/body&gt;&lt;/html&gt;&quot;);
 }
}
</pre>
<p><strong>DonutsServlet.java</strong></p>
<pre class="brush: java;">
package com.engineplay.servlet;

import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.engineplay.datastore.pojos.UserPrefs;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class DonutsServlet extends HttpServlet {

 public void doPost(HttpServletRequest req, HttpServletResponse resp)
 throws IOException {
 UserService userService = UserServiceFactory.getUserService();
 User user = userService.getCurrentUser();
 UserPrefs userPrefs = UserPrefs.getPrefsForUser(user);
 try {

 String deleteOpt = req.getParameter(&quot;deleteBtn&quot;);
 if (deleteOpt == null){
 int donuts = new Integer(req.getParameter(&quot;donuts&quot;)).intValue();
 int oldDonuts = new Integer(req.getParameter(&quot;olddonuts&quot;)).intValue();

 userPrefs.setDonuts(donuts + oldDonuts);
 userPrefs.save();
 }else{
 String userId = req.getParameter(&quot;userId&quot;);
 userPrefs.setUserId(userId);
 userPrefs.remove();
 }
 } catch (Exception e) {
 e.printStackTrace();
 }
 resp.sendRedirect(&quot;/Login&quot;);
 }
}
</pre>
<p><strong>persistence.xml:</strong> Configuration file required for JPA</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
&lt;persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot;
 xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
 xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence

http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot;

 version=&quot;1.0&quot;&gt;
 &lt;persistence-unit name=&quot;transactions-optional&quot;&gt;
 &lt;provider&gt;
 org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider
 &lt;/provider&gt;
 &lt;properties&gt;
 &lt;property name=&quot;datanucleus.NontransactionalRead&quot;
 value=&quot;true&quot; /&gt;
 &lt;property name=&quot;datanucleus.NontransactionalWrite&quot;
 value=&quot;true&quot; /&gt;
 &lt;property name=&quot;datanucleus.ConnectionURL&quot;
 value=&quot;appengine&quot; /&gt;
 &lt;/properties&gt;
 &lt;/persistence-unit&gt;
&lt;/persistence&gt;
</pre>
<p><strong>web.xml</strong></p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;!DOCTYPE web-app PUBLIC
 &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;
 &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt;

&lt;web-app xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot; version=&quot;2.5&quot;&gt;

 &lt;servlet&gt;
 &lt;servlet-name&gt;LoginServlet&lt;/servlet-name&gt;
 &lt;servlet-class&gt;com.engineplay.servlet.LoginServlet&lt;/servlet-class&gt;
 &lt;/servlet&gt;
 &lt;servlet&gt;
 &lt;servlet-name&gt;DonutsServlet&lt;/servlet-name&gt;
 &lt;servlet-class&gt;com.engineplay.servlet.DonutsServlet&lt;/servlet-class&gt;
 &lt;/servlet&gt;

 &lt;servlet-mapping&gt;
 &lt;servlet-name&gt;LoginServlet&lt;/servlet-name&gt;
 &lt;url-pattern&gt;/Login&lt;/url-pattern&gt;
 &lt;/servlet-mapping&gt;
 &lt;servlet-mapping&gt;
 &lt;servlet-name&gt;DonutsServlet&lt;/servlet-name&gt;
 &lt;url-pattern&gt;/donuts&lt;/url-pattern&gt;
 &lt;/servlet-mapping&gt;

 &lt;welcome-file-list&gt;
 &lt;welcome-file&gt;Login&lt;/welcome-file&gt;
 &lt;/welcome-file-list&gt;
&lt;/web-app&gt;
</pre>
<p>Access the project here: http://engineplay.appspot.com</p>
<p><img class="aligncenter size-full wp-image-718" title="run_gae_project" src="http://www.pakzilla.com/wp-content/upload/run_gae_project.png" alt="run_gae_project" width="562" height="281" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2009/12/13/tutorial-jpa-on-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
