Package com.orientechnologies.orient.core.record.impl

Examples of com.orientechnologies.orient.core.record.impl.ORecordBytes


      for (int i = 0; i < count; i++) {
        doc.reset();
        doc.setClassName("Chunk");
        doc.field("hash", "key" + Integer.toString(i));
        doc.field("binary", new ORecordBytes(database, data));
        doc.save();

        ORID rid = doc.getIdentity();
        if (i % 100 == 0)
          System.out.println("ORID=" + rid);
View Full Code Here


        OIdentifiable result = (OIdentifiable) index.get("key" + Integer.toString(rand));
        Assert.assertNotNull(result);

        ODocument doc = (ODocument) result.getRecord();
        System.out.println("loaded " + i + "(" + rand + "), binary record: " + doc.field("binary", ORID.class));
        ORecordBytes record = doc.field("binary");
        Assert.assertNotNull(record);
        if (record != null) {
          byte[] data = record.toStream();
          Assert.assertTrue(data.length == size);
        }

        if (i % 100 == 0)
          System.out.println("loaded " + i);
View Full Code Here

    database.begin(TXTYPE.NOTX);
  }

  @Override
  public void cycle() {
    record = new ORecordBytes(database, payload);
    record.save();

    if (data.getCyclesDone() == data.getCycles() - 1)
      database.commit();
  }
View Full Code Here

  @Override
  public void init() {
    Orient.instance().getProfiler().startRecording();

    database = new ODatabaseFlat(System.getProperty("url")).open("admin", "admin");
    record = new ORecordBytes();

    database.declareIntent(new OIntentMassiveInsert());
    database.begin(TXTYPE.NOTX);
    Random rnd = new Random();
    recordContent = new byte[RECORD_SIZE];
View Full Code Here

    ODocument testDocument = new ODocument();
    testDocument.field("testField", "testValue");

    p.setDocument(testDocument);

    ORecordBytes testRecordBytes = new ORecordBytes(
        "this is a bytearray test. if you read this Object database has stored it correctly".getBytes());

    p.setByteArray(testRecordBytes);

    database.save(p);

    ORID rid = database.getRecordByUserObject(p, false).getIdentity();

    database.close();

    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    JavaComplexTestClass loaded = database.load(rid);

    Assert.assertTrue(loaded.getByteArray() instanceof ORecordBytes);
    try {
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      try {
        loaded.getByteArray().toOutputStream(out);
        Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctly".getBytes(),
            out.toByteArray());
        Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctly",
            new String(out.toByteArray()));
      } finally {
        out.close();
      }
    } catch (IOException ioe) {
      Assert.assertTrue(false);
      OLogManager.instance().error(this, "Error reading byte[]", ioe);
    }
    Assert.assertTrue(loaded.getDocument() instanceof ODocument);
    Assert.assertEquals("testValue", loaded.getDocument().field("testField"));
    Assert.assertTrue(loaded.getDocument().getIdentity().isPersistent());

    Assert.assertTrue(loaded.getEmbeddedDocument() instanceof ODocument);
    Assert.assertEquals("testEmbeddedValue", loaded.getEmbeddedDocument().field("testEmbeddedField"));
    Assert.assertFalse(loaded.getEmbeddedDocument().getIdentity().isValid());

    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    p = database.newInstance(JavaComplexTestClass.class);
    byte[] thumbnailImageBytes = "this is a bytearray test. if you read this Object database has stored it correctlyVERSION2"
        .getBytes();
    ORecordBytes oRecordBytes = new ORecordBytes(database.getUnderlying(), thumbnailImageBytes);
    oRecordBytes.save();
    p.setByteArray(oRecordBytes);
    p = database.save(p);
    Assert.assertTrue(p.getByteArray() instanceof ORecordBytes);
    try {
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      try {
        p.getByteArray().toOutputStream(out);
        Assert.assertEquals(
            "this is a bytearray test. if you read this Object database has stored it correctlyVERSION2".getBytes(),
            out.toByteArray());
        Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctlyVERSION2",
            new String(out.toByteArray()));
      } finally {
        out.close();
      }
    } catch (IOException ioe) {
      Assert.assertTrue(false);
      OLogManager.instance().error(this, "Error reading byte[]", ioe);
    }
    rid = database.getIdentity(p);

    database.close();

    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    loaded = database.load(rid);

    Assert.assertTrue(loaded.getByteArray() instanceof ORecordBytes);
    try {
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      try {
        loaded.getByteArray().toOutputStream(out);
        Assert.assertEquals(
            "this is a bytearray test. if you read this Object database has stored it correctlyVERSION2".getBytes(),
            out.toByteArray());
        Assert.assertEquals("this is a bytearray test. if you read this Object database has stored it correctlyVERSION2",
            new String(out.toByteArray()));
      } finally {
        out.close();
      }
    } catch (IOException ioe) {
      Assert.assertTrue(false);
      OLogManager.instance().error(this, "Error reading byte[]", ioe);
    }
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    p = new JavaComplexTestClass();
    thumbnailImageBytes = "this is a bytearray test. if you read this Object database has stored it correctlyVERSION2".getBytes();
    oRecordBytes = new ORecordBytes(database.getUnderlying(), thumbnailImageBytes);
    oRecordBytes.save();
    p.setByteArray(oRecordBytes);
    p = database.save(p);
    Assert.assertTrue(p.getByteArray() instanceof ORecordBytes);
    try {
      ByteArrayOutputStream out = new ByteArrayOutputStream();
View Full Code Here

  @Test(dependsOnMethods = "oidentifableFieldsTest")
  public void oRecordBytesFieldsTest() {
    try {
      OObjectIteratorClass<JavaComplexTestClass> browseClass = database.browseClass(JavaComplexTestClass.class);
      for (JavaComplexTestClass ebookPropertyItem : browseClass) {
        ORecordBytes coverThumbnail = ebookPropertyItem.getByteArray(); // The IllegalArgumentException is thrown here.
      }
    } catch (IllegalArgumentException iae) {
      Assert.fail("ORecordBytes field getter should not throw this exception", iae);
    }
  }
View Full Code Here

  }

  @Test(dependsOnMethods = "testAddingORecordBytesAfterParentCreation")
  public void testObjectDelete() {
    Media media = new Media();
    ORecordBytes testRecord = new ORecordBytes("This is a test".getBytes());
    media.setContent(testRecord);
    media = database.save(media);

    Assert.assertEquals(new String(media.getContent().toStream()), "This is a test");
View Full Code Here

  }

  @Test(dependsOnMethods = "testObjectDelete")
  public void testOrphanDelete() {
    Media media = new Media();
    ORecordBytes testRecord = new ORecordBytes("This is a test".getBytes());
    media.setContent(testRecord);
    media = database.save(media);

    Assert.assertEquals(new String(media.getContent().toStream()), "This is a test");
View Full Code Here

      }
      final List<ORID> chunkRids = new ArrayList<ORID>(totalChunks);

      // Make only one ORecordBytes instance and reuse it for every chunk,
      // to reduce heap garbage.
      final ORecordBytes chunk = new ORecordBytes();

      // Handle the full chunks.
      for (int page = 0; page < fullChunks; page++) {
        // Read a full chunk of data from the file into a buffer.
        bufferedBytes = 0;
        while (bufferedBytes < buffer.length) {
          final int bytesRead = in.read(buffer, bufferedBytes, buffer.length - bufferedBytes);
          if (bytesRead == -1) {
            throw new Exception("Reached end of file prematurely. (File changed while reading?) fileName=" + file.getAbsolutePath());
          }
          bufferedBytes += bytesRead;
        }

        // Save the chunk to the database.
        final long saveStartTime = System.currentTimeMillis();
        chunk.reset(buffer);
        chunk.save();
        final long saveMs = System.currentTimeMillis() - saveStartTime;

        // Log the amount of time taken by the save.
        System.out.printf("Saved chunk %d in %d ms.\n", page, saveMs);

        // Save the chunk's record ID in the list.
        // Have to copy() the ORID or else every chunk in the list gets the same last ORID.
        // This is because we are using the chunk.reset(); approach to reduce garbage objects.
        chunkRids.add(chunk.getIdentity().copy());

        // Only report progress if it has changed.
        final byte percent = (byte) ((page + 1) * 100 / totalChunks);
        if (percent > currentPercent) {
          System.out.printf("Progress: %d%%\n", percent);
          currentPercent = percent;
        }
      }

      // Handle the final partial chunk (if any).
      if (fullChunks < totalChunks) {
        final int remainder = (int) (fileSize - fullChunksSize);
        // Read the remaining data from the file into a buffer.
        bufferedBytes = 0;
        while (bufferedBytes < remainder) {
          final int bytesRead = in.read(buffer, bufferedBytes, remainder - bufferedBytes);
          if (bytesRead == -1) {
            throw new Exception("Reached end of file prematurely. (File changed while reading?) fileName=" + file.getAbsolutePath());
          }
          bufferedBytes += bytesRead;
        }

        // Save the chunk to the database.
        final long saveStartTime = System.currentTimeMillis();
        chunk.reset(Arrays.copyOf(buffer, remainder));
        chunk.save();
        final long saveMs = System.currentTimeMillis() - saveStartTime;

        // Log the amount of time taken by the save.
        System.out.printf("Saved partial chunk %d in %d ms.\n", fullChunks, saveMs);

        // Save the chunk's record ID in the list.
        chunkRids.add(chunk.getIdentity());
      }

      // Should be no more data, so validate this.
      final int b = in.read();
      if (b != -1) {
View Full Code Here

  public ORecordBytes getContent() {
    return content;
  }

  public void setContent(ORecordBytes content) {
    ORecordBytes current = this.getContent();
    this.content = content;
    if (current != null)
      current.getRecord().delete();
  }
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.record.impl.ORecordBytes

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.