congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Entity$Builder.build
Code IndexAdd Tabnine to your IDE (free)

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

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

origin: googleapis/google-cloud-java

@Test
public void testGetWithTransaction() throws Exception {
 Transaction transaction = createStrictMock(Transaction.class);
 IncompleteKey pKey1 = IncompleteKey.newBuilder("ds", "k").build();
 Key key1 = Key.newBuilder(pKey1, 1).build();
 Entity entity1 = Entity.newBuilder(key1).build();
 Key key2 = Key.newBuilder(pKey1, 2).build();
 expect(transaction.get(new Key[] {key1}))
   .andReturn(Collections.singletonList(entity1).iterator());
 expect(transaction.get(new Key[] {key2})).andReturn(Collections.<Entity>emptyIterator());
 replay(transaction);
 assertEquals(entity1, DatastoreHelper.get(transaction, key1));
 assertNull(DatastoreHelper.get(transaction, key2));
 verify(transaction);
}
origin: googleapis/google-cloud-java

@Test
public void testAdd() throws Exception {
 Datastore datastore = createStrictMock(Datastore.class);
 IncompleteKey pKey = IncompleteKey.newBuilder("ds", "k").build();
 Key key = Key.newBuilder(pKey, 1).build();
 Entity entity = Entity.newBuilder(key).build();
 expect(datastore.add(new Entity[] {entity})).andReturn(Collections.singletonList(entity));
 replay(datastore);
 assertEquals(entity, DatastoreHelper.add(datastore, entity));
 verify(datastore);
}
origin: googleapis/google-cloud-java

 public static void main(String... args) {
  Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
  KeyFactory keyFactory = datastore.newKeyFactory().setKind("keyKind");
  Key key = keyFactory.newKey("keyName");
  Entity entity = datastore.get(key);
  if (entity != null) {
   System.out.println("Updating access_time for " + entity.getString("name"));
   entity = Entity.newBuilder(entity).set("access_time", Timestamp.now()).build();
   datastore.update(entity);
  }
 }
}
origin: googleapis/google-cloud-java

/** Example of starting a new batch. */
// [TARGET newBatch()]
// [VARIABLE "my_key_name_1"]
// [VARIABLE "my_key_name_2"]
public Batch newBatch(String keyName1, String keyName2) {
 // [START newBatch]
 Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
 Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
 Batch batch = datastore.newBatch();
 Entity entity1 = Entity.newBuilder(key1).set("name", "John").build();
 Entity entity2 = Entity.newBuilder(key2).set("title", "title").build();
 batch.add(entity1);
 batch.add(entity2);
 batch.submit();
 // [END newBatch]
 return batch;
}
origin: googleapis/google-cloud-java

 @Test
 public void testStartStopReset() throws IOException, InterruptedException, TimeoutException {
  LocalDatastoreHelper helper = LocalDatastoreHelper.create();
  helper.start();
  Datastore datastore = helper.getOptions().getService();
  Key key = datastore.newKeyFactory().setKind("kind").newKey("name");
  datastore.put(Entity.newBuilder(key).build());
  assertNotNull(datastore.get(key));
  helper.reset();
  assertNull(datastore.get(key));
  helper.stop(Duration.ofMinutes(1));
  thrown.expect(DatastoreException.class);
  datastore.get(key);
 }
}
origin: googleapis/google-cloud-java

/** Example of rolling back a transaction. */
// [TARGET rollback()]
public Key rollback() {
 Datastore datastore = transaction.getDatastore();
 // [START rollback]
 // create an entity
 KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
 Key key = datastore.allocateId(keyFactory.newKey());
 Entity entity = Entity.newBuilder(key).set("description", "rollback()").build();
 // add the entity and rollback
 transaction.put(entity);
 transaction.rollback();
 // calling transaction.commit() now would fail
 // [END rollback]
 return key;
}
origin: googleapis/google-cloud-java

/** Example of adding a single entity. */
// [TARGET add(FullEntity)]
// [VARIABLE "my_key_name"]
public void addSingleEntity(String keyName) {
 Datastore datastore = transaction.getDatastore();
 // [START addSingleEntity]
 Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
 Entity.Builder entityBuilder = Entity.newBuilder(key);
 entityBuilder.set("propertyName", "value");
 Entity entity = entityBuilder.build();
 transaction.add(entity);
 transaction.commit();
 // [END addSingleEntity]
}
origin: googleapis/google-cloud-java

