本文整理汇总了Java中com.google.cloud.datastore.Entity.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.getValue方法的具体用法?Java Entity.getValue怎么用?Java Entity.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.cloud.datastore.Entity
的用法示例。
在下文中一共展示了Entity.getValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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;
}
示例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"));
}