當前位置: 首頁>>代碼示例>>Java>>正文


Java DatastoreService.put方法代碼示例

本文整理匯總了Java中com.google.appengine.api.datastore.DatastoreService.put方法的典型用法代碼示例。如果您正苦於以下問題:Java DatastoreService.put方法的具體用法?Java DatastoreService.put怎麽用?Java DatastoreService.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.appengine.api.datastore.DatastoreService的用法示例。


在下文中一共展示了DatastoreService.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: saveFile

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
/**
 * Save Full File
 *
 * @param inputStream
 */
private static void saveFile(InputStream inputStream) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Calendar time = Calendar.getInstance(TimeZone.getTimeZone("CET"));
    time.set(Calendar.HOUR_OF_DAY,0);
    time.set(Calendar.MINUTE,0);
    time.set(Calendar.SECOND,0);
    Date measuredAt = time.getTime();
    long millis = time.getTimeInMillis();
    //
    Entity entity = new Entity(ENTITY_TYPE_FICHEROS,millis);
    entity.setIndexedProperty("Date", measuredAt);
    entity.setUnindexedProperty("File", GlobalUtils.getString(inputStream));
    // Store
    datastore.put(entity);
}
 
開發者ID:medialab-prado,項目名稱:puremadrid,代碼行數:21,代碼來源:GetNewData.java

示例2: newSharedProduct

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void newSharedProduct(@FormParam("productID") String productID,
		@FormParam("productName") String productName,
		@Context HttpServletResponse servletResponse) throws Exception {
	UserService userService = UserServiceFactory.getUserService();
	User user = userService.getCurrentUser();
	if (user == null) {
		System.out.println("Login first");
		return;
	}

	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	Entity entity = new Entity("SharedList", productID);
	entity.setProperty("email", user.getEmail());
	entity.setProperty("productName", productName);
	entity.setProperty("sharedDate", new Date());
	datastore.put(entity);
	servletResponse.getWriter().println(productName + " has been added.");
	servletResponse.flushBuffer();
}
 
開發者ID:fasthall,項目名稱:amazon-price-tracker,代碼行數:24,代碼來源:Sharedlist.java

示例3: contextInitialized

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@Override
public void contextInitialized(ServletContextEvent event) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key key = KeyFactory.createKey(ENTITY_KIND, ENTITY_KEY);

    Entity entity;
    try {
      entity = datastore.get(key);
    } catch(EntityNotFoundException e) {
        entity = new Entity(key);
        // NOTE: it's not possible to change entities in the local server, so
        // it will be necessary to hardcode the API key below if you are running
        // it locally.
        entity.setProperty(ACCESS_KEY_FIELD,
          API_KEY);
        datastore.put(entity);
        mLogger.severe("Created fake key. Please go to App Engine admin "
                + "console, change its value to your API Key (the entity "
                + "type is '" + ENTITY_KIND + "' and its field to be changed is '"
                + ACCESS_KEY_FIELD + "'), then restart the server!");
    }
    String accessKey = (String) entity.getProperty(ACCESS_KEY_FIELD);
    event.getServletContext().setAttribute(ATTRIBUTE_ACCESS_KEY, accessKey);
}
 
開發者ID:xunboo,項目名稱:JJCamera,代碼行數:25,代碼來源:ApiKeyInitializer.java

示例4: readPolicy_strong_returnsAllResults

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@Test
public void readPolicy_strong_returnsAllResults() {
  double deadline = 5.0;
  ReadPolicy policy = new ReadPolicy(ReadPolicy.Consistency.STRONG);
  DatastoreServiceConfig datastoreConfig =
      DatastoreServiceConfig.Builder.withReadPolicy(policy).deadline(deadline);
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(datastoreConfig);

  Entity parent = new Entity("Person", "a");
  Entity child = new Entity("Person", "b", parent.getKey());
  datastore.put(ImmutableList.<Entity>of(parent, child));

  Query q = new Query("Person").setAncestor(parent.getKey());
  List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults());
  assertThat(results).named("query results").hasSize(2);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:17,代碼來源:ReadPolicyTest.java