/** Example of putting a single entity. */
// [TARGET put(FullEntity)]
// [VARIABLE "my_key_name"]
public void putSingleEntity(String keyName) {
 Datastore datastore = transaction.getDatastore();
 // [START putSingleEntity]
 Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
 Entity.Builder entityBuilder = Entity.newBuilder(key);
 entityBuilder.set("propertyName", "value");
 Entity entity = entityBuilder.build();
 transaction.put(entity);
 transaction.commit();
 // [END putSingleEntity]
}
origin: googleapis/google-cloud-java

 static Entity fromPb(com.google.datastore.v1.Entity entityPb) {
  return new Builder().fill(entityPb).build();
 }
}
origin: googleapis/google-cloud-java

 public static void main(String... args) {
  Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
  KeyFactory keyFactory = datastore.newKeyFactory().setKind("keyKind");
  Key key = keyFactory.newKey("keyName");
  Entity entity =
    Entity.newBuilder(key)
      .set("name", "John Doe")
      .set("age", 30)
      .set("access_time", Timestamp.now())
      .build();
  datastore.put(entity);
 }
}
origin: googleapis/google-cloud-java

@Test
public void testPutAfterUpdate() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
 batchWriter.update(ENTITY1);
 Entity putEntity = batchWriter.put(entity);
 assertEquals(entity, putEntity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}
origin: googleapis/google-cloud-java

@Test
public void testUpdateAfterUpdate() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpdate(entity.toPb()).build());
 batchWriter.update(ENTITY1);
 batchWriter.update(entity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}
origin: googleapis/google-cloud-java

 @Test
 public void testCopyFromIncompleteEntity() throws Exception {
  Entity.Builder builder = Entity.newBuilder(KEY2, INCOMPLETE_ENTITY);
  Entity entity = builder.build();
  assertNotEquals(INCOMPLETE_ENTITY, entity);
  assertEquals(INCOMPLETE_ENTITY.getProperties(), entity.getProperties());
 }
}
origin: googleapis/google-cloud-java

@Test
public void testPutAfterDelete() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
 batchWriter.delete(KEY1);
 Entity putEntity = batchWriter.put(entity);
 assertEquals(entity, putEntity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}
origin: googleapis/google-cloud-java

@Test
public void testPutAfterPut() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
 Entity putEntity1 = batchWriter.put(ENTITY1);
 Entity putEntity2 = batchWriter.put(entity);
 assertEquals(ENTITY1, putEntity1);
 assertEquals(entity, putEntity2);
 assertEquals(pbs, batchWriter.toMutationPbList());
}
origin: googleapis/google-cloud-java

@Test
public void testUpdateAfterPut() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
 batchWriter.put(ENTITY1);
 batchWriter.update(entity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}
origin: googleapis/google-cloud-java

@Test
public void testCopyFrom() throws Exception {
 Entity.Builder builder = Entity.newBuilder(ENTITY);
 assertEquals(ENTITY, builder.build());
 Entity entity = builder.setKey(KEY2).build();
 assertNotEquals(ENTITY, entity);
 assertEquals(KEY2, entity.getKey());
 assertEquals(ENTITY.getProperties(), entity.getProperties());
}
origin: googleapis/google-cloud-java

/** Example of putting a single entity. */
// [TARGET put(FullEntity)]
// [VARIABLE "my_key_name"]
public void putSingleEntity(String keyName) {
 // [START putSingleEntity]
 Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
 Entity.Builder entityBuilder = Entity.newBuilder(key);
 entityBuilder.set("propertyName", "value");
 Entity entity = entityBuilder.build();
 datastore.put(entity);
 // [END putSingleEntity]
}
origin: googleapis/google-cloud-java

@Test
public void testPutAfterAdd() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
 batchWriter.add(ENTITY1);
 batchWriter.put(entity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}
origin: googleapis/google-cloud-java

@Test
public void testUpdateAfterAdd() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
 batchWriter.add(ENTITY1);
 batchWriter.update(entity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}
com.google.cloud.datastoreEntity$Builderbuild

Popular methods of Entity$Builder

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

Popular in Java

  • Creating JSON documents from java classes using gson
  • setContentView (Activity)
  • getExternalFilesDir (Context)
  • getApplicationContext (Context)
  • Kernel (java.awt.image)
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • Github Copilot alternatives
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