Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.DatastoreService


            HttpServletResponse resp)
          throws IOException {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
        Key userKey = KeyFactory.createKey("UserPrefs", user.getUserId());
        Entity userPrefs = new Entity(userKey);

        MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
        String cacheKey = "UserPrefs:" + user.getUserId();

        try {
            int tzOffset = new Integer(req.getParameter("tz_offset")).intValue();

            userPrefs.setProperty("tz_offset", tzOffset);
            userPrefs.setProperty("user", user);
            ds.put(userPrefs);
            memcache.delete(cacheKey);

        } catch (NumberFormatException nfe) {
            // User entered a value that wasn't an integer. Ignore for now.
        }
View Full Code Here


  }

  private String checkAndGetCompletedBackupGSHandle(String backupName) throws IOException {
    log.warning("backupName: " + backupName);
   
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
   
    Query q = new Query("_AE_Backup_Information");
   
    // for some reason the datastore admin code appends the date to the backup name even when creating programatically,
    // so test for greater than or equal to and then take the first result
    FilterPredicate greater = new FilterPredicate("name", FilterOperator.GREATER_THAN_OR_EQUAL, backupName);
    FilterPredicate less = new FilterPredicate("name", FilterOperator.LESS_THAN_OR_EQUAL, backupName + "Z");
    List<Query.Filter> filters = new ArrayList<Query.Filter>();
    filters.add(greater);
    filters.add(less);
    CompositeFilter comp = new CompositeFilter(CompositeFilterOperator.AND, filters);
    q.setFilter(comp);
   
    PreparedQuery pq = datastore.prepare(q);
    List<Entity> results = pq.asList(FetchOptions.Builder.withLimit(1));
    if (results.size() != 1 || !results.get(0).getProperty("name").toString().contains(backupName)) {
      System.err.println("BuiltinDatatoreToBigqueryIngesterTask: can't find backupName: " + backupName);
    }
    Entity result = results.get(0);
View Full Code Here

                    + (getMaxInactiveIntervalSeconds(session) * 1000));
            Expiration expires = Expiration.onDate(expire);

            memcache.put(id, bytes, expires);

            DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
            Entity entity = new Entity(AC_BASE, id);
            entity.setProperty(PROPERTY_EXPIRES, expire.getTime());
            entity.setProperty(PROPERTY_DATA, new Blob(bytes));
            ds.put(entity);

        } catch (DeadlineExceededException e) {
            getLogger().log(Level.WARNING, "DeadlineExceeded for {0}",
                    session.getId());
            sendDeadlineExceededNotification(request, response);
View Full Code Here

  private static final String ACCESS_KEY_FIELD = "ApiKey";

  private final Logger logger = Logger.getLogger(getClass().getName());

  public void contextInitialized(ServletContextEvent event) {
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key key = KeyFactory.createKey(ENTITY_KIND, ENTITY_KEY);

    Entity entity;
    try {
      entity = datastore.get(key);
    } catch (EntityNotFoundException e) {
      entity = new Entity(key);
      // NOTE: it's not possible to change entities in the local server, so
      // it will be necessary to hardcode the API key below if you are running
      // it locally.
      entity.setProperty(ACCESS_KEY_FIELD,
          "replace_this_text_by_your_Simple_API_Access_key");
      datastore.put(entity);
      logger.severe("Created fake key. Please go to App Engine admin "
          + "console, change its value to your API Key (the entity "
          + "type is '" + ENTITY_KIND + "' and its field to be changed is '"
          + ACCESS_KEY_FIELD + "'), then restart the server!");
    }
View Full Code Here

      entity.removeProperty((String) keyList.get(index));

      list.add(entity);

    }
    DatastoreService service = DatastoreServiceFactory.getDatastoreService();
    service.put(list);

    Queue queue = QueueFactory.getDefaultQueue();
    // Call the next chain.
    queue.add(TaskOptions.Builder.url(request.getRequestURI()).param(
      "count",
View Full Code Here

   * Gets or creates an empty CounterNamesShard with the given key
   * @param key
   * @return - the stored entity, or a newly stored entity
   */
  public static Entity getOrInsertCounterNamesShard(Key key) {
    DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
   
    try {
      Entity entity = datastoreService.get(key);
      _logger.info("Got entity: " + entity);
      return entity;
    } catch (EntityNotFoundException e) {
      //if the entity doesn't exist, create it
      _logger.info("Entity doesn't exist, creating and inserting");
      Entity entity = new Entity(key);
     
      entity.setUnindexedProperty("names", new ArrayList<String>());
      entity.setProperty("timestamp", new Date());
     
      datastoreService.put(entity);
     
      return entity;
    }
  }
View Full Code Here

  public static ResultType addNames(long id, Set<String> names) {
    Key key = KeyFactory.createKey("CounterNamesShard", id);
   
    _logger.info("Key to add names for: " + key);
   
    DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();

    Transaction txn = datastoreService.beginTransaction();
   
    try {
      Entity entity = datastoreService.get(txn, key);
     
      @SuppressWarnings("unchecked")
      List<String> localNames = (List<String>) entity.getProperty("names");
     
      if (null == localNames) {
        _logger.info("names property is null. Creating new names property list");
        localNames = new ArrayList<String>();
      }
     
      Set<String> localNamesSet = new HashSet<String>(localNames);
      for (String name : names) {
        if (!localNamesSet.contains(name)) {
          localNamesSet.add(name);
        }
      }
     
      localNames = new ArrayList<String>(localNamesSet);
     
      try {
        entity.setProperty("names", localNames);
       
        datastoreService.put(txn, entity);
       
        txn.commit();

        return ResultType.ADD_SUCCESS;
      } catch (Exception e) {
View Full Code Here

    NamespaceManager.set(NAMESPACE);
   
    try { //put in a try so that we can have a finally block which resets namespaces
      Key key = KeyFactory.createKey("AuthKey", "master");
     
      DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
     
      // look for the auth key in the datastore
      Entity authEntity = null;
      try {
        authEntity = datastoreService.get(key);
      } catch (EntityNotFoundException e) {
        _logger.info("Authentication entity not found");
        authEntity = null;
      }
     
      if (null != updateAuth) {
        //if were updating the auth
        if (null == authEntity || !authEntity.getProperty("secret").equals(updateAuth)) {
          //if there is no auth key, or the auth key doesn't match the one provided
          try {
            URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
            HTTPResponse response = fetchService.fetch(new URL(SECURE_HOST + "/auth/?site=" + req.getHeader("Host") + "&auth=" + updateAuth));
           
            if (response.getResponseCode() == 200) {
              //if successfully received a response, save the new auth key
              String content = new String(response.getContent());
              if (content.equals(new String("OK"))) {
                authEntity = new Entity(key);
                authEntity.setProperty("secret", updateAuth);
               
                datastoreService.put(authEntity);
              }
            }
          } catch (Exception e) {
            _logger.severe("Exception while updating key: " + e);
            return null;
View Full Code Here

  @Test
  public void runFirstTimeTest() throws Exception {

    List<Entity> bulkData = TestDataUtil.bulkData("TestKind1", 5);
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    datastore.put(bulkData);

    String[] kinds = { "TestKind1" };
    SpreadsheetEntry ssEntry = SpreadsheetUtil.createBlunkSpreadsheet(authSubToken, kinds);
    try {
      ControllerTester tester = new ControllerTester();
View Full Code Here

  @Test
  public void runWithDataTest() throws Exception {

    List<Entity> bulkData = TestDataUtil.bulkData("TestKind1", 10);
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    datastore.put(bulkData);

    String[] kinds = { "TestKind1" };
    SpreadsheetEntry ssEntry = SpreadsheetUtil.createSpreadsheet(authSubToken, kinds);

    try {
View Full Code Here

TOP

Related Classes of com.google.appengine.api.datastore.DatastoreService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.