com.google.appengine.api.datastore.Entity.getProperties()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中com.google.appengine.api.datastore.Entity.getProperties()方法的一些代码示例,展示了Entity.getProperties()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.getProperties()方法的具体详情如下:
包路径:com.google.appengine.api.datastore.Entity
类名称:Entity
方法名:getProperties

Entity.getProperties介绍

暂无

代码示例

代码示例来源:origin: PeterKnego/LeanEngine-Server

public static LeanAccount toLeanAccount(Entity entity) {

    Map<String, Object> props = new HashMap<String, Object>(entity.getProperties().size() - 3);
    for (Map.Entry<String, Object> entityProp : entity.getProperties().entrySet()) {
      if(!entityProp.getKey().startsWith("_"))
        props.put(entityProp.getKey(), entityProp.getValue());
    }

    return new LeanAccount(
        entity.getKey().getId(),
        (String) entity.getProperty("_nickname"),
        (String) entity.getProperty("_provider_id"),
        (String) entity.getProperty("_provider"),
        props
    );
  }
}

代码示例来源:origin: com.googlecode.cedar-common/objectify

/**
 * Loads the property data in an Entity into a POJO.  Does not affect id/parent
 * (ie key) fields; those are assumed to already have been set.
 * 
 * @param fromEntity is a raw datastore entity
 * @param toPojo is your typed entity
 */
