Ejemplo n.º 1
0
  public Key store(Key orig, String type, long storeDate) {
    //		long start = System.currentTimeMillis();
    final int MAXSIZE = 1000000;
    Entity ent;
    Key next = null;
    this.storeTime = storeDate;
    this.nanoTime = System.nanoTime();

    byte[] data = this.serialize();
    Integer length = data.length;
    int pointer = 0;
    //		int counter = 0;
    while (length - pointer >= MAXSIZE) {
      // Expensive, should not be used too much!
      ent = new Entity(type + "_fragment");
      ent.setUnindexedProperty(
          "payload", new Blob(Arrays.copyOfRange(data, pointer, pointer + MAXSIZE)));
      if (next != null) ent.setUnindexedProperty("next", next);
      datastore.put(ent);
      //			counter++;
      next = ent.getKey();
      pointer += MAXSIZE;
    }

    if (orig != null) {
      System.err.println(
          "Warning, storing storable twice! Strange, should not happen with our immutable structures.");
      ent = new Entity(orig);
    } else {
      ent = new Entity(type);
    }
    ent.setUnindexedProperty("payload", new Blob(Arrays.copyOfRange(data, pointer, length)));
    if (next != null) ent.setUnindexedProperty("next", next);
    ent.setProperty("timestamp", this.storeTime);
    ent.setProperty("size", length);
    ent.setProperty("spread", this.spread);
    datastore.put(ent);
    //		counter++;
    myKey = ent.getKey();
    // Try to force index writing
    try {
      datastore.get(myKey);
    } catch (EntityNotFoundException e) {
    }
    this.storedSize = length;
    // System.out.println("Just stored shard of "+length+ " bytes in "+counter+" fragments  in
    // "+(System.currentTimeMillis()-start)+" ms");
    return myKey;
  }
Ejemplo n.º 2
0
  /**
   * This method is used for updating an existing entity. If the entity does not exist in the
   * datastore, an exception is thrown. It uses HTTP PUT method.
   *
   * @param store the entity to be updated.
   * @return The updated entity.
   * @throws UnauthorizedException
   */
  @ApiMethod(
      name = "modify",
      scopes = {Config.EMAIL_SCOPE},
      clientIds = {Config.CHROME_CLIENT_ID, Config.WEB_CLIENT_ID, Config.API_EXPLORER_CLIENT_ID})
  public ServiceResponse modify(
      @Named("_name") String _name, @Named("_id") Long _id, ServiceRequest req, User user)
      throws UnauthorizedException {
    if (user == null) {
      throw new UnauthorizedException("UnauthorizedException # User is Null.");
    }
    Key key = KeyFactory.createKey(_name, _id);
    Date currentDate = new Date();
    String userEmail = user.getEmail();

    DatastoreService dsService = DatastoreServiceFactory.getDatastoreService();
    ServiceResponse res = new ServiceResponse();
    try {
      Entity entity = dsService.get(key);

      entity.setProperty(_updatedAt, currentDate);
      entity.setProperty(_updatedBy, userEmail);

      entity.setUnindexedProperty(data, new Text(req.getData()));

      dsService.put(entity);

      res.set_id(entity.getKey().getId());
    } catch (com.google.appengine.api.datastore.EntityNotFoundException e) {
      throw new EntityNotFoundException("Object does not exist.");
    }

    return res;
  }
Ejemplo n.º 3
0
  /**
   * This inserts a new entity into App Engine datastore. If the entity already exists in the
   * datastore, an exception is thrown. It uses HTTP POST method.
   *
   * @param req the entity to be inserted.
   * @return The inserted entity.
   * @throws UnauthorizedException
   */
  @ApiMethod(
      name = "add",
      scopes = {Config.EMAIL_SCOPE},
      clientIds = {Config.CHROME_CLIENT_ID, Config.WEB_CLIENT_ID, Config.API_EXPLORER_CLIENT_ID})
  public ServiceResponse add(@Named("_name") String _name, ServiceRequest req, User user)
      throws UnauthorizedException {
    if (user == null) {
      throw new UnauthorizedException("UnauthorizedException # User is Null.");
    } else if (req == null || req.getData() == null) {
      return null;
    }

    String userEmail = user.getEmail();
    Date currentDate = new Date();

    DatastoreService dsService = DatastoreServiceFactory.getDatastoreService();
    Entity entity = new Entity(_name);

    entity.setProperty(_createdAt, currentDate);
    entity.setProperty(_createdBy, userEmail);

    entity.setProperty(_updatedAt, currentDate);
    entity.setProperty(_updatedBy, userEmail);

    entity.setProperty(_status, ACTIVE);
    entity.setUnindexedProperty(data, new Text(req.getData()));

    dsService.put(entity);

    ServiceResponse res = new ServiceResponse();
    res.set_id(entity.getKey().getId());

    return res;
  }
Ejemplo n.º 4
0
 @Override
 public com.google.appengine.api.datastore.Entity modelToEntity(java.lang.Object model) {
   cz.artique.shared.model.label.Label m = (cz.artique.shared.model.label.Label) model;
   com.google.appengine.api.datastore.Entity entity = null;
   if (m.getKey() != null) {
     entity = new com.google.appengine.api.datastore.Entity(m.getKey());
   } else {
     entity = new com.google.appengine.api.datastore.Entity(kind);
   }
   entity.setUnindexedProperty("appearance", serializableToBlob(m.getAppearance()));
   entity.setUnindexedProperty("backupLevel", enumToString(m.getBackupLevel()));
   entity.setProperty("labelType", enumToString(m.getLabelType()));
   entity.setProperty("name", m.getName());
   entity.setUnindexedProperty("priority", m.getPriority());
   entity.setProperty("userId", m.getUserId());
   entity.setProperty("version", m.getVersion());
   entity.setProperty("slim3.schemaVersion", 1);
   return entity;
 }
