Tabnine Logo
Entity$Builder.clear
Code IndexAdd Tabnine to your IDE (free)

How to use
clear
method
in
com.google.cloud.datastore.Entity$Builder

Best Java code snippets using com.google.cloud.datastore.Entity$Builder.clear (Showing top 16 results out of 315)

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.getProperties(), entities.get(3).getProperties());
 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);
}
origin: googleapis/google-cloud-java

@Test
public void testNewTransactionCommit() {
 Transaction transaction = datastore.newTransaction();
 transaction.add(ENTITY3);
 Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla").build();
 transaction.update(entity2);
 transaction.delete(KEY1);
 transaction.commit();
 List<Entity> list = datastore.fetch(KEY1, KEY2, KEY3);
 assertNull(list.get(0));
 assertEquals(entity2, list.get(1));
 assertEquals(ENTITY3, list.get(2));
 assertEquals(3, list.size());
 try {
  transaction.commit();
  fail("Expecting a failure");
 } catch (DatastoreException ex) {
  // expected to fail
 }
 try {
  transaction.rollback();
  fail("Expecting a failure");
 } catch (DatastoreException ex) {
  // expected to fail
 }
 verifyNotUsable(transaction);
}
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

 Entity oldEntity = c.element();

// We need to get the property map, but the one from DatastoreHelper is an unmodifiableMap
Map<String, Value> oldEntity_map = DatastoreHelper.getPropertyMap(oldEntity);
Map<String, Value> newEntity_map = new HashMap<String, Value>();
newEntity_map.putAll(oldEntity_map);

// Adding or updating a property
newEntity_map.put("newProperty", DatastoreHelper.makeValue("Value").build());
// Deleting a property
newEntity_map.remove("delete-this");

Entity.Builder updatedEntity = Entity.newBuilder(oldEntity);
updatedEntity.clear();
updatedEntity.setKey(oldEntity.getKey());

for (Map.Entry<String, Value> property : newEntity_map.entrySet())
{
  updatedEntity.addProperty(
    DatastoreHelper.makeProperty(property.getKey(), property.getValue()));
}

c.output(updatedEntity.build());
origin: googleapis/google-cloud-java

