當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。