本文整理匯總了Java中com.google.appengine.api.datastore.Entity.setProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java Entity.setProperty方法的具體用法?Java Entity.setProperty怎麽用?Java Entity.setProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.appengine.api.datastore.Entity
的用法示例。
在下文中一共展示了Entity.setProperty方法的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: 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();
}
示例3: newSharedProduct
import com.google.appengine.api.datastore.Entity; //導入方法依賴的package包/類
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void newSharedProduct(@FormParam("productID") String productID,
@FormParam("productName") String productName,
@Context HttpServletResponse servletResponse) throws Exception {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user == null) {
System.out.println("Login first");
return;
}
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
Entity entity = new Entity("SharedList", productID);
entity.setProperty("email", user.getEmail());
entity.setProperty("productName", productName);
entity.setProperty("sharedDate", new Date());
datastore.put(entity);
servletResponse.getWriter().println(productName + " has been added.");
servletResponse.flushBuffer();
}
示例4: addEntityProto
import com.google.appengine.api.datastore.Entity; //導入方法依賴的package包/類
/**
* Adds a record containing a new entity protobuf to the file.
*
* <p>Returns the ComparableEntity object rather than "this" so that we can check for the presence
* of the entity in the result set.
*/
ComparableEntity addEntityProto(int id, Property... properties) throws IOException {
Entity entity = new Entity(TEST_ENTITY_KIND, id);
for (Property prop : properties) {
entity.setProperty(prop.name(), prop.value());
}
EntityProto proto = EntityTranslator.convertToPb(entity);
byte[] protoBytes = proto.toByteArray();
if (protoBytes.length > BLOCK_SIZE - (currentPos + HEADER_SIZE)) {
out.write(currentBlock);
currentBlock = new byte[BLOCK_SIZE];
currentPos = 0;
}
currentPos = LevelDbUtil.addRecord(currentBlock, currentPos, ChunkType.FULL, protoBytes);
return new ComparableEntity(entity);
}
示例5: 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());
}
示例6: putIntoDatabase
import com.google.appengine.api.datastore.Entity; //導入方法依賴的package包/類
public void putIntoDatabase() {
Entity textSummaryEntity = getNewEntity();
textSummaryEntity.setProperty("sentence", new Text(sentence));
textSummaryEntity.setProperty("position", position);
textSummaryEntity.setProperty("salience", salience);
putIntoDatabase(textSummaryEntity);
}
示例7: KnowledgeNodeDataStore
import com.google.appengine.api.datastore.Entity; //導入方法依賴的package包/類
public KnowledgeNodeDataStore(Key parentKey, KnowledgeNode node) {
super("TextKnowledgeGraph");
setParentKey(parentKey);
Entity knowledgeGraphEntity = getNewEntity();
knowledgeGraphEntity.setProperty("name", node.getName());
knowledgeGraphEntity.setProperty("type", node.getType());
knowledgeGraphEntity.setProperty("URL", node.getMetadataURL());
knowledgeGraphEntity.setProperty("salience", node.getSalience());
knowledgeGraphEntity.setProperty("sentimentScore",
node.getSentimentScore());
putIntoDatabase(knowledgeGraphEntity);
}
示例8: setNonNullIndexedProperty
import com.google.appengine.api.datastore.Entity; //導入方法依賴的package包/類
/** For Blob and Text, this doesn't really make the property indexed.
* TODO(ohler): disallow Blob and Text? */
public static void setNonNullIndexedProperty(Entity e, String propertyName, Object value) {
Preconditions.checkNotNull(e, "Null entity");
Preconditions.checkNotNull(propertyName, "Null propertyName");
Preconditions.checkNotNull(value, "Null value");
e.setProperty(propertyName, value);
}
示例9: setOrRemoveIndexedProperty
import com.google.appengine.api.datastore.Entity; //導入方法依賴的package包/類
/** For Blob and Text, this doesn't really make the property indexed.
* TODO(ohler): disallow Blob and Text? */
public static void setOrRemoveIndexedProperty(
Entity e, String propertyName, @Nullable Object value) {
Preconditions.checkNotNull(e, "Null entity");
Preconditions.checkNotNull(propertyName, "Null propertyName");
if (value == null) {
e.removeProperty(propertyName);
} else {
e.setProperty(propertyName, value);
}
}
示例10: newWishlistProductJson
import com.google.appengine.api.datastore.Entity; //導入方法依賴的package包/類
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_JSON)
public void newWishlistProductJson(WishlistProduct product,
@Context HttpServletResponse servletResponse) throws Exception {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user == null) {
System.out.println("Login first");
return;
}
DatastoreService datastore = DatastoreServiceFactory
.getDatastoreService();
MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
Entity entity = new Entity(user.getEmail(), product.getProductID());
entity.setProperty("productName", product.getProductName());
entity.setProperty("currentPrice", product.getCurrentPrice());
entity.setProperty("lowestPrice", product.getLowestPrice());
entity.setProperty("lowestDate", new Date());
datastore.put(entity);
syncCache.put(product.getProductID(), product.getCurrentPrice());
servletResponse.getWriter().println("<html><head>");
servletResponse
.getWriter()
.println(
"<meta http-equiv=\"refresh\" content=\"3;url=/wishlist.jsp\" />");
servletResponse.getWriter().println("</head><body>");
servletResponse.getWriter()
.println(
"<h1>" + product.getProductName()
+ " has been added.</h1><br>");
servletResponse
.getWriter()
.println(
"<h2>Redirecting in 3 seconds...</h2> <a href=\"/wishlist.jsp\">Go back now</a>");
servletResponse.getWriter().println("</body></html>");
servletResponse.flushBuffer();
return;
}
示例11: test_mapreduceSuccessfullyResavesEntity
import com.google.appengine.api.datastore.Entity; //導入方法依賴的package包/類
@Test
public void test_mapreduceSuccessfullyResavesEntity() throws Exception {
createTld("tld");
DomainResource domain = persistActiveDomain("test.tld");
ContactResource contact = persistActiveContact("humanBeing");
Entity domainEntry =
ofy().save().toEntity(new HistoryEntry.Builder().setParent(domain).build());
Entity contactEntry =
ofy().save().toEntity(new HistoryEntry.Builder().setParent(contact).build());
// Set raw properties outside the Objectify schema, which will be deleted upon re-save.
domainEntry.setProperty("clientId", "validId");
contactEntry.setProperty("otherClientId", "anotherId");
domainEntry.setProperty("propertyToBeDeleted", "123blah");
contactEntry.setProperty("alsoShouldBeDeleted", "456nah");
datastoreService.put(domainEntry);
datastoreService.put(contactEntry);
ofy().clearSessionCache();
runMapreduce();
Entity updatedDomainEntry = datastoreService.get(domainEntry.getKey());
Entity updatedContactEntry = datastoreService.get(contactEntry.getKey());
assertThat(updatedDomainEntry.getProperty("clientId")).isEqualTo("validId");
assertThat(updatedDomainEntry.getProperty("propertyToBeDeleted")).isNull();
assertThat(updatedContactEntry.getProperty("otherClientId")).isEqualTo("anotherId");
assertThat(updatedContactEntry.getProperty("alsoShouldBeDeleted")).isNull();
}
示例12: testEquals
import com.google.appengine.api.datastore.Entity; //導入方法依賴的package包/類
@Test
public void testEquals() {
// Create an entity with a key and some properties.
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);
EntityProto proto2 = EntityTranslator.convertToPb(entity);
// Reorder the property list of proto2 (the protobuf stores this as a repeated field, so
// we just have to clear and re-add them in a different order).
ImmutableList<Property> properties =
ImmutableList.of(proto2.getProperty(2), proto2.getProperty(0), proto2.getProperty(1));
proto2.clearProperty();
for (Property property : properties) {
proto2.addProperty(property);
}
// Construct entity objects from the two protos.
Entity e1 = EntityTranslator.createFromPb(proto1);
Entity e2 = EntityTranslator.createFromPb(proto2);
// Ensure that we have a normalized representation.
ComparableEntity ce1 = new ComparableEntity(e1);
ComparableEntity ce2 = new ComparableEntity(e2);
assertThat(ce1).isEqualTo(ce2);
assertThat(ce1.hashCode()).isEqualTo(ce2.hashCode());
// Ensure that the original entity is equal.
assertThat(new ComparableEntity(entity)).isEqualTo(ce1);
}
示例13: before
import com.google.appengine.api.datastore.Entity; //導入方法依賴的package包/類
@Before
public void before() throws Exception {
inject.setStaticField(DatastoreBackupInfo.class, "clock", clock);
backupEntity = new Entity("_unused_");
backupEntity.setProperty("name", "backup1");
backupEntity.setProperty("kinds", ImmutableList.of("one", "two", "three"));
backupEntity.setProperty("start_time", new Date(startTime.getMillis()));
}
示例14: persistBackupEntityWithName
import com.google.appengine.api.datastore.Entity; //導入方法依賴的package包/類
private static void persistBackupEntityWithName(String name) {
Entity entity = new Entity(DatastoreBackupService.BACKUP_INFO_KIND);
entity.setProperty("name", name);
entity.setProperty("kinds", ImmutableList.of("one", "two", "three"));
entity.setProperty("start_time", new Date(START_TIME.getMillis()));
getDatastoreService().put(entity);
}
示例15: process
import com.google.appengine.api.datastore.Entity; //導入方法依賴的package包/類
@Override
public void process() {
Entity textEntity = getEntityByKey(parentKey);
textEntity.setProperty("type", sentimentScore);
putIntoDatabase(textEntity);
}