当前位置: 首页>>代码示例>>Java>>正文


Java Entity.newBuilder方法代码示例

本文整理汇总了Java中com.google.datastore.v1.Entity.newBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.newBuilder方法的具体用法?Java Entity.newBuilder怎么用?Java Entity.newBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.datastore.v1.Entity的用法示例。


在下文中一共展示了Entity.newBuilder方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processElement

import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) {
  Entity.Builder entityBuilder = Entity.newBuilder();
  Key key = makeKey(makeKey(kind, ancestorKey).build(), kind, c.element().getKey()).build();

  entityBuilder.setKey(key);
  List<Value> candidates = new ArrayList<>();
  Map<String, Value> properties = new HashMap<>();
  for (CompletionCandidate tag : c.element().getValue()) {
    Entity.Builder tagEntity = Entity.newBuilder();
    properties.put("tag", makeValue(tag.value).build());
    properties.put("count", makeValue(tag.count).build());
    candidates.add(makeValue(tagEntity).build());
  }
  properties.put("candidates", makeValue(candidates).build());
  entityBuilder.putAllProperties(properties);
  c.output(entityBuilder.build());
}
 
开发者ID:apache,项目名称:beam,代码行数:19,代码来源:AutoComplete.java

示例2: processElement

import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) throws Exception {
  String entityJson = c.element();

  if (getJSTransform().hasTransform()) {
    entityJson = getJSTransform().invoke(entityJson);
  }

  Entity.Builder builder = Entity.newBuilder();
  getJsonParser().merge(entityJson, builder);
  Entity entity = builder.build();

  // Remove old project id reference from key
  Key k = entity.getKey();
  builder.setKey(Key.newBuilder()
      .addAllPath(k.getPathList())
      .setPartitionId(PartitionId.newBuilder()
          .setNamespaceId(k.getPartitionId().getNamespaceId()))
      .build());
  c.output(builder.build());
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:22,代码来源:GcsToDatastore.java

示例3: testDatastoreToGcs_EntityToJson_noTransform

import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
@Test
public void testDatastoreToGcs_EntityToJson_noTransform() throws Exception {
  DoFnTester<Entity, String> fnTester = DoFnTester.of(EntityToJson.newBuilder()
      .setJsTransformPath(StaticValueProvider.of(null))
      .setJsTransformFunctionName(StaticValueProvider.of(null))
      .build());

  Builder entityBuilder = Entity.newBuilder();
  JsonFormat.parser().usingTypeRegistry(
      TypeRegistry.newBuilder()
          .add(Entity.getDescriptor())
          .build())
      .merge(mEntityJson, entityBuilder);

  Entity entity = entityBuilder.build();
  List<String> entityJsonOutputs = fnTester.processBundle(entity);
  Assert.assertEquals(mEntityJson, entityJsonOutputs.get(0));
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:19,代码来源:DatastoreToGcsTest.java

示例4: testDatastoreToGcs_EntityToJson_withTransform

import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
@Test
public void testDatastoreToGcs_EntityToJson_withTransform() throws Exception {
  DoFnTester<Entity, String> fnTester = DoFnTester.of(EntityToJson.newBuilder()
      .setJsTransformPath(StaticValueProvider.of(jsTransformPath))
      .setJsTransformFunctionName(StaticValueProvider.of("transform"))
      .build());

  Builder entityBuilder = Entity.newBuilder();
  JsonFormat.parser().usingTypeRegistry(
      TypeRegistry.newBuilder()
          .add(Entity.getDescriptor())
          .build())
      .merge(mEntityJson, entityBuilder);

  Entity entity = entityBuilder.build();
  List<String> entityJsonOutputs = fnTester.processBundle(entity);
  Assert.assertEquals(mTransformedEntityJson, entityJsonOutputs.get(0));
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:19,代码来源:DatastoreToGcsTest.java

示例5: testDatastoreToBq_EntityToTableRow_notransform

import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
@Test
public void testDatastoreToBq_EntityToTableRow_notransform() throws Exception, IOException {
  DoFnTester<Entity, TableRow> fnTester = DoFnTester.of(EntityToTableRow.newBuilder()
      .setStrictCast(StaticValueProvider.of(true))
      .setTableSchemaJson(StaticValueProvider.of(mTableSchemaJson))
      .setJsTransformFunctionName(StaticValueProvider.of(null))
      .setJsTransformPath(StaticValueProvider.of(null))
  .build());

  Builder entityBuilder = Entity.newBuilder();
  JsonFormat.parser().usingTypeRegistry(
      TypeRegistry.newBuilder()
          .add(Entity.getDescriptor())
          .build())
      .merge(mEntityJson, entityBuilder);

  Entity entity = entityBuilder.build();
  List<TableRow> tableRows = fnTester.processBundle(entity);
  TableRow tr = tableRows.get(0);

  Assert.assertEquals(1, tableRows.size());
  Assert.assertEquals("key(Drawing, '31ce830e-91d0-405e-855a-abe416cadc1f')", tr.get("__key__"));
  Assert.assertEquals("79a1d9d9-e255-427a-9b09-f45157e97790", tr.get("canvasId"));
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:25,代码来源:DatastoreToBqTest.java

示例6: processElement

import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
@Override
public void processElement(ProcessContext c) {
	String[] columns = c.element().split(",");

	Builder builder = Key.newBuilder();
	PathElement pathElement = builder.addPathBuilder().setKind("Product").setName(columns[0]).build();
	Key key = builder.setPath(0, pathElement).build();

	Entity.Builder entityBuilder = Entity.newBuilder();
	entityBuilder.setKey(key);
	entityBuilder.getMutableProperties().put("ProductCode", makeValue(columns[0]).build());
	entityBuilder.getMutableProperties().put("CategoryCode", makeValue(columns[1]).build());
	entityBuilder.getMutableProperties().put("ProductName", makeValue(columns[2]).build());
	entityBuilder.getMutableProperties().put("Price", makeValue(Integer.valueOf(columns[3])).build());
	
	String imageURL = "";
	if (columns.length > 4) {
		imageURL = columns[4];
	}
	entityBuilder.getMutableProperties().put("ImageURL", makeValue(imageURL).build());
	Entity entity = entityBuilder.build();
	c.output(entity);
}
 
开发者ID:topgate,项目名称:retail-demo,代码行数:24,代码来源:StorageToDatastore.java

示例7: makeEntity

import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
/**
 * Build an entity for the given ancestorKey, kind, namespace and value.
 * @param largePropertySize if greater than 0, add an unindexed property of the given size.
 */
static Entity makeEntity(Long value, Key ancestorKey, String kind, @Nullable String namespace,
    int largePropertySize) {
  Entity.Builder entityBuilder = Entity.newBuilder();
  Key.Builder keyBuilder = makeKey(ancestorKey, kind, UUID.randomUUID().toString());
  // NOTE: Namespace is not inherited between keys created with DatastoreHelper.makeKey, so
  // we must set the namespace on keyBuilder. TODO: Once partitionId inheritance is added,
  // we can simplify this code.
  if (namespace != null) {
    keyBuilder.getPartitionIdBuilder().setNamespaceId(namespace);
  }

  entityBuilder.setKey(keyBuilder.build());
  entityBuilder.putProperties("value", makeValue(value).build());
  if (largePropertySize > 0) {
    entityBuilder.putProperties("unindexed_value", makeValue(new String(
        new char[largePropertySize]).replace("\0", "A")).setExcludeFromIndexes(true).build());
  }
  return entityBuilder.build();
}
 
开发者ID:apache,项目名称:beam,代码行数:24,代码来源:V1TestUtil.java

示例8: makeEntity

import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
public Entity makeEntity(KV<Integer, Iterable<TableRow>> content) {

			Key key = Key.newBuilder()
					.addPath(PathElement.newBuilder().setKind(this.kind).setId(content.getKey())).build();

			String keyword = "";
			List<Value> list = new ArrayList<>();
			for (TableRow row : content.getValue()) {
				String utterance = row.get("utterance").toString();
				if (utterance == null || utterance.length() < 1) {
					continue;
				}
				String word = row.get("keyword").toString();
				if (keyword.equals(row.get("keyword")) == false) {
					keyword = word;
				}
				if (list.size() > 1000) {
					LOG.info("Truncated the text." + "keyword_id = " + content.getKey() + ", keyword = " + word);
					break;
				}
				list.add(Value.newBuilder().setStringValue(utterance).build());
			}

			Entity.Builder entityBuilder = Entity.newBuilder();
			entityBuilder.setKey(key);

			Map<String, Value> propertyMap = new HashMap<String, Value>();
			propertyMap.put("KeywordID", Value.newBuilder().setIntegerValue(content.getKey()).build());
			propertyMap.put("Keyword", Value.newBuilder().setStringValue(keyword).build());
			ArrayValue array = ArrayValue.newBuilder().addAllValues(list).build();
			propertyMap.put("Candidates", Value.newBuilder().setArrayValue(array).build());

			entityBuilder.putAllProperties(propertyMap);

			return entityBuilder.build();
		}
 
开发者ID:sinmetal,项目名称:iron-hippo,代码行数:37,代码来源:BigQueryToDatastore.java

示例9: makeStatKindResponse

import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
/** Builds a per-kind statistics response with the given entity size. */
private static RunQueryResponse makeStatKindResponse(long entitySizeInBytes) {
  RunQueryResponse.Builder statKindResponse = RunQueryResponse.newBuilder();
  Entity.Builder entity = Entity.newBuilder();
  entity.setKey(makeKey("dummyKind", "dummyId"));
  entity.putProperties("entity_bytes", makeValue(entitySizeInBytes).build());
  EntityResult.Builder entityResult = EntityResult.newBuilder();
  entityResult.setEntity(entity);
  QueryResultBatch.Builder batch = QueryResultBatch.newBuilder();
  batch.addEntityResults(entityResult);
  statKindResponse.setBatch(batch);
  return statKindResponse.build();
}
 
开发者ID:apache,项目名称:beam,代码行数:14,代码来源:DatastoreV1Test.java

示例10: makeLatestTimestampResponse

import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
/** Builds a response of the given timestamp. */
private static RunQueryResponse makeLatestTimestampResponse(long timestamp) {
  RunQueryResponse.Builder timestampResponse = RunQueryResponse.newBuilder();
  Entity.Builder entity = Entity.newBuilder();
  entity.setKey(makeKey("dummyKind", "dummyId"));
  entity.putProperties("timestamp", makeValue(new Date(timestamp * 1000)).build());
  EntityResult.Builder entityResult = EntityResult.newBuilder();
  entityResult.setEntity(entity);
  QueryResultBatch.Builder batch = QueryResultBatch.newBuilder();
  batch.addEntityResults(entityResult);
  timestampResponse.setBatch(batch);
  return timestampResponse.build();
}
 
开发者ID:apache,项目名称:beam,代码行数:14,代码来源:DatastoreV1Test.java

示例11: processElement

import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
@Override
public void processElement(DoFn<String, Entity>.ProcessContext context) throws Exception {
  String json = context.element();
  Builder builder = Entity.newBuilder();
  jsonParser.merge(json, builder);
  context.output(builder.build());
}
 
开发者ID:cobookman,项目名称:DatastoreToGCS,代码行数:8,代码来源:GCSRestore.java

示例12: addGreeting

import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
/**
 * Add a greeting to the specified guestbook.
 */
private void addGreeting(String guestbookName, String user, String message)
    throws DatastoreException {
  Entity.Builder greeting = Entity.newBuilder();
  greeting.setKey(makeKey(GUESTBOOK_KIND, guestbookName, GREETING_KIND));
  greeting.getMutableProperties().put(USER_PROPERTY, makeValue(user).build());
  greeting.getMutableProperties().put(MESSAGE_PROPERTY, makeValue(message).build());
  greeting.getMutableProperties().put(DATE_PROPERTY, makeValue(new Date()).build());
  Key greetingKey = insert(greeting.build());
  System.out.println("greeting key is: " + greetingKey);
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-datastore,代码行数:14,代码来源:Guestbook.java


注:本文中的com.google.datastore.v1.Entity.newBuilder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。