本文整理匯總了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);
}
}
示例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;
}
示例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());
}