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


Java DatastoreService.get方法代碼示例

本文整理匯總了Java中com.google.appengine.api.datastore.DatastoreService.get方法的典型用法代碼示例。如果您正苦於以下問題:Java DatastoreService.get方法的具體用法?Java DatastoreService.get怎麽用?Java DatastoreService.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.appengine.api.datastore.DatastoreService的用法示例。


在下文中一共展示了DatastoreService.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getHTML

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的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.DatastoreService; //導入方法依賴的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: contextInitialized

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的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

示例4: kindExample_writesEntity

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@Test
public void kindExample_writesEntity() throws Exception {
  //CHECKSTYLE.OFF: VariableDeclarationUsageDistance - Increased clarity in sample
  // [START kind_example]
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

  Entity employee = new Entity("Employee", "asalieri");
  employee.setProperty("firstName", "Antonio");
  employee.setProperty("lastName", "Salieri");
  employee.setProperty("hireDate", new Date());
  employee.setProperty("attendedHrTraining", true);

  datastore.put(employee);
  // [END kind_example]
  //CHECKSTYLE.ON: VariableDeclarationUsageDistance

  Entity got = datastore.get(employee.getKey());
  assertThat((String) got.getProperty("firstName")).named("got.firstName").isEqualTo("Antonio");
  assertThat((String) got.getProperty("lastName")).named("got.lastName").isEqualTo("Salieri");
  assertThat((Date) got.getProperty("hireDate")).named("got.hireDate").isNotNull();
  assertThat((boolean) got.getProperty("attendedHrTraining"))
      .named("got.attendedHrTraining")
      .isTrue();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:25,代碼來源:EntitiesTest.java

示例5: kindExample_writesEntity

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@Test
public void kindExample_writesEntity() throws Exception {
  // [START kind_example]
  Entity employee = new Entity("Employee", "asalieri");
  employee.setProperty("firstName", "Antonio");
  employee.setProperty("lastName", "Salieri");
  employee.setProperty("hireDate", new Date());
  employee.setProperty("attendedHrTraining", true);

  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
  datastore.put(employee);
  // [END kind_example]

  Entity got = datastore.get(employee.getKey());
  assertThat((String) got.getProperty("firstName")).named("got.firstName").isEqualTo("Antonio");
  assertThat((String) got.getProperty("lastName")).named("got.lastName").isEqualTo("Salieri");
  assertThat((Date) got.getProperty("hireDate")).named("got.hireDate").isNotNull();
  assertThat((boolean) got.getProperty("attendedHrTraining"))
      .named("got.attendedHrTraining")
      .isTrue();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:22,代碼來源:EntitiesTest.java

示例6: getByKey

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
public static SessionLog getByKey(DatastoreService datastore, Transaction txn, Key key) {
    try {
        Entity sessionLogEntity = datastore.get(txn, key);
        return new SessionLog(sessionLogEntity);
    }
    catch(EntityNotFoundException e) { }
    return null;
}
 
開發者ID:kerafill1116,項目名稱:apollo-datastore,代碼行數:9,代碼來源:SessionLogFactory.java

示例7: getByKey

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
public static ResetPasswordRequest getByKey(DatastoreService datastore, Transaction txn, Key key) {
    try {
        Entity resetPasswordRequestEntity = datastore.get(txn, key);
        return new ResetPasswordRequest(resetPasswordRequestEntity);
    }
    catch(EntityNotFoundException e) { }
    return null;
}
 
開發者ID:kerafill1116,項目名稱:apollo-datastore,代碼行數:9,代碼來源:ResetPasswordRequestFactory.java

示例8: getByKey

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
public static TimeZone getByKey(DatastoreService datastore, Transaction txn, Key key) {
    try {
        Entity timeZoneEntity = datastore.get(txn, key);
        return new TimeZone(timeZoneEntity);
    }
    catch(EntityNotFoundException e) { }
    return null;
}
 
開發者ID:kerafill1116,項目名稱:apollo-datastore,代碼行數:9,代碼來源:TimeZoneFactory.java

示例9: getByKey

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
public static ChangeEmailAddressRequest getByKey(DatastoreService datastore, Transaction txn, Key key) {
    try {
        Entity changeEmailAddressRequestEntity = datastore.get(txn, key);
        return new ChangeEmailAddressRequest(changeEmailAddressRequestEntity);
    }
    catch(EntityNotFoundException e) { }
    return null;
}
 
開發者ID:kerafill1116,項目名稱:apollo-datastore,代碼行數:9,代碼來源:ChangeEmailAddressRequestFactory.java

示例10: getByKey

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
public static User getByKey(DatastoreService datastore, Transaction txn, Key key) {
    try {
        Entity userEntity = datastore.get(txn, key);
        return new User(userEntity);
    }
    catch(EntityNotFoundException e) { }
    return null;
}
 
開發者ID:kerafill1116,項目名稱:apollo-datastore,代碼行數:9,代碼來源:UserFactory.java

示例11: getByKey

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
public static Session getByKey(DatastoreService datastore, Transaction txn, Key key) {
    try {
        Entity sessionEntity = datastore.get(txn, key);
        return new Session(sessionEntity);
    }
    catch(EntityNotFoundException e) { }
    return null;
}
 
開發者ID:kerafill1116,項目名稱:apollo-datastore,代碼行數:9,代碼來源:SessionFactory.java

示例12: getAdminPermissionsByKey

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
public static AdminPermissions getAdminPermissionsByKey(DatastoreService datastore, Transaction txn, Key key) {
    try {
        Entity adminPermissionsEntity = datastore.get(txn, key);
        return new AdminPermissions(adminPermissionsEntity);
    }
    catch(EntityNotFoundException e) { }
    return null;
}
 
開發者ID:kerafill1116,項目名稱:apollo-datastore,代碼行數:9,代碼來源:PermissionsFactory.java

示例13: getUserPermissionsByKey

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
public static UserPermissions getUserPermissionsByKey(DatastoreService datastore, Transaction txn, Key key) {
    try {
        Entity userPermissionsEntity = datastore.get(txn, key);
        return new UserPermissions(userPermissionsEntity);
    }
    catch(EntityNotFoundException e) { }
    return null;
}
 
開發者ID:kerafill1116,項目名稱:apollo-datastore,代碼行數:9,代碼來源:PermissionsFactory.java

示例14: doGet

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
  resp.setContentType("text/plain");
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

  Key isPopulatedKey = KeyFactory.createKey(IS_POPULATED_ENTITY, IS_POPULATED_KEY_NAME);
  boolean isAlreadyPopulated;
  try {
    datastore.get(isPopulatedKey);
    isAlreadyPopulated = true;
  } catch (EntityNotFoundException expected) {
    isAlreadyPopulated = false;
  }
  if (isAlreadyPopulated) {
    resp.getWriter().println("ok");
    return;
  }

  ImmutableList.Builder<Entity> people = ImmutableList.builder();
  for (String name : US_PRESIDENTS) {
    Entity person = new Entity(PERSON_ENTITY);
    person.setProperty(NAME_PROPERTY, name);
    people.add(person);
  }
  datastore.put(people.build());
  datastore.put(new Entity(isPopulatedKey));
  resp.getWriter().println("ok");
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:30,代碼來源:StartupServlet.java

示例15: customTask

import com.google.appengine.api.datastore.DatastoreService; //導入方法依賴的package包/類
private void customTask( final HttpServletRequest request, final PersistenceManager pm ) throws IOException {
	LOGGER.fine( "Key: " + request.getParameter( "key" ) + ", file type: " + request.getParameter( "fileType" ) );
	
	final FileType fileType = FileType.fromString( request.getParameter( "fileType" ) );
	if ( fileType == null ) {
		LOGGER.severe( "Invalid File type!" );
		return;
	}
	
	final Key key = KeyFactory.stringToKey( request.getParameter( "key" ) );
	
	final DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
       final Entity e;
	try {
        e = ds.get( key );
       } catch ( final EntityNotFoundException enfe ) {
		LOGGER.log( Level.WARNING, "Entity not found!", enfe );
        return;
       }
	
       if ( !e.getKind().equals( "Rep" ) && !e.getKind().equals( "Smpd" ) && !e.getKind().equals( "OtherFile" ) ) {
		LOGGER.severe( "Invalid Entity kind:" + e.getKind() );
		return;
       }
       
       if ( (Long) e.getProperty( "v" ) == 4 ) {
		LOGGER.warning( "Entity is already v4!" );
		return;
	}
       
       // Update common properties:
       // TODO
       final int size = ( (Long) e.getProperty( "size" ) ).intValue();
       if ( size < FileServlet.DATASTORE_CONTENT_STORE_LIMIT ) {
           final FileService fileService = FileServiceFactory.getFileService();
   		final AppEngineFile   appeFile = new AppEngineFile( FileSystem.BLOBSTORE, ( (BlobKey) e.getProperty( "blobKey" ) ).getKeyString() );
   		final FileReadChannel channel  = fileService.openReadChannel( appeFile, false );
   		final byte[]          content  = new byte[ size ];
   		final ByteBuffer      wrapper  = ByteBuffer.wrap( content );
   		while ( channel.read( wrapper ) > 0 )
   			;
   		channel.close();
   		
   		e.setProperty( "content", new Blob( content ) );
   		e.setProperty( "blobKey", null );
   		fileService.delete( appeFile );
       }
       e.setUnindexedProperty( "blobKey", e.getProperty( "blobKey" ) );
       e.setUnindexedProperty( "content", e.getProperty( "content" ) );
       
       switch ( fileType ) {
       case SC2REPLAY :
           e.setUnindexedProperty( "matchup", e.getProperty( "matchup" ) );
       	break;
       case MOUSE_PRINT :
       	break;
       case OTHER :
       	break;
       default:
       	throw new RuntimeException( "Invalid file type!" );
       }
       
       // UPGRADE COMPLETE!
	e.setProperty( "v", 4 );
	ds.put( e );
}
 
開發者ID:icza,項目名稱:sc2gears,代碼行數:67,代碼來源:TaskServlet.java


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