Hi Vinny,

thanks again for your reply.
well my understanding is that the code written in Noteendpoint.java (that 
was automatically generated from the Note.java on selecting Create 
Endpoint) is actually doing the writing part to the datastore.

Below is the code for the Noteendpoint.java that was generated.
As seen in the my code inside the EndpointsTask class, it invokes 
Noteendpoint.insertNote (highlighted in Bold below) to do the insertion of 
Note into the datastore.

package com.cloudnotes;

import com.cloudnotes.EMF;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.google.api.server.spi.response.CollectionResponse;
import com.google.appengine.api.datastore.Cursor;
import com.google.appengine.datanucleus.query.JPACursorHelper;

import java.util.List;

import javax.annotation.Nullable;
import javax.inject.Named;
import javax.persistence.EntityExistsException;
import javax.persistence.EntityNotFoundException;
import javax.persistence.EntityManager;
import javax.persistence.Query;

@Api(name = "noteendpoint", namespace = @ApiNamespace(ownerDomain = 
"cloudnotes.com", ownerName = "cloudnotes.com", packagePath = ""))
public class NoteEndpoint {

/**
 * This method lists all the entities inserted in datastore.
 * It uses HTTP GET method and paging support.
 *
 * @return A CollectionResponse class containing the list of all entities
 * persisted and a cursor to the next page.
 */
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "listNote")
public CollectionResponse<Note> listNote(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {

EntityManager mgr = null;
Cursor cursor = null;
List<Note> execute = null;

try {
mgr = getEntityManager();
Query query = mgr.createQuery("select from Note as Note");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}

if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}

execute = (List<Note>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null)
cursorString = cursor.toWebSafeString();

// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (Note obj : execute)
;
} finally {
mgr.close();
}

return CollectionResponse.<Note> builder().setItems(execute)
.setNextPageToken(cursorString).build();
}

/**
 * This method gets the entity having primary key id. It uses HTTP GET 
method.
 *
 * @param id the primary key of the java bean.
 * @return The entity with primary key id.
 */
@ApiMethod(name = "getNote")
public Note getNote(@Named("id") String id) {
EntityManager mgr = getEntityManager();
Note note = null;
try {
note = mgr.find(Note.class, id);
} finally {
mgr.close();
}
return note;
}

*/***
* * This inserts a new entity into App Engine datastore. If the entity 
already*
* * exists in the datastore, an exception is thrown.*
* * It uses HTTP POST method.*
* **
* * @param note the entity to be inserted.*
* * @return The inserted entity.*
* */*
* @ApiMethod(name = "insertNote")*
* public Note insertNote(Note note) {*
* System.out.println("inserting note - "+note);*
* EntityManager mgr = getEntityManager();*
* try {*
* if (containsNote(note)) {*
* throw new EntityExistsException("Object already exists");*
* }*
* mgr.persist(note);*
* } finally {*
* mgr.close();*
* }*
* return note;*
* }*

/**
 * This method is used for updating an existing entity. If the entity does 
not
 * exist in the datastore, an exception is thrown.
 * It uses HTTP PUT method.
 *
 * @param note the entity to be updated.
 * @return The updated entity.
 */
@ApiMethod(name = "updateNote")
public Note updateNote(Note note) {
EntityManager mgr = getEntityManager();
try {
if (!containsNote(note)) {
throw new EntityNotFoundException("Object does not exist");
}
mgr.persist(note);
} finally {
mgr.close();
}
return note;
}

/**
 * This method removes the entity with primary key id.
 * It uses HTTP DELETE method.
 *
 * @param id the primary key of the entity to be deleted.
 */
@ApiMethod(name = "removeNote")
public void removeNote(@Named("id") String id) {
EntityManager mgr = getEntityManager();
try {
Note note = mgr.find(Note.class, id);
mgr.remove(note);
} finally {
mgr.close();
}
}

private boolean containsNote(Note note) {
EntityManager mgr = getEntityManager();
boolean contains = true;
try {
Note item = mgr.find(Note.class, note.getId());
if (item == null) {
contains = false;
}
} finally {
mgr.close();
}
return contains;
}

private static EntityManager getEntityManager() {
return EMF.get().createEntityManager();
}

}




On Wednesday, August 7, 2013 12:06:40 PM UTC+5:30, Vinny P wrote:
>
> On Wed, Aug 7, 2013 at 12:13 AM, Lekh Raj <lekhraj...@gmail.com<javascript:>
> > wrote:
>
>> Is there any other way to debug this and identify what might be going 
>> wrong?
>>
>> public void sendMsg(View view) {
>>      EditText msgTxt = (EditText) findViewById(R.id.editText1);
>>      String msg = msgTxt.getText().toString();
>>      System.out.println("Note to be inserted - " + msg);
>>      
>>      if (msg.length() > 0){
>>      new EndpointsTask().execute(**getApplicationContext());
>>      }
>>     }
>>
>  
>  
>  
> Well, that looks like Android + Endpoints client code, so there's nothing 
> to debug in regards to the datastore. What code are you using server-side 
> to interact with the datastore?
>
>  
> -----------------
> -Vinny P
> Technology & Media Advisor
> Chicago, IL
>
> App Engine Code Samples: http://www.learntogoogleit.com
>   
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to