public static Builder newBuilder(Key parent, String kind, String name) { Builder builder = newBuilder(parent.getProjectId(), kind, name); addParentToBuilder(parent, builder); return builder; }
public static Builder newBuilder(Key parent, String kind, long id) { Builder builder = newBuilder(parent.getProjectId(), kind, id); addParentToBuilder(parent, builder); return builder; }
public static Builder newBuilder(Key parent, String kind) { return newBuilder(parent.getProjectId(), kind) .setNamespace(parent.getNamespace()) .addAncestors(parent.getPath()); } }
@Test public void testNewKeyFactory() { DatastoreOptions options = createMock(DatastoreOptions.class); expect(options.getProjectId()).andReturn("ds1").once(); expect(options.getNamespace()).andReturn("ns1").once(); replay(options); KeyFactory keyFactory = DatastoreHelper.newKeyFactory(options); Key key = keyFactory.setKind("k").newKey("bla"); assertEquals("ds1", key.getProjectId()); assertEquals("ns1", key.getNamespace()); assertEquals("k", key.getKind()); assertEquals("bla", key.getName()); verify(options); }
assertSame(entity4, entities.get(0)); assertEquals(PARTIAL_ENTITY2.getProperties(), entity6.getProperties()); assertEquals(PARTIAL_ENTITY2.getKey().getProjectId(), entity6.getKey().getProjectId()); assertEquals(PARTIAL_ENTITY2.getKey().getNamespace(), entity6.getKey().getNamespace()); assertEquals(PARTIAL_ENTITY2.getKey().getAncestors(), entity6.getKey().getAncestors());
assertSame(entity4, entities.get(0)); assertEquals(PARTIAL_ENTITY2.getNames(), entity6.getNames()); assertEquals(PARTIAL_ENTITY2.getKey().getProjectId(), entity6.getKey().getProjectId()); assertEquals(PARTIAL_ENTITY2.getKey().getNamespace(), entity6.getKey().getNamespace()); assertEquals(PARTIAL_ENTITY2.getKey().getAncestors(), entity6.getKey().getAncestors());
@Test public void testAllocateId() { KeyFactory keyFactory = datastore.newKeyFactory().setKind(KIND1); IncompleteKey pk1 = keyFactory.newKey(); Key key1 = datastore.allocateId(pk1); assertEquals(key1.getProjectId(), pk1.getProjectId()); assertEquals(key1.getNamespace(), pk1.getNamespace()); assertEquals(key1.getAncestors(), pk1.getAncestors()); assertEquals(key1.getKind(), pk1.getKind()); assertTrue(key1.hasId()); assertFalse(key1.hasName()); assertEquals(Key.newBuilder(pk1, key1.getId()).build(), key1); Key key2 = datastore.allocateId(pk1); assertNotEquals(key1, key2); assertEquals(Key.newBuilder(pk1, key2.getId()).build(), key2); try { datastore.allocateId(key1); fail("Expecting a failure"); } catch (IllegalArgumentException expected) { assertEquals(expected.getMessage(), "keys must be IncompleteKey instances"); } }
@Test public void testAllocateId() { KeyFactory keyFactory = DATASTORE.newKeyFactory().setKind(KIND1); IncompleteKey pk1 = keyFactory.newKey(); Key key1 = DATASTORE.allocateId(pk1); assertEquals(key1.getProjectId(), pk1.getProjectId()); assertEquals(key1.getNamespace(), pk1.getNamespace()); assertEquals(key1.getAncestors(), pk1.getAncestors()); assertEquals(key1.getKind(), pk1.getKind()); assertTrue(key1.hasId()); assertFalse(key1.hasName()); assertEquals(Key.newBuilder(pk1, key1.getId()).build(), key1); Key key2 = DATASTORE.allocateId(pk1); assertNotEquals(key1, key2); assertEquals(Key.newBuilder(pk1, key2.getId()).build(), key2); }
final int result = this.raw.getProjectId().compareTo(other.raw.getProjectId()); if (result != 0) return result;
@Override public String projectId() { return key.getProjectId(); }
public String formatOldStyleAppEngineKey(Key key) { Descriptors.Descriptor referenceDescriptor = keyDescriptor.findMessageTypeByName("Reference"); DynamicMessage.Builder keyMessageBuilder = DynamicMessage.newBuilder(referenceDescriptor); String fullProjectId = key.getProjectId(); if (!fullProjectId.startsWith("s~")) { fullProjectId = "s~" + fullProjectId;
public static Builder newBuilder(Key parent, String kind, String name) { Builder builder = newBuilder(parent.getProjectId(), kind, name); addParentToBuilder(parent, builder); return builder; }
public static Builder newBuilder(Key parent, String kind, long id) { Builder builder = newBuilder(parent.getProjectId(), kind, id); addParentToBuilder(parent, builder); return builder; }
public static Builder newBuilder(Key parent, String kind) { return newBuilder(parent.getProjectId(), kind) .setNamespace(parent.getNamespace()) .addAncestors(parent.getPath()); } }