• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java FullEntity类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



FullEntity类属于com.google.cloud.datastore包,在下文中一共展示了FullEntity类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: save

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
@Override
public <S extends T> Iterable<S> save(Iterable<S> entities) {
	Datastore datastore = this.datastoreOptions.getService();

	List<FullEntity<? extends IncompleteKey>> buffer = new ArrayList<>();

	for (S entity : entities) {
		ID id = this.entityInformation.getId(entity);
		Key key = getKey(id);

		buffer.add(this.marshaller.toEntity(entity, key));
		if (buffer.size() >= BUFFER_SIZE) {
			datastore.put(buffer.toArray(new FullEntity[buffer.size()]));
			buffer.clear();
		}
	}
	if (buffer.size() > 0) {
		datastore.put(buffer.toArray(new FullEntity[buffer.size()]));
	}

	return entities;
}
 
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:23,代码来源:SimpleGcloudDatastoreRepository.java


示例2: toModel

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object toModel(Value<?> input) {
  if (input instanceof NullValue) {
    return null;
  }
  EntityValue entityValue = (EntityValue) input;
  FullEntity<?> entity = entityValue.get();
  Map<String, Object> map;
  if (Modifier.isAbstract(mapClass.getModifiers())) {
    if (SortedMap.class.equals(mapClass)) {
      map = new TreeMap<>();
    } else {
      map = new HashMap<>();
    }
  } else {
    map = (Map<String, Object>) IntrospectionUtils.instantiateObject(mapClass);
  }
  for (String property : entity.getNames()) {
    map.put(property, valueMapper.toModel(entity.getValue(property)));
  }
  return map;
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:24,代码来源:MapMapper.java


示例3: toModel

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
@Override
public Object toModel(Value<?> input) {
  if (input.getType() == ValueType.NULL) {
    return null;
  }
  try {
    FullEntity<?> entity = ((EntityValue) input).get();
    ConstructorMetadata constructorMetadata = metadata.getConstructorMetadata();
    Object embeddedObject = constructorMetadata.getConstructorMethodHandle().invoke();
    for (PropertyMetadata propertyMetadata : metadata.getPropertyMetadataCollection()) {
      String mappedName = propertyMetadata.getMappedName();
      if (entity.contains(mappedName)) {
        Value<?> propertyValue = entity.getValue(mappedName);
        Object fieldValue = propertyMetadata.getMapper().toModel(propertyValue);
        propertyMetadata.getWriteMethod().invoke(embeddedObject, fieldValue);
      }
    }
    if (constructorMetadata.isBuilderConstructionStrategy()) {
      embeddedObject = metadata.getConstructorMetadata().getBuildMethodHandle()
          .invoke(embeddedObject);
    }
    return embeddedObject;
  } catch (Throwable exp) {
    throw new MappingException(exp);
  }
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:27,代码来源:EmbeddedObjectMapper.java


示例4: marshal

import com.google.cloud.datastore.FullEntity; //导入依赖的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


示例5: insert

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
/**
 * Inserts the given list of entities into the Cloud Datastore.
 * 
 * @param entities
 *          the entities to insert.
 * @return the inserted entities. The inserted entities will not be same as the passed in
 *         entities. For example, the inserted entities may contain generated ID, key, parent key,
 *         etc.
 * @throws EntityManagerException
 *           if any error occurs while inserting.
 */
@SuppressWarnings("unchecked")
public <E> List<E> insert(List<E> entities) {
  if (entities == null || entities.isEmpty()) {
    return new ArrayList<>();
  }
  try {
    entityManager.executeEntityListeners(CallbackType.PRE_INSERT, entities);
    FullEntity<?>[] nativeEntities = toNativeFullEntities(entities, entityManager, Intent.INSERT);
    Class<?> entityClass = entities.get(0).getClass();
    List<Entity> insertedNativeEntities = nativeWriter.add(nativeEntities);
    List<E> insertedEntities = (List<E>) toEntities(entityClass, insertedNativeEntities);
    entityManager.executeEntityListeners(CallbackType.POST_INSERT, insertedEntities);
    return insertedEntities;
  } catch (DatastoreException exp) {
    throw DatastoreUtils.wrap(exp);
  }
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:29,代码来源:DefaultDatastoreWriter.java


示例6: upsert

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
/**
 * Updates or inserts the given list of entities in the Cloud Datastore. If the entities do not
 * have a valid ID, IDs may be generated.
 * 
 * @param entities
 *          the entities to update/or insert.
 * @return the updated or inserted entities
 * @throws EntityManagerException
 *           if any error occurs while saving.
 */
@SuppressWarnings("unchecked")
public <E> List<E> upsert(List<E> entities) {
  if (entities == null || entities.isEmpty()) {
    return new ArrayList<>();
  }
  try {
    entityManager.executeEntityListeners(CallbackType.PRE_UPSERT, entities);
    FullEntity<?>[] nativeEntities = toNativeFullEntities(entities, entityManager, Intent.UPSERT);
    Class<?> entityClass = entities.get(0).getClass();
    List<Entity> upsertedNativeEntities = nativeWriter.put(nativeEntities);
    List<E> upsertedEntities = (List<E>) toEntities(entityClass, upsertedNativeEntities);
    entityManager.executeEntityListeners(CallbackType.POST_UPSERT, upsertedEntities);
    return upsertedEntities;
  } catch (DatastoreException exp) {
    throw DatastoreUtils.wrap(exp);
  }
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:28,代码来源:DefaultDatastoreWriter.java


示例7: testBatchUpsert

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
@Test
public void testBatchUpsert() {
  // [START batch_upsert]
  FullEntity<IncompleteKey> task1 = FullEntity.newBuilder(keyFactory.newKey())
      .set("category", "Personal")
      .set("done", false)
      .set("priority", 4)
      .set("description", "Learn Cloud Datastore")
      .build();
  FullEntity<IncompleteKey> task2 = Entity.newBuilder(keyFactory.newKey())
      .set("category", "Personal")
      .set("done", false)
      .set("priority", 5)
      .set("description", "Integrate Cloud Datastore")
      .build();
  List<Entity> tasks = datastore.add(task1, task2);
  Key taskKey1 = tasks.get(0).getKey();
  Key taskKey2 = tasks.get(1).getKey();
  // [END batch_upsert]
  assertEquals(Entity.newBuilder(taskKey1, task1).build(), datastore.get(taskKey1));
  assertEquals(Entity.newBuilder(taskKey2, task2).build(), datastore.get(taskKey2));
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:23,代码来源:ConceptsTest.java


示例8: save

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
public void save() {
  if (key == null) {
    key = getDatastore().allocateId(makeIncompleteKey()); // Give this greeting a unique ID
  }

  Builder<Key> builder = FullEntity.builder(key);

  if (authorEmail != null) {
    builder.set("authorEmail", authorEmail);
  }

  if (authorId != null) {
    builder.set("authorId", authorId);
  }

  builder.set("content", content);
  builder.set("date", DateTime.copyFrom(date));

  getDatastore().put(builder.build());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:21,代码来源:Greeting.java


示例9: save

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
public void save() {
  if (key == null) {
    key = getDatastore().allocateId(makeIncompleteKey()); // Give this greeting a unique ID
  }

  Builder<Key> builder = FullEntity.newBuilder(key);

  if (authorEmail != null) {
    builder.set("authorEmail", authorEmail);
  }

  if (authorId != null) {
    builder.set("authorId", authorId);
  }

  builder.set("content", content);
  builder.set("date", Timestamp.of(date));

  getDatastore().put(builder.build());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:21,代码来源:Greeting.java


示例10: save

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
/**
 * Save the specified Session into this Store. Any previously saved information for
 * the associated session identifier is replaced.
 *
 * <p>Attempt to serialize the session and send it to the datastore.</p>
 *
 * @throws IOException If an error occurs during the serialization of the session.
 *
 * @param session Session to be saved
 */
@Override
public void save(Session session) throws IOException {
  log.debug("Persisting session: " + session.getId());

  if (!(session instanceof DatastoreSession)) {
    throw new IOException(
        "The session must be an instance of DatastoreSession to be serialized");
  }
  DatastoreSession datastoreSession = (DatastoreSession) session;
  Key sessionKey = newKey(session.getId());
  KeyFactory attributeKeyFactory = datastore.newKeyFactory()
      .setKind(sessionKind)
      .addAncestor(PathElement.of(sessionKind, sessionKey.getName()));

  List<Entity> entities = serializeSession(datastoreSession, sessionKey, attributeKeyFactory);

  TraceContext datastoreSaveContext = startSpan("Storing the session in the Datastore");
  datastore.put(entities.toArray(new FullEntity[0]));
  datastore.delete(datastoreSession.getSuppressedAttributes().stream()
      .map(attributeKeyFactory::newKey)
      .toArray(Key[]::new));
  endSpan(datastoreSaveContext);
}
 
开发者ID:GoogleCloudPlatform,项目名称:tomcat-runtime,代码行数:34,代码来源:DatastoreStore.java


示例11: testSessionSave

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
@Test
public void testSessionSave() throws Exception {
  DatastoreSession session = spy(new DatastoreSession(manager));
  session.setValid(true);
  session.setId(keyId);
  session.setAttribute("count", 5);

  store.save(session);
  ArgumentCaptor captor = ArgumentCaptor.forClass(Entity.class);
  verify(datastore).put((FullEntity<?>[]) captor.capture());
  verify(session).saveAttributesToEntity(any());

  List<Entity> entities = captor.getAllValues();
  assertEquals(2, entities.size());

  assertTrue(entities.stream()
      .map(e -> e.getKey().getName())
      .collect(Collectors.toList())
      .containsAll(Arrays.asList("count", keyId)));

}
 
开发者ID:GoogleCloudPlatform,项目名称:tomcat-runtime,代码行数:22,代码来源:DatastoreStoreTest.java


示例12: toEntity

import com.google.cloud.datastore.FullEntity; //导入依赖的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


示例13: unmarshal

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
public <K extends IncompleteKey, T> T unmarshal(
		FullEntity<? extends IncompleteKey> entity, Class<T> clazz) {
	try {
		T obj = clazz.newInstance();
		unmarshalToObject(entity, obj);
		return obj;
	}
	catch (InstantiationException | IllegalAccessException e) {
		throw new IllegalStateException();
	}
}
 
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:12,代码来源:Unmarshaller.java


示例14: unmarshalToMap

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
public <K extends IncompleteKey> void unmarshalToMap(FullEntity<K> entity,
		Map<String, Object> map) {

	for (String name : entity.getNames()) {
		Value<?> value = entity.getValue(name);
		ValueType valueType = value.getType();
		switch (valueType) {
		case ENTITY:
			if (map.containsKey(name)) {
				unmarshalToObject(entity.getEntity(name), map.get(name));
			}
			else {
				Map<String, Object> newMap = new HashMap<>();
				unmarshalToMap(entity.getEntity(name), newMap);
				map.put(name, newMap);
			}
			break;
		case BLOB:
		case BOOLEAN:
		case DOUBLE:
		case LAT_LNG:
		case LIST:
		case LONG:
		case NULL:
		case STRING:
		case TIMESTAMP:
			map.put(name, unmarshal(value));
			break;
		case KEY:
			break;
		case RAW_VALUE:
			throw new UnsupportedOperationException(valueType.toString());
		}
	}
}
 
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:36,代码来源:Unmarshaller.java


示例15: toDatastore

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
  if (input == null) {
    return NullValue.newBuilder();
  }
  Map<String, ?> map = (Map<String, ?>) input;
  FullEntity.Builder<IncompleteKey> entityBuilder = FullEntity.newBuilder();
  for (Map.Entry<String, ?> entry : map.entrySet()) {
    String key = entry.getKey();
    entityBuilder.set(key, valueMapper.toDatastore(entry.getValue()).build());
  }
  return EntityValue.newBuilder(entityBuilder.build());
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:15,代码来源:MapMapper.java


示例16: toDatastore

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
  if (input == null) {
    return NullValue.newBuilder();
  }
  try {
    FullEntity.Builder<IncompleteKey> entityBuilder = FullEntity.newBuilder();
    for (PropertyMetadata propertyMetadata : metadata.getPropertyMetadataCollection()) {
      Object propertyValue = propertyMetadata.getReadMethod().invoke(input);
      if (propertyValue == null && propertyMetadata.isOptional()) {
        continue;
      }
      ValueBuilder<?, ?, ?> valueBuilder = propertyMetadata.getMapper()
          .toDatastore(propertyValue);
      // ListValues cannot have indexing turned off. Indexing is turned on by
      // default, so we don't touch excludeFromIndexes for ListValues.
      if (valueBuilder.getValueType() != ValueType.LIST) {
        valueBuilder.setExcludeFromIndexes(!propertyMetadata.isIndexed());
      }
      Value<?> value = valueBuilder.build();
      entityBuilder.set(propertyMetadata.getMappedName(), value);
      Indexer indexer = propertyMetadata.getSecondaryIndexer();
      if (indexer != null) {
        entityBuilder.set(propertyMetadata.getSecondaryIndexName(), indexer.index(value));
      }
    }
    return EntityValue.newBuilder(entityBuilder.build());
  } catch (Throwable exp) {
    throw new MappingException(exp);
  }
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:32,代码来源:EmbeddedObjectMapper.java


示例17: toDatastore

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
  ValueBuilder<?, ?, ?> builder;
  if (input == null) {
    builder = NullValue.newBuilder();
  } else if (input instanceof Long) {
    builder = LongValue.newBuilder((long) input);
  } else if (input instanceof Double) {
    builder = DoubleValue.newBuilder((double) input);
  } else if (input instanceof Boolean) {
    builder = BooleanValue.newBuilder((boolean) input);
  } else if (input instanceof String) {
    builder = StringValue.newBuilder((String) input);
  } else if (input instanceof DatastoreKey) {
    builder = KeyValue.newBuilder(((DatastoreKey) input).nativeKey());
  } else if (input instanceof GeoLocation) {
    GeoLocation geoLocation = (GeoLocation) input;
    builder = LatLngValue
        .newBuilder(LatLng.of(geoLocation.getLatitude(), geoLocation.getLongitude()));
  } else if (input instanceof Map) {
    @SuppressWarnings("unchecked")
    Map<String, ?> map = (Map<String, ?>) input;
    FullEntity.Builder<IncompleteKey> entityBuilder = FullEntity.newBuilder();
    for (Map.Entry<String, ?> entry : map.entrySet()) {
      String key = entry.getKey();
      entityBuilder.set(key, toDatastore(entry.getValue()).build());
    }
    builder = EntityValue.newBuilder(entityBuilder.build());
  } else {
    throw new MappingException(String.format("Unsupported type: %s", input.getClass().getName()));
  }
  return builder;
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:34,代码来源:CatchAllMapper.java


示例18: toModel

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
@Override
public Object toModel(Value<?> input) {
  Object javaValue;
  if (input instanceof NullValue) {
    javaValue = null;
  } else if (input instanceof StringValue) {
    javaValue = input.get();
  } else if (input instanceof LongValue) {
    javaValue = input.get();
  } else if (input instanceof DoubleValue) {
    javaValue = input.get();
  } else if (input instanceof BooleanValue) {
    javaValue = input.get();
  } else if (input instanceof KeyValue) {
    javaValue = new DefaultDatastoreKey(((KeyValue) input).get());
  } else if (input instanceof LatLngValue) {
    LatLng latLong = ((LatLngValue) input).get();
    javaValue = new GeoLocation(latLong.getLatitude(), latLong.getLongitude());
  } else if (input instanceof EntityValue) {
    EntityValue entityValue = (EntityValue) input;
    FullEntity<?> entity = entityValue.get();
    Map<String, Object> map = new HashMap<>();
    for (String property : entity.getNames()) {
      map.put(property, toModel(entity.getValue(property)));
    }
    javaValue = map;
  } else {
    throw new MappingException(String.format("Unsupported type %s", input.getClass().getName()));
  }
  return javaValue;
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:32,代码来源:CatchAllMapper.java


示例19: insertWithDeferredIdAllocation

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
@Override
public <E> void insertWithDeferredIdAllocation(E entity) {
  try {
    DatastoreUtils.validateDeferredIdAllocation(entity);
    FullEntity<?> nativeEntity = (FullEntity<?>) Marshaller.marshal(entityManager, entity,
        Intent.INSERT);
    nativeBatch.addWithDeferredIdAllocation(nativeEntity);
  } catch (DatastoreException exp) {
    throw DatastoreUtils.wrap(exp);
  }
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:12,代码来源:DefaultDatastoreBatch.java


示例20: upsertWithDeferredIdAllocation

import com.google.cloud.datastore.FullEntity; //导入依赖的package包/类
@Override
public <E> void upsertWithDeferredIdAllocation(E entity) {
  try {
    DatastoreUtils.validateDeferredIdAllocation(entity);
    FullEntity<?> nativeEntity = (FullEntity<?>) Marshaller.marshal(entityManager, entity,
        Intent.UPSERT);
    nativeBatch.putWithDeferredIdAllocation(nativeEntity);
  } catch (DatastoreException exp) {
    throw DatastoreUtils.wrap(exp);
  }

}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:13,代码来源:DefaultDatastoreBatch.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Entry类代码示例发布时间:2022-05-23
下一篇:
Java DefaultFileTypeSpecificInputFilter类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap