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


Java Entity.newBuilder方法代码示例

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


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

示例1: marshal

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
/**
 * Marshals the given entity and and returns the equivalent Entity needed for the underlying Cloud
 * Datastore API.
 * 
 * @return A native entity that is equivalent to the POJO being marshalled. The returned value
 *         could either be a FullEntity or Entity.
 */
private BaseEntity<?> marshal() {
  marshalKey();
  if (key instanceof Key) {
    entityBuilder = Entity.newBuilder((Key) key);
  } else {
    entityBuilder = FullEntity.newBuilder(key);
  }
  marshalFields();
  marshalAutoTimestampFields();
  if (intent == Intent.UPDATE) {
    marshalVersionField();
  }
  marshalEmbeddedFields();
  return entityBuilder.build();
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:23,代码来源:Marshaller.java

示例2: updateRow

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
@Override
public void updateRow(String key, Map<String, Object> recordValues) {
    Key entityKey = datastore.newKeyFactory().setKind(kind).newKey(key);
    Builder builder = Entity.newBuilder(entityKey);
    for (Entry<String, Object> entry : recordValues.entrySet()) {
        builder.set(entry.getKey(), GoogleDatastoreKeyStore.valerie(entry.getKey(), entry.getValue()));
    }
    Entity entity = builder.build();

    try {
        datastore.put(entity);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:17,代码来源:GoogleIndexHandler.java

示例3: put

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
/**
 * TODO https://cloud.google.com/datastore/docs/best-practices
 *
 * For a key that uses a custom name, always use UTF-8 characters except a forward slash (/). Non-UTF-8 characters interfere with various processes such as
 * importing a Cloud Datastore backup into Google BigQuery. A forward slash could interfere with future functionality.
 */

@Override
public void put(String key, String value) {
    Key entityKey = datastore.newKeyFactory().setKind(kind).newKey(encode(key));
    Map<String, Object> map = JacksonUtil.getMapFromJson(value);
    Builder builder = Entity.newBuilder(entityKey);
    for (Entry<String, Object> entry : map.entrySet()) {
        builder.set(encode(entry.getKey()), valerie(entry.getKey(), entry.getValue()));
    }
    Entity entity = builder.build();

    try {
        datastore.put(entity);
    } catch (Exception e) {
        String error = ExceptionToString.format(e);
        log.error(error);
        throw e;
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:26,代码来源:GoogleDatastoreKeyStore.java

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

示例5: toEntity

import com.google.cloud.datastore.Entity; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public FullEntity<? extends IncompleteKey> toEntity(Object object, Key key) {
	FullEntity.Builder<? extends IncompleteKey> builder;
	if (key == null) {
		builder = Entity.newBuilder();
	}
	else {
		builder = FullEntity.newBuilder(key);
	}

	if (object instanceof Map) {
		for (Map.Entry<String, Object> entry : ((Map<String, Object>) object)
				.entrySet()) {
			setEntityValue(builder, entry.getKey(), entry.getValue());
		}
	}
	else {
		BeanWrapper beanWrapper = PropertyAccessorFactory
				.forBeanPropertyAccess(object);
		for (PropertyDescriptor propertyDescriptor : beanWrapper
				.getPropertyDescriptors()) {
			String name = propertyDescriptor.getName();
			if ("class".equals(name))
				continue;
			setEntityValue(builder, name, beanWrapper.getPropertyValue(name));
		}
	}
	return builder.build();
}
 
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:30,代码来源:Marshaller.java

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

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

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

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


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