示例5: kindExample_writesEntity

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@Test
public void kindExample_writesEntity() throws Exception {
  // [START kind_example]
  Entity employee = new Entity("Employee", "asalieri");
  employee.setProperty("firstName", "Antonio");
  employee.setProperty("lastName", "Salieri");
  employee.setProperty("hireDate", new Date());
  employee.setProperty("attendedHrTraining", true);

  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
  datastore.put(employee);
  // [END kind_example]

  Entity got = datastore.get(employee.getKey());
  assertThat((String) got.getProperty("firstName")).named("got.firstName").isEqualTo("Antonio");
  assertThat((String) got.getProperty("lastName")).named("got.lastName").isEqualTo("Salieri");
  assertThat((Date) got.getProperty("hireDate")).named("got.hireDate").isNotNull();
  assertThat((boolean) got.getProperty("attendedHrTraining"))
      .named("got.attendedHrTraining")
      .isTrue();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:22,代碼來源:EntitiesTest.java

示例6: printEntityGroupVersions

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
private static void printEntityGroupVersions(DatastoreService ds, PrintWriter writer) {
  Entity entity1 = new Entity("Simple");
  Key key1 = ds.put(entity1);
  Key entityGroupKey = Entities.createEntityGroupKey(key1);

  // Print entity1's entity group version
  writer.println("version " + getEntityGroupVersion(ds, null, key1));

  // Write to a different entity group
  Entity entity2 = new Entity("Simple");
  ds.put(entity2);

  // Will print the same version, as entity1's entity group has not changed
  writer.println("version " + getEntityGroupVersion(ds, null, key1));

  // Change entity1's entity group by adding a new child entity
  Entity entity3 = new Entity("Simple", entity1.getKey());
  ds.put(entity3);

  // Will print a higher version, as entity1's entity group has changed
  writer.println("version " + getEntityGroupVersion(ds, null, key1));
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:23,代碼來源:MetadataEntityGroupTest.java

示例7: crossGroupTransactions

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@Test
public void crossGroupTransactions() throws Exception {
  // [START cross-group_XG_transactions_using_the_Java_low-level_API]
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
  TransactionOptions options = TransactionOptions.Builder.withXG(true);
  Transaction txn = datastore.beginTransaction(options);

  Entity a = new Entity("A");
  a.setProperty("a", 22);
  datastore.put(txn, a);

  Entity b = new Entity("B");
  b.setProperty("b", 11);
  datastore.put(txn, b);

  txn.commit();
  // [END cross-group_XG_transactions_using_the_Java_low-level_API]
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:19,代碼來源:TransactionsTest.java

示例8: newWishlistProductJson

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_JSON)
public void newWishlistProductJson(WishlistProduct product,
		@Context HttpServletResponse servletResponse) throws Exception {
	UserService userService = UserServiceFactory.getUserService();
	User user = userService.getCurrentUser();
	if (user == null) {
		System.out.println("Login first");
		return;
	}

	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
	Entity entity = new Entity(user.getEmail(), product.getProductID());
	entity.setProperty("productName", product.getProductName());
	entity.setProperty("currentPrice", product.getCurrentPrice());
	entity.setProperty("lowestPrice", product.getLowestPrice());
	entity.setProperty("lowestDate", new Date());
	datastore.put(entity);
	syncCache.put(product.getProductID(), product.getCurrentPrice());
	servletResponse.getWriter().println("<html><head>");
	servletResponse
			.getWriter()
			.println(
					"<meta http-equiv=\"refresh\" content=\"3;url=/wishlist.jsp\" />");
	servletResponse.getWriter().println("</head><body>");
	servletResponse.getWriter()
			.println(
					"<h1>" + product.getProductName()
							+ " has been added.</h1><br>");
	servletResponse
			.getWriter()
			.println(
					"<h2>Redirecting in 3 seconds...</h2> <a href=\"/wishlist.jsp\">Go back now</a>");
	servletResponse.getWriter().println("</body></html>");
	servletResponse.flushBuffer();
	return;
}
 
開發者ID:fasthall,項目名稱:amazon-price-tracker,代碼行數:41,代碼來源:Wishlist.java

示例9: createGreeting

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@Override
protected Entity createGreeting(
    DatastoreService datastore, User user, Date date, String content) {
  // No parent key specified, so Greeting is a root entity.
  Entity greeting = new Entity("Greeting");
  greeting.setProperty("user", user);
  greeting.setProperty("date", date);
  greeting.setProperty("content", content);

  datastore.put(greeting);
  return greeting;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:13,代碼來源:Guestbook.java

示例10: createGreeting

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@Override
protected Entity createGreeting(
    DatastoreService datastore, User user, Date date, String content) {
  // String guestbookName = "my guestbook"; -- Set elsewhere (injected to the constructor).
  Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);

  // Place greeting in the same entity group as guestbook.
  Entity greeting = new Entity("Greeting", guestbookKey);
  greeting.setProperty("user", user);
  greeting.setProperty("date", date);
  greeting.setProperty("content", content);

  datastore.put(greeting);
  return greeting;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:16,代碼來源:GuestbookStrong.java

示例11: doGet

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
  resp.setContentType("text/plain");
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

  Key isPopulatedKey = KeyFactory.createKey(IS_POPULATED_ENTITY, IS_POPULATED_KEY_NAME);
  boolean isAlreadyPopulated;
  try {
    datastore.get(isPopulatedKey);
    isAlreadyPopulated = true;
  } catch (EntityNotFoundException expected) {
    isAlreadyPopulated = false;
  }
  if (isAlreadyPopulated) {
    resp.getWriter().println("ok");
    return;
  }

  ImmutableList.Builder<Entity> people = ImmutableList.builder();
  for (String name : US_PRESIDENTS) {
    Entity person = new Entity(PERSON_ENTITY);
    person.setProperty(NAME_PROPERTY, name);
    people.add(person);
  }
  datastore.put(people.build());
  datastore.put(new Entity(isPopulatedKey));
  resp.getWriter().println("ok");
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:30,代碼來源:StartupServlet.java

示例12: resetPassword

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
public static String resetPassword(DatastoreService datastore, Transaction txn, User user)
        throws ConcurrentModificationException {

    String newPassword = MiscFunctions.getEncryptedHash(MiscFunctions.toUTCDateString(new Date()), HashAlgorithms.MD5).substring(0, 8);
    user.setPassword(newPassword);
    datastore.put(txn, user.getEntity());
    return newPassword;
}
 
開發者ID:kerafill1116,項目名稱:apollo-datastore,代碼行數:9,代碼來源:UserFactory.java

示例13: doTest

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
private void doTest() {
  DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
  assertEquals(0, ds.prepare(new Query("yam")).countEntities(withLimit(10)));
  ds.put(new Entity("yam"));
  ds.put(new Entity("yam"));
  assertEquals(2, ds.prepare(new Query("yam")).countEntities(withLimit(10)));
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:8,代碼來源:LocalDatastoreTest.java

示例14: ancestorQueryExample_kindlessKeyFilterFull_returnsMatchingEntities

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@Test
public void ancestorQueryExample_kindlessKeyFilterFull_returnsMatchingEntities()
    throws Exception {
  // [START kindless_ancestor_query_example]
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

  Entity tom = new Entity("Person", "Tom");
  Key tomKey = tom.getKey();
  datastore.put(tom);

  Entity weddingPhoto = new Entity("Photo", tomKey);
  weddingPhoto.setProperty("imageURL", "http://domain.com/some/path/to/wedding_photo.jpg");

  Entity weddingVideo = new Entity("Video", tomKey);
  weddingVideo.setProperty("videoURL", "http://domain.com/some/path/to/wedding_video.avi");

  List<Entity> mediaList = Arrays.asList(weddingPhoto, weddingVideo);
  datastore.put(mediaList);

  // By default, ancestor queries include the specified ancestor itself.
  // The following filter excludes the ancestor from the query results.
  Filter keyFilter =
      new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.GREATER_THAN, tomKey);

  Query mediaQuery = new Query().setAncestor(tomKey).setFilter(keyFilter);

  // Returns both weddingPhoto and weddingVideo,
  // even though they are of different entity kinds
  List<Entity> results =
      datastore.prepare(mediaQuery).asList(FetchOptions.Builder.withDefaults());
  // [END kindless_ancestor_query_example]

  assertThat(results).named("query result keys").containsExactly(weddingPhoto, weddingVideo);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:35,代碼來源:QueriesTest.java

示例15: saveToDataStore

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
private void saveToDataStore(List<Medicion> mediciones) {
    mLogger.info("Storing " + mediciones.size() + " hours");

    // Saved date
    Date savedDate = Calendar.getInstance(TimeZone.getTimeZone("CET")).getTime();

    // Load datastore
    List<Entity> batch = new ArrayList<>();
    for (Medicion medicion : mediciones){
        // Measured date
        long measuredAtMillis = medicion.getMeasuredAt();
        Date measuredAt = new Date();
        Calendar measuredAtCalendar = Calendar.getInstance(TimeZone.getTimeZone("CET"));
        measuredAtCalendar.setTimeInMillis(measuredAtMillis);
        measuredAt.setTime(measuredAtMillis);
        //
        long savedAtMillis = medicion.getSavedAtHour();
        Date savedAt = new Date();
        savedAt.setTime(savedAtMillis);

        // Una entidad por cada compuesto
        for (Compuesto compuesto: Compuesto.measuredCompuestos()) {
            // Build entity
            Entity entity = new Entity(ENTITY_TYPE_MEDIDAS, measuredAt.getTime() + compuesto.getId());
            entity.setIndexedProperty(PROPERTY_COMPUESTO, compuesto.name());
            entity.setIndexedProperty(PROPERTY_AVISO, medicion.getAviso());
            entity.setIndexedProperty(PROPERTY_AVISO_STATE, medicion.getAvisoState());
            entity.setIndexedProperty(PREPERTY_AVISO_MAX_TODAY, medicion.getAvisoMaxToday());
            entity.setIndexedProperty(PROPERTY_ESCENARIO_STATE_TODAY, medicion.getEscenarioStateToday());
            entity.setIndexedProperty(PROPERTY_ESCENARIO_STATE_TOMORROW, medicion.getEscenarioStateTomorrow());
            entity.setIndexedProperty(PROPERTY_ESCENARIO_STATE_TOMORROW_MANUAL, medicion.getEscenarioManualTomorrow());
            entity.setIndexedProperty(PROPERTY_SAVED_AT, savedDate);
            entity.setIndexedProperty(PROPERTY_MEASURE_DATE, measuredAt);
            entity.setIndexedProperty(PROPERTY_MEASURE_TIME, stringHour(measuredAtCalendar.get(Calendar.HOUR_OF_DAY)));
            // Build stations
            Map<String, Object> valueMap = medicion.getCompuestoValues(compuesto);
            if (valueMap != null) {
                for (Map.Entry<String, Object> entry : valueMap.entrySet()) {
                    entity.setUnindexedProperty(entry.getKey(), entry.getValue());
                }
            }
            // Store
            batch.add(entity);
        }
    }
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    datastore.put(batch);

}
 
開發者ID:medialab-prado,項目名稱:puremadrid,代碼行數:50,代碼來源:GetNewData.java


注:本文中的com.google.appengine.api.datastore.DatastoreService.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。