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


Java Entity類代碼示例

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


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

示例1: process

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
@Override
public void process() {
    UserService userService = UserServiceFactory.getUserService();
    // Step 1: Add Text into DB.
    Entity textEntity = getNewEntity();
    textEntity.setProperty("rawText", new Text(text));
    textEntity.setProperty("user",
            userService.getCurrentUser().getNickname());
    textEntity.setProperty("date", new Date());
    putIntoDatabase(textEntity);
    Key parentKey = textEntity.getKey();
    factory.setParentKey(parentKey);
    // Step 2: Call other processors.
    factory.createTypePredictor().process();
    factory.createKnowledgeGraphBuilder().process();
    factory.createSummaryGenerator().process();
}
 
開發者ID:SamChou19815,項目名稱:chunk-reader,代碼行數:18,代碼來源:MainProcessor.java

示例2: saveFile

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
/**
 * Save Full File
 *
 * @param inputStream
 */
private static void saveFile(InputStream inputStream) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Calendar time = Calendar.getInstance(TimeZone.getTimeZone("CET"));
    time.set(Calendar.HOUR_OF_DAY,0);
    time.set(Calendar.MINUTE,0);
    time.set(Calendar.SECOND,0);
    Date measuredAt = time.getTime();
    long millis = time.getTimeInMillis();
    //
    Entity entity = new Entity(ENTITY_TYPE_FICHEROS,millis);
    entity.setIndexedProperty("Date", measuredAt);
    entity.setUnindexedProperty("File", GlobalUtils.getString(inputStream));
    // Store
    datastore.put(entity);
}
 
開發者ID:medialab-prado,項目名稱:puremadrid,代碼行數:21,代碼來源:GetNewData.java

示例3: getOptionalProperty

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
@Nullable public static <T> T getOptionalProperty(
    Entity e, String propertyName, Class<T> propertyType)
    throws InvalidPropertyException {
  Preconditions.checkNotNull(e, "Null entity");
  Preconditions.checkNotNull(propertyName, "Null propertyName");
  Preconditions.checkNotNull(propertyType, "Null propertyType");
  Object value = e.getProperty(propertyName);
  if (value == null) {
    return null;
  }
  if (!propertyType.isInstance(value)) {
    throw new InvalidPropertyException(e, propertyName, "Expected property type "
        + propertyType + ", found " + value.getClass() + ": " + value);
  }
  return propertyType.cast(value);
}
 
開發者ID:ArloJamesBarnes,項目名稱:walkaround,代碼行數:17,代碼來源:DatastoreUtil.java

