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


Java Key.Builder方法代码示例

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


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

示例1: makeEntity

import com.google.datastore.v1.Key; //导入方法依赖的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

示例2: makeAncestorKey

import com.google.datastore.v1.Key; //导入方法依赖的package包/类
/**
 * A helper function to create the ancestor key for all created and queried entities.
 */
static Key makeAncestorKey(@Nullable String namespace, String kind, String ancestor) {
  Key.Builder keyBuilder = makeKey(kind, ancestor);
  if (namespace != null) {
    keyBuilder.getPartitionIdBuilder().setNamespaceId(namespace);
  }
  return keyBuilder.build();
}
 
开发者ID:apache,项目名称:beam,代码行数:11,代码来源:V1TestUtil.java

示例3: makeValue

import com.google.datastore.v1.Key; //导入方法依赖的package包/类
/**
 * Make a key value.
 */
public static Value.Builder makeValue(Key.Builder key) {
  return makeValue(key.build());
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-datastore,代码行数:7,代码来源:DatastoreHelper.java

示例4: makeKey

import com.google.datastore.v1.Key; //导入方法依赖的package包/类
/**
 * Make a key from the specified path of kind/id-or-name pairs
 * and/or Keys.
 *
 * <p>The id-or-name values must be either String, Long, Integer or Short.
 *
 * <p>The last id-or-name value may be omitted, in which case an entity without
 * an id is created (for use with automatic id allocation).
 *
 * <p>The PartitionIds of all Keys in the path must be equal. The returned
 * Key.Builder will use this PartitionId.
 */
public static Key.Builder makeKey(Object... elements) {
  Key.Builder key = Key.newBuilder();
  PartitionId partitionId = null;
  for (int pathIndex = 0; pathIndex < elements.length; pathIndex += 2) {
    PathElement.Builder pathElement = PathElement.newBuilder();
    Object element =  elements[pathIndex];
    if (element instanceof Key) {
      Key subKey = (Key) element;
      if (partitionId == null) {
        partitionId = subKey.getPartitionId();
      } else if (!partitionId.equals(subKey.getPartitionId())) {
        throw new IllegalArgumentException("Partition IDs did not match, found: "
            + partitionId + " and " + subKey.getPartitionId());
      }
      key.addAllPath(((Key) element).getPathList());
      // We increment by 2, but since we got a Key argument we're only consuming 1 element in this
      // iteration of the loop. Decrement the index so that when we jump by 2 we end up in the
      // right spot.
      pathIndex--;
    } else {
      String kind;
      try {
        kind = (String) element;
      } catch (ClassCastException e) {
        throw new IllegalArgumentException("Expected string or Key, got: " + element.getClass());
      }
      pathElement.setKind(kind);
      if (pathIndex + 1 < elements.length) {
        Object value = elements[pathIndex + 1];
        if (value instanceof String) {
          pathElement.setName((String) value);
        } else if (value instanceof Long) {
          pathElement.setId((Long) value);
        } else if (value instanceof Integer) {
          pathElement.setId((Integer) value);
        } else if (value instanceof Short) {
          pathElement.setId((Short) value);
        } else {
          throw new IllegalArgumentException(
              "Expected string or integer, got: " + value.getClass());
        }
      }
      key.addPath(pathElement);
    }
  }
  if (partitionId != null && !partitionId.equals(PartitionId.getDefaultInstance())) {
    key.setPartitionId(partitionId);
  }
  return key;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-datastore,代码行数:63,代码来源:DatastoreHelper.java


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