本文整理汇总了Java中com.google.appengine.api.datastore.EntityNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java EntityNotFoundException类的具体用法?Java EntityNotFoundException怎么用?Java EntityNotFoundException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityNotFoundException类属于com.google.appengine.api.datastore包,在下文中一共展示了EntityNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHTML
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的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.EntityNotFoundException; //导入依赖的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.EntityNotFoundException; //导入依赖的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: contextInitialized
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent event) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key key = KeyFactory.createKey(ENTITY_KIND, ENTITY_KEY);
Entity entity;
try {
entity = datastore.get(key);
} catch(EntityNotFoundException e) {
entity = new Entity(key);
// NOTE: it's not possible to change entities in the local server, so
// it will be necessary to hardcode the API key below if you are running
// it locally.
entity.setProperty(ACCESS_KEY_FIELD,
API_KEY);
datastore.put(entity);
mLogger.severe("Created fake key. Please go to App Engine admin "
+ "console, change its value to your API Key (the entity "
+ "type is '" + ENTITY_KIND + "' and its field to be changed is '"
+ ACCESS_KEY_FIELD + "'), then restart the server!");
}
String accessKey = (String) entity.getProperty(ACCESS_KEY_FIELD);
event.getServletContext().setAttribute(ATTRIBUTE_ACCESS_KEY, accessKey);
}
示例5: fetchOrCreate
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的package包/类
private Entity fetchOrCreate(String boardName) {
// [START uses_for_transactions_2]
Transaction txn = datastore.beginTransaction();
Entity messageBoard;
Key boardKey;
try {
boardKey = KeyFactory.createKey("MessageBoard", boardName);
messageBoard = datastore.get(boardKey);
} catch (EntityNotFoundException e) {
messageBoard = new Entity("MessageBoard", boardName);
messageBoard.setProperty("count", 0L);
boardKey = datastore.put(txn, messageBoard);
}
txn.commit();
// [END uses_for_transactions_2]
return messageBoard;
}
示例6: deletingAnEntity_deletesAnEntity
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的package包/类
@Test
public void deletingAnEntity_deletesAnEntity() throws Exception {
Entity employee = new Entity("Employee", "asalieri");
datastore.put(employee);
Key employeeKey = KeyFactory.createKey("Employee", "asalieri");
// [START deleting_an_entity]
// Key employeeKey = ...;
datastore.delete(employeeKey);
// [END deleting_an_entity]
try {
Entity got = datastore.get(employeeKey);
fail("Expected EntityNotFoundException");
} catch (EntityNotFoundException expected) {
assertThat(expected.getKey().getName()).named("exception key name").isEqualTo("asalieri");
}
}
示例7: testCreateServingUrl
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的package包/类
@Test
public void testCreateServingUrl() throws Exception {
when(mockDatastoreService.get(any(Key.class)))
.thenThrow(new EntityNotFoundException(null));
assertEquals(SERVING_URL,
ServingUrlManager.INSTANCE.createServingUrl(GCS_FILENAME, Optional.<String>absent()));
verify(mockImagesService).getServingUrl(eq(ServingUrlOptions.Builder
.withGoogleStorageFileName(GCS_FULLPATH).secureUrl(true)));
ArgumentCaptor<Entity> entityCaptor = ArgumentCaptor.forClass(Entity.class);
verify(mockDatastoreService).put(entityCaptor.capture());
Entity entity = entityCaptor.getValue();
assertEquals(ServingUrlManager.ENTITY_KIND, entity.getKey().getKind());
assertEquals(GCS_FULLPATH, entity.getKey().getName());
assertEquals("", entity.getProperty(ServingUrlManager.SOURCE_URL_PROPERTY));
assertEquals(SERVING_URL, entity.getProperty(ServingUrlManager.SERVING_URL_PROPERTY));
}
示例8: testCreateServingUrl_withSourceUrl
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的package包/类
@Test
public void testCreateServingUrl_withSourceUrl() throws Exception {
when(mockDatastoreService.get(any(Key.class)))
.thenThrow(new EntityNotFoundException(null));
assertEquals(SERVING_URL,
ServingUrlManager.INSTANCE.createServingUrl(GCS_FILENAME, Optional.of(SOURCE_URL)));
verify(mockImagesService).getServingUrl(eq(ServingUrlOptions.Builder
.withGoogleStorageFileName(GCS_FULLPATH).secureUrl(true)));
ArgumentCaptor<Entity> entityCaptor = ArgumentCaptor.forClass(Entity.class);
verify(mockDatastoreService).put(entityCaptor.capture());
Entity entity = entityCaptor.getValue();
assertEquals(ServingUrlManager.ENTITY_KIND, entity.getKey().getKind());
assertEquals(GCS_FULLPATH, entity.getKey().getName());
assertEquals(SOURCE_URL, entity.getProperty(ServingUrlManager.SOURCE_URL_PROPERTY));
assertEquals(SERVING_URL, entity.getProperty(ServingUrlManager.SERVING_URL_PROPERTY));
}
示例9: execute
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的package包/类
@Override
ExecutionResult execute(DatastoreConnection conn) {
DatastoreService ds = conn.getDatastoreService();
Entity e;
try {
e = ds.get(key);
} catch (EntityNotFoundException e1) {
return new ExecutionResult(1, "No entity with the specified Key could be found.");
}
if (obj != null) {
for (String k : obj.keySet()) {
e.setProperty(k, obj.get(k));
}
ds.put(e);
return new ExecutionResult(0, "entity saved successfully at " + new JsonFormat().format(key));
} else if (arr!=null){
throw new UnsupportedOperationException();
}
throw new NullPointerException();
}
示例10: getEntity
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的package包/类
private Entity getEntity(String logString, final Key key) throws NoSuchObjectException {
try {
return tryFiveTimes(new Operation<Entity>(logString) {
@Override
public Entity call() throws EntityNotFoundException {
return dataStore.get(null, key);
}
});
} catch (NonRetriableException|RetriesExhaustedException e) {
Throwable cause = e.getCause();
if (cause instanceof EntityNotFoundException) {
throw new NoSuchObjectException(key.toString(), cause);
} else {
throw e;
}
}
}
示例11: doGet
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/plain");
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Entity e = new Entity("foo");
e.setProperty("foo", 23);
Key key = ds.put(e);
try {
e = ds.get(key);
} catch (EntityNotFoundException e1) {
throw new ServletException(e1);
}
e.setProperty("bar", 44);
ds.put(e);
Query q = new Query("foo");
q.addFilter("foo", Query.FilterOperator.GREATER_THAN_OR_EQUAL, 22);
Iterator<Entity> iter = ds.prepare(q).asIterator();
iter.next();
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:25,代码来源:LocalDatastoreSmoketestServlet.java
示例12: testNewSession
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testNewSession() throws EntityNotFoundException {
assertTrue(manager.getSessionIdManager() instanceof SessionManager.SessionIdManager);
manager.setMaxInactiveInterval(SESSION_EXPIRATION_SECONDS);
HttpServletRequest request = makeMockRequest(true);
replay(request);
AppEngineSession session = manager.newSession(request);
assertNotNull(session);
assertTrue(session instanceof SessionManager.AppEngineSession);
assertEquals(SessionManager.lastId(), session.getId());
session.setAttribute("foo", "bar");
session.save();
}
示例13: testSessionNotAvailableInMemcache
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的package包/类
public void testSessionNotAvailableInMemcache() throws EntityNotFoundException {
HttpServletRequest request = makeMockRequest(true);
replay(request);
AppEngineSession session = manager.newSession(request);
session.setAttribute("foo", "bar");
session.save();
memcache.clearAll();
manager =
new SessionManager(Arrays.asList(new DatastoreSessionStore(), new MemcacheSessionStore()));
HttpSession session2 = manager.getSession(session.getId());
assertEquals(session.getId(), session2.getId());
assertEquals("bar", session2.getAttribute("foo"));
manager =
new SessionManager(Collections.<SessionStore>singletonList(new MemcacheSessionStore()));
assertNull(manager.getSession(session.getId()));
}
示例14: testDatastoreTimeouts
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testDatastoreTimeouts() throws EntityNotFoundException {
Delegate original = ApiProxy.getDelegate();
// Throw in a couple of datastore timeouts
TimeoutGeneratingDelegate newDelegate = new TimeoutGeneratingDelegate(original);
try {
ApiProxy.setDelegate(newDelegate);
HttpServletRequest request = makeMockRequest(true);
replay(request);
AppEngineSession session = manager.newSession(request);
session.setAttribute("foo", "bar");
newDelegate.setTimeouts(3);
session.save();
assertEquals(newDelegate.getTimeoutsRemaining(), 0);
memcache.clearAll();
manager =
new SessionManager(Collections.<SessionStore>singletonList(new DatastoreSessionStore()));
HttpSession session2 = manager.getSession(session.getId());
assertEquals(session.getId(), session2.getId());
assertEquals("bar", session2.getAttribute("foo"));
} finally {
ApiProxy.setDelegate(original);
}
}
示例15: get
import com.google.appengine.api.datastore.EntityNotFoundException; //导入依赖的package包/类
/**
* Returns an entity with device subscription information from memcache or datastore based on the
* provided deviceId.
*
* @param deviceId A unique device identifier
* @return an entity with device subscription information; or null when no corresponding
* information found
*/
public Entity get(String deviceId) {
if (StringUtility.isNullOrEmpty(deviceId)) {
throw new IllegalArgumentException("DeviceId cannot be null or empty");
}
Key key = getKey(deviceId);
Entity entity = (Entity) this.memcacheService.get(key);
// Get from datastore if unable to get data from cache
if (entity == null) {
try {
entity = this.datastoreService.get(key);
} catch (EntityNotFoundException e) {
return null;
}
}
return entity;
}