Package com.google.code.gaeom

Examples of com.google.code.gaeom.ObjectStoreSession


  }

  @Test
  public void testCustomPropertyEncoder() throws Exception
  {
    ObjectStoreSession oss = ObjectStore.Factory.create().beginSession();
    LongEncodedEntity e = new LongEncodedEntity();
    Key key = oss.store(e).now();
    Point orig = e.p;
    Long l = new PointLongEncoder().encode(orig);
   
    e.p = null;
    oss.refresh(e).now();
    assertEquals(orig, e.p);

    Entity ent = DatastoreServiceFactory.getDatastoreService().get(key);
    assertEquals(l, ent.getProperty("p"));
  }
View Full Code Here


  {
    Map1 m = new Map1();
    m.map.put("foo", "bar");
    m.map.put("bas", "bat");
   
    ObjectStoreSession oss = ObjectStore.Factory.create().beginSession();
    oss.store(m).now();
   
    Map<String, String> orig = m.map;
    m.map = null;
   
    oss.refresh(m).now();
   
    assertEquals(orig, m.map);
  }
View Full Code Here

  @Test
  public void testUnactivatedLoad()
  {
    ObjectStore os = ObjectStore.Factory.create();
    ObjectStoreSession oss = os.beginSession();
    Key key = oss.store(new Foo("Fred Flintstone")).now();

    ObjectStoreSession oss2 = os.beginSession();
    Foo foo = oss2.load(key).unactivated().now();
    assertTrue(foo.name == null);
    assertEquals(key, oss2.getKey(foo));
  }
View Full Code Here

  @Test
  public void testSimpleStoreLoad()
  {
    ObjectStore osf = ObjectStore.Factory.create();
    ObjectStoreSession os = osf.beginSession();

    Person p1 = new Person();

    p1.firstName = "Fred";
    p1.lastName = "Flintstone";
    p1.shoeSize = 12L;

    Key key = os.store(p1).id(33L).now();
    assertEquals(33L, key.getId());
   
    ObjectStoreSession os2 = osf.beginSession();
    Person p2 = (Person) os2.load(Person.class).id(33L).now();

    assertTrue(p2 != p1);
    assertEquals(p1.firstName, p2.firstName);
    assertEquals(p1.lastName, p2.lastName);
    assertEquals(p1.shoeSize, p2.shoeSize);
View Full Code Here

  @Test
  public void queryOnEmbeddedProperty() throws Exception
  {
    ObjectStore os = ObjectStore.Factory.create();
    ObjectStoreSession oss = os.beginSession();

    A a = new A();
    a.name = "Fred";
    a.b = new B();
    a.b.foo = "Blah";

    oss.store(a).now();

    A a2 = oss.find(A.class).filter("b.foo", "Blah").single().now();
    assertTrue(a == a2);
  }
View Full Code Here

  @Test
  public void queryOnEmbeddedListProperty() throws Exception
  {
    ObjectStore os = ObjectStore.Factory.create();
    ObjectStoreSession oss = os.beginSession();

    A a = new A();
    a.name = "Fred";
    a.bs.add(new B());
    a.bs.add(new B());
    a.bs.add(new B());
    a.bs.get(0).foo = "Blah";
    a.bs.get(1).foo = "Blah1";
    a.bs.get(2).foo = "Blah2";

    oss.store(a).now();

    A a2 = oss.find(A.class).filter("bs.foo", "Blah").single().now();
    assertTrue(a == a2);
  }
View Full Code Here

 
  @Test
  public void queryOnEmbeddedListStringProperty() throws Exception
  {
    ObjectStore os = ObjectStore.Factory.create();
    ObjectStoreSession oss = os.beginSession();

    A a = new A();
    a.name = "Fred";
    a.strings.add("Blah");
    a.strings.add("Blah2");
    a.strings.add("Blah3");

    oss.store(a).now();

    A a2 = oss.find(A.class).filter("strings", "Blah").single().now();
    assertTrue(a == a2);
  }
View Full Code Here

  @Test
  public void testRefreshSingleKey()
  {
    ObjectStore os = ObjectStore.Factory.create();
    ObjectStoreSession oss = os.beginSession();
    X x = new X();
    x.blah = "fred";
    Key key = oss.store(x).now();
    x.blah = "mary";
    assertEquals("mary", oss.load(key).<X> now().blah);
    assertEquals("fred", oss.load(key).refresh().<X> now().blah);
  }
View Full Code Here

  @Test
  public void testRefreshSingleKey2()
  {
    ObjectStore os = ObjectStore.Factory.create();
    ObjectStoreSession oss = os.beginSession();
    X x = new X();
    x.blah = "fred";
    Key key = oss.store(x).now();
    x.blah = "mary";
    assertEquals("mary", oss.load(key).<X> now().blah);
    assertEquals("fred", oss.refresh(x).now().blah);
  }
View Full Code Here

  @Test
  public void testRefreshMultipleKeys()
  {
    ObjectStore os = ObjectStore.Factory.create();
    ObjectStoreSession oss = os.beginSession();
    X x1 = new X();
    x1.blah = "fred1";
    X x2 = new X();
    x2.blah = "fred2";
    X x3 = new X();
    x3.blah = "fred3";
    List<Key> keys = oss.store(x1, x2, x3).now();
    x1.blah = null;
    x2.blah = null;
    x3.blah = null;

    // without refresh
    List<X> same = Lists.newArrayList(oss.load(keys).<X> now());
    assertNull(same.get(0).blah);
    assertNull(same.get(1).blah);
    assertNull(same.get(2).blah);

    List<X> list = Lists.newArrayList(oss.load(keys).refresh().<X> now());

    assertEquals(x1, list.get(0));
    assertEquals(x2, list.get(1));
    assertEquals(x3, list.get(2));
View Full Code Here

TOP

Related Classes of com.google.code.gaeom.ObjectStoreSession

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.