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); } } }
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); } }
/** Uses default datastore, no memcache */ public ObjectifyFactory() { this(DatastoreOptions.getDefaultInstance().getService()); }
/** Uses default datastore */ public ObjectifyFactory(final MemcacheService memcache) { this(DatastoreOptions.getDefaultInstance().getService(), memcache); }
/** Uses default datastore */ public ObjectifyFactory(final MemcachedClient memcache) { this(DatastoreOptions.getDefaultInstance().getService(), memcache); }
public static void main(String... args) { Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
/** * Starts the webapp on localhost:8080. */ public static void main(String[] args) { port(8080); String kind = "DemoUser"; if (args != null) { for (String arg : args) { if (arg.startsWith("kind=")) { kind = arg.substring("kind=".length()); } } } UserController userController = new UserController(new UserService( DatastoreOptions.getDefaultInstance().getService(), kind)); } }
public static void main(String... args) throws Exception { // Instantiates a client Datastore datastore = DatastoreOptions.getDefaultInstance().getService(); // The kind for the new entity String kind = "Task"; // The name/ID for the new entity String name = "sampletask1"; // The Cloud Datastore key for the new entity Key taskKey = datastore.newKeyFactory().setKind(kind).newKey(name); // Prepares the new entity Entity task = Entity.newBuilder(taskKey) .set("description", "Buy milk") .build(); // Saves the entity datastore.put(task); System.out.printf("Saved %s: %s%n", task.getKey().getName(), task.getString("description")); //Retrieve entity Entity retrieved = datastore.get(taskKey); System.out.printf("Retrieved %s: %s%n", taskKey.getName(), retrieved.getString("description")); } }
@Override protected void doStart() throws Exception { if (!_dsProvided) { if (!StringUtil.isBlank(getNamespace())) _datastore = DatastoreOptions.newBuilder().setNamespace(getNamespace()).build().getService(); else _datastore = DatastoreOptions.getDefaultInstance().getService(); } if (_model == null) { _model = new EntityDataModel(); addBean(_model,true); } _keyFactory = _datastore.newKeyFactory().setKind(_model.getKind()); _indexesPresent = checkIndexes(); if (!_indexesPresent) LOG.warn("Session indexes not uploaded, falling back to less efficient queries"); super.doStart(); }