Package com.google.appengine.api.datastore

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


        void visit(String key, Double val) { entity.setProperty(key, val); }
        void visit(String key, Integer val) { entity.setProperty(key, val); }
        void visit(String key, Long val) { entity.setProperty(key, val); }
        void visit(String key, String val) { entity.setProperty(key, val); }
        void visit(String key, JSONObject val) {
          EmbeddedEntity embedded = new EmbeddedEntity();
          setProperties(embedded, val);
          entity.setProperty(key, embedded);
        }
        void visit(String key, JSONArray val) {
          Collection<Object> objs = new ArrayList<Object>(val.length());
          for (int i = 0; i < val.length(); i++) {
            Object arrVal;
            try {
              arrVal = val.get(i);
            } catch(JSONException e) {
              throw new ArrayIndexOutOfBoundsException("" + e);
            }
            if (arrVal instanceof JSONObject) {
              EmbeddedEntity embedded = new EmbeddedEntity();
              setProperties(embedded, (JSONObject) arrVal);
              objs.add(embedded);
            } else {
              objs.add(arrVal);
            }
View Full Code Here


   
    Key<OuterWithMap> key = ofy().save().entity(outer).now();
   
    Entity entity = ds().get(key.getRaw());
   
    EmbeddedEntity entityInner = (EmbeddedEntity)entity.getProperty("map");
    assert entityInner.getProperty("asdf").equals(123L);
   
    ofy().clear();
    OuterWithMap fetched = ofy().load().key(key).now();
    assert fetched.map.equals(outer.map);
  }
View Full Code Here

   
    Key<Outer> key = ofy().save().entity(outer).now();
   
    Entity entity = ds().get(key.getRaw());
   
    EmbeddedEntity entityInner = (EmbeddedEntity)entity.getProperty("inner");
    assert entityInner.getProperty("stuff").equals("stuff");
   
    ofy().clear();
    Outer fetched = ofy().load().key(key).now();
    assert fetched.inner.stuff.equals(inner.stuff);
  }
View Full Code Here

  @Test
  public void normalEmbeddedEntityFieldWorksFine() throws Exception {
    fact().register(HasEmbeddedEntity.class);

    HasEmbeddedEntity h = new HasEmbeddedEntity();
    h.normal = new EmbeddedEntity();
    h.normal.setProperty("stuff", "stuff");
   
    HasEmbeddedEntity fetched = ofy().saveClearLoad(h);
    assert fetched.normal.getProperty("stuff").equals("stuff");
  }
View Full Code Here

  public void listEmbeddedEntityFieldWorksFine() throws Exception {
    fact().register(HasEmbeddedEntityList.class);

    HasEmbeddedEntityList h = new HasEmbeddedEntityList();
   
    EmbeddedEntity emb0 = new EmbeddedEntity();
    emb0.setProperty("stuff", "stuff0");
    h.list.add(emb0);
   
    HasEmbeddedEntityList fetched = ofy().saveClearLoad(h);
    assert fetched.list.size() == 1;
    assert fetched.list.get(0).getProperty("stuff").equals("stuff0");
View Full Code Here

    this.helper.tearDown();
  }

  /** */
  protected EmbeddedEntity makeEmbeddedEntityWithProperty(String name, Object value) {
    EmbeddedEntity emb = new EmbeddedEntity();
    emb.setProperty(name, value);
    return emb;
  }
View Full Code Here

    Thing thing = new Thing();
    thing.foo = "bar";

    SaveContext saveCtx = new SaveContext();
    EmbeddedEntity ent = (EmbeddedEntity)translator.save(thing, false, saveCtx, thingPath);

    assert ent.getKey() == null;
    assert ent.getProperties().size() == 1;
    assert ent.getProperty("foo").equals("bar");
  }
View Full Code Here

  @Override
  public PropertyContainer save(P pojo, boolean index, SaveContext ctx, Path path) throws SkipException {
    if (path.isRoot()) {
      return keyMetadata.initEntity(pojo);
    } else {
      EmbeddedEntity ent = new EmbeddedEntity();
      ent.setKey(keyMetadata.getRawKey(pojo));
      return ent;
    }
  }
View Full Code Here

      public EmbeddedEntity save(Map<Object, Object> pojo, boolean index, SaveContext ctx, Path path) throws SkipException {
        // Make this work more like collections than atomic values
        if (pojo == null || pojo.isEmpty())
          throw new SkipException();

        EmbeddedEntity emb = new EmbeddedEntity();

        for (Map.Entry<Object, Object> entry: pojo.entrySet()) {
          String key = stringifier.toString(entry.getKey());
          Path propPath = path.extend(key);
          Object value = componentTranslator.save(entry.getValue(), index, ctx, propPath);
View Full Code Here

    return construct(path);
  }

  @Override
  public PropertyContainer save(P pojo, boolean index, SaveContext ctx, Path path) throws SkipException {
    return new EmbeddedEntity();
  }
View Full Code Here

TOP

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

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.