當前位置: 首頁>>代碼示例>>Java>>正文


Java EntityNotFoundException類代碼示例

本文整理匯總了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.");
	}
}
 
開發者ID:fasthall,項目名稱:amazon-price-tracker,代碼行數:20,代碼來源:WishlistProductResource.java

示例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.");
	}
}
 
開發者ID:fasthall,項目名稱:amazon-price-tracker,代碼行數:20,代碼來源:WishlistProductResource.java

示例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();
    }
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:getting-started-java,代碼行數:26,代碼來源:DatastoreSessionFilter.java

示例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);
}
 
開發者ID:The-WebOps-Club,項目名稱:saarang-iosched,代碼行數:25,代碼來源:ApiKeyInitializer.java

示例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;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:19,代碼來源:TransactionsTest.java

示例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");
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:19,代碼來源:EntitiesTest.java

示例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));
}
 
開發者ID:google,項目名稱:iosched,代碼行數:21,代碼來源:ServingUrlManagerTest.java

示例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));
}
 
開發者ID:google,項目名稱:iosched,代碼行數:21,代碼來源:ServingUrlManagerTest.java

示例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();
}
 
開發者ID:inpun,項目名稱:gaecl,代碼行數:21,代碼來源:SetCommand.java

示例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;
    }
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-pipelines,代碼行數:18,代碼來源:AppEngineBackEnd.java

示例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();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:17,代碼來源:SessionManagerTest.java

示例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()));
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:19,代碼來源:SessionManagerTest.java

示例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);
   }
 }
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:27,代碼來源:SessionManagerTest.java

示例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;
}
 
開發者ID:googlesamples,項目名稱:io2014-codelabs,代碼行數:27,代碼來源:DeviceSubscription.java


注:本文中的com.google.appengine.api.datastore.EntityNotFoundException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。