Ejemplo n.º 5
0
  public static void storeString(String id, String text) {
    Entity entity = getEntity(id);

    if (entity == null) entity = new Entity("storedString");
    // log.warning("store :"+id+" : "+entity.getKey());

    entity.setProperty("id", id);
    entity.setUnindexedProperty("string", new Text(text));
    datastore.put(entity);
    syncCache.put(id, entity);
  }
Ejemplo n.º 6
0
 private void setProperty(MimeMessage message, String name, Entity blog, boolean indexed)
     throws MessagingException, IOException {
   Object header = getHeader(message, name);
   if (header != null) {
     if (indexed) {
       blog.setProperty(name, header);
     } else {
       blog.setUnindexedProperty(name, header);
     }
   }
 }
Ejemplo n.º 7
0
 @Override
 public com.google.appengine.api.datastore.Entity modelToEntity(java.lang.Object model) {
   biz.storebiz.db.entity.customer.Customer m = (biz.storebiz.db.entity.customer.Customer) model;
   com.google.appengine.api.datastore.Entity entity = null;
   if (m.getCustomerKey() != null) {
     entity = new com.google.appengine.api.datastore.Entity(m.getCustomerKey());
   } else {
     entity = new com.google.appengine.api.datastore.Entity(kind);
   }
   entity.setProperty("creationDate", m.getCreationDate());
   entity.setProperty("customerId", m.getCustomerId());
   entity.setProperty("customerLastModificationDate", m.getCustomerLastModificationDate());
   entity.setProperty("customerRegistrationDate", m.getCustomerRegistrationDate());
   entity.setProperty("customerRegistrationExpiryDate", m.getCustomerRegistrationExpiryDate());
   entity.setProperty("customerType", m.getCustomerType());
   entity.setProperty("email", m.getEmail());
   entity.setUnindexedProperty("emailPreference", serializableToBlob(m.getEmailPreference()));
   entity.setUnindexedProperty("emailSubscription", serializableToBlob(m.getEmailSubscription()));
   entity.setProperty("name", m.getName());
   entity.setUnindexedProperty("password", serializableToBlob(m.getPassword()));
   entity.setProperty("postalAddresses", m.getPostalAddresses());
   return entity;
 }
Ejemplo n.º 8
0
  @Test
  public void test() {
    Entity parent = new Entity("Parent");
    // set parent properties...
    List<EmbeddedEntity> children = new ArrayList<EmbeddedEntity>();
    for (int i = 0; i < 5; i++) {
      EmbeddedEntity child = new EmbeddedEntity();
      // set child properties...
      children.add(child);
    }
    parent.setUnindexedProperty("children", children);
    parent.setUnindexedProperty("children2", list("tag1", "tag2", "tag3"));

    DatastoreServiceFactory.getDatastoreService().put(parent);

    try {
      Entity e = DatastoreServiceFactory.getDatastoreService().get(parent.getKey());
      e.getKey();
      Object children2 = e.getProperty("children2");
      assertTrue(children2 instanceof List);
    } catch (EntityNotFoundException e1) {
      e1.printStackTrace();
    }
  }
Ejemplo n.º 9
0
 public static Note createNewNote(
     Key tactKey, NoteValue noteValue, Long orderNumber, Accidental accid, NotePitch pitch) {
   Entity note = new Entity(Note.KIND);
   if (tactKey != null) {
     note.setProperty(Note.TACT_ID, tactKey.getId());
   }
   note.setProperty(NUMBER, orderNumber);
   note.setUnindexedProperty(Note.VALUE, noteValue.toString());
   note.setUnindexedProperty(Note.PITCH, pitch.toString());
   note.setUnindexedProperty(Note.DYNAMIC, Dynamic.f.toString());
   note.setUnindexedProperty(Note.ACCIDENTAL, accid.toString());
   note.setUnindexedProperty(Note.TRIOLA, false);
   note.setUnindexedProperty(Note.WITH_DOT, false);
   note.setUnindexedProperty(Note.AKCENT, false);
   note.setUnindexedProperty(TO_REMOVE, false);
   DataStoreWrapper.save(note);
   return new Note(note);
 }
Ejemplo n.º 10
0
 /**
  * Set an unindexed UUID property to an entity.
  *
  * @param entity the entity to add the UUID to
  * @param propertyName name of the property
  * @param uuid the UUID to add to the entity
  */
 public static void setUnindexedProperty(Entity entity, String propertyName, UUID uuid) {
   if (uuid != null) {
     entity.setUnindexedProperty(propertyName, uuid.toString());
   }
 }
Ejemplo n.º 11
0
 /**
  * Set an unindexed property which has a IIdStore
  *
  * @param entity the entity to set the property in
  * @param propertyName name of the property
  * @param idObject object which has an id
  */
 public static void setUnindexedProperty(Entity entity, String propertyName, IIdStore idObject) {
   if (idObject != null) {
     entity.setUnindexedProperty(propertyName, idObject.toId());
   }
 }
Ejemplo n.º 12
0
 /**
  * Set an unindexed property to an entity, but only if it's not null
  *
  * @param entity the entity to set the property in
  * @param propertyName name of the property
  * @param value the object to set as the property value. If null this method does nothing.
  */
 public static void setUnindexedProperty(Entity entity, String propertyName, Object value) {
   if (value != null) {
     entity.setUnindexedProperty(propertyName, value);
   }
 }