当前位置: 首页>>代码示例>>Java>>正文


Java DatastoreService类代码示例

本文整理汇总了Java中com.google.appengine.api.datastore.DatastoreService的典型用法代码示例。如果您正苦于以下问题:Java DatastoreService类的具体用法?Java DatastoreService怎么用?Java DatastoreService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DatastoreService类属于com.google.appengine.api.datastore包,在下文中一共展示了DatastoreService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGet_repeatedPropertyEntities_writesWidgets

import com.google.appengine.api.datastore.DatastoreService; //导入依赖的package包/类
@SuppressWarnings("VariableDeclarationUsageDistance")
@Test
public void doGet_repeatedPropertyEntities_writesWidgets() throws Exception {
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
  // [START exploding_index_example_3]
  Entity widget = new Entity("Widget");
  widget.setProperty("x", Arrays.asList(1, 2, 3, 4));
  widget.setProperty("y", Arrays.asList("red", "green", "blue"));
  widget.setProperty("date", new Date());
  datastore.put(widget);
  // [END exploding_index_example_3]

  servletUnderTest.doGet(mockRequest, mockResponse);

  assertThat(responseWriter.toString())
      .named("IndexesServlet response")
      .isEqualTo("Got 1 widgets.\n");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:19,代码来源:IndexesServletTest.java

示例2: 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

示例3: doGet

import com.google.appengine.api.datastore.DatastoreService; //导入依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws IOException {
	resp.setContentType("text/html");
	resp.getWriter().println("<html><body>");

	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	Query query = new Query("SharedList");
	query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
	List<Entity> results = datastore.prepare(query).asList(
			FetchOptions.Builder.withDefaults());
	for (Entity entity : results) {
		String email = (String) entity.getProperty("email");
		String productID = (String) entity.getKey().getName();
		String productName = (String) entity.getProperty("productName");
		Date sharedDate = (Date) entity.getProperty("sharedDate");

		resp.getWriter().println(
				email + " shared <a href=\"http://www.amazon.com/dp/"
						+ productID + "\" target=\"_blank\">" + "<b>"
						+ productName + "</b></a>!<br>");
	}

	resp.getWriter().println("</body></html>");
}
 
开发者ID:fasthall,项目名称:amazon-price-tracker,代码行数:26,代码来源:SharedlistServlet.java

示例4: getEntitiesBrowser

import com.google.appengine.api.datastore.DatastoreService; //导入依赖的package包/类
@GET
@Produces(MediaType.TEXT_XML)
public List<SharedProduct> getEntitiesBrowser() {
	List<SharedProduct> list = new ArrayList<SharedProduct>();
	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	Query query = new Query("SharedList");
	query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
	List<Entity> results = datastore.prepare(query).asList(
			FetchOptions.Builder.withDefaults());
	for (Entity entity : results) {
		String email = (String) entity.getProperty("email");
		String productID = (String) entity.getKey().getName();
		String productName = (String) entity.getProperty("productName");
		Date sharedDate = (Date) entity.getProperty("sharedDate");

		list.add(new SharedProduct(email, productID, productName,
				sharedDate));
	}

	return list;
}
 
开发者ID:fasthall,项目名称:amazon-price-tracker,代码行数:23,代码来源:Sharedlist.java

示例5: getEntities

import com.google.appengine.api.datastore.DatastoreService; //导入依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<SharedProduct> getEntities() {
	List<SharedProduct> list = new ArrayList<SharedProduct>();
	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	Query query = new Query("SharedList");
	query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
	List<Entity> results = datastore.prepare(query).asList(
			FetchOptions.Builder.withDefaults());
	for (Entity entity : results) {
		String email = (String) entity.getProperty("email");
		String productID = (String) entity.getKey().getName();
		String productName = (String) entity.getProperty("productName");
		Date sharedDate = (Date) entity.getProperty("sharedDate");

		list.add(new SharedProduct(email, productID, productName,
				sharedDate));
	}

	return list;
}
 
开发者ID:fasthall,项目名称:amazon-price-tracker,代码行数:23,代码来源:Sharedlist.java

示例6: 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

示例7: getHTML

import com.google.appengine.api.datastore.DatastoreService; //导入依赖的package包/类
@GET
@Produces(MediaType.TEXT_XML)
public WishlistProduct getHTML() {
	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	try {
		Key entKey = KeyFactory.createKey(email, productID);
		Entity entity = datastore.get(entKey);
		String productName = (String) entity.getProperty("productName");
		double currentPrice = (double) entity.getProperty("currentPrice");
		double lowestPrice = (double) entity.getProperty("lowestPrice");
		Date lowestDate = (Date) entity.getProperty("lowestDate");
		return new WishlistProduct(productID, productName, currentPrice,
				lowestPrice, lowestDate);
	} catch (EntityNotFoundException e) {
		throw new RuntimeException("GET: Wishlist with " + productID
				+ " not found.");
	}
}
 
开发者ID:fasthall,项目名称:amazon-price-tracker,代码行数:20,代码来源:WishlistProductResource.java

示例8: get