public void load(Entity fromEntity, T toPojo)
{
  LoadContext context = new LoadContext(toPojo, fromEntity);
  
  for (Map.Entry<String, Object> property: fromEntity.getProperties().entrySet())
  {
    String key = property.getKey();
    Object value = property.getValue();
    loadSingleValue(key, value, toPojo, context);
  }
  
  context.done();
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

private static <T extends TempData> T entityToTempData(Entity entity, Class<T> type, DatastoreService ds) throws Exception {
  T data = type.newInstance();
  data.preGet(ds);
  data.fromProperties(entity.getProperties());
  data.postGet(ds);
  return data;
}

代码示例来源:origin: PeterKnego/LeanEngine-Server

private static Map<String, Object> load() {
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
  Key key = KeyFactory.createKey("_settings", 1);
  Entity leanEntity;
  try {
    leanEntity = datastore.get(key);
    settings = leanEntity.getProperties();
  } catch (EntityNotFoundException e) {
    settings = new HashMap<String, Object>();
    // By default enable all logins on Development server
    if (ServerUtils.isDevServer()) {
      settings.put("fbLoginEnable", true);
      settings.put("fbAppId", "mockFacebookAppId");
      settings.put("fbAppSecret", "mockFacebookAppSecret");
      settings.put("openIdLoginEnable", true);
      saveSettings(settings);
    }
  }
  return settings;
}

代码示例来源:origin: bedatadriven/activityinfo

for (String property : blockEntity.getProperties().keySet()) {
  if(property.startsWith(bitsetPrefix)) {
    toUnset.add(property);

代码示例来源:origin: PeterKnego/LeanEngine-Server

public static JsonNode entityToJson(Entity entity) throws LeanException {
  ObjectNode json = getObjectMapper().createObjectNode();
  json.put("_id", entity.getKey().getId());
  json.putPOJO("_kind", entity.getKind());
  json.putPOJO("_account", entity.getProperty("_account"));
  Map<String, Object> props = entity.getProperties();
  for (Map.Entry<String, Object> prop : props.entrySet()) {
    addTypedNode(json, prop.getKey(), prop.getValue());
  }
  return json;
}

代码示例来源:origin: com.google.appengine.orm/datanucleus-appengine

if (NucleusLogger.DATASTORE_NATIVE.isDebugEnabled()) {
 StringBuffer str = new StringBuffer();
 for (Map.Entry<String, Object> entry : entity.getProperties().entrySet()) {
  str.append(entry.getKey() + "[" + entry.getValue() + "]");
  str.append(", ");
  if (previouslyPut == null || !previouslyPut.getProperties().equals(entity.getProperties())) {
   putMe.add(entity);

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

private void checkQueryType(String property, Class<?> type) {
  Query query = new Query(kindName, rootKey);
  query.addProjection(new PropertyProjection(property, type));
  String sql = "SELECT " + property + " FROM " + kindName + " WHERE __ancestor__ is " + rootKey;
  assertEquals(sql.toLowerCase(), query.toString().toLowerCase());
  List<Entity> results = service.prepare(query).asList(fetchOption);
  for (Entity e : results) {
    assertEquals(1, e.getProperties().size());
    assertTrue(e.getProperties().containsKey(property));
  }
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

protected static void deleteTempDataInTx(DatastoreService ds, Entity entity, Class<? extends TempData> type) {
  Transaction txn = ds.beginTransaction(TransactionOptions.Builder.withXG(true));
  try {
    TempData data = type.newInstance();
    data.fromProperties(entity.getProperties());
    data.preDelete(ds);
    ds.delete(txn, entity.getKey());
    data.postDelete(ds);
    txn.commit();
  } catch (Exception e) {
    throw new IllegalStateException(e);
  } finally {
    if (txn.isActive()) {
      txn.rollback();
    }
  }
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testListQuery() {
  Query query = new Query(kindName, rootKey);
  query.addProjection(new PropertyProjection("stringList", String.class));
  query.addProjection(new PropertyProjection("intList", Integer.class));
  List<Entity> results = service.prepare(query).asList(fetchOption);
  // Distinct stringList data 2 * Distinct intList data 3 * entity's count 10
  assertEquals(60, results.size());
  Entity e = results.get(0);
  assertEquals(2, e.getProperties().size());
  assertTrue(e.getProperties().containsKey("stringList"));
  assertTrue(e.getProperties().containsKey("intList"));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testBasicQuery() {
  Query query = new Query(kindName, rootKey);
  query.addProjection(new PropertyProjection("stringData", String.class));
  query.addProjection(new PropertyProjection("intData", Integer.class));
  String sql = "SELECT stringData, intData FROM " + kindName + " WHERE __ancestor__ is " + rootKey;
  assertEquals(sql.toLowerCase(), query.toString().toLowerCase());
  List<Entity> results = service.prepare(query).asList(fetchOption);
  assertEquals(count, results.size());
  for (Entity e : results) {
    assertEquals(2, e.getProperties().size());
    assertTrue(e.getProperties().containsKey("stringData"));
    assertTrue(e.getProperties().containsKey("intData"));
  }
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
  public void testEntityGainsNoAdditionalPropertiesWhenStored() throws Exception {
    clearData(kindName);
    Entity entity = new Entity(kindName);
    Key key = service.put(entity);
    entity = service.get(key);
    assertEquals(Collections.<String, Object>emptyMap(), entity.getProperties());
  }
}

代码示例来源:origin: com.google.appengine.orm/datanucleus-appengine

protected int[] internalShift(ObjectProvider op, boolean batched, int oldIndex, int amount) 
throws MappedDatastoreException {
 if (orderMapping == null) {
  return null;
 }
 DatastoreServiceConfig config = storeMgr.getDefaultDatastoreServiceConfigForReads();
 DatastoreService service = DatastoreServiceFactoryInternal.getDatastoreService(config);
 AbstractClassMetaData acmd = elementCmd;
 String kind =
   storeMgr.getIdentifierFactory().newDatastoreContainerIdentifier(acmd).getIdentifierName();
 Query q = new Query(kind);
 ExecutionContext ec = op.getExecutionContext();
 Object id = ec.getApiAdapter().getTargetKeyForSingleFieldIdentity(op.getInternalObjectId());
 Key key = id instanceof Key ? (Key) id : KeyFactory.stringToKey((String) id);
 q.setAncestor(key);
 // create an entity just to capture the name of the index property
 Entity entity = new Entity(kind);
 orderMapping.setObject(ec, entity, new int[] {1}, oldIndex);
 String indexProp = entity.getProperties().keySet().iterator().next();
 q.addFilter(indexProp, Query.FilterOperator.GREATER_THAN_OR_EQUAL, oldIndex);
 for (Entity shiftMe : service.prepare(service.getCurrentTransaction(null), q).asIterable()) {
  Long pos = (Long) shiftMe.getProperty(indexProp);
  shiftMe.setProperty(indexProp, pos + amount);
  EntityUtils.putEntityIntoDatastore(ec, shiftMe);
 }
 return null;
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testWithPropertyProjection() {
  Query query = new Query(kindName, rootKey);
  query.addProjection(new PropertyProjection("geoptData", GeoPt.class));
  Filter filter1 = Query.CompositeFilterOperator.or(
    Query.FilterOperator.LESS_THAN.of("intList", 5),
    Query.FilterOperator.GREATER_THAN.of("intList", 90));
  Filter filter2 = Query.FilterOperator.EQUAL.of("intList", 52);
  query.setFilter(Query.CompositeFilterOperator.and(filter1, filter2));
  // sql statement
  String sql = "SELECT geoptData FROM " + kindName;
  sql += " WHERE ((intList < 5 or intList > 90) AND intList = 52)";
  sql += " AND __ancestor__ is " + rootKey;
  assertEquals(sql.toLowerCase(), query.toString().toLowerCase());
  // check query result
  List<Entity> results = service.prepare(query).asList(fo);
  Assert.assertTrue(results.size() > 0);
  assertEquals(new GeoPt((float) (2.12), (float) (2.98)), results.get(0).getProperty("geoptData"));
  for (Entity e : results) {
    assertEquals(1, e.getProperties().size());
    assertTrue(e.getProperties().containsKey("geoptData"));
  }
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testEntityOnlyContainsProjectedProperties() throws Exception {
  String methodName = "testEntityOnlyContainsProjectedProperties";
  Entity parent = createTestEntityWithUniqueMethodNameKey("Product", methodName);
  Key key = parent.getKey();
  Entity b = createEntity("Product", key)
    .withProperty("name", "b")
    .withProperty("price", 1L)
    .store();
  Entity a = createEntity("Product", key)
    .withProperty("name", "a")
    .withProperty("price", 2L)
    .store();
  Query query = new Query("Product")
    .setAncestor(key)
    .addProjection(new PropertyProjection("price", Long.class))
    .setFilter(new Query.FilterPredicate("name", IN, Arrays.asList("a", "b")));
  Entity firstResult = service.prepare(query).asList(FetchOptions.Builder.withDefaults()).get(0);
  assertEquals(1, firstResult.getProperties().size());
  assertEquals("price", firstResult.getProperties().keySet().iterator().next());
  query = new Query("Product")
    .setKeysOnly()
    .setFilter(new Query.FilterPredicate("name", IN, Arrays.asList("a", "b")));
  firstResult = service.prepare(query).asList(FetchOptions.Builder.withDefaults()).get(0);
  assertEquals(0, firstResult.getProperties().size());
}

代码示例来源:origin: com.google.appengine.orm/datanucleus-appengine

String indexProp = entity.getProperties().keySet().iterator().next();
q.addFilter(indexProp, Query.FilterOperator.GREATER_THAN, index);
for (Entity shiftMe : service.prepare(service.getCurrentTransaction(null), q).asIterable()) {

相关文章