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


Java KeyFactory类代码示例

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


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

示例1: taskInvoked

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的package包/类
public void taskInvoked(final SlobId slobId) {
  try {
    new RetryHelper().run(new RetryHelper.VoidBody() {
      @Override
      public void run() throws RetryableFailure, PermanentFailure {
        CheckedTransaction tx = datastore.beginTransaction();
        tx.put(new Entity(KeyFactory.createKey(
            MutationLog.makeRootEntityKey(rootEntityKind, slobId),
            syncEntityKind, SYNC_ENTITY_NAME)));
        tx.commit();
      }
    });
  } catch (PermanentFailure e) {
    throw new RuntimeException("Failed to touch sync entity, trying again later", e);
  }
  for (PostCommitAction action : getActions()) {
    log.info("Running reliable post-commit action " + action
        + " on " + slobId + " (" + rootEntityKind + ")");
    // TODO(danilatos): Should this be wrapped in a try...catch and just log
    // any exceptions in order to truly reliably run all the post-commit actions?
    action.reliableDelayedPostCommit(slobId);
  }
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:24,代码来源:PostCommitActionScheduler.java

示例2: getHTML

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的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

示例3: get

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的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

示例4: testSuccess_createsCommitLogs

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的package包/类
@Test
public void testSuccess_createsCommitLogs() throws Exception {
  ContactResource contact1 = persistActiveContact("contact1");
  ContactResource contact2 = persistActiveContact("contact2");
  deleteEntitiesOfTypes(CommitLogManifest.class, CommitLogMutation.class);
  assertThat(ofy().load().type(CommitLogManifest.class).keys()).isEmpty();
  assertThat(ofy().load().type(CommitLogMutation.class).keys()).isEmpty();
  runCommandForced(
      KeyFactory.keyToString(Key.create(contact1).getRaw()),
      KeyFactory.keyToString(Key.create(contact2).getRaw()));

  assertThat(ofy().load().type(CommitLogManifest.class).keys()).hasSize(1);
  Iterable<ImmutableObject> savedEntities =
      transform(
          ofy().load().type(CommitLogMutation.class).list(),
          mutation -> ofy().load().fromEntity(mutation.getEntity()));
  // Reload the contacts before asserting, since their update times will have changed.
  ofy().clearSessionCache();
  assertThat(savedEntities)
      .containsExactlyElementsIn(ofy().load().entities(contact1, contact2).values());
}
 
开发者ID:google,项目名称:nomulus,代码行数:22,代码来源:ResaveEntitiesCommandTest.java

示例5: doPost

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的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

示例6: deleteSessionVariables

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的package包/类
/**
 * Delete a value stored in the project's datastore.
 * @param sessionId Request from which the session is extracted.
 */
protected void deleteSessionVariables(String sessionId, String... varNames) {
  if (sessionId.equals("")) {
    return;
  }
  Key key = KeyFactory.createKey(SESSION_KIND, sessionId);
  Transaction transaction = datastore.beginTransaction();
  try {
    Entity stateEntity = datastore.get(transaction, key);
    for (String varName : varNames) {
      stateEntity.removeProperty(varName);
    }
    datastore.put(transaction, stateEntity);
    transaction.commit();
  } catch (EntityNotFoundException e) {
    // Ignore - if there's no session, there's nothing to delete.
  } finally {
    if (transaction.isActive()) {
      transaction.rollback();
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:26,代码来源:DatastoreSessionFilter.java

示例7: deleteUserGroup

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的package包/类
/**
 * Delete a User Group from a mobile device
 * @param req:
 * 			the HTTP request
 * @param customer:
 * 			the customer who is executing the action
 * @throws Exception
 * @throws IOException 
 * @throws UnauthorizedUserOperationException
 */
public void deleteUserGroup(HttpServletRequest req, 
		Customer customer) 
				throws Exception, IOException,
				UnauthorizedUserOperationException {
	
	String userGroupKeyString = req.getParameter("g_key");
	Key userGroupKey = KeyFactory.stringToKey(userGroupKeyString);
    
	// Check that the group belongs to the user
    if (!userGroupKey.getParent().equals(customer.getKey())) {
        throw new UnauthorizedUserOperationException(customer.getUser(), 
        		"This group does not belong to the given user.");
    }
	
	UserGroupManager.deleteUserGroup(userGroupKey);
}
 
开发者ID:gfigueroa,项目名称:internet-radio-gae,代码行数:27,代码来源:CloudSyncServlet.java

示例8: toJson

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的package包/类
/**
* Returns the customer profile information as a JSON object.
* @return the customer profile in JSON format
*/
  @Get("json")
  public CustomerSimple toJson() {
  	
  	String queryInfo = (String) getRequest().getAttributes()
              .get("queryinfo");
          
      char searchBy = queryInfo.charAt(0);
      String searchEmailString = queryInfo.substring(2);
      Email searchEmail = new Email(searchEmailString);
      
      log.info("Query: " + searchBy + "=" + searchEmailString);
  	
      Customer customer = CustomerManager.getCustomer(searchEmail);
      CustomerSimple customerSimple = new CustomerSimple(KeyFactory.keyToString(customer.getKey()),
      		customer.getCustomerName(), customer.getCustomerPhone(), customer.getCustomerGenderString(),
      		customer.getCustomerAddress());
      
      return customerSimple;
  }
 
开发者ID:gfigueroa,项目名称:internet-radio-gae,代码行数:24,代码来源:CustomerProfileResource.java

示例9: getAccountKeyByAuthKey

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的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

示例10: getCustomer

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的package包/类
/**
    * Get a Customer instance from the datastore given the user's email.
    * The method uses this email to obtain the Customer key.
    * @param email
    * 			: the customer's email address
    * @return customer instance, null if customer is not found
    */
public static Customer getCustomer(Email email) {		
	PersistenceManager pm = PMF.get().getPersistenceManager();
	Key key = KeyFactory.createKey(Customer.class.getSimpleName(), 
                                      email.getEmail());
	
	Customer customer;
	try  {
		customer = pm.getObjectById(Customer.class, key);
	}
	catch (JDOObjectNotFoundException e) {
		return null;
	}
	pm.close();
	return customer;
}
 
开发者ID:gfigueroa,项目名称:internet-radio-gae,代码行数:23,代码来源:CustomerManager.java

示例11: getXmlAsString

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的package包/类
public static String getXmlAsString(OaiParameters op) {
	String returnString = getOaiFirstPart(op);
	returnString += "	<GetRecord>";
	PersistenceManager pm = PMF.get().getPersistenceManager();
	try {
		if (op.getIdentifier() != null) {
               LomJDO l = pm.getObjectById(LomJDO.class, KeyFactory.createKey(LomJDO.class.getSimpleName(), Long.parseLong(op.getIdentifier())));
	
			returnString += getHeader(l);
			if (!l.isDeleted()) {
			returnString += "<metadata>";
			returnString += l.getLom();
			returnString += "</metadata>";
			}
		}

	} finally {
		pm.close();

	}
	returnString += "	</GetRecord>";
	return returnString + getOaiLastPart();
}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:24,代码来源:GetRecord.java

示例12: deleteCustomer

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的package包/类
/**
   * Delete Customer from datastore.
   * Deletes the customer corresponding to the given email 
   * from the datastore calling the PersistenceManager's deletePersistent() method.
   * @param email
   * 			: the email of the customer instance to delete
   */
public static void deleteCustomer(Email email) {	
	
	PersistenceManager pm = PMF.get().getPersistenceManager();
	
	Transaction tx = pm.currentTransaction();
	try {
		Key key = KeyFactory.createKey(Customer.class.getSimpleName(), email.getEmail());
		Customer customer = pm.getObjectById(Customer.class, key);
		tx.begin();
		pm.deletePersistent(customer);
		tx.commit();
		log.info("Customer \"" + email.getEmail() + "\" deleted successfully from datastore.");
	}
	finally {
		if (tx.isActive()) {
			tx.rollback();
		}
		pm.close();
	}
}
 
开发者ID:gfigueroa,项目名称:internet-radio-gae,代码行数:28,代码来源:CustomerManager.java

示例13: updateCustomerPassword

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的package包/类
/**
   * Update Customer password in datastore.
   * Update's the customer's password in the datastore.
   * @param email
   * 			: the email of the customer whose password will be changed
   * @param newPassword
   * 			: the new password for this customer
* @throws MissingRequiredFieldsException 
   */
public static void updateCustomerPassword(Email email, String newPassword) 
		throws MissingRequiredFieldsException {	
	
	PersistenceManager pm = PMF.get().getPersistenceManager();
	
	Transaction tx = pm.currentTransaction();
	try {
		Key key = KeyFactory.createKey(Customer.class.getSimpleName(), email.getEmail());
		Customer customer = pm.getObjectById(Customer.class, key);
		tx.begin();
		customer.getUser().setUserPassword(newPassword);
		tx.commit();
		log.info("Customer \"" + email.getEmail() + "\"'s password updated in datastore.");
	}
	finally {
		if (tx.isActive()) {
			tx.rollback();
		}
		pm.close();
	}
}
 
开发者ID:gfigueroa,项目名称:internet-radio-gae,代码行数:31,代码来源:CustomerManager.java

示例14: getAdministrator

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的package包/类
/**
    * Get a Administrator instance from the datastore given the user's email.
    * The method uses this email to obtain the Administrator key.
    * @param email
    * 			: the administrator's email address
    * @return administrator instance, null if administrator is not found
    */
public static Administrator getAdministrator(Email email) {		
	PersistenceManager pm = PMF.get().getPersistenceManager();
	Key key = KeyFactory.createKey(Administrator.class.getSimpleName(), 
                                      email.getEmail());
	
	Administrator administrator;
	try  {
		administrator = pm.getObjectById(Administrator.class, key);
	}
	catch (JDOObjectNotFoundException e) {
		return null;
	}
	pm.close();
	return administrator;
}
 
开发者ID:gfigueroa,项目名称:internet-radio-gae,代码行数:23,代码来源:AdministratorManager.java

示例15: keyToString_getsPerson

import com.google.appengine.api.datastore.KeyFactory; //导入依赖的package包/类
@Test
public void keyToString_getsPerson() throws Exception {
  Entity p = new Entity("Person");
  p.setProperty("relationship", "Me");
  datastore.put(p);
  Key k = p.getKey();

  // [START generating_keys_3]
  String personKeyStr = KeyFactory.keyToString(k);

  // Some time later (for example, after using personKeyStr in a link).
  Key personKey = KeyFactory.stringToKey(personKeyStr);
  Entity person = datastore.get(personKey);
  // [END generating_keys_3]

  assertThat(personKey).isEqualTo(k);
  assertThat((String) person.getProperty("relationship"))
      .named("person.relationship")
      .isEqualTo("Me");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:21,代码来源:EntitiesTest.java


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