Package info.bliki.gae.db

Source Code of info.bliki.gae.db.PropertyService

package info.bliki.gae.db;

import info.bliki.gae.model.PropertyEntity;

import java.util.Enumeration;
import java.util.Properties;

import org.jamwiki.model.OS;

import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.QueryResultIterable;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.Query;

public class PropertyService {

  public static PropertyEntity save(PropertyEntity page) {
    Objectify ofy = OS.begin();
    ofy.put(page);
    return page;
  }

  public static void delete(PropertyEntity property) {
    Objectify ofy = OS.begin();
    ofy.delete(property);
  }

  public static PropertyEntity findByKey(String key) {
    try {
      Objectify ofy = OS.begin();
      return ofy.get(PropertyEntity.class, key);
    } catch (EntityNotFoundException enf) {
    }
    return null;
  }

  public static QueryResultIterable<PropertyEntity> getAll() {
    Objectify ofy = OS.begin();
    Query<PropertyEntity> q = ofy.query(PropertyEntity.class);
    return q;
  }

  public static void saveAll(Properties properties) {
    PropertyEntity page;
    Objectify ofy = OS.begin();

    Enumeration<Object> keyEnum = properties.keys();
    while (keyEnum.hasMoreElements()) {
      String key = (String) keyEnum.nextElement();
      String value = (String) properties.get(key.toString());
      if (value != null) {
        page = new PropertyEntity(key, value);
        ofy.put(page);
      }
    }
  }
}
TOP

Related Classes of info.bliki.gae.db.PropertyService

TOP
Copyright © 2018 www.massapi.com. 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.