public static void main(String[] args) throws IOException { String serverString = args[0]; RemoteApiOptions options; if (serverString.equals("localhost")) { options = new RemoteApiOptions().server(serverString, 8080).useDevelopmentServerCredential(); } else { options = new RemoteApiOptions().server(serverString, 443).useApplicationDefaultCredential(); } RemoteApiInstaller installer = new RemoteApiInstaller(); installer.install(options); try { DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); System.out.println("Key of new entity is " + ds.put(new Entity("Hello Remote API!"))); } finally { installer.uninstall(); } } }
/** * A simple API client. * @param args . * @throws IOException . */ public static void main(String[] args) throws IOException { String serverString = args[0]; RemoteApiOptions options; if (serverString.equals("localhost")) { options = new RemoteApiOptions().server(serverString, 8080).useDevelopmentServerCredential(); } else { options = new RemoteApiOptions().server(serverString, 443).useApplicationDefaultCredential(); } RemoteApiInstaller installer = new RemoteApiInstaller(); installer.install(options); try { DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); System.out.println("Key of new entity is " + ds.put(new Entity("Hello Remote API!"))); } finally { installer.uninstall(); } } }
/** * Constructor for a StoreFieldManager when inserting a new object. * The Entity will be constructed. * @param op ObjectProvider of the object being stored * @param kind Kind of entity */ public StoreFieldManager(ObjectProvider op, String kind) { super(op, new Entity(kind), null); this.insert = true; }
public static void saveSettings(Map<String, Object> newSettings) { // there is only one instance of LeanEngineSettings so the same ID=1 is always used Entity leanEntity = new Entity("_settings", 1); for (String propName : newSettings.keySet()) { leanEntity.setProperty(propName, newSettings.get(propName)); } DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); datastore.put(leanEntity); LeanEngineSettings.settings = newSettings; }
private Entity makeCopy(Entity entity) { // We don't check key when we look for changes so it's // ok that the copy doesn't have its key set. Entity copy = new Entity(entity.getKind()); EntityUtils.copyProperties(entity, copy); return copy; }
protected Entity toProtoEntity() { Entity entity = new Entity(key); entity.setProperty(ROOT_JOB_KEY_PROPERTY, rootJobKey); if (generatorJobKey != null) { entity.setProperty(GENERATOR_JOB_PROPERTY, generatorJobKey); } if (graphGUID != null) { entity.setUnindexedProperty(GRAPH_GUID_PROPERTY, graphGUID); } return entity; }
private Entity createEntity(ObjectHolder objectHolder) { IdRef<?> id = objectHolder.getId(); if (id == null) { return createEntityWithNewKey(objectHolder); } return new Entity(IdRefToKey.toKey(r, id)); }
protected Entity createTestEntity(String kind) { Entity entity = new Entity(kind); entity.setProperty("text", "Some text."); return entity; }
protected Entity createTestEntity(String kind, Key key) { Entity entity = new Entity(kind, key); entity.setProperty("text", "Some text."); return entity; }
protected Entity createTestEntity(String kind, long id) { Key key = KeyFactory.createKey(kind, id); Entity entity = new Entity(key); entity.setProperty("text", "Some text."); return entity; }
@Override public void put(Vertex vertex) { URI owlClass = getType(vertex); String entityKind = entityNamer.entityName(owlClass); if (entityKind == null) { throw new KonigException("Entity type not defined for OWL Class: " + owlClass); } Entity entity = new Entity(entityKind); addProperties(vertex, entity); DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); ds.put(entity); }
public void putMarker(String marker) { Entity entity = new Entity(entityName); entity.setProperty(TEST_RUN_ID, testRunId); entity.setProperty(EXECUTED_AT, System.currentTimeMillis()); entity.setProperty(MARKER, marker); saveEntity(entity); }
@Test public void batchGetReturnsOnlyExistingKeysInMap() throws Exception { Key existingKey = KeyFactory.createKey("batch", "existing"); Key nonExistingKey = KeyFactory.createKey("batch", "nonExisting"); service.put(new Entity(existingKey)); Map<Key, Entity> map = service.get(Arrays.asList(existingKey, nonExistingKey)); assertEquals(1, map.size()); assertTrue(map.containsKey(existingKey)); }
@Test public void testAllocateChild() { Entity parent = new Entity(ALLOCATE_IDS_ENTITY); parent.setProperty("name", "parent-" + System.currentTimeMillis()); Key parentKey = service.put(parent); final int allocateSize = 10; KeyRange range = service.allocateIds(parentKey, ALLOCATE_IDS_ENTITY, allocateSize); Entity child = new Entity(range.getStart()); Key key = service.put(child); // child with allocated key should have correct parent. Assert.assertEquals(parentKey, key.getParent()); }
@Test(expected = IllegalStateException.class) public void testClosedTx() throws InterruptedException { clearData(kindName); Transaction tx = service.beginTransaction(); Entity newRec = new Entity(kindName); newRec.setProperty("check", "4100331"); newRec.setProperty("stamp", new Date()); service.put(newRec); tx.commit(); service.put(tx, new Entity(kindName)); }
@Override public void store(String userId, Credential credential) { DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Entity entity = new Entity(KIND, userId); entity.setProperty("accessToken", credential.getAccessToken()); entity.setProperty("refreshToken", credential.getRefreshToken()); entity.setProperty("expirationTimeMillis", credential.getExpirationTimeMilliseconds()); datastore.put(entity); }
@Test public void testNoIdKey() throws Exception { Entity entity = new Entity("NO_ID"); Key key = service.put(entity); assertTrue(key.isComplete()); }
@Test public void testEntityGainsNoAdditionalPropertiesWhenStored() throws Exception { clearData(kindName); Entity entity = new Entity(kindName); Key key = service.put(entity); entity = service.get(key); assertEquals(Collections.<String, Object>emptyMap(), entity.getProperties()); } }
@Test public void queryingByKindOnlyReturnsEntitiesOfRequestedKind() throws Exception { Key parentKey = createQueryBasicsTestParent("queryingByKindOnlyReturnsEntitiesOfRequestedKind"); Entity person = new Entity(KeyFactory.createKey(parentKey, "Person", 1)); service.put(person); Entity address = new Entity(KeyFactory.createKey(parentKey, "Address", 1)); service.put(address); assertSingleResult(person, new Query("Person").setAncestor(parentKey)); }
@Test(expected = ApiDeadlineExceededException.class) public void testDeadlineConfig() { DatastoreServiceConfig config = DatastoreServiceConfig.Builder.withDeadline(0.00001); DatastoreService ds = DatastoreServiceFactory.getDatastoreService(config); assertNotNull(ds); Entity g1 = new Entity("test"); g1.setProperty("deadline", "0.00001"); ds.put(g1); }