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

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


    Set<String> tags = new HashSet<String>();
    tags.add("smart");
    tags.add("nice");

    ODocument doc = new ODocument(database, "Profile");
    doc.field("tags", tags);

    doc.save();

    List<ODocument> resultset = database.query(new OSQLSynchQuery<ODocument>("select from Profile where tags CONTAINS 'smart'"));

    Assert.assertEquals(resultset.size(), 1);
    Assert.assertEquals(resultset.get(0).getIdentity(), doc.getIdentity());

    database.close();
  }
View Full Code Here


  @Test
  public void queryContainsInEmbeddedMapClassic() {
    database.open("admin", "admin");

    Map<String, ODocument> customReferences = new HashMap<String, ODocument>();
    customReferences.put("first", new ODocument("name", "Luca", "surname", "Garulli"));
    customReferences.put("second", new ODocument("name", "Jay", "surname", "Miner"));

    ODocument doc = new ODocument(database, "Profile");
    doc.field("customReferences", customReferences, OType.EMBEDDEDMAP);

    doc.save();

    List<ODocument> resultset = database.query(new OSQLSynchQuery<ODocument>(
        "select from Profile where customReferences CONTAINSKEY 'first'"));

    Assert.assertEquals(resultset.size(), 1);
    Assert.assertEquals(resultset.get(0).getIdentity(), doc.getIdentity());

    resultset = database.query(new OSQLSynchQuery<ODocument>(
        "select from Profile where customReferences CONTAINSVALUE ( name like 'Ja%')"));

    Assert.assertEquals(resultset.size(), 1);
    Assert.assertEquals(resultset.get(0).getIdentity(), doc.getIdentity());

    doc.delete();

    database.close();
  }
View Full Code Here

  @Test
  public void queryContainsInEmbeddedMapNew() {
    database.open("admin", "admin");

    Map<String, ODocument> customReferences = new HashMap<String, ODocument>();
    customReferences.put("first", new ODocument("name", "Luca", "surname", "Garulli"));
    customReferences.put("second", new ODocument("name", "Jay", "surname", "Miner"));

    ODocument doc = new ODocument(database, "Profile");
    doc.field("customReferences", customReferences, OType.EMBEDDEDMAP);

    doc.save();

    List<ODocument> resultset = database.query(new OSQLSynchQuery<ODocument>(
        "select from Profile where customReferences.keys() CONTAINS 'first'"));

    Assert.assertEquals(resultset.size(), 1);
    Assert.assertEquals(resultset.get(0).getIdentity(), doc.getIdentity());

    resultset = database.query(new OSQLSynchQuery<ODocument>(
        "select from Profile where customReferences.values() CONTAINS ( name like 'Ja%')"));

    Assert.assertEquals(resultset.size(), 1);
    Assert.assertEquals(resultset.get(0).getIdentity(), doc.getIdentity());

    doc.delete();

    database.close();
  }
View Full Code Here

    final long times = OProfiler.getInstance().getCounter("Cache.reused");
    List<ODocument> resultset = database.query(new OSQLSynchQuery<ODocument>("select * from Profile").setFetchPlan("*:-1"));
    Assert.assertEquals(OProfiler.getInstance().getCounter("Cache.reused"), times);

    ODocument linked;
    for (ODocument d : resultset) {
      linked = ((ODocument) d.field("location"));
      if (linked != null)
        Assert.assertNotNull(database.getLevel1Cache().findRecord(linked.getIdentity()));
    }

    database.close();
  }
View Full Code Here

  @Test
  public void updateWithWildcardsOnSetAndWhere() {

    database.open("admin", "admin");
    ODocument doc = new ODocument(database, "Person");
    doc.field("name", "Raf");
    doc.field("city", "Torino");
    doc.field("gender", "fmale");
    doc.save();
    checkUpdatedDoc(database, "Raf", "Torino", "fmale");

    /* THESE COMMANDS ARE OK */
    OCommandSQL updatecommand = new OCommandSQL("update Person set gender = 'female' where name = 'Raf'");
    database.command(updatecommand).execute("Raf");
View Full Code Here

  public static final String            DICTIONARY_NAME      = "dictionary";
  protected Map<String, OIndexInternal>  indexes              = new HashMap<String, OIndexInternal>();
  protected String                      defaultClusterName  = OStorage.CLUSTER_INDEX_NAME;

  public OIndexManagerAbstract(final ODatabaseRecord iDatabase) {
    super(new ODocument(iDatabase));
  }
View Full Code Here

    database.close();
  }

  private void checkUpdatedDoc(ODatabaseDocument database, String expectedName, String expectedCity, String expectedGender) {
    List<ODocument> result = database.query(new OSQLSynchQuery<Object>("select * from person"));
    ODocument oDoc = result.get(0);
    Assert.assertEquals(expectedName, oDoc.field("name"));
    Assert.assertEquals(expectedCity, oDoc.field("city"));
    Assert.assertEquals(expectedGender, oDoc.field("gender"));
  }
View Full Code Here

  }

  public ORecordFactoryManager() {
    declareRecordType(ODocument.RECORD_TYPE, "document", ODocument.class, new ORecordFactory() {
      public ORecord<?> newRecord(ODatabaseRecord iDatabase) {
        return new ODocument(iDatabase);
      }
    });
    declareRecordType(ORecordFlat.RECORD_TYPE, "flat", ORecordFlat.class, new ORecordFactory() {
      public ORecord<?> newRecord(ODatabaseRecord iDatabase) {
        return new ORecordFlat(iDatabase);
View Full Code Here

  public void testDateConversion() throws ParseException {
    database.open("admin", "admin");

    final long begin = System.currentTimeMillis();

    ODocument doc1 = new ODocument(database, "Order");
    doc1.field("context", "test");
    doc1.field("date", new Date());
    doc1.save();

    ODocument doc2 = new ODocument(database, "Order");
    doc2.field("context", "test");
    doc2.field("date", System.currentTimeMillis());
    doc2.save();

    doc2.reload();
    Assert.assertTrue(doc2.field("date", OType.DATE) instanceof Date);

    doc2.reload();
    Assert.assertTrue(doc2.field("date", Date.class) instanceof Date);

    List<ODocument> result = database.command(
        new OSQLSynchQuery<ODocument>("select * from Order where date >= ? and context = 'test'")).execute(begin);

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

  }

  public ODocument getIndexChanges() {
    final StringBuilder value = new StringBuilder();

    final ODocument result = new ODocument();

    for (Entry<String, OTransactionIndexChanges> indexEntry : indexEntries.entrySet()) {
      final ODocument indexDoc = new ODocument();
      result.field(indexEntry.getKey(), indexDoc);

      if (indexEntry.getValue().cleared)
        indexDoc.field("clear", Boolean.TRUE);

      final List<ODocument> entries = new ArrayList<ODocument>();
      indexDoc.field("entries", entries);

      // STORE INDEX ENTRIES
      for (OTransactionIndexChangesPerKey entry : indexEntry.getValue().changesPerKey.values()) {
        // SERIALIZE KEY
        value.setLength(0);
        if (entry.key != null)
          ORecordSerializerStringAbstract.fieldTypeToString(value, null, OType.getTypeByClass(entry.key.getClass()), entry.key);
        else
          value.append('*');
        String key = value.toString();

        final List<ODocument> operations = new ArrayList<ODocument>();

        // SERIALIZE VALUES
        if (entry.entries != null && !entry.entries.isEmpty()) {
          for (OTransactionIndexEntry e : entry.entries) {
            final ODocument changeDoc = new ODocument();

            // SERIALIZE OPERATION
            changeDoc.field("o", e.operation.ordinal());

            if (e.value instanceof ORecord<?> && e.value.getIdentity().isNew())
              ((ORecord<?>) e.value).save();

            changeDoc.field("v", e.value.getIdentity());

            operations.add(changeDoc);
          }
        }

        entries.add(new ODocument().field("k", OStringSerializerHelper.encode(key)).field("ops", operations));
      }
    }

    indexEntries.clear();

View Full Code Here

TOP

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

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.