Query query = new Query("__BlobInfo__"); query.addFilter("filename", FilterOperator.EQUAL, filename); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); PreparedQuery pq = datastore.prepare(query); List<Entity> entList = pq.asList(FetchOptions.Builder.withLimit(1)); String name = entList.get(0).getKey().getName();
Entity loginEntity = new Entity("login", id); loginEntity.setProperty("password", "admin@123"); datastore.put(loginEntity);
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(); } } }
public void purgeTestRunRecords() { DatastoreService datastoreService = DatastoreServiceFactory. getDatastoreService(); FilterPredicate testRunFilter = new FilterPredicate(TEST_RUN_ID, FilterOperator.EQUAL, testRunId); Query query = new Query(entityName).setFilter(testRunFilter).setKeysOnly(); for (Entity readRec : datastoreService.prepare(query).asIterable()) { datastoreService.delete(readRec.getKey()); } }
private void saveEntity(Entity entity) { DatastoreService service = DatastoreServiceFactory.getDatastoreService(); Transaction tx = service.beginTransaction(); try { service.put(tx, entity); tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } } }
public Entity getMarker(String marker) { DatastoreService service = DatastoreServiceFactory.getDatastoreService(); FilterPredicate testRunFilter = new FilterPredicate(TEST_RUN_ID, FilterOperator.EQUAL, testRunId); FilterPredicate markerFilter = new FilterPredicate(MARKER, FilterOperator.EQUAL, marker); CompositeFilter filter = CompositeFilterOperator.and(testRunFilter, markerFilter); Query query = new Query(entityName).setFilter(filter); return service.prepare(query).asSingleEntity(); }
private QueryResultList<Entity> getNamespaces() { FetchOptions fetchOptions = FetchOptions.Builder.withDefaults(); fetchOptions.limit(BATCH_SIZE); if (cursor != null) { fetchOptions.startCursor(Cursor.fromWebSafeString(cursor)); } Query q = new Query(NAMESPACE_METADATA_KIND); q.setKeysOnly(); return datastore.prepare(q).asQueryResultList(fetchOptions); }
protected List<Entity> doQuery(String kind, String pName, Class<?> type, boolean indexed) { FetchOptions fo = FetchOptions.Builder.withDefaults(); Query query = new Query(kind, rootKey); if (indexed) { query.addProjection(new PropertyProjection(pName, type)); query.addSort(pName); } return service.prepare(query).asList(fo); }
@Override public void delete(String userId, Credential credential) { DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Key key = KeyFactory.createKey(KIND, userId); datastore.delete(key); }
private Entity getTestDataEntity() throws EntityNotFoundException { DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); return datastore.get(KeyFactory.createKey(ENTITY_KIND, ENTITY_NAME)); } }
private Entity getParent() { Query query = new Query(PARENTKIND); query.setFilter(new FilterPredicate("name", Query.FilterOperator.EQUAL, "argonaut")); Entity parent = service.prepare(query).asSingleEntity(); return parent; } }
protected Object[] getResult(Query query, String pName) { int count = service.prepare(query).countEntities(FetchOptions.Builder.withDefaults()); Object result[] = new Object[count]; int pt = 0; for (Entity readRec : service.prepare(query).asIterable()) { result[pt++] = readRec.getProperty(pName); } return result; }
@Override public List<Entity> getAll(String kind) { Query query = new Query(kind); PreparedQuery prepared = datastore.prepare(query); return prepared.asList(FetchOptions.Builder.withChunkSize(CHUNKSIZE)); }
} else { println("Start from cursor position: " + cursorPosition); cursor = Cursor.fromWebSafeString(cursorPosition); while (iterator.hasNext()) { shouldContinue = true; Key<T> keyOfEntityToMigrate = iterator.next(); cursor = iterator.getCursor(); println(String.format("Cursor Position: %s", cursor.toWebSafeString())); println(String.format("Number Of Entity Key Scanned: %d", numberOfScannedKey.get())); println(String.format("Number Of Entity affected: %d", numberOfAffectedEntities.get()));
public ShardedValue(Entity entity) { super(entity); this.shardId = (Long) entity.getProperty(SHARD_ID_PROPERTY); this.value = ((Blob) entity.getProperty(VALUE_PROPERTY)).getBytes(); }
/** * Fetches entities in batches and puts them into the buffer. */ private void batchFetching() { Query<T> newQuery = this.query.limit(BUFFER_SIZE); if (this.cursor != null) { newQuery = newQuery.startAt(this.cursor); } QueryResultIterator<T> iterator = newQuery.iterator(); boolean shouldContinue = false; while (iterator.hasNext()) { shouldContinue = true; this.buffer.offer(iterator.next()); } if (shouldContinue) { this.cursor = iterator.getCursor(); } }
static DatastoreServiceConfig copyDatastoreServiceConfig(DatastoreServiceConfig config) { DatastoreServiceConfig newConfig = DatastoreServiceConfig.Builder. withImplicitTransactionManagementPolicy(config.getImplicitTransactionManagementPolicy()). readPolicy(config.getReadPolicy()); if (config.getDeadline() != null) { newConfig.deadline(config.getDeadline()); } return newConfig; }
/** * 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(); } } }
/** * Executes the specified query with the specified fetch options. * * @param query The query to be executed. * @param options The fetch options which the specified query is executed * with. * @return The query result as {@code List} view. */ public List<Entity> query(Query query, FetchOptions options) { return datastore.prepare(query).asList(options); }