Examples of ORecordBytes


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

      }
    } else
      keySerializer = new OSimpleKeySerializer();

    final ODatabaseRecordInternal database = getDatabase();
    final ORecordBytes identityRecord = new ORecordBytes();
    final OAbstractPaginatedStorage storageLocalAbstract = (OAbstractPaginatedStorage) database.getStorage();

    database.save(identityRecord, clusterIndexName);
    identity = identityRecord.getIdentity();

    hashFunction.setValueSerializer(keySerializer);
    hashTable.create(indexName, keySerializer, (OBinarySerializer<V>) valueSerializer,
        indexDefinition != null ? indexDefinition.getTypes() : null, storageLocalAbstract, indexDefinition != null
            && !indexDefinition.isNullValuesIgnored());
View Full Code Here

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

    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

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

  @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

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

  }

  @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

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

  }

  @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

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

    long rec = database.countClusterElements("binary");

    database.begin();

    ORecordBytes recordBytes = new ORecordBytes("This is the first version".getBytes());
    recordBytes.save("binary");

    database.rollback();

    Assert.assertEquals(database.countClusterElements("binary"), rec);
  }
View Full Code Here

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

    long tot = database.countClusterElements("binary");

    database.begin();

    ORecordBytes recordBytes = new ORecordBytes("This is the first version".getBytes());
    recordBytes.save("binary");

    database.commit();

    Assert.assertEquals(database.countClusterElements("binary"), tot + 1);
  }
View Full Code Here

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

    ODatabaseDocumentTx db2 = new ODatabaseDocumentTx(database.getURL());
    db2.open("admin", "admin");

    ODatabaseRecordThreadLocal.INSTANCE.set(database);
    ORecordBytes record1 = new ORecordBytes("This is the first version".getBytes());
    record1.save("binary");

    try {
      database.begin();

      // RE-READ THE RECORD
      record1.load();

      ODatabaseRecordThreadLocal.INSTANCE.set(db2);
      ORecordBytes record2 = db2.load(record1.getIdentity());

      record2.setDirty();
      record2.fromStream("This is the second version".getBytes());
      record2.save();

      ODatabaseRecordThreadLocal.INSTANCE.set(database);
      record1.setDirty();
      record1.fromStream("This is the third version".getBytes());
      record1.save();
View Full Code Here

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

  @Test(dependsOnMethods = "testTransactionOptimisticConcurrentException")
  public void testTransactionOptimisticCacheMgmt1Db() throws IOException {
    if (database.getClusterIdByName("binary") == -1)
      database.addCluster("binary");

    ORecordBytes record = new ORecordBytes("This is the first version".getBytes());
    record.save();

    try {
      database.begin();

      // RE-READ THE RECORD
      record.load();
      int v1 = record.getRecordVersion().getCounter();
      record.setDirty();
      record.fromStream("This is the second version".getBytes());
      record.save();
      database.commit();

      record.reload();
      Assert.assertEquals(record.getRecordVersion().getCounter(), v1 + 1);
      Assert.assertTrue(new String(record.toStream()).contains("second"));
    } finally {
      database.close();
    }
  }
View Full Code Here

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

      database.addCluster("binary");

    ODatabaseDocumentTx db2 = new ODatabaseDocumentTx(database.getURL());
    db2.open("admin", "admin");

    ORecordBytes record1 = new ORecordBytes("This is the first version".getBytes());
    record1.save();

    try {
      ODatabaseRecordThreadLocal.INSTANCE.set(database);
      database.begin();

      // RE-READ THE RECORD
      record1.load();
      int v1 = record1.getRecordVersion().getCounter();
      record1.setDirty();
      record1.fromStream("This is the second version".getBytes());
      record1.save();

      database.commit();

      ODatabaseRecordThreadLocal.INSTANCE.set(db2);

      ORecordBytes record2 = db2.load(record1.getIdentity(), "*:-1", true);
      Assert.assertEquals(record2.getRecordVersion().getCounter(), v1 + 1);
      Assert.assertTrue(new String(record2.toStream()).contains("second"));

    } finally {

      database.close();
      db2.close();
View Full Code Here
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.