import com.google.appengine.api.datastore.DatastoreService; //导入依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public WishlistProduct get() {
	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	try {
		Key entKey = KeyFactory.createKey(email, productID);
		Entity entity = datastore.get(entKey);
		String productName = (String) entity.getProperty("productName");
		double currentPrice = (double) entity.getProperty("currentPrice");
		double lowestPrice = (double) entity.getProperty("lowestPrice");
		Date lowestDate = (Date) entity.getProperty("lowestDate");
		return new WishlistProduct(productID, productName, currentPrice,
				lowestPrice, lowestDate);
	} catch (EntityNotFoundException e) {
		throw new RuntimeException("GET: Wishlist with " + productID
				+ " not found.");
	}
}
 
开发者ID:fasthall,项目名称:amazon-price-tracker,代码行数:20,代码来源:WishlistProductResource.java

示例9: MapreduceEntityCleanupAction

import com.google.appengine.api.datastore.DatastoreService; //导入依赖的package包/类
@Inject
MapreduceEntityCleanupAction(
    @Parameter("jobId") Optional<String> jobId,
    @Parameter("jobName") Optional<String> jobName,
    @Parameter("numJobsToDelete") Optional<Integer> numJobsToDelete,
    @Parameter("daysOld") Optional<Integer> daysOld,
    @Parameter("force") Optional<Boolean> force,
    MapreduceEntityCleanupUtil mapreduceEntityCleanupUtil,
    Clock clock,
    DatastoreService datastore,
    Response response) {
  this.jobId = jobId;
  this.jobName = jobName;
  this.numJobsToDelete = numJobsToDelete;
  this.daysOld = daysOld;
  this.force = force;
  this.mapreduceEntityCleanupUtil = mapreduceEntityCleanupUtil;
  this.clock = clock;
  this.datastore = datastore;
  this.response = response;
}
 
开发者ID:google,项目名称:nomulus,代码行数:22,代码来源:MapreduceEntityCleanupAction.java

示例10: doPost

import com.google.appengine.api.datastore.DatastoreService; //导入依赖的package包/类
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
  UserService userService = UserServiceFactory.getUserService();
  User user = userService.getCurrentUser();

  String guestbookName = req.getParameter("guestbookName");
  Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);
  String content = req.getParameter("content");
  Date date = new Date();
  Entity greeting = new Entity("Greeting", guestbookKey);
  if (user != null) {
    greeting.setProperty("author_id", user.getUserId());
    greeting.setProperty("author_email", user.getEmail());
  }
  greeting.setProperty("date", date);
  greeting.setProperty("content", content);

  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
  datastore.put(greeting);

  resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName);
}
 
开发者ID:luisibanez,项目名称:running-with-zebras-101,代码行数:24,代码来源:SignGuestbookServlet.java

示例11: map

import com.google.appengine.api.datastore.DatastoreService; //导入依赖的package包/类
@Override
        public void map(Entity entity) {
            System.out.println(entity);
            Long lastModificationDate = (Long) entity.getProperty("lastModificationDate");
            if (lastModificationDate == null) {
                final DatastoreService dss = DatastoreServiceFactory.getDatastoreService();
                entity.setProperty("lastModificationDate", System.currentTimeMillis());
                dss.put(entity);
            }
//            incrementCounter("total entities", 1);
//            incrementCounter("map calls in shard " + getContext().getShardNumber(), 1);
//
//            String name = entity.getKey().getName();
//            if (name != null) {
//                incrementCounter("total entity key size", name.length());
//                emitCharacterCounts(name);
//            }
//
//            Text property = (Text) entity.getProperty("payload");
//            if (property != null) {
//                incrementCounter("total entity payload size", property.getValue().length());
//                emitCharacterCounts(property.getValue());
//            }
        }
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:25,代码来源:Messages.java

示例12: 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

示例13: 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

示例14: doGet

import com.google.appengine.api.datastore.DatastoreService; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    Error error = Error.NONE;

    String jsonEnd = HtmlVariable.AVAILABLE.getName();
    String userId = req.getParameter(HtmlVariable.USER_ID.getName());
    if(userId == null || userId.length() == 0) {
        error = Error.REQUIRED_USER_ID;
        jsonEnd = jsonEnd + "\": false }";
    }
    else {
        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        User user = UserFactory.getByUserId(datastore, null, userId);
        jsonEnd = (user != null) ? jsonEnd + "\": false }" : jsonEnd + "\": true }";
    }

    String jsonStart = "{ \"" + HtmlVariable.ERROR.getName() + "\": " + error.toString() + ", \"";
    resp.setContentType("application/json; charset=UTF-8");
    resp.getWriter().print(jsonStart + jsonEnd);
}
 
开发者ID:kerafill1116,项目名称:apollo-datastore,代码行数:23,代码来源:CheckUserIdAvailabilityServlet.java

示例15: propertiesOfKind

import com.google.appengine.api.datastore.DatastoreService; //导入依赖的package包/类
List<String> propertiesOfKind(DatastoreService ds, String kind) {

    // Start with unrestricted keys-only property query
    Query q = new Query(Entities.PROPERTY_METADATA_KIND).setKeysOnly();

    // Limit to specified kind
    q.setAncestor(Entities.createKindKey(kind));

    // Initialize result list
    ArrayList<String> results = new ArrayList<String>();

    //Build list of query results
    for (Entity e : ds.prepare(q).asIterable()) {
      results.add(e.getKey().getName());
    }

    // Return result list
    return results;
  }
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:20,代码来源:MetadataPropertiesTest.java


注:本文中的com.google.appengine.api.datastore.DatastoreService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。