0

我有 Datastore 类,我使用这个类来尝试 GCM 。我不明白数据的保存位置(注册 ID),但我可以在重新启动我的 IDE(Eclipse)后检索它

谢谢朋友

private static final DatastoreService datastore =
    DatastoreServiceFactory.getDatastoreService();

private Datastore() {
  throw new UnsupportedOperationException();
}

/**
 * Registers a device.
 *
 * @param regId device's registration id.
 */

public static void register(String regId) {
  logger.info("Registering " + regId);
  Transaction txn = datastore.beginTransaction();
  try {
    Entity entity = findDeviceByRegId(regId);
    if (entity != null) {
      logger.fine(regId + " is already registered; ignoring.");
      return;
    }
    entity = new Entity(DEVICE_TYPE);
    entity.setProperty(DEVICE_REG_ID_PROPERTY, regId);
    datastore.put(entity);
    txn.commit();
    } finally {
    if (txn.isActive()) {
      txn.rollback();
    }
  }
}

/**
 * Gets all registered devices.
 */

public static List<String> getDevices() {
  List<String> devices;
  Transaction txn = datastore.beginTransaction();
  try {
    Query query = new Query(DEVICE_TYPE);
    Iterable<Entity> entities =
        datastore.prepare(query).asIterable(DEFAULT_FETCH_OPTIONS);
    devices = new ArrayList<String>();
    for (Entity entity : entities) {
      String device = (String) entity.getProperty(DEVICE_REG_ID_PROPERTY);
      devices.add(device);
    }
    txn.commit();
  } finally {
    if (txn.isActive()) {
      txn.rollback();
    }
  }
  return devices;
}
4

1 回答 1

0

当您在生产服务器中时,数据存储在 GAE 数据存储中,或者当您在本地开发环境中时,数据存储在本地文件中 ( https://appengine.google.com/ --> application --> Datastore Indexes)。在任何情况下,您都可以从管理控制台查看您的应用程序中存储了哪些数据。对于开发环境,您可以查看

localhost:8888/_ah/admin(来自您的浏览器)

于 2012-12-29T16:50:42.140 回答