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


Java KeyFactory.createKey方法代码示例

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


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

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

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

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

示例4: getStation

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

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

示例6: deleteAdministrator

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

示例7: updateAdministratorPassword

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

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

示例9: getValue

import com.google.appengine.api.datastore.KeyFactory; //导入方法依赖的package包/类
public static String getValue(String key) {
	String cacheKey = ConfigurationCache.getInstance().getValue(key); 
	if (cacheKey!= null) return cacheKey;
	Key keyDB = KeyFactory.createKey(ConfigurationJDO.class.getSimpleName(), key);
	PersistenceManager pm = PMF.get().getPersistenceManager();
	try {
		ConfigurationJDO confJDO = pm.getObjectById(ConfigurationJDO.class, keyDB);
		ConfigurationCache.getInstance().storeKeyValue(key, confJDO.getValue());
		return confJDO.getValue();
	} catch (Exception e) {
		ConfigurationJDO jdo = new ConfigurationJDO();
		jdo.setKey(key);
		jdo.setValue("");
		pm.makePersistent(jdo);
		return null;
	} finally {
		pm.close();
	}
}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:20,代码来源:ConfigurationManager.java

示例10: creatingAnEntityInASpecificEntityGroup

import com.google.appengine.api.datastore.KeyFactory; //导入方法依赖的package包/类
@Test
public void creatingAnEntityInASpecificEntityGroup() throws Exception {
  String boardName = "my-message-board";

  //CHECKSTYLE.OFF: VariableDeclarationUsageDistance - Increased clarity in sample
  // [START creating_an_entity_in_a_specific_entity_group]
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

  String messageTitle = "Some Title";
  String messageText = "Some message.";
  Date postDate = new Date();

  Transaction txn = datastore.beginTransaction();

  Key messageBoardKey = KeyFactory.createKey("MessageBoard", boardName);

  Entity message = new Entity("Message", messageBoardKey);
  message.setProperty("message_title", messageTitle);
  message.setProperty("message_text", messageText);
  message.setProperty("post_date", postDate);
  datastore.put(txn, message);

  txn.commit();
  // [END creating_an_entity_in_a_specific_entity_group]
  //CHECKSTYLE.ON: VariableDeclarationUsageDistance
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:27,代码来源:TransactionsTest.java

示例11: shouldTransform

import com.google.appengine.api.datastore.KeyFactory; //导入方法依赖的package包/类
@Test
public void shouldTransform() {
    Key key = KeyFactory.createKey("kind", 4321L);
    Key childKey = KeyFactory.createKey(key, "other-kind", 1234L);
    assertThat(transformer.from(key), is(4321L));
    assertThat(transformer.from(childKey), is(1234L));
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:8,代码来源:DatastoreKeyToLongTransformerTest.java

示例12: shouldTransform

import com.google.appengine.api.datastore.KeyFactory; //导入方法依赖的package包/类
@Test
public void shouldTransform() {
    Key key = KeyFactory.createKey("kind", "dcba");
    Key childKey = KeyFactory.createKey(key, "other-kind", "abcd");
    assertThat(transformer.from(key), is(KeyFactory.keyToString(key)));
    assertThat(transformer.from(childKey), is(KeyFactory.keyToString(childKey)));
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:8,代码来源:DatastoreKeyToStringTransformerTest.java

示例13: shouldTransform

import com.google.appengine.api.datastore.KeyFactory; //导入方法依赖的package包/类
@Test
public void shouldTransform() {
    Key key = KeyFactory.createKey("kind", "dcba");
    Key childKey = KeyFactory.createKey(key, "other-kind", 1234);
    assertThat(transformer.from(KeyFactory.keyToString(key)), is(key));
    assertThat(transformer.from(KeyFactory.keyToString(childKey)), is(childKey));
}
 
开发者ID:monPlan,项目名称:springboot-spwa-gae-demo,代码行数:8,代码来源:StringToDatastoreKeyTransformerTest.java

示例14: getKey

import com.google.appengine.api.datastore.KeyFactory; //导入方法依赖的package包/类
protected Key getKey(ID id) {
    String kind = entityToModelMapper.getKind(entityInformation.getJavaType());
    if (id instanceof Number) {
        return KeyFactory.createKey(kind, Number.class.cast(id).longValue());
    } else if (id instanceof String) {
        return KeyFactory.createKey(kind, (String) id);
    } else {
        throw new IllegalArgumentException("Can only handle Number and String ids in GAE!");
    }
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:11,代码来源:GaeCrudAdapter.java

示例15: getKey

import com.google.appengine.api.datastore.KeyFactory; //导入方法依赖的package包/类
/**
  * Gets the access key.
  */
 protected String getKey() {
     com.google.appengine.api.datastore.DatastoreService datastore = DatastoreServiceFactory
             .getDatastoreService();
     Key key = KeyFactory.createKey(ENTITY_KIND, ENTITY_KEY);
     String apiKey = "";
     try {
         Entity entity = datastore.get(key);
         apiKey = (String) entity.getProperty(ACCESS_KEY_FIELD);
     } catch (EntityNotFoundException e) {
         mLogger.severe("Exception will retrieving the API Key"
                 + e.toString());
     }
     return apiKey;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:18,代码来源:ApiKeyInitializer.java


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