示例4: toModel

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
@Override
public <T> T toModel(Class<T> entityClass, Entity entity) {
    try {
        T instance = entityClass.newInstance();

        Field idField = getIdField(entityClass);
        Key key = entity.getKey();
        Object id = (key.getName() != null ? key.getName() : key.getId());
        idField.set(instance, id);

        Map<String, Object> properties = entity.getProperties();
        for (Map.Entry<String, Object> entry : properties.entrySet()) {
            Field field = ReflectionUtils.findRequiredField(entityClass, entry.getKey());
            ReflectionUtils.setField(field, instance, entry.getValue());
        }

        return instance;
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
 
開發者ID:snowdrop,項目名稱:spring-data-snowdrop,代碼行數:22,代碼來源:GenericEntityToModelMapper.java

示例5: logUpdateRun

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
public void logUpdateRun(int majorVersion, int minorVersion, String filename, byte[] hash,
    JsonObject data, boolean forced) {
  Entity updateRun = new Entity(UPDATERUN_ENTITY_KIND);
  updateRun.setProperty("date", new Date());
  updateRun.setProperty("hash", new ShortBlob(hash));
  updateRun.setProperty("forced", forced);
  updateRun.setProperty("majorVersion", majorVersion);
  updateRun.setProperty("minorVersion", minorVersion);
  for (Entry<String, Long> performanceItem: timers.entrySet()) {
    updateRun.setProperty("time_"+performanceItem.getKey(), performanceItem.getValue());
  }
  updateRun.setProperty("filename", filename);
  StringBuilder sb = new StringBuilder();
  for (Entry<String, JsonElement> el: data.entrySet()) {
    if (el.getValue().isJsonArray()) {
      sb.append(el.getKey()).append("=").append(el.getValue().getAsJsonArray().size()).append(" ");
    }
  }
  if (sb.length()>0) {
    // remove trailing space
    sb.deleteCharAt(sb.length()-1);
  }
  updateRun.setProperty("summary", sb.toString());
  datastore.put(updateRun);
  timers.clear();
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:27,代碼來源:UpdateRunLogger.java

示例6: getMonthlyHighScores

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
/**
 * Method to retrieve the monthly high scores 
 * @return
 */
public List<Entity> getMonthlyHighScores(){
	log.info("Retrieving monthly high scores");
	
	//calculate calendar info
	Calendar calendar= Calendar.getInstance();		
	int year=calendar.get(Calendar.YEAR);
	int month=calendar.get(Calendar.MONTH);
	
	//create filters
	Filter yearFilter = new FilterPredicate(Constants.YEAR,FilterOperator.EQUAL,year);
	Filter monthFilter = new FilterPredicate(Constants.MONTH,FilterOperator.EQUAL,month);
		
	//create the query to read the records sorted by score
	Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
	//set filters to the query
	q.setFilter(yearFilter);
	q.setFilter(monthFilter);
	
	//prepare query
	PreparedQuery pq = datastore.prepare(q);
	
	//retrieve and return the list of records	
	return pq.asList(FetchOptions.Builder.withLimit(100));
}
 
開發者ID:mastorak,項目名稱:LeaderboardServer,代碼行數:29,代碼來源:ScoreDAO.java

示例7: getWeeklyHighScores

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
/**
 * Method to retrieve the weekly high scores 
 * @return
 */
public List<Entity> getWeeklyHighScores(){
	log.info("Retrieving weekly high scores");
	
	//calculate calendar info
	Calendar calendar= Calendar.getInstance();		
	int year=calendar.get(Calendar.YEAR);
	int week=calendar.get(Calendar.WEEK_OF_YEAR);
	
	//create filters
	Filter yearFilter = new FilterPredicate(Constants.YEAR,FilterOperator.EQUAL,year);
	Filter weekFilter = new FilterPredicate(Constants.WEEK_OF_THE_YEAR,FilterOperator.EQUAL,week);
		
	//create the query to read the records sorted by score
	Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
	//set filters to the query
	q.setFilter(yearFilter);
	q.setFilter(weekFilter);
	
	//prepare query
	PreparedQuery pq = datastore.prepare(q);
	
	//retrieve and return the list of records	
	return pq.asList(FetchOptions.Builder.withLimit(100));
}
 
開發者ID:mastorak,項目名稱:LeaderboardServer,代碼行數:29,代碼來源:ScoreDAO.java

示例8: getDailyHighScores

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
/**
 * Method to retrieve the daily high scores 
 * @return
 */
public List<Entity> getDailyHighScores(){
	log.info("Retrieving weekly high scores");
	
	//calculate calendar info
	Calendar calendar= Calendar.getInstance();
	int year=calendar.get(Calendar.YEAR);
	int day=calendar.get(Calendar.DAY_OF_YEAR);
	
	//create filters
	Filter yearFilter = new FilterPredicate(Constants.YEAR,FilterOperator.EQUAL,year);
	Filter dayFilter = new FilterPredicate(Constants.DAY_OF_THE_YEAR,FilterOperator.EQUAL,day);
	
	//create the query to read the records sorted by score
	Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
	
	//set filters to the query
	q.setFilter(yearFilter);
	q.setFilter(dayFilter);
	
	//prepare query
	PreparedQuery pq = datastore.prepare(q);
	
	//retrieve and return the list of records	
	return pq.asList(FetchOptions.Builder.withLimit(100));
}
 
開發者ID:mastorak,項目名稱:LeaderboardServer,代碼行數:30,代碼來源:ScoreDAO.java

示例9: getEntitiesBrowser

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
@GET
@Produces(MediaType.TEXT_XML)
public List<SharedProduct> getEntitiesBrowser() {
	List<SharedProduct> list = new ArrayList<SharedProduct>();
	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	Query query = new Query("SharedList");
	query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
	List<Entity> results = datastore.prepare(query).asList(
			FetchOptions.Builder.withDefaults());
	for (Entity entity : results) {
		String email = (String) entity.getProperty("email");
		String productID = (String) entity.getKey().getName();
		String productName = (String) entity.getProperty("productName");
		Date sharedDate = (Date) entity.getProperty("sharedDate");

		list.add(new SharedProduct(email, productID, productName,
				sharedDate));
	}

	return list;
}
 
開發者ID:fasthall,項目名稱:amazon-price-tracker,代碼行數:23,代碼來源:Sharedlist.java

示例10: testSingleRecordWrites

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
@Test
public void testSingleRecordWrites() throws FileNotFoundException, IOException {
  File subdir = tempFs.newFolder("folder");
  File logFile = new File(subdir, "testfile");
  LevelDbFileBuilder builder = new LevelDbFileBuilder(logFile);
  ComparableEntity entity =
      builder.addEntityProto(
          BASE_ID, Property.create("first", 100L), Property.create("second", 200L));
  builder.build();

  LevelDbLogReader reader = new LevelDbLogReader();
  reader.readFrom(new FileInputStream(logFile));

  ImmutableList<byte[]> records = reader.getRecords();
  assertThat(records).hasSize(1);

  // Reconstitute an entity, make sure that what we've got is the same as what we started with.
  EntityProto proto = new EntityProto();
  proto.parseFrom(records.get(0));
  Entity materializedEntity = EntityTranslator.createFromPb(proto);
  assertThat(new ComparableEntity(materializedEntity)).isEqualTo(entity);
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:23,代碼來源:LevelDbFileBuilderTest.java

示例11: DatastoreBackupInfo

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
/** DatastoreBackupInfo instances should only be obtained via DatastoreBackupService. */
DatastoreBackupInfo(Entity backupEntity) {
  backupName = (String) checkNotNull(backupEntity.getProperty("name"), "name");
  @SuppressWarnings("unchecked")
  List<String> rawKinds = (List<String>) checkNotNull(backupEntity.getProperty("kinds"), "kinds");
  Date rawStartTime = (Date) checkNotNull(backupEntity.getProperty("start_time"), "start_time");
  Date rawCompleteTime = (Date) backupEntity.getProperty("complete_time");
  Text rawGcsFilename = (Text) backupEntity.getProperty("gs_handle");

  kinds = ImmutableSet.copyOf(rawKinds);
  startTime = new DateTime(rawStartTime).withZone(UTC);
  completeTime = Optional.ofNullable(
      rawCompleteTime == null ? null : new DateTime(rawCompleteTime).withZone(UTC));
  gcsFilename = Optional.ofNullable(
      rawGcsFilename == null ? null : gcsPathToUri(rawGcsFilename.getValue()));
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:17,代碼來源:DatastoreBackupInfo.java

示例12: getEntities

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<SharedProduct> getEntities() {
	List<SharedProduct> list = new ArrayList<SharedProduct>();
	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	Query query = new Query("SharedList");
	query.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
	List<Entity> results = datastore.prepare(query).asList(
			FetchOptions.Builder.withDefaults());
	for (Entity entity : results) {
		String email = (String) entity.getProperty("email");
		String productID = (String) entity.getKey().getName();
		String productName = (String) entity.getProperty("productName");
		Date sharedDate = (Date) entity.getProperty("sharedDate");

		list.add(new SharedProduct(email, productID, productName,
				sharedDate));
	}

	return list;
}
 
開發者ID:fasthall,項目名稱:amazon-price-tracker,代碼行數:23,代碼來源:Sharedlist.java

示例13: testDifferentPropertiesNotEqual

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
@Test
public void testDifferentPropertiesNotEqual() {
  Entity entity = new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID);
  // Note that we need to specify these as long for property comparisons to work because that's
  // how they are deserialized from protos.
  entity.setProperty("eeny", 100L);
  entity.setProperty("meeny", 200L);
  entity.setProperty("miney", 300L);

  EntityProto proto1 = EntityTranslator.convertToPb(entity);

  entity.setProperty("moe!", 400);
  EntityProto proto2 = EntityTranslator.convertToPb(entity);

  // Construct entity objects from the two protos.
  Entity e1 = EntityTranslator.createFromPb(proto1);
  Entity e2 = EntityTranslator.createFromPb(proto2);

  ComparableEntity ce1 = new ComparableEntity(e1);
  ComparableEntity ce2 = new ComparableEntity(e2);
  assertThat(e1).isEqualTo(e2); // The keys should still be the same.
  assertThat(ce1).isNotEqualTo(ce2);
  assertThat(ce1.hashCode()).isNotEqualTo(ce2.hashCode());
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:25,代碼來源:ComparableEntityTest.java

示例14: getHTML

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

示例15: parseWaveletEntity

import com.google.appengine.api.datastore.Entity; //導入依賴的package包/類
private RemoteConvWavelet parseWaveletEntity(Entity entity) {
  Pair<SourceInstance, WaveletName> instanceAndWaveId = parseWaveletKey(entity.getKey());
  try {
    RobotSearchDigest digest = GsonProto.fromGson(new RobotSearchDigestGsonImpl(),
        DatastoreUtil.getExistingProperty(entity, WAVELET_DIGEST_PROPERTY, Text.class)
        .getValue());
    Assert.check(
        instanceAndWaveId.getSecond().waveId.equals(WaveId.deserialise(digest.getWaveId())),
        "Wave id mismatch: %s, %s", instanceAndWaveId, entity);
    Assert.check(DatastoreUtil.getExistingProperty(
            entity, WAVELET_LAST_MODIFIED_MILLIS_PROPERTY, Long.class)
        .equals(digest.getLastModifiedMillis()),
        "Mismatched last modified times: %s, %s", digest, entity);
    @Nullable String privateLocalId = DatastoreUtil.getOptionalProperty(
        entity, WAVELET_PRIVATE_LOCAL_ID_PROPERTY, String.class);
    @Nullable String sharedLocalId = DatastoreUtil.getOptionalProperty(
        entity, WAVELET_SHARED_LOCAL_ID_PROPERTY, String.class);
    return new RemoteConvWavelet(instanceAndWaveId.getFirst(), digest,
        instanceAndWaveId.getSecond().waveletId,
        privateLocalId == null ? null : new SlobId(privateLocalId),
        sharedLocalId == null ? null : new SlobId(sharedLocalId));
  } catch (MessageException e) {
    throw new RuntimeException("Failed to parse wave entity: " + entity, e);
  }
}
 
開發者ID:ArloJamesBarnes,項目名稱:walkaround,代碼行數:26,代碼來源:PerUserTable.java


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