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


Java Entity.Builder方法代码示例

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


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

示例1: backfillToEntity

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
private Entity backfillToEntity(Backfill backfill) {
  final Key key = datastore.newKeyFactory().setKind(KIND_BACKFILL).newKey(backfill.id());

  Entity.Builder builder = Entity.newBuilder(key)
      .set(PROPERTY_CONCURRENCY, backfill.concurrency())
      .set(PROPERTY_START, instantToTimestamp(backfill.start()))
      .set(PROPERTY_END, instantToTimestamp(backfill.end()))
      .set(PROPERTY_COMPONENT, backfill.workflowId().componentId())
      .set(PROPERTY_WORKFLOW, backfill.workflowId().id())
      .set(PROPERTY_SCHEDULE, backfill.schedule().toString())
      .set(PROPERTY_NEXT_TRIGGER, instantToTimestamp(backfill.nextTrigger()))
      .set(PROPERTY_ALL_TRIGGERED, backfill.allTriggered())
      .set(PROPERTY_HALTED, backfill.halted());

  backfill.description().ifPresent(x -> builder.set(PROPERTY_DESCRIPTION, StringValue
      .newBuilder(x).setExcludeFromIndexes(true).build()));

  return builder.build();
}
 
开发者ID:spotify,项目名称:styx,代码行数:20,代码来源:DatastoreStorage.java

示例2: deleteSessionVariables

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
/**
 * Delete a value stored in the project's datastore.
 * @param sessionId Request from which the session is extracted.
 */
