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


Java DatastoreServiceFactory類代碼示例

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


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

示例1: doGet_repeatedPropertyEntities_writesWidgets

import com.google.appengine.api.datastore.DatastoreServiceFactory; //導入依賴的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.DatastoreServiceFactory; //導入依賴的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.DatastoreServiceFactory; //導入依賴的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.DatastoreServiceFactory; //導入依賴的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.DatastoreServiceFactory; //導入依賴的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.DatastoreServiceFactory; //導入依賴的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.DatastoreServiceFactory; //導入依賴的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.DatastoreServiceFactory; //導入依賴的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: testJobIdAndNumJobs_fails

import com.google.appengine.api.datastore.DatastoreServiceFactory; //導入依賴的package包/類
@Test
public void testJobIdAndNumJobs_fails() throws Exception {
  action = new MapreduceEntityCleanupAction(
      Optional.of("jobid"),
      Optional.empty(), // jobName
      Optional.of(1), // numJobsToDelete
      Optional.empty(), // daysOld
      Optional.empty(), // force
      mapreduceEntityCleanupUtil,
      clock,
      DatastoreServiceFactory.getDatastoreService(),
      response);

  action.run();

  assertThat(response.getStatus()).isEqualTo(SC_BAD_REQUEST);
  assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8);
  assertThat(response.getPayload())
      .isEqualTo("Do not specify both a job ID and a number of jobs to delete");
  assertNumMapreducesAndShardedJobs(0, 0);
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:22,代碼來源:MapreduceEntityCleanupActionTest.java

示例10: testDeleteZeroJobs_throwsUsageError

import com.google.appengine.api.datastore.DatastoreServiceFactory; //導入依賴的package包/類
@Test
public void testDeleteZeroJobs_throwsUsageError() throws Exception {
  new MapreduceEntityCleanupAction(
          Optional.empty(), // jobId
          Optional.empty(), // jobName
          Optional.of(0), // numJobsToDelete
          Optional.empty(), // daysOld
          Optional.empty(), // force
          mapreduceEntityCleanupUtil,
          clock,
          DatastoreServiceFactory.getDatastoreService(),
          response)
      .run();
  assertThat(response.getStatus()).isEqualTo(SC_BAD_REQUEST);
  assertThat(response.getPayload())
      .isEqualTo("Do not specify a non-positive integer for the number of jobs to delete");
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:18,代碼來源:MapreduceEntityCleanupActionTest.java

示例11: doPost

import com.google.appengine.api.datastore.DatastoreServiceFactory; //導入依賴的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

示例12: doGet

import com.google.appengine.api.datastore.DatastoreServiceFactory; //導入依賴的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

示例13: doPost

import com.google.appengine.api.datastore.DatastoreServiceFactory; //導入依賴的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);
  greeting.setProperty("user", user);
  greeting.setProperty("date", date);
  greeting.setProperty("content", content);

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

  resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName);
}
 
開發者ID:raghu-sannlingappa,項目名稱:push-to-delploy,代碼行數:21,代碼來源:SignGuestbookServlet.java

示例14: contextInitialized

import com.google.appengine.api.datastore.DatastoreServiceFactory; //導入依賴的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:gdg-bh,項目名稱:AppDevFestSudeste2015,代碼行數:25,代碼來源:ApiKeyInitializer.java

示例15: getAccountKeyByAuthKey

import com.google.appengine.api.datastore.DatastoreServiceFactory; //導入依賴的package包/類
/**
 * Returns the Account key associated with the specified authorization key.
 * @param pm               reference to the persistence manager
 * @param authorizationKey authorization key to return the account key for
 * @return the Account key associated with the specified authorization key; or <code>null</code> if the authorization key is invalid
 */
public static Key getAccountKeyByAuthKey( final PersistenceManager pm, final String authorizationKey ) {
	final String memcacheKey = CACHE_KEY_AUTH_KEY_ACCOUNT_KEY_PREFIX + authorizationKey;
	final String accountKeyString = (String) memcacheService.get( memcacheKey );
	if ( accountKeyString != null )
		return KeyFactory.stringToKey( accountKeyString );
	
	final Query q = new Query( Account.class.getSimpleName() );
	q.setFilter( new FilterPredicate( "authorizationKey", FilterOperator.EQUAL, authorizationKey ) );
	q.setKeysOnly();
	final List< Entity > entityList = DatastoreServiceFactory.getDatastoreService().prepare( q ).asList( FetchOptions.Builder.withDefaults() );
	if ( entityList.isEmpty() )
		return null;
	
	final Key accountKey = entityList.get( 0 ).getKey();
	try {
		memcacheService.put( memcacheKey, KeyFactory.keyToString( accountKey ) );
	}
	catch ( final MemcacheServiceException mse ) {
		LOGGER.log( Level.WARNING, "Failed to put key to memcache: " + memcacheKey, mse );
		// Ignore memcache errors, do not prevent serving user request
	}
	
	return accountKey;
}
 
開發者ID:icza,項目名稱:sc2gears,代碼行數:31,代碼來源:CachingService.java


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