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