本文整理了Java中com.google.cloud.datastore.Datastore.delete()
方法的一些代码示例,展示了Datastore.delete()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Datastore.delete()
方法的具体详情如下:
包路径:com.google.cloud.datastore.Datastore
类名称:Datastore
方法名:delete
[英]Example of deleting multiple entities.
String keyName1 = "my_key_name1";
[中]
代码示例来源:origin: google/data-transfer-project
/**
* Removes the {@link PortabilityJob} keyed by {@code jobId} in Datastore.
*
* @throws IOException if the job doesn't exist, or there was a different problem deleting it.
*/
@Override
public void remove(UUID jobId) throws IOException {
try {
datastore.delete(getKey(jobId));
} catch (DatastoreException e) {
throw new IOException("Could not remove jobId: " + jobId, e);
}
}
代码示例来源:origin: googleapis/google-cloud-java
@After
public void tearDown() {
DATASTORE.delete(KEY1, KEY2, KEY3);
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of deleting multiple entities. */
// [TARGET delete(Key...)]
// [VARIABLE "my_key_name1"]
// [VARIABLE "my_key_name2"]
public void batchDeleteEntities(String keyName1, String keyName2) {
// [START batchDeleteEntities]
Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
datastore.delete(key1, key2);
// [END batchDeleteEntities]
}
代码示例来源:origin: googleapis/google-cloud-java
/** Deletes all entities in the namespace associated with this {@link RemoteDatastoreHelper}. */
public void deleteNamespace() {
StructuredQuery<Key> query = Query.newKeyQueryBuilder().setNamespace(namespace).build();
QueryResults<Key> keys = datastore.run(query);
while (keys.hasNext()) {
datastore.delete(keys.next());
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testDelete() {
Iterator<Entity> keys =
DATASTORE.fetch(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey()).iterator();
assertEquals(ENTITY1, keys.next());
assertEquals(ENTITY2, keys.next());
assertNull(keys.next());
assertFalse(keys.hasNext());
DATASTORE.delete(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey());
keys = DATASTORE.fetch(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey()).iterator();
assertNull(keys.next());
assertNull(keys.next());
assertNull(keys.next());
assertFalse(keys.hasNext());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testDelete() {
Iterator<Entity> keys =
datastore.fetch(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey()).iterator();
assertEquals(ENTITY1, keys.next());
assertEquals(ENTITY2, keys.next());
assertNull(keys.next());
assertFalse(keys.hasNext());
datastore.delete(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey());
keys = datastore.fetch(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey()).iterator();
assertNull(keys.next());
assertNull(keys.next());
assertNull(keys.next());
assertFalse(keys.hasNext());
}
代码示例来源:origin: googleapis/google-cloud-java
@Before
public void setUp() {
rpcFactoryMock = EasyMock.createStrictMock(DatastoreRpcFactory.class);
rpcMock = EasyMock.createStrictMock(DatastoreRpc.class);
rpcMockOptions =
options
.toBuilder()
.setRetrySettings(ServiceOptions.getDefaultRetrySettings())
.setServiceRpcFactory(rpcFactoryMock)
.build();
EasyMock.expect(rpcFactoryMock.create(rpcMockOptions)).andReturn(rpcMock);
StructuredQuery<Key> query = Query.newKeyQueryBuilder().build();
QueryResults<Key> result = datastore.run(query);
datastore.delete(Iterators.toArray(result, Key.class));
datastore.add(ENTITY1, ENTITY2);
}
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* Delete a user from Cloud Datastore.
*/
public String deleteUser(String id) {
Key key = keyFactory.newKey(id);
datastore.delete(key);
return "ok";
}
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* Deletes a task entity.
*
* @param id The ID of the task entity as given by {@link Key#id()}
* @throws DatastoreException if the delete fails
*/
void deleteTask(long id) {
datastore.delete(keyFactory.newKey(id));
}
// [END datastore_delete_entity]
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testAddEntity() {
List<Entity> keys = DATASTORE.fetch(ENTITY1.getKey(), ENTITY3.getKey());
assertEquals(ENTITY1, keys.get(0));
assertNull(keys.get(1));
assertEquals(2, keys.size());
try {
DATASTORE.add(ENTITY1);
fail("Expecting a failure");
} catch (DatastoreException expected) {
// expected;
}
List<Entity> entities = DATASTORE.add(ENTITY3, PARTIAL_ENTITY1, PARTIAL_ENTITY2);
assertEquals(ENTITY3, DATASTORE.get(ENTITY3.getKey()));
assertEquals(ENTITY3, entities.get(0));
assertEquals(PARTIAL_ENTITY1.getNames(), entities.get(1).getNames());
assertEquals(PARTIAL_ENTITY1.getKey().getAncestors(), entities.get(1).getKey().getAncestors());
assertNotNull(DATASTORE.get(entities.get(1).getKey()));
assertEquals(PARTIAL_ENTITY2.getNames(), entities.get(2).getNames());
assertEquals(PARTIAL_ENTITY2.getKey().getAncestors(), entities.get(2).getKey().getAncestors());
assertNotNull(DATASTORE.get(entities.get(2).getKey()));
for (Entity entity : entities) {
DATASTORE.delete(entity.getKey());
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testPut() {
Entity updatedEntity = Entity.newBuilder(ENTITY1).set("new_property", 42L).build();
assertEquals(updatedEntity, DATASTORE.put(updatedEntity));
assertEquals(updatedEntity, DATASTORE.get(updatedEntity.getKey()));
Entity entity2 = Entity.newBuilder(ENTITY2).clear().set("bla", new NullValue()).build();
assertNotEquals(ENTITY2, entity2);
List<Entity> entities = DATASTORE.put(ENTITY1, entity2, ENTITY3, PARTIAL_ENTITY1);
assertEquals(ENTITY1, entities.get(0));
assertEquals(entity2, entities.get(1));
assertEquals(ENTITY3, entities.get(2));
assertEquals(PARTIAL_ENTITY1.getNames(), entities.get(3).getNames());
assertEquals(PARTIAL_ENTITY1.getKey().getAncestors(), entities.get(3).getKey().getAncestors());
assertEquals(ENTITY1, DATASTORE.get(ENTITY1.getKey()));
assertEquals(entity2, DATASTORE.get(entity2.getKey()));
assertEquals(ENTITY3, DATASTORE.get(ENTITY3.getKey()));
Entity entity = DATASTORE.get(entities.get(3).getKey());
assertEquals(entities.get(3), entity);
for (Entity entityToDelete : entities) {
DATASTORE.delete(entityToDelete.getKey());
}
}
代码示例来源:origin: stackoverflow.com
Delete.java
String key1=req.getParameter("key").toString();
PrintWriter out = resp.getWriter();
out.println("I m in delete");
System.out.println("the first key is "+key1);
Datastore ds= DatastoreServiceFactory.getDatastoreService();
Key UserKey = KeyFactory.createKey("safc",key1 );
System.out.println("the value od userkey is" +UserKey);
ds.delete(UserKey);
代码示例来源:origin: stackoverflow.com
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
// ...
Entity old = null /* some value */;
Key oldKey = old.getKey();
KeyFactory kf = datastore.newKeyFactory().setKind(oldKey.getKind());
Entity newEntity = Entity.newBuilder(old)
.setKey(kf.newKey(oldKey.getName()))
.build();
datastore.delete(oldKey);
datastore.put(newEntity);
代码示例来源:origin: org.eclipse.jetty.gcloud/jetty-gcloud-session-manager
@Override
public boolean delete(String id) throws Exception
{
if (LOG.isDebugEnabled()) LOG.debug("Removing session {} from DataStore", id);
_datastore.delete(makeKey(id, _context));
return true;
}
代码示例来源:origin: sai-pullabhotla/catatumbo
@Override
public long deleteAll(String kind) {
if (Utility.isNullOrEmpty(kind)) {
throw new IllegalArgumentException("kind cannot be null or blank");
}
String query = "SELECT __key__ FROM " + kind;
try {
GqlQuery<Key> gqlQuery = Query.newGqlQueryBuilder(Query.ResultType.KEY, query)
.setNamespace(getEffectiveNamespace()).build();
QueryResults<Key> keys = datastore.run(gqlQuery);
Key[] nativeKeys = new Key[DEFAULT_DELETE_ALL_BATCH_SIZE];
long deleteCount = 0;
int i = 0;
while (keys.hasNext()) {
nativeKeys[i++] = keys.next();
if (i % DEFAULT_DELETE_ALL_BATCH_SIZE == 0) {
datastore.delete(nativeKeys);
deleteCount += DEFAULT_DELETE_ALL_BATCH_SIZE;
i = 0;
}
}
if (i > 0) {
datastore.delete(Arrays.copyOfRange(nativeKeys, 0, i));
deleteCount += i;
}
return deleteCount;
} catch (DatastoreException exp) {
throw new EntityManagerException(exp);
}
}
代码示例来源:origin: com.google.cloud/google-cloud-datastore
/** Deletes all entities in the namespace associated with this {@link RemoteDatastoreHelper}. */
public void deleteNamespace() {
StructuredQuery<Key> query = Query.newKeyQueryBuilder().setNamespace(namespace).build();
QueryResults<Key> keys = datastore.run(query);
while (keys.hasNext()) {
datastore.delete(keys.next());
}
}
内容来源于网络,如有侵权,请联系作者删除!