本文整理汇总了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.");
}
}
示例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.");
}
}
示例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();
}
}
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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
}
示例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));
}
示例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)));
}
示例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));
}
示例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!");
}
}
示例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;
}