I tried :

PersistenceManager pm = PMF.get().getPersistenceManager();
                try
                {
                        DatastoreService datastore =
DatastoreServiceFactory.getDatastoreService();
                        Query query = new Query("__Stat_Kind__");
                        query.addFilter("kind_name", FilterOperator.EQUAL,
Gestionnaire.class.getName());
                        Entity stat = datastore.prepare(query).asSingleEntity();
                        Long count = (Long) stat.getProperty("count");

                        if(count.equals(0))
                        {
                                Gestionnaire admin = new Gestionnaire 
("admin","chuck");
                                pm.makePersistent(admin);
                                return "base initialisée";
                        }
                        else return "base déjà initialisée";
                }

but the line : Long count = (Long) stat.getProperty("count");  throws
a nullPointerException

On 15 mar, 03:44, John Patterson <[email protected]> wrote:
> Use the __Stat_total__  pseudo kind
>
> http://code.google.com/appengine/docs/java/datastore/stats.html
>
> On 15 Mar 2010, at 09:36, Robert Lancer wrote:
>
> > A query has to specify an entity kind as its minimum parameter, and
> > then doing a count and seeing if its equal to zero for a known entity
> > kind would be the best way.
>
> > On Mar 13, 1:44 pm, vchalmel <[email protected]> wrote:
> >> hi !
>
> >> I want to set up an initialization script, and i must, in a first
> >> part, check if the appengine datastore is empty.
> >> I tried to send a query, with :
>
> >> query.setUnique(true);
> >> if(query.execute()==null)
>
> >> But it throws a null pointer exception.
>
> >> How to check that my datastore is empty ?
>
> > --  
> > You received this message because you are subscribed to the Google  
> > Groups "Google App Engine for Java" group.
> > To post to this group, send email to [email protected]
> > .
> > To unsubscribe from this group, send email to 
> > [email protected]
> > .
> > For more options, visit this group 
> > athttp://groups.google.com/group/google-appengine-java?hl=en
> > .

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to