protected void deleteSessionVariables(String sessionId, String... varNames) {
  if (sessionId.equals("")) {
    return;
  }
  Key key = keyFactory.newKey(sessionId);
  Transaction transaction = datastore.newTransaction();
  try {
    Entity stateEntity = transaction.get(key);
    if (stateEntity != null) {
      Entity.Builder builder = Entity.newBuilder(stateEntity);
      StringBuilder delNames = new StringBuilder();
      for (String varName : varNames) {
        delNames.append(varName + " ");
        builder = builder.remove(varName);
      }
      datastore.update(builder.build());
    }
  } finally {
    if (transaction.isActive()) {
      transaction.rollback();
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:28,代码来源:DatastoreSessionFilter.java

示例3: save

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
@Override
public void save(Message message) {
  // Save message to "messages"
  Datastore datastore = getDatastoreInstance();
  Key key = datastore.allocateId(keyFactory.newKey());

  Entity.Builder messageEntityBuilder = Entity.newBuilder(key)
      .set("messageId", message.getMessageId());

  if (message.getData() != null) {
    messageEntityBuilder = messageEntityBuilder.set("data", message.getData());
  }

  if (message.getPublishTime() != null) {
    messageEntityBuilder = messageEntityBuilder.set("publishTime", message.getPublishTime());
  }
  datastore.put(messageEntityBuilder.build());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:19,代码来源:MessageRepositoryImpl.java

示例4: saveMetadataToEntity

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
/**
 * Store the metadata of the session in an entity.
 * @param sessionKey Identifier of the session on the Datastore
 * @return An entity containing the metadata.
 */
@VisibleForTesting
Entity saveMetadataToEntity(Key sessionKey) {
  Entity.Builder sessionEntity = Entity.newBuilder(sessionKey)
      .set(SessionMetadata.CREATION_TIME, getCreationTime())
      .set(SessionMetadata.LAST_ACCESSED_TIME, getLastAccessedTime())
      .set(SessionMetadata.MAX_INACTIVE_INTERVAL, getMaxInactiveInterval())
      .set(SessionMetadata.IS_NEW, isNew())
      .set(SessionMetadata.IS_VALID, isValid())
      .set(SessionMetadata.THIS_ACCESSED_TIME, getThisAccessedTime());

  // A negative time indicates that the session should never time out
  if (getMaxInactiveInterval() >= 0) {
    sessionEntity.set(SessionMetadata.EXPIRATION_TIME,
        getLastAccessedTime() + getMaxInactiveInterval() * 1000);
  }

  return sessionEntity.build();
}
 
开发者ID:GoogleCloudPlatform,项目名称:tomcat-runtime,代码行数:24,代码来源:DatastoreSession.java

示例5: getNextIdGen

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
@Override
public Long getNextIdGen(Long interval) {
    if (!isValid()) throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, googleMsgCatalog.getMessage("GeneratorInvalid"));

    Key entityKey = datastore.newKeyFactory().setKind(kind).newKey(kind);
    Entity entity = datastore.get(entityKey);
    Long next = interval;

    if (entity != null) {
        Set<String> names = entity.getNames();
        if ((names == null) || (names.size() != 1)) throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST,
                googleMsgCatalog.getMessage("IdGenerator"));

        Value<?> value = entity.getValue(names.iterator().next());
        if (!(value instanceof LongValue)) throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST,
                googleMsgCatalog.getMessage("IdGenerator"));
        next = ((LongValue) value).get() + interval;
    }
    try {
        Entity.Builder builder = Entity.newBuilder(entityKey);
        builder.set(kind, new LongValue(next));
        entity = builder.build();
        datastore.put(entity);
    } catch (Exception e) {
        throw new RuntimeException("Cannot initialise idgen ", e);
    }
    return next;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:29,代码来源:IdGenGoogleDatastore.java

示例6: resetIdGen

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
@Override
public void resetIdGen(Long number) {
    Key entityKey = datastore.newKeyFactory().setKind(kind).newKey(kind);
    Entity entity = datastore.get(entityKey);
    try {
        Entity.Builder builder = Entity.newBuilder(entityKey);
        builder.set(kind, new LongValue(number));
        entity = builder.build();
        datastore.put(entity);
    } catch (Exception e) {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, googleMsgCatalog.getMessage("CannotReset"), e);
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:14,代码来源:IdGenGoogleDatastore.java

示例7: setValid

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
public void setValid(Boolean flag) {
    Key entityKey = datastore.newKeyFactory().setKind(kind).newKey(VALID);
    Entity entity = datastore.get(entityKey);
    try {
        Entity.Builder builder = Entity.newBuilder(entityKey);
        builder.set(kind, new BooleanValue(flag));
        entity = builder.build();
        datastore.put(entity);
    } catch (Exception e) {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, googleMsgCatalog.getMessage("CannotUpdate" + flag), e);
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:13,代码来源:IdGenGoogleDatastore.java

示例8: save

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
@Override
public void save(Message message) {
  // Save message to "messages"
  Datastore datastore = getDatastoreInstance();
  Key key = datastore.allocateId(keyFactory.newKey());

  Entity.Builder messageEntityBuilder = Entity.newBuilder(key)
      .set("messageId", message.getMessageId());

  String translated = message.getTranslated();
  if (translated != null) {
    messageEntityBuilder = messageEntityBuilder.set("data", translated);
  }

  if (message.getPublishTime() != null) {
    messageEntityBuilder = messageEntityBuilder.set("publishTime", message.getPublishTime());
  }

  if (message.getSourceLang() != null) {
    messageEntityBuilder = messageEntityBuilder.set("sourceLang", message.getSourceLang());
  }

  if (message.getTargetLang() != null) {
    messageEntityBuilder = messageEntityBuilder.set("targetLang", message.getTargetLang());
  }
  datastore.put(messageEntityBuilder.build());
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:28,代码来源:MessageRepositoryImpl.java

示例9: setSessionVariables

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
/**
 * Stores the state value in each key-value pair in the project's datastore.
 * @param sessionId Request from which to extract session.
 * @param varName the name of the desired session variable
 * @param varValue the value of the desired session variable
 */
protected void setSessionVariables(String sessionId, Map<String, String> setMap) {
  if (sessionId.equals("")) {
    return;
  }
  Key key = keyFactory.newKey(sessionId);
  Transaction transaction = datastore.newTransaction();
  DateTime dt = DateTime.now(DateTimeZone.UTC);
  dt.toString(dtf);
  try {
    Entity stateEntity = transaction.get(key);
    Entity.Builder seBuilder;
    if (stateEntity == null) {
      seBuilder = Entity.newBuilder(key);
    } else {
      seBuilder = Entity.newBuilder(stateEntity);
    }
    for (String varName : setMap.keySet()) {
      seBuilder.set(varName, setMap.get(varName));
    }
    transaction.put(seBuilder.set("lastModified", dt.toString(dtf)).build());
    transaction.commit();
  } finally {
    if (transaction.isActive()) {
      transaction.rollback();
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:34,代码来源:DatastoreSessionFilter.java

示例10: asBuilderOrNew

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
/**
 * Convert an optional {@link Entity} into a builder if it exists, otherwise create a new builder.
 *
 * @param entityOpt  The optional entity
 * @param key        The key for which to create a new builder if the entity is not present
 * @return an entity builder either based of the given entity or a new one using the key.
 */
private Entity.Builder asBuilderOrNew(Optional<Entity> entityOpt, Key key) {
  return entityOpt
      .map(c -> Entity.newBuilder(c))
      .orElse(Entity.newBuilder(key));
}
 
开发者ID:spotify,项目名称:styx,代码行数:13,代码来源:DatastoreStorage.java


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