{"id":51,"date":"2009-04-21T15:25:30","date_gmt":"2009-04-21T15:25:30","guid":{"rendered":"http:\/\/shirishranjit.com\/blog1\/?page_id=51"},"modified":"2014-06-02T15:06:40","modified_gmt":"2014-06-02T15:06:40","slug":"entertainment","status":"publish","type":"page","link":"https:\/\/shirishranjit.com\/blog1\/entertainment","title":{"rendered":"Google Technology"},"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(),\u00a0<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 {<\/p>\n<p>\tString modelIdQuery = \"Select persitObj from \" + persistObject.getName() + \" persitObj \"<br \/>\n\t        + \" where  persitObj.modelId = :modelId \";<\/p>\n<p>\ttry {<br \/>\n\t    validateEntityManager();<\/p>\n<p>\t    \/\/ user name query<br \/>\n\t    Query query = em.createQuery(modelIdQuery);<br \/>\n\t    query.setParameter(\"modelId\", modelId);<br \/>\n\t    List resultList = query.getResultList();<br \/>\n\t    \/\/ lets see if we got a user already in our db.<br \/>\n\t    if (resultList.size() > 0) {<br \/>\n\t\treturn resultList.get(0);<br \/>\n\t    }<\/p>\n<p>\t    return null;<\/p>\n<p>\t}<br \/>\n\tcatch (Exception e) {<br \/>\n\t    throw e;<br \/>\n\t}<br \/>\n    }<br \/>\n<\/code><\/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+Technology+\" class=\"twitter-share-button\" data-via=\"\" data-hashtags=\"\"  data-size=\"default\" data-url=\"https:\/\/shirishranjit.com\/blog1\/entertainment\"  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\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-51","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/51"}],"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=51"}],"version-history":[{"count":22,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/51\/revisions"}],"predecessor-version":[{"id":319,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/51\/revisions\/319"}],"wp:attachment":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/media?parent=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}