@Test
public void testNewBatch() {
 Batch batch = DATASTORE.newBatch();
 Entity entity1 = Entity.newBuilder(ENTITY1).clear().build();
 Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla").build();
 Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build();
 Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build();
origin: googleapis/google-cloud-java

@Test
public void testNewBatch() {
 Batch batch = datastore.newBatch();
 Entity entity1 = Entity.newBuilder(ENTITY1).clear().build();
 Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla").build();
 Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build();
 Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build();
origin: googleapis/google-cloud-java

@Test
public void testRunInTransactionReadWrite() {
 final Entity entity1 = Entity.newBuilder(ENTITY1).clear().setNull("bla").build();
 assertEquals(result, 2);
 final Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla").build();
 Datastore.TransactionCallable<Integer> callable2 =
   new Datastore.TransactionCallable<Integer>() {
origin: googleapis/google-cloud-java

transaction.delete(ENTITY3.getKey());
DATASTORE.put(Entity.newBuilder(ENTITY2).clear().build());
try {
 transaction.commit();
origin: googleapis/google-cloud-java

@Test
public void testNewTransactionCommit() {
 Transaction transaction = DATASTORE.newTransaction();
 transaction.add(ENTITY3);
 Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla").build();
 transaction.update(entity2);
 transaction.delete(KEY1);
 transaction.commit();
 assertFalse(transaction.isActive());
 List<Entity> list = DATASTORE.fetch(KEY1, KEY2, KEY3);
 assertNull(list.get(0));
 assertEquals(entity2, list.get(1));
 assertEquals(ENTITY3, list.get(2));
 assertEquals(3, list.size());
 try {
  transaction.commit();
  fail("Expecting a failure");
 } catch (DatastoreException expected) {
  assertEquals("FAILED_PRECONDITION", expected.getReason());
 }
 try {
  transaction.rollback();
  fail("Expecting a failure");
 } catch (DatastoreException expected) {
  assertEquals("FAILED_PRECONDITION", expected.getReason());
 }
}
origin: googleapis/google-cloud-java

@Test
public void testNewTransactionRollback() {
 Transaction transaction = DATASTORE.newTransaction();
 transaction.add(ENTITY3);
 Entity entity2 =
   Entity.newBuilder(ENTITY2)
     .clear()
     .setNull("bla")
     .set("list3", StringValue.of("bla"), StringValue.newBuilder("bla").build())
     .build();
 transaction.update(entity2);
 transaction.delete(KEY1);
 transaction.rollback();
 transaction.rollback(); // should be safe to repeat rollback calls
 try {
  transaction.commit();
  fail("Expecting a failure");
 } catch (DatastoreException expected) {
  assertEquals("FAILED_PRECONDITION", expected.getReason());
 }
 List<Entity> list = DATASTORE.fetch(KEY1, KEY2, KEY3);
 assertEquals(ENTITY1, list.get(0));
 assertEquals(ENTITY2, list.get(1));
 assertNull(list.get(2));
 assertEquals(3, list.size());
}
origin: googleapis/google-cloud-java

@Test
public void testNewTransactionRollback() {
 Transaction transaction = datastore.newTransaction();
 transaction.add(ENTITY3);
 Entity entity2 =
   Entity.newBuilder(ENTITY2)
     .clear()
     .setNull("bla")
     .set("list3", StringValue.of("bla"), StringValue.newBuilder("bla").build())
     .build();
 transaction.update(entity2);
 transaction.delete(KEY1);
 transaction.rollback();
 transaction.rollback(); // should be safe to repeat rollback calls
 try {
  transaction.commit();
  fail("Expecting a failure");
 } catch (DatastoreException ex) {
  // expected to fail
 }
 verifyNotUsable(transaction);
 List<Entity> list = datastore.fetch(KEY1, KEY2, KEY3);
 assertEquals(ENTITY1, list.get(0));
 assertEquals(ENTITY2, list.get(1));
 assertNull(list.get(2));
 assertEquals(3, list.size());
}
origin: googleapis/google-cloud-java

@Test
public void testTransactionWithQuery() {
 Query<Entity> query =
   Query.newEntityQueryBuilder()
     .setKind(KIND2)
     .setFilter(PropertyFilter.hasAncestor(KEY2))
     .build();
 Transaction transaction = datastore.newTransaction();
 QueryResults<Entity> results = transaction.run(query);
 assertEquals(ENTITY2, results.next());
 assertFalse(results.hasNext());
 transaction.add(ENTITY3);
 transaction.commit();
 assertEquals(ENTITY3, datastore.get(KEY3));
 transaction = datastore.newTransaction();
 results = transaction.run(query);
 assertEquals(ENTITY2, results.next());
 transaction.delete(ENTITY3.getKey());
 // update entity2 during the transaction
 datastore.put(Entity.newBuilder(ENTITY2).clear().build());
 try {
  transaction.commit();
  fail("Expecting a failure");
 } catch (DatastoreException expected) {
  assertEquals("ABORTED", expected.getReason());
 }
}
origin: googleapis/google-cloud-java

@Test
public void testUpdate() {
 List<Entity> keys = DATASTORE.fetch(ENTITY1.getKey(), ENTITY3.getKey());
 assertEquals(ENTITY1, keys.get(0));
 assertNull(keys.get(1));
 assertEquals(2, keys.size());
 try {
  DATASTORE.update(ENTITY3);
  fail("Expecting a failure");
 } catch (DatastoreException expected) {
  // expected;
 }
 DATASTORE.add(ENTITY3);
 assertEquals(ENTITY3, DATASTORE.get(ENTITY3.getKey()));
 Entity entity3 = Entity.newBuilder(ENTITY3).clear().set("bla", new NullValue()).build();
 assertNotEquals(ENTITY3, entity3);
 DATASTORE.update(entity3);
 assertEquals(entity3, DATASTORE.get(ENTITY3.getKey()));
}
origin: googleapis/google-cloud-java

@Test
public void testTransactionWithRead() {
 Transaction transaction = DATASTORE.newTransaction();
 assertNull(transaction.get(KEY3));
 transaction.add(ENTITY3);
 transaction.commit();
 assertEquals(ENTITY3, DATASTORE.get(KEY3));
 transaction = DATASTORE.newTransaction();
 assertEquals(ENTITY3, transaction.get(KEY3));
 // update entity3 during the transaction
 DATASTORE.put(Entity.newBuilder(ENTITY2).clear().set("from", "datastore").build());
 transaction.update(Entity.newBuilder(ENTITY2).clear().set("from", "transaction").build());
 try {
  transaction.commit();
  fail("Expecting a failure");
 } catch (DatastoreException expected) {
  assertEquals("ABORTED", expected.getReason());
 }
}
origin: googleapis/google-cloud-java

@Test
public void testTransactionWithRead() {
 Transaction transaction = datastore.newTransaction();
 assertNull(transaction.get(KEY3));
 transaction.add(ENTITY3);
 transaction.commit();
 assertEquals(ENTITY3, datastore.get(KEY3));
 transaction = datastore.newTransaction();
 assertEquals(ENTITY3, transaction.get(KEY3));
 // update entity3 during the transaction
 datastore.put(Entity.newBuilder(ENTITY3).clear().build());
 transaction.update(ENTITY2);
 try {
  transaction.commit();
  fail("Expecting a failure");
 } catch (DatastoreException expected) {
  assertEquals("ABORTED", expected.getReason());
 }
}
origin: googleapis/google-cloud-java

@Test
public void testUpdate() {
 List<Entity> keys = datastore.fetch(ENTITY1.getKey(), ENTITY3.getKey());
 assertEquals(ENTITY1, keys.get(0));
 assertNull(keys.get(1));
 assertEquals(2, keys.size());
 try {
  datastore.update(ENTITY3);
  fail("Expecting a failure");
 } catch (DatastoreException expected) {
  // expected;
 }
 datastore.add(ENTITY3);
 assertEquals(ENTITY3, datastore.get(ENTITY3.getKey()));
 Entity entity3 = Entity.newBuilder(ENTITY3).clear().set("bla", new NullValue()).build();
 assertNotEquals(ENTITY3, entity3);
 datastore.update(entity3);
 assertEquals(entity3, datastore.get(ENTITY3.getKey()));
}
com.google.cloud.datastoreEntity$Builderclear

Popular methods of Entity$Builder

  • build
  • set
  • setKey
  • <init>
  • addProperty
  • fill
  • key
  • setNull
  • setProperties

Popular in Java

  • Making http requests using okhttp
  • requestLocationUpdates (LocationManager)
  • notifyDataSetChanged (ArrayAdapter)
  • startActivity (Activity)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • JList (javax.swing)
  • Runner (org.openjdk.jmh.runner)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now