本文整理汇总了Java中com.google.datastore.v1.Entity.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.Builder方法的具体用法?Java Entity.Builder怎么用?Java Entity.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.datastore.v1.Entity
的用法示例。
在下文中一共展示了Entity.Builder方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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());
}
示例3: 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);
}
示例4: 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();
}
示例5: 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();
}
示例6: 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();
}
示例7: 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();
}
示例8: 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);
}
示例9: makeValue
import com.google.datastore.v1.Entity; //导入方法依赖的package包/类
/**
* Make a entity value.
*/
public static Value.Builder makeValue(Entity.Builder entity) {
return makeValue(entity.build());
}