Package com.google.appengine.api.datastore

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


    public static void index() {
      Employee emp = new Employee();
      emp.firstName = "alpha";
      emp.lastName = "beta";
      emp.blob = new Blob(new byte[] { 0x00, 0x01 });
     
      emp.insert();
      try {
        Logger.info("blob:%d %d", emp.blob.getBytes()[0], emp.blob.getBytes()[1]);
      }catch(Exception ex){}
View Full Code Here


        for(Upload upload : uploads) {
            if(upload.getFieldName().equals(value)) {
              byte[] data = upload.asBytes();
             
              if(data.length > 0)
                return new Blob(data);
            }
        }
        return Binder.MISSING;
    }
View Full Code Here

  public static class ProtocolBufferSerializationStrategy implements SerializationStrategy {

    public Blob serialize(Object obj) {
      ProtocolMessage<?> pb = (ProtocolMessage<?>) obj;
      return new Blob(pb.toByteArray());
    }
View Full Code Here

                     ((ShortBlob) e.getProperty("byteSet")).getBytes())));
    assertEquals(new ShortBlob("byte collection".getBytes()), e.getProperty("byteCollection"));
    assertEquals(1L, e.getProperty("onePrimByte"));
    assertEquals(2L, e.getProperty("oneByte"));
    assertEquals(new ShortBlob("short blob".getBytes()), e.getProperty("shortBlob"));
    assertEquals(new Blob("serialized prim bytes".getBytes()), e.getProperty("serializedPrimBytes"));
    assertEquals(new Blob("serialized bytes".getBytes()), e.getProperty("serializedBytes"));
    assertEquals(SS.serialize(PrimitiveArrays.asList("serialized byte list".getBytes())),
                 e.getProperty("serializedByteList"));
    assertEquals(SS.serialize(new HashSet<Byte>(PrimitiveArrays.asList(
        "serialized byte set".getBytes()))), e.getProperty("serializedByteSet"));
  }
View Full Code Here

    e.setProperty("byteSet", new ShortBlob("byte set".getBytes()));
    e.setProperty("byteCollection", new ShortBlob("byte collection".getBytes()));
    e.setProperty("onePrimByte", 1L);
    e.setProperty("oneByte", 2L);
    e.setProperty("shortBlob", new ShortBlob("short blob".getBytes()));
    e.setProperty("serializedPrimBytes", new Blob("serialized prim bytes".getBytes()));
    e.setProperty("serializedBytes", new Blob("serialized bytes".getBytes()));
    e.setProperty("serializedByteList", SS.serialize(PrimitiveArrays.asList("serialized byte list".getBytes())));
    e.setProperty("serializedByteSet", SS.serialize(new HashSet<Byte>(PrimitiveArrays.asList("serialized byte set".getBytes()))));

    ds.put(e);

    beginTxn();
    HasBytesJPA pojo = em.find(HasBytesJPA.class, e.getKey());
    assertTrue(Arrays.equals("prim bytes".getBytes(), pojo.getPrimBytes()));
    assertEquals(PrimitiveArrays.asList("bytes".getBytes()), Arrays.asList(pojo.getBytes()));
    assertEquals(PrimitiveArrays.asList("byte list".getBytes()), pojo.getByteList());
    assertEquals(new HashSet<Byte>(PrimitiveArrays.asList("byte set".getBytes())), pojo.getByteSet());
    assertEquals(PrimitiveArrays.asList("byte collection".getBytes()), pojo.getByteCollection());
    assertEquals(Integer.valueOf(1).byteValue(), pojo.getOnePrimByte());
    assertEquals(Integer.valueOf(2).byteValue(), pojo.getOneByte().byteValue());
    assertEquals(new ShortBlob("short blob".getBytes()), pojo.getShortBlob());
    assertEquals(new Blob("serialized prim bytes".getBytes()), new Blob(pojo.getSerializedPrimBytes()));
    assertEquals(new Blob("serialized bytes".getBytes()),
                 new Blob(PrimitiveArrays.toByteArray(Arrays.asList(pojo.getSerializedBytes()))));
    assertEquals(PrimitiveArrays.asList("serialized byte list".getBytes()),
                 pojo.getSerializedByteList());
    assertEquals(new HashSet<Byte>(PrimitiveArrays.asList("serialized byte set".getBytes())),
                 pojo.getSerializedByteSet());
    commitTxn();
View Full Code Here

  public void testInsert() throws EntityNotFoundException, IllegalAccessException {
    HasUnindexedPropertiesJDO pojo = new HasUnindexedPropertiesJDO();
    pojo.setUnindexedString("str");
    pojo.setUnindexedList(Utils.newArrayList("a", "b", "c"));
    pojo.setUnindexedText(new Text("unindexed text"));
    pojo.setUnindexedBlob(new Blob("unindexed blob".getBytes()));
    pojo.setText(new Text("text"));
    pojo.setBlob(new Blob("blob".getBytes()));

    beginTxn();
    pm.makePersistent(pojo);
    commitTxn();
View Full Code Here

      return privateKeyBytes.getBytes();
    }
  }

  public void setPrivateKeyBytes(byte[] privateKeyBytes) {
    this.privateKeyBytes = new Blob(privateKeyBytes);
  }
View Full Code Here

    pm.makePersistent(hasSerializable);
    commitTxn();

    SerializationStrategy ss = SerializationManager.DEFAULT_SERIALIZATION_STRATEGY;
    Entity e = ds.get(TestUtils.createKey(hasSerializable, hasSerializable.getId()));
    Blob yamBlob = (Blob) e.getProperty("yam");
    assertNotNull(yamBlob);
    HasSerializableJDO.Yam reloadedYam = (HasSerializableJDO.Yam)
        ss.deserialize(yamBlob, HasSerializableJDO.Yam.class);
    assertEquals(yam.getStr1(), reloadedYam.getStr1());
    assertEquals(yam.getStr2(), reloadedYam.getStr2());
    Blob yamListBlob = (Blob) e.getProperty("yamList");
    List<HasSerializableJDO.Yam> reloadedYamList = (List<HasSerializableJDO.Yam>)
        ss.deserialize(yamListBlob, List.class);
    assertEquals(1, reloadedYamList.size());
    reloadedYam = reloadedYamList.get(0);
    assertEquals(yam.getStr1(), reloadedYam.getStr1());
    assertEquals(yam.getStr2(), reloadedYam.getStr2());
    Blob queryBlob = (Blob) e.getProperty("query");
    assertNotNull(queryBlob);
    DatastorePb.Query reloadedQuery = (DatastorePb.Query)
        new HasSerializableJDO.ProtocolBufferSerializationStrategy().deserialize(queryBlob, DatastorePb.Query.class);
    assertEquals(query.getApp(), reloadedQuery.getApp());
    assertEquals(query.getKind(), reloadedQuery.getKind());
    Blob integerBlob = (Blob) e.getProperty("integer");
    assertEquals(Integer.valueOf(3), ss.deserialize(integerBlob, Integer.class));
    Blob flightBlob = (Blob) e.getProperty("flight");
    Flight f2 = (Flight) ss.deserialize(flightBlob, Flight.class);
    assertEquals(f.getDest(), f2.getDest());
    assertEquals(f.getOrigin(), f2.getOrigin());
  }
View Full Code Here

*/
public class SerializationManagerTest extends TestCase {

  public void testDeserialize_NonObjectBytes() {
    try {
      SerializationManager.DEFAULT_SERIALIZATION_STRATEGY.deserialize(new Blob("yar".getBytes()), getClass());
      fail("Expcted NucleusException");
    } catch (NucleusException ne) {
      // good
    }
  }
View Full Code Here

  public static final class MySerializable1 implements Serializable {}
  public static final class MySerializable2 implements Serializable {}

  public void testDeserialize_BytesAreOfWrongType() {
    MySerializable1 ser1 = new MySerializable1();
    Blob ser1Blob = SerializationManager.DEFAULT_SERIALIZATION_STRATEGY.serialize(ser1);
    try {
      SerializationManager.DEFAULT_SERIALIZATION_STRATEGY.deserialize(ser1Blob, MySerializable2.class);
      fail("Expcted NucleusException");
    } catch (NucleusException ne) {
      // good
View Full Code Here

TOP

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

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.