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