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


Java DatastoreService.prepare方法代码示例

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


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

示例1: getLastStatus

import com.google.appengine.api.datastore.DatastoreService; //导入方法依赖的package包/类
private ArrayList<Medicion> getLastStatus(int amountData) {
    // Poner Key estacion + hora_muestra
    Calendar calendarTwoAgo = Calendar.getInstance(TimeZone.getTimeZone("CET"));
    calendarTwoAgo.add(Calendar.DATE, -3);
    Date dateTwoAgo = calendarTwoAgo.getTime();

    // Prepare
    Query.Filter keyFilter = new Query.FilterPredicate(PROPERTY_MEASURE_DATE, Query.FilterOperator.GREATER_THAN, dateTwoAgo);
    Query.Filter no2Filter = new Query.FilterPredicate(PROPERTY_COMPUESTO, Query.FilterOperator.EQUAL, NO2.name());
    List<Query.Filter> filterList = new ArrayList<>();
    filterList.add(keyFilter);
    filterList.add(no2Filter);
    Query.Filter filter = new Query.CompositeFilter(Query.CompositeFilterOperator.AND, filterList);
    Query query = new Query(ENTITY_TYPE_MEDIDAS)
            .setFilter(filter)
            .addSort(PROPERTY_MEASURE_DATE
                    , Query.SortDirection.DESCENDING);

    // Query
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    PreparedQuery pq = datastore.prepare(query);
    // Get results

    List<com.google.appengine.api.datastore.Entity> resultList = pq.asList(FetchOptions.Builder.withLimit(amountData));
    ArrayList<Medicion> result = new ArrayList<>();
    if (resultList.size()!=0) {
        mLogger.info("Watching " + resultList.size() + " last values of ESTADO");
        for (com.google.appengine.api.datastore.Entity item : resultList){
            result.add(new Medicion((Date) item.getProperty(PROPERTY_MEASURE_DATE), (String) item.getProperty(PROPERTY_AVISO), (String) item.getProperty(PROPERTY_AVISO_STATE), (String) item.getProperty(PREPERTY_AVISO_MAX_TODAY), (String) item.getProperty(PROPERTY_ESCENARIO_STATE_TODAY), (String) item.getProperty(PROPERTY_ESCENARIO_STATE_TOMORROW),  (String) item.getProperty(PROPERTY_ESCENARIO_STATE_TOMORROW_MANUAL) ,isPureMadrid()));
        }
    } else {
        // No hay datos
        mLogger.info("No previous values for ESTADO");
    }
    return result;
}
 
开发者ID:medialab-prado,项目名称:puremadrid,代码行数:37,代码来源:GetNewData.java

示例2: listRawEntity

import com.google.appengine.api.datastore.DatastoreService; //导入方法依赖的package包/类
public Iterable<Entity> listRawEntity(Query q, Boolean returnKeysOnly) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    if (returnKeysOnly) {
        q.setKeysOnly();
    }
    PreparedQuery pq = datastore.prepare(q);
    return pq.asIterable();
}
 
开发者ID:deniotokiari,项目名称:training-epam-2016,代码行数:9,代码来源:StoreServlet.java

示例3: timeZonesArray

import com.google.appengine.api.datastore.DatastoreService; //导入方法依赖的package包/类
public static ArrayList<TimeZone> timeZonesArray() {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Query q = new Query(TimeZone.DatastoreProperties.KIND.getName());
    q.addProjection(new PropertyProjection(TimeZone.DatastoreProperties.TIME_ZONE_ID.getName(), String.class));
    PreparedQuery pq = datastore.prepare(q);
    ArrayList<TimeZone> timeZones = new ArrayList<TimeZone>();
    for(Entity result : pq.asIterable())
        timeZones.add(new TimeZone(result));
    return timeZones;
}
 
开发者ID:kerafill1116,项目名称:apollo-datastore,代码行数:11,代码来源:JSTLFunctions.java

示例4: getSessionsByUserKey

import com.google.appengine.api.datastore.DatastoreService; //导入方法依赖的package包/类
public static ArrayList<Session> getSessionsByUserKey(DatastoreService datastore, Key userKey) {
    Filter userFilter = new FilterPredicate(DatastoreProperties.USER_KEY.getName(), FilterOperator.EQUAL, userKey);
    Query q = new Query(DatastoreProperties.KIND.getName());
    q.setFilter(userFilter);
    PreparedQuery pq = datastore.prepare(q);
    ArrayList<Session> sessions = new ArrayList<Session>();
    for(Entity result : pq.asIterable())
        sessions.add(new Session(result));
    return sessions;
}
 
开发者ID:kerafill1116,项目名称:apollo-datastore,代码行数:11,代码来源:SessionFactory.java

示例5: cleanDatastore

import com.google.appengine.api.datastore.DatastoreService; //导入方法依赖的package包/类
public static void cleanDatastore(DatastoreService ds, String book) {
  Query query = new Query("Greeting")
      .setAncestor(new KeyFactory.Builder("Guestbook", book)
          .getKey()).setKeysOnly();
  PreparedQuery pq = ds.prepare(query);
  List<Entity> entities = pq.asList(FetchOptions.Builder.withDefaults());
  ArrayList<Key> keys = new ArrayList<>(entities.size());

  for (Entity e : entities) {
    keys.add(e.getKey());
  }
  ds.delete(keys);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:14,代码来源:GuestbookTestUtilities.java

示例6: getTallestPeople

import com.google.appengine.api.datastore.DatastoreService; //导入方法依赖的package包/类
private List<Entity> getTallestPeople() {
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

  Query q = new Query("Person").addSort("height", SortDirection.DESCENDING);

  PreparedQuery pq = datastore.prepare(q);
  return pq.asList(FetchOptions.Builder.withLimit(5));
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:9,代码来源:QueriesTest.java

示例7: cleanDatastore

import com.google.appengine.api.datastore.DatastoreService; //导入方法依赖的package包/类
public static void cleanDatastore(DatastoreService ds, String book) {
  Query query =
      new Query("Greeting")
          .setAncestor(new KeyFactory.Builder("Guestbook", book).getKey())
          .setKeysOnly();
  PreparedQuery pq = ds.prepare(query);
  List<Entity> entities = pq.asList(FetchOptions.Builder.withDefaults());
  ArrayList<Key> keys = new ArrayList<>(entities.size());

  for (Entity e : entities) {
    keys.add(e.getKey());
  }
  ds.delete(keys);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:15,代码来源:GuestbookTestUtilities.java

示例8: getStatusAt

import com.google.appengine.api.datastore.DatastoreService; //导入方法依赖的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

示例9: getImpliedDominantAttributeFilter

import com.google.appengine.api.datastore.DatastoreService; //导入方法依赖的package包/类
/**
 * If there is no filter criteria on the dominant sort attribute, we need
 * to query the database to find the min/max value for the attribute and then
 * apply that to the query.  This is a work-around for broken GAE functionality.
 *
 * @return null if no records in table; otherwise, produce the needed filter.
 * @throws ODKDatastoreException
 */
private SimpleFilterTracker getImpliedDominantAttributeFilter() throws ODKDatastoreException {
  // GAE production throws an exception when a query with equality
  // filters and a sort on a column not constrained by any filter
  // is issued.
  //
  // To work around this, issue a query to return the current min/max
  // value of the dominant sort attribute and apply a GE/LE
  // constraint using that value. This is effectively a no-op,
  // but keeps GAE happy.
  //
  // this is the dominant sort:
  SortTracker dominantSort = sortList.get(0);
  DataField dominantSortAttr = dominantSort.getAttribute();
  SortDirection dominantSortDirection =
      dominantSort.direction.equals(Direction.ASCENDING)
      ? SortDirection.ASCENDING
      : SortDirection.DESCENDING;


  DatastoreService ds = datastore.getDatastoreService();
  EntityRowMapper m = new EntityRowMapper(relation, user);

  Query orderingHack = new com.google.appengine.api.datastore.Query(
      relation.getSchemaName() + "." + relation.getTableName());
  orderingHack.addSort(dominantSort.getAttribute().getName(), dominantSortDirection);

  PreparedQuery orderingPrep = ds.prepare(orderingHack);
  logger.debug("hqrLoop: finding min/max in " + relation.getSchemaName() + "."
      + relation.getTableName() + " of dominantSortAttr: " + dominantSortAttr.getName());

  List<com.google.appengine.api.datastore.Entity> values = orderingPrep
      .asList(FetchOptions.Builder.withDefaults().prefetchSize(1).chunkSize(20).limit(3));
  datastore.recordQueryUsage(relation, values.size());
  if (values == null || values.isEmpty()) {
    // the table is empty -- no need to go further...
    return null;
  }

  Object dominantFilterValue = null;
  // and apply the filter...
  try {
    CommonFieldsBase odkEntity = (CommonFieldsBase) m.mapRow(datastore, values.get(0), 0);
    dominantFilterValue = EngineUtils.getDominantSortAttributeValue(odkEntity, dominantSortAttr);
  } catch (SQLException e) {
    throw new ODKDatastoreException("[" + loggingContextTag + "] Unable to complete request", e);
  }

  SimpleFilterTracker impliedDominantFilter = constructFilter(dominantSortAttr,
      dominantSort.direction.equals(Direction.ASCENDING)
      ? FilterOperation.GREATER_THAN_OR_EQUAL
      : FilterOperation.LESS_THAN_OR_EQUAL, dominantFilterValue );

  return impliedDominantFilter;
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:63,代码来源:QueryImpl.java


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