Examples of ODocument


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

    List<ODocument> result = database.getUnderlying()
        .command(new OSQLSynchQuery<ODocument>("select * from Profile where name = 'Barack' and surname = 'Obama'")).execute();
    int i = 0;
    for (ODocument doc : result) {
      String jsonFull = doc.toJSON("type,rid,version,class,attribSameRow,indent:0,fetchPlan:*:-1");
      ODocument loadedDoc = new ODocument().fromJSON(jsonFull);

      Assert.assertTrue(doc.hasSameContentOf(loadedDoc));
      i++;
    }
  }
View Full Code Here

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

        if (o != null) {
          fieldTypeToString(iOutput, iDatabase, OType.STRING, o.getKey());
          iOutput.append(OStringSerializerHelper.ENTRY_SEPARATOR);

          if (o.getValue() instanceof ORecord<?>) {
            final ODocument record;
            if (o.getValue() instanceof ODocument)
              record = (ODocument) o.getValue();
            else
              record = OObjectSerializerHelper.toStream(o.getValue(), new ODocument((ODatabaseRecord) iDatabase, o.getValue()
                  .getClass().getSimpleName()),
                  iDatabase instanceof ODatabaseObjectTx ? ((ODatabaseObjectTx) iDatabase).getEntityManager()
                      : OEntityManagerInternal.INSTANCE, iLinkedClass, iObjHandler != null ? iObjHandler
                      : new OUserObject2RecordHandler() {

                        public Object getUserObjectByRecord(ORecordInternal<?> iRecord, final String iFetchPlan) {
                          return iRecord;
                        }

                        public ORecordInternal<?> getRecordByUserObject(Object iPojo, boolean iCreateIfNotAvailable) {
                          return new ODocument(iLinkedClass);
                        }

                        public boolean existsUserObjectByRID(ORID iRID) {
                          return false;
                        }
View Full Code Here

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

        if (item.length() > 0) {
          // EMBEDDED RECORD, EXTRACT THE CLASS NAME IF DIFFERENT BY THE PASSED (SUB-CLASS OR IT WAS PASSED NULL)
          iLinkedClass = OStringSerializerHelper.getRecordClassName(iDatabase, item, iLinkedClass);

          if (iLinkedClass != null) {
            objectToAdd = fromString(iDocument.getDatabase(), item, new ODocument(iDatabase, iLinkedClass.getName()));
          } else
            // EMBEDDED OBJECT
            objectToAdd = fieldTypeFromStream(iDocument, iLinkedType, item);
        }
      } else {
View Full Code Here

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

      if (o == null)
        continue;

      OIdentifiable id = null;
      ODocument doc = null;

      final OClass linkedClass;
      if (!(o instanceof OIdentifiable)) {
        final String fieldBound = OObjectSerializerHelper.getDocumentBoundField(o.getClass());
        if (fieldBound != null) {
          OObjectSerializerHelper.invokeCallback(o, null, OBeforeSerialization.class);
          doc = (ODocument) OObjectSerializerHelper.getFieldValue(o, fieldBound);
          OObjectSerializerHelper.invokeCallback(o, doc, OAfterSerialization.class);
          id = doc;
        }
        linkedClass = iLinkedClass;
      } else {
        id = (OIdentifiable) o;

        if (iLinkedType == null)
          // AUTO-DETERMINE LINKED TYPE
          if (id.getIdentity().isValid())
            iLinkedType = OType.LINK;
          else
            iLinkedType = OType.EMBEDDED;

        if (id instanceof ODocument) {
          doc = (ODocument) id;

          if (id.getIdentity().isTemporary())
            doc.save();

          linkedClass = doc.getSchemaClass();
        } else
          linkedClass = null;
      }

      if (id != null && iLinkedType != OType.LINK)
        iOutput.append(OStringSerializerHelper.PARENTHESIS_BEGIN);

      if (iLinkedType != OType.LINK && (linkedClass != null || doc != null)) {
        if (id == null)
          // EMBEDDED OBJECTS
          id = OObjectSerializerHelper.toStream(o, new ODocument((ODatabaseRecord) iDatabase, o.getClass().getSimpleName()),
              iDatabase instanceof ODatabaseObjectTx ? ((ODatabaseObjectTx) iDatabase).getEntityManager()
                  : OEntityManagerInternal.INSTANCE, iLinkedClass, iObjHandler != null ? iObjHandler
                  : new OUserObject2RecordHandler() {
                    public Object getUserObjectByRecord(ORecordInternal<?> iRecord, final String iFetchPlan) {
                      return iRecord;
                    }

                    public ORecordInternal<?> getRecordByUserObject(Object iPojo, boolean iCreateIfNotAvailable) {
                      return new ODocument(linkedClass);
                    }

                    public boolean existsUserObjectByRID(ORID iRID) {
                      return false;
                    }
View Full Code Here

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

    // BROWSE IN THE OPPOSITE ORDER
    byte[] binary;
    int i = 0;
    ORecordIterator<ODocument> it = database.browseCluster("Account");
    for (it.last(); it.hasPrevious();) {
      ODocument rec = it.previous();

      Assert.assertEquals(((Number) rec.field("id")).intValue(), i);
      Assert.assertEquals(rec.field("name"), "Gipsy");
      Assert.assertEquals(rec.field("location"), "Italy");
      Assert.assertEquals(((Number) rec.field("testLong")).longValue(), 10000000000L);
      Assert.assertEquals(((Number) rec.field("salary")).intValue(), i + 300);
      Assert.assertNotNull(rec.field("extra"));
      Assert.assertEquals(((Byte) rec.field("value", Byte.class)).byteValue(), (byte) 10);

      binary = rec.field("binary", OType.BINARY);

      for (int b = 0; b < binary.length; ++b)
        Assert.assertEquals(binary[b], (byte) b);

      i++;
View Full Code Here

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

  @Test(dependsOnMethods = "testUpdate")
  public void testDoubleChanges() {
    database = ODatabaseDocumentPool.global().acquire(url, "admin", "admin");

    ODocument vDoc = database.newInstance();
    vDoc.setClassName("Profile");
    vDoc.field("nick", "JayM1").field("name", "Jay").field("surname", "Miner");
    vDoc.save();

    vDoc = database.load(vDoc.getIdentity());
    vDoc.field("nick", "JayM2");
    vDoc.field("nick", "JayM3");
    vDoc.save();

    OPropertyIndex index = database.getMetadata().getSchema().getClass("Profile").getProperty("nick").getIndex();

    Collection<OIdentifiable> vOldName = index.getUnderlying().get("JayM1");
    Assert.assertEquals(vOldName.size(), 0);
View Full Code Here

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

  @Test(dependsOnMethods = "testDoubleChanges")
  public void testMultiValues() {
    database = ODatabaseDocumentPool.global().acquire(url, "admin", "admin");

    ODocument vDoc = database.newInstance();
    vDoc.setClassName("Profile");
    vDoc.field("nick", "Jacky").field("name", "Jack").field("surname", "Tramiel");
    vDoc.save();

    // add a new record with the same name "nameA".
    vDoc = database.newInstance();
    vDoc.setClassName("Profile");
    vDoc.field("nick", "Jack").field("name", "Jack").field("surname", "Bauer");
    vDoc.save();

    OPropertyIndex indexName = database.getMetadata().getSchema().getClass("Profile").getProperty("name").getIndex();

    // We must get 2 records for "nameA".
    Collection<OIdentifiable> vName1 = indexName.getUnderlying().get("Jack");
View Full Code Here

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

  @Test(dependsOnMethods = "testMultiValues")
  public void testUnderscoreField() {
    database = ODatabaseDocumentPool.global().acquire(url, "admin", "admin");

    ODocument vDoc = database.newInstance();
    vDoc.setClassName("Profile");
    vDoc.field("nick", "MostFamousJack").field("name", "Kiefer").field("surname", "Sutherland")
        .field("tag_list", new String[] { "actor", "myth" });
    vDoc.save();

    List<ODocument> result = database.command(
        new OSQLSynchQuery<ODocument>("select from Profile where name = 'Kiefer' and tag_list.size() > 0 ")).execute();

    Assert.assertEquals(result.size(), 1);
View Full Code Here

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

  @SuppressWarnings("unchecked")
  @Test
  public void testDbCacheUpdated() {
    database = ODatabaseDocumentPool.global().acquire(url, "admin", "admin");

    ODocument vDoc = database.newInstance();
    vDoc.setClassName("Profile");

    Set<String> tags = new HashSet<String>();
    tags.add("test");
    tags.add("yeah");

    vDoc.field("nick", "Dexter").field("name", "Michael").field("surname", "Hall").field("tag_list", tags);
    vDoc.save();

    List<ODocument> result = database.command(new OSQLSynchQuery<ODocument>("select from Profile where name = 'Michael'"))
        .execute();

    Assert.assertEquals(result.size(), 1);
    ODocument dexter = result.get(0);
    ((Collection<String>) dexter.field("tag_list")).add("actor");

    dexter.setDirty();
    dexter.save();

    result = database
        .command(new OSQLSynchQuery<ODocument>("select from Profile where tag_list in 'actor' and tag_list in 'test'")).execute();
    Assert.assertEquals(result.size(), 1);
View Full Code Here

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

  }

  @SuppressWarnings("unchecked")
  @Test
  public void testNestedEmbeddedMap() {
    ODocument newDoc = new ODocument(database);

    final Map<String, HashMap<?, ?>> map1 = new HashMap<String, HashMap<?, ?>>();
    newDoc.field("map1", map1, OType.EMBEDDEDMAP);

    final Map<String, HashMap<?, ?>> map2 = new HashMap<String, HashMap<?, ?>>();
    map1.put("map2", (HashMap<?, ?>) map2);

    final Map<String, HashMap<?, ?>> map3 = new HashMap<String, HashMap<?, ?>>();
    map2.put("map3", (HashMap<?, ?>) map3);

    final ORecordId rid = (ORecordId) newDoc.save().getIdentity();

    final ODocument loadedDoc = database.load(rid);

    Assert.assertTrue(newDoc.hasSameContentOf(loadedDoc));

    Assert.assertTrue(loadedDoc.containsField("map1"));
    Assert.assertTrue(loadedDoc.field("map1") instanceof Map<?, ?>);
    final Map<String, ODocument> loadedMap1 = loadedDoc.field("map1");
    Assert.assertEquals(loadedMap1.size(), 1);

    Assert.assertTrue(loadedMap1.containsKey("map2"));
    Assert.assertTrue(loadedMap1.get("map2") instanceof Map<?, ?>);
    final Map<String, ODocument> loadedMap2 = (Map<String, ODocument>) loadedMap1.get("map2");
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.