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


Java Entity.getNames方法代码示例

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


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

示例1: get

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
@Override
public String get(String key) {
    try {
        Key entityKey = datastore.newKeyFactory().setKind(kind).newKey(encode(key));
        Entity entity = datastore.get(entityKey);
        Map<String, Object> map = new HashMap<>();
        if (entity != null) {
            for (String name : entity.getNames()) {
                Value<?> value = entity.getValue(name);
                if (value != null) {
                    put(map, name, value);
                }
            }
        }
        if (map.isEmpty()) return null;
        return JacksonUtil.jsonFromObject(map);
    } catch (Exception e) {
        String error = ExceptionToString.format(e);
        log.info(e.getMessage());
        log.trace(error);
        return null;
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:24,代码来源:GoogleDatastoreKeyStore.java

示例2: 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

示例3: isValid

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
public boolean isValid() {
    Key entityKey = datastore.newKeyFactory().setKind(kind).newKey(VALID);
    Entity entity = datastore.get(entityKey);
    if (entity != null) {
        Set<String> names = entity.getNames();
        if ((names != null) && (names.size() == 1)) {
            Value<?> value = entity.getValue(names.iterator().next());
            if (value instanceof BooleanValue) return ((BooleanValue) value).get();
        }
    }
    throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, googleMsgCatalog.getMessage("isValid"));
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:13,代码来源:IdGenGoogleDatastore.java

示例4: loadSessionVariables

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
/**
 * Take an HttpServletRequest, and copy all of the current session variables over to it
 * @param req Request from which to extract session.
 * @return a map of strings containing all the session variables loaded or an empty map.
 */
protected Map<String, String> loadSessionVariables(HttpServletRequest req)
    throws ServletException {
  Map<String, String> datastoreMap = new HashMap<>();
  String sessionId = getCookieValue(req, "bookshelfSessionId");
  if (sessionId.equals("")) {
    return datastoreMap;
  }
  Key key = keyFactory.newKey(sessionId);
  Transaction transaction = datastore.newTransaction();
  try {
    Entity stateEntity = transaction.get(key);
    StringBuilder logNames = new StringBuilder();
    if (stateEntity != null) {
      for (String varName : stateEntity.getNames()) {
        req.getSession().setAttribute(varName, stateEntity.getString(varName));
        datastoreMap.put(varName, stateEntity.getString(varName));
        logNames.append(varName + " ");
      }
    }
  } finally {
    if (transaction.isActive()) {
      transaction.rollback();
    }
  }
  return datastoreMap;
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:32,代码来源:DatastoreSessionFilter.java


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