当前位置: 首页>>代码示例>>Java>>正文


Java Entity.getProperties方法代码示例

本文整理汇总了Java中com.google.appengine.api.datastore.Entity.getProperties方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.getProperties方法的具体用法?Java Entity.getProperties怎么用?Java Entity.getProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.appengine.api.datastore.Entity的用法示例。


在下文中一共展示了Entity.getProperties方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: getStatusAt

import com.google.appengine.api.datastore.Entity; //导入方法依赖的package包/类
@ApiMethod(path = "getStatusAt", name = "getStatusAt", httpMethod = ApiMethod.HttpMethod.GET)
    public ApiMedicion getStatusAt(@Named("amount") Date date) {

        Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("CET"));

//         Fix offset
        if (date.getTime() < 1505341800L * 1000){
            date.setTime(date.getTime() - 3600L * 1000);
        }
        date.setTime(date.getTime());

        calendar.setTime(date);
        calendar.setTimeZone(TimeZone.getTimeZone("CET"));



        // Prepare
        Query.FilterPredicate filter = new Query.FilterPredicate(PROPERTY_MEASURE_DATE, Query.FilterOperator.EQUAL, date);
        Query query = new Query(ENTITY_TYPE_MEDIDAS).setFilter(filter);

        // Query
        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        PreparedQuery pq = datastore.prepare(query);
        List<Entity> resultList = pq.asList(FetchOptions.Builder.withDefaults());

        ApiMedicion medicion = new Medicion(MainServlet.isPureMadrid());
        for (Entity entity : resultList){

            Map<String, Object> properties = entity.getProperties();
            Map<String, Object> mapMeditions = new HashMap<>();

            String propertyCompuesto = (String) entity.getProperty(PROPERTY_COMPUESTO);
            Compuesto compuesto = Compuesto.withName(propertyCompuesto);

            medicion.setMeasuredAt((Date) entity.getProperty(PROPERTY_MEASURE_DATE));
            medicion.setSavedAtHour((Date) entity.getProperty(PROPERTY_SAVED_AT));
            if (entity.getProperty(PROPERTY_COMPUESTO).equals(Compuesto.NO2)){
                medicion.setAviso((String) entity.getProperty(PROPERTY_AVISO));
                medicion.setAvisoState((String) entity.getProperty(PROPERTY_AVISO_STATE));
                medicion.setAvisoMaxToday((String) entity.getProperty(PREPERTY_AVISO_MAX_TODAY));
                medicion.setEscenarioStateToday((String) entity.getProperty(PROPERTY_ESCENARIO_STATE_TODAY));
                medicion.setEscenarioStateTomorrow((String)  entity.getProperty(PROPERTY_ESCENARIO_STATE_TOMORROW));
            }

            for (Map.Entry<String, Object> entry : properties.entrySet()) {
                if(entry.getKey().contains(PROPERTY_ESTACION_BEGINS)){
                    try {
                        mapMeditions.put(entry.getKey(), parseValue(entry.getValue()));
                    } catch (Exception e){
                        mLogger.warning("Error parsing data from Datastore: " + entry.getValue());
                    }
                }
            }
            medicion.put(compuesto,mapMeditions);

        }

        return medicion;
    }
 
开发者ID:medialab-prado,项目名称:puremadrid,代码行数:60,代码来源:PureMadridApi.java

示例3: doGet

import com.google.appengine.api.datastore.Entity; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {

  resp.setContentType("application/json");

  UpdateRunLogger logger = new UpdateRunLogger();
  JsonObject response = new JsonObject();

  int limitElements = 10;
  if (req.getParameter("limit")!=null) {
    limitElements = Integer.parseInt(req.getParameter("limit"));
  }
  List<Entity> lastRunsEntities = logger.getMostRecentRuns(limitElements);
  JsonArray lastRuns = new JsonArray();
  for (Entity run: lastRunsEntities) {
    JsonObject obj= new JsonObject();
    JsonObject timings = new JsonObject();
    TreeMap<String, Object> sortedMap = new TreeMap<String, Object>(run.getProperties());
    for (Entry<String, Object> property: sortedMap.entrySet()) {
      Object value = property.getValue();
      String key = property.getKey();
      if (key.startsWith("time_")) {
        timings.add(key.substring("time_".length()), new JsonPrimitive((Number) value));
      } else {
        JsonPrimitive converted = null;
        if (value instanceof ShortBlob) {
          converted = new JsonPrimitive(bytesToHex(((ShortBlob) value).getBytes()));
        } else if (value instanceof String) {
          converted = new JsonPrimitive((String) value);
        } else if (value instanceof Number) {
          converted = new JsonPrimitive((Number) value);
        } else if (value instanceof Boolean) {
          converted = new JsonPrimitive((Boolean) value);
        } else if (value instanceof Character) {
          converted = new JsonPrimitive((Character) value);
        } else if (value instanceof Date) {
          converted = new JsonPrimitive(DateFormat.getDateTimeInstance().format((Date) value));
        }
        if (converted != null) {
          obj.add(key, converted);
        }
      }
    }
    obj.add("timings", timings);
    lastRuns.add(obj);
  }
  response.add("lastruns", lastRuns);
  CloudFileManager cloudManager = new CloudFileManager();
  response.add("bucket", new JsonPrimitive(cloudManager.getBucketName()));
  response.add("productionManifest", new JsonPrimitive(cloudManager.getProductionManifestURL()));
  response.add("stagingManifest", new JsonPrimitive(cloudManager.getStagingManifestURL()));

  new GsonBuilder()
    .setPrettyPrinting()
    .disableHtmlEscaping()
    .create().toJson(response, resp.getWriter());
}
 
开发者ID:silicon-mountain,项目名称:smconf-android,代码行数:59,代码来源:LogDataServlet.java


注:本文中的com.google.appengine.api.datastore.Entity.getProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。