{"id":320,"date":"2014-06-02T15:07:00","date_gmt":"2014-06-02T15:07:00","guid":{"rendered":"http:\/\/shirishranjit.com\/blog1\/?page_id=320"},"modified":"2015-03-04T10:24:00","modified_gmt":"2015-03-04T15:24:00","slug":"google-app-engine-and-google-web-toolkit","status":"publish","type":"page","link":"https:\/\/shirishranjit.com\/blog1\/entertainment\/google-app-engine-and-google-web-toolkit","title":{"rendered":"Google App Engine"},"content":{"rendered":"<p>Google App Engine and Google Web toolkit<\/p>\n<p>&nbsp;<\/p>\n<p>App Engine Datastore &#8211; steps on creating JPA objects:<\/p>\n<p>1) Create JPA Objects with appropriate relationship. The JPA objects require the Key class if you are going to use the JPA relationship to create a relational datastore.<\/p>\n<p>2) Follow documents in adding test jars for app engine datastore and write test classes. Initialize the \u00a0LocalServiceTestHelper class and then call DAO classes to store and retrieve.<\/p>\n<p>&nbsp;<\/p>\n<p>Creating a datastore key:<br \/>\n<code><br \/>\nKey modelId = KeyFactory.createKey(ModelClass.class.getSimpleName(),<br \/>\nsomeModel.getModelLongId());<br \/>\n<\/code><br \/>\nMake sure that the Key.toString produces the same string such as ClassSimpleName(1). If the toString does not matches then you do not have the same key.<\/p>\n<p>&nbsp;<\/p>\n<p>How to Query Datastore with key:<\/p>\n<p><code><br \/>\nprotected Object findByKey(Key modelId, Class persistObject) throws Exception {<\/code><\/p>\n<p>String modelIdQuery = &#8220;Select persitObj from &#8221; + persistObject.getName() + &#8221; persitObj &#8221;<br \/>\n+ &#8221; where persitObj.modelId = :modelId &#8220;;<\/p>\n<p>try {<br \/>\nvalidateEntityManager();<\/p>\n<p>\/\/ user name query<br \/>\nQuery query = em.createQuery(modelIdQuery);<br \/>\nquery.setParameter(&#8220;modelId&#8221;, modelId);<br \/>\nList resultList = query.getResultList();<br \/>\n\/\/ lets see if we got a user already in our db.<br \/>\nif (resultList.size() &gt; 0) {<br \/>\nreturn resultList.get(0);<br \/>\n}<\/p>\n<p>return null;<\/p>\n<p>}<br \/>\ncatch (Exception e) {<br \/>\nthrow e;<br \/>\n}<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<div class=\"twttr_buttons\"><div class=\"twttr_twitter\">\n\t\t\t\t\t<a href=\"http:\/\/twitter.com\/share?text=Google+App+Engine\" class=\"twitter-share-button\" data-via=\"\" data-hashtags=\"\"  data-size=\"default\" data-url=\"https:\/\/shirishranjit.com\/blog1\/entertainment\/google-app-engine-and-google-web-toolkit\"  data-related=\"\" target=\"_blank\">Tweet<\/a>\n\t\t\t\t<\/div><div class=\"twttr_followme\">\n\t\t\t\t\t\t<a href=\"https:\/\/twitter.com\/shiranjit\" class=\"twitter-follow-button\" data-size=\"default\"  data-show-screen-name=\"false\"  target=\"_blank\">Follow me<\/a>\n\t\t\t\t\t<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Google App Engine and Google Web toolkit &nbsp; App Engine Datastore &#8211; steps on creating JPA objects: 1) Create JPA Objects with appropriate relationship. The JPA objects require the Key class if you are going to use the JPA relationship &hellip; <a href=\"https:\/\/shirishranjit.com\/blog1\/entertainment\/google-app-engine-and-google-web-toolkit\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":51,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-320","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/320"}],"collection":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/comments?post=320"}],"version-history":[{"count":2,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/320\/revisions"}],"predecessor-version":[{"id":790,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/320\/revisions\/790"}],"up":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/51"}],"wp:attachment":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/media?parent=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}