Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.DatastoreService


public class EntityRemove extends AbstractSubscriber {

  public void onMessage(Message message) {
    SimpleMessage msg = (SimpleMessage) message;
    String kind =  msg.getMessage();
    DatastoreService datastore = getBusiness().getSystemService()
              .getDatastore();
        Query query = new Query(kind);
        PreparedQuery results = datastore.prepare(query);
        int i = 0;
        boolean end = true;
        for (Entity entity : results.asIterable()) {
          datastore.delete(entity.getKey());
          i++;
        if (getBusiness().getSystemService()
            .getRequestCPUTimeSeconds() > 25) {
          addEntityRemoveTask(kind);
          end = false;
View Full Code Here


    String mode =  msg.getMessage();
    if (mode != null && mode.equals("start")) {
      addSessionCleanTask();
    }
    else {
          DatastoreService datastore = getBusiness().getSystemService()
              .getDatastore();
          Query query = new Query("_ah_SESSION");
          query.addFilter("_expires", FilterOperator.LESS_THAN,
              System.currentTimeMillis());
          PreparedQuery results = datastore.prepare(query);
          int i = 0;
          boolean end = true;
          for (Entity session : results.asIterable()) {
            datastore.delete(session.getKey());
            i++;
          if (getBusiness().getSystemService()
              .getRequestCPUTimeSeconds() > 25) {
            addSessionCleanTask();
            end = false;
View Full Code Here

            MemcacheService memcache) throws ServletException {
        HttpSession session = request.getSession();
        String id = AC_BASE + session.getId();
        byte[] serializedAC = (byte[]) memcache.get(id);
        if (serializedAC == null) {
            DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
            Key key = KeyFactory.createKey(AC_BASE, id);
            Entity entity = null;
            try {
                entity = ds.get(key);
            } catch (EntityNotFoundException e) {
                // Ok, we were a bit optimistic; we'll create a new one later
            }
            if (entity != null) {
                Blob blob = (Blob) entity.getProperty(PROPERTY_DATA);
View Full Code Here

     * continue w/ next.
     */
    private void cleanDatastore() {
        long expire = new Date().getTime();
        try {
            DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
            // Vaadin stuff first
            {
                Query q = new Query(AC_BASE);
                q.setKeysOnly();

                q.addFilter(PROPERTY_EXPIRES,
                        FilterOperator.LESS_THAN_OR_EQUAL, expire);
                PreparedQuery pq = ds.prepare(q);
                List<Entity> entities = pq.asList(Builder
                        .withLimit(CLEANUP_LIMIT));
                if (entities != null) {
                    getLogger()
                            .log(Level.INFO,
                                    "Vaadin cleanup deleting {0} expired Vaadin sessions.",
                                    entities.size());
                    List<Key> keys = new ArrayList<Key>();
                    for (Entity e : entities) {
                        keys.add(e.getKey());
                    }
                    ds.delete(keys);
                }
            }
            // Also cleanup GAE sessions
            {
                Query q = new Query(APPENGINE_SESSION_KIND);
                q.setKeysOnly();
                q.addFilter(PROPERTY_APPENGINE_EXPIRES,
                        FilterOperator.LESS_THAN_OR_EQUAL, expire);
                PreparedQuery pq = ds.prepare(q);
                List<Entity> entities = pq.asList(Builder
                        .withLimit(CLEANUP_LIMIT));
                if (entities != null) {
                    getLogger()
                            .log(Level.INFO,
                                    "Vaadin cleanup deleting {0} expired appengine sessions.",
                                    entities.size());
                    List<Key> keys = new ArrayList<Key>();
                    for (Entity e : entities) {
                        keys.add(e.getKey());
                    }
                    ds.delete(keys);
                }
            }
        } catch (Exception e) {
            getLogger().log(Level.WARNING, "Exception while cleaning.", e);
        }
View Full Code Here

    f.bars2 = generate(Bar.class, 10);
    f.bars2[6] = null;

    Key key = os.beginSession().store(f).now();

    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
    Entity e = ds.get(key);
    assertTrue(e.getProperty("b") instanceof Blob);
    assertTrue(e.getProperty("c") instanceof String);

    Foo f2 = os.beginSession().load(key).now();
    assertTrue(ReflectionUtils.fieldsEqual(f, f2));
View Full Code Here

    oss.store(new Foo("Barney Rubble")).now();

    List<Foo> foos = Lists.newArrayList(oss.find(Foo.class).now());
    assertEquals(2, foos.size());

    DatastoreService service = DatastoreServiceFactory.getDatastoreService();
    List<Entity> entities = Lists.newArrayList(service.prepare(new Query("Foo")).asIterable());
    assertEquals(2, entities.size());
    for(Entity e : entities)
    {
      String name = e.getProperty("name").toString();
      assertTrue (name.equals("Fred Flintstone") || name.equals("Barney Rubble"));
View Full Code Here

    writer.write(entity2);
    writer.write(entity3);
    writer.endSlice();
    writer.endShard();

    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
    try {
      ds.get(entity1.getKey());
      fail("Should ot be able to find entity1");
    } catch (EntityNotFoundException ignore) {
      // expected
    }
    assertEquals(entity2, ds.get(entity2.getKey()));
    assertEquals(entity3, ds.get(entity3.getKey()));
  }
View Full Code Here

    executeTasksUntilEmpty();
    ShardedJobState state = service.getJobState(jobId);
    assertEquals(new Status(DONE), state.getStatus());
    IncrementalTaskState<IncrementalTask> it = Iterators.getOnlyElement(service.lookupTasks(state));
    assertNull(((TestTask) it.getTask()).getPayload());
    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
    assertEquals(2, ds.prepare(new Query()).countEntities(FetchOptions.Builder.withDefaults()));
  }
View Full Code Here

    TestTask s1 = new TestTask(0, 2, 2, 2, bytes);
    TestTask s2 = new TestTask(1, 2, 2, 1);
    jobService.startJob("testCleanupJob", ImmutableList.of(s1, s2), controller, settings);
    assertFalse(jobService.cleanupJob("testCleanupJob"));
    executeTasksUntilEmpty();
    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
    assertEquals(3, ds.prepare(new Query()).countEntities(FetchOptions.Builder.withDefaults()));
    assertTrue(jobService.cleanupJob("testCleanupJob"));
    executeTasksUntilEmpty();
    assertEquals(0, ds.prepare(new Query()).countEntities(FetchOptions.Builder.withDefaults()));
  }
View Full Code Here

      super(expectedResult);
    }

    @Override
    public void completed(Iterator<TestTask> results) {
      DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
      assertEquals(7, ds.prepare(new Query()).countEntities(FetchOptions.Builder.withDefaults()));
      super.completed(results);
    }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.datastore.DatastoreService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.