Skip to content

What's the best way for a total n00b to start with this library? #34

@jgeewax

Description

@jgeewax

I'm having trouble getting a HelloDatastore project working. Hoping that you can help me get this going...

Here's what I did:

$ git clone https://github.com/GoogleCloudPlatform/gcloud-java.git
$ cd gcloud-java
$ sudo apt-get install maven
$ mvn install
$ export CLASSPATH=~/gcdjavasample/gcloud-java/target/gcloud-java-0.0.3.jar

Here's the file I'm trying to run (HelloDatastore.java):

import com.google.gcloud.datastore.DatastoreService;
import com.google.gcloud.datastore.DatastoreServiceFactory;
import com.google.gcloud.datastore.DatastoreServiceOptions;
import com.google.gcloud.datastore.Entity;
import com.google.gcloud.datastore.Key;
import com.google.gcloud.datastore.KeyFactory;



public class HelloDatastore {
  private static final String DATASET = "gcloud-datastore-demo";

  public static void main(String[] args) {
    DatastoreServiceOptions options = DatastoreServiceOptions.builder().dataset(DATASET).build();
    DatastoreService datastore = DatastoreServiceFactory.getDefault(options);
    KeyFactory keyFactory = datastore.newKeyFactory().kind("Person");
    Key key = keyFactory.newKey("Jimmy");

    System.out.println("Trying to get the entity by its key!");

    Entity entity = datastore.get(key);

    if (entity == null) {
      System.out.println("Entity not found! Creating it!");
      entity = Entity.builder(key)
          .set("name", "John Doe")
          .set("age", 30)
          .set("updated", false)
          .build();
      datastore.put(entity);
    } else {
      System.out.println("Entity found! Updating it!");
      boolean updated = entity.getBoolean("updated");
      if (!updated) {
        String[] name = entity.getString("name").split(" ");
        entity = Entity.builder(entity)
            .set("name", name[0])
            .set("last_name", name[1])
            .set("updated", true)
            .remove("old_property")
            .set("new_property", 1.1)
            .build();
        datastore.update(entity);
      }
    }

    System.out.println("Done!");
  }
}

I can get it to compile just fine, then I run into problems running the class. Apparently I need Guava? And google-auth-library-java ? And google-api-java-client ?

What exactly is the best way to get this so that I can run... java HelloDatastore and I'll see some stuff happening.... ?

(Sorry for the dumb question....)

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: coreauthtriage meI really want to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions