@Test
  public void testConvertToDocument() throws Exception {
    IPictogram pictogram = new Pictogram();
    pictogram.setTitle("title");
    pictogram.setFileIdentifier("test.txt");

    ODocument document = repository.convertToDocument(pictogram);

    assertEquals("title", document.field("title"));
    assertEquals("test.txt", document.field("fileIdentifier"));

    // class name should be correct
    assertEquals("Pictogram", document.getClassName());

    // save document to get id
    document.save();
    String id = document.getIdentity().toString();

    // set id and test conversion
    pictogram.setId(id);

    ODocument newDocument = repository.convertToDocument(pictogram);

    assertEquals(document.getIdentity().toString(), newDocument.getIdentity().toString());
  }
 @Override
 protected RESULT onUpdate(ODocument document, ODatabase connection) throws Exception {
   if (document != null && "DSDDataset".equals(document.getClassName())) {
     linkCodes(document, "columns.domain.codes", "columns.values.codes");
   }
   return RESULT.RECORD_CHANGED;
 }
  @Test
  public void queryProjectionOk() {
    database.open("admin", "admin");

    List<ODocument> result =
        database
            .command(
                new OSQLSynchQuery<ODocument>(
                    " select nick, followings, followers from Profile where nick is defined and followings is defined and followers is defined"))
            .execute();

    Assert.assertTrue(result.size() != 0);

    for (ODocument d : result) {
      String[] colNames = d.fieldNames();
      Assert.assertEquals(colNames.length, 3);
      Assert.assertEquals(colNames[0], "nick");
      Assert.assertEquals(colNames[1], "followings");
      Assert.assertEquals(colNames[2], "followers");

      Assert.assertNull(d.getClassName());
      Assert.assertEquals(d.getRecordType(), ODocument.RECORD_TYPE);
    }

    database.close();
  }
예제 #4
0
 @Override
 public OUser getUser(ODatabaseDocumentInternal db) {
   if (this.rid != null) {
     ODocument result = db.load(new ORecordId(this.rid), "roles:1");
     if (result != null && result.getClassName().equals(OUser.CLASS_NAME)) {
       return new OUser(result);
     }
   }
   return null;
 }
예제 #5
0
  @Test
  public void insertCluster() {
    database.open("admin", "admin");

    ODocument doc =
        (ODocument)
            database
                .command(
                    new OCommandSQL(
                        "insert into Account cluster default (id, title) values (10, 'NoSQL movement')"))
                .execute();

    Assert.assertTrue(doc != null);
    Assert.assertEquals(doc.getIdentity().getClusterId(), database.getDefaultClusterId());
    Assert.assertEquals(doc.getClassName(), "Account");

    database.close();
  }
  @Test
  public void queryProjectionObjectLevel() {
    ODatabaseObjectTx db = new ODatabaseObjectTx(url);
    db.open("admin", "admin");

    List<ODocument> result =
        db.query(
            new OSQLSynchQuery<ODocument>(" select nick, followings, followers from Profile "));

    Assert.assertTrue(result.size() != 0);

    for (ODocument d : result) {
      Assert.assertTrue(d.fieldNames().length <= 3);
      Assert.assertNull(d.getClassName());
      Assert.assertEquals(d.getRecordType(), ODocument.RECORD_TYPE);
    }

    db.close();
  }
  @Test
  public void queryProjectionContentCollection() {
    database.open("admin", "admin");

    List<ODocument> result =
        database
            .command(
                new OSQLSynchQuery<ODocument>(
                    "SELECT FLATTEN( out ) FROM OGraphVertex WHERE out TRAVERSE(1,1) (@class = 'OGraphEdge')"))
            .execute();

    Assert.assertTrue(result.size() != 0);

    for (ODocument d : result) {
      Assert.assertEquals(d.getClassName(), "OGraphEdge");
      Assert.assertEquals(d.getRecordType(), ODocument.RECORD_TYPE);
    }

    database.close();
  }
  @Test
  public void queryProjectionSimpleValues() {
    database.open("admin", "admin");

    List<ODocument> result =
        database
            .command(new OSQLSynchQuery<ODocument>("select 10, 'ciao' from Profile LIMIT 1"))
            .execute();

    Assert.assertTrue(result.size() != 0);

    for (ODocument d : result) {
      Assert.assertTrue(d.fieldNames().length <= 2);
      Assert.assertEquals(((Integer) d.field("10")).intValue(), 10l);
      Assert.assertEquals(d.field("ciao"), "ciao");

      Assert.assertNull(d.getClassName());
      Assert.assertEquals(d.getRecordType(), ODocument.RECORD_TYPE);
    }

    database.close();
  }
  @Test
  public void queryProjectionLinkedAndFunction() {
    database.open("admin", "admin");

    List<ODocument> result =
        database
            .command(
                new OSQLSynchQuery<ODocument>(
                    "select name.toUppercase(), address.city.country.name from Profile"))
            .execute();

    Assert.assertTrue(result.size() != 0);

    for (ODocument d : result) {
      Assert.assertTrue(d.fieldNames().length <= 2);
      if (d.field("name") != null)
        Assert.assertTrue(d.field("name").equals(((String) d.field("name")).toUpperCase()));

      Assert.assertNull(d.getClassName());
      Assert.assertEquals(d.getRecordType(), ODocument.RECORD_TYPE);
    }

    database.close();
  }
  @Test
  public void queryProjectionAliases() {
    database.open("admin", "admin");

    List<ODocument> result =
        database
            .command(
                new OSQLSynchQuery<ODocument>(
                    "select name.append('!') as 1, surname as 2 from Profile where name is not null and surname is not null"))
            .execute();

    Assert.assertTrue(result.size() != 0);

    for (ODocument d : result) {
      Assert.assertTrue(d.fieldNames().length <= 2);
      Assert.assertTrue(d.field("1").toString().endsWith("!"));
      Assert.assertNotNull(d.field("2"));

      Assert.assertNull(d.getClassName());
      Assert.assertEquals(d.getRecordType(), ODocument.RECORD_TYPE);
    }

    database.close();
  }
  @Test
  public void queryProjectionFunctionsAndFieldOperators() {
    database.open("admin", "admin");

    List<ODocument> result =
        database
            .command(
                new OSQLSynchQuery<ODocument>(
                    "select max(name.append('.')).prefix('Mr. ') as name from Profile where name is not null"))
            .execute();

    Assert.assertTrue(result.size() != 0);

    for (ODocument d : result) {
      Assert.assertTrue(d.fieldNames().length <= 1);
      Assert.assertTrue(d.field("name").toString().startsWith("Mr. "));
      Assert.assertTrue(d.field("name").toString().endsWith("."));

      Assert.assertNull(d.getClassName());
      Assert.assertEquals(d.getRecordType(), ODocument.RECORD_TYPE);
    }

    database.close();
  }
  @Test
  public void queryProjectionStaticValues() {
    database.open("admin", "admin");

    List<ODocument> result =
        database
            .command(
                new OSQLSynchQuery<ODocument>(
                    "select location.city.country.name, address.city.country.name from Profile where location.city.country.name is not null"))
            .execute();

    Assert.assertTrue(result.size() != 0);

    for (ODocument d : result) {

      Assert.assertNotNull(d.field("location"));
      Assert.assertNull(d.field("address"));

      Assert.assertNull(d.getClassName());
      Assert.assertEquals(d.getRecordType(), ODocument.RECORD_TYPE);
    }

    database.close();
  }
  @Test
  public void queryProjectionSameFieldTwice() {
    database.open("admin", "admin");

    List<ODocument> result =
        database
            .command(
                new OSQLSynchQuery<ODocument>(
                    "select name, name.toUppercase() from Profile where name is not null"))
            .execute();

    Assert.assertTrue(result.size() != 0);

    for (ODocument d : result) {
      Assert.assertTrue(d.fieldNames().length <= 2);
      Assert.assertNotNull(d.field("name"));
      Assert.assertNotNull(d.field("name2"));

      Assert.assertNull(d.getClassName());
      Assert.assertEquals(d.getRecordType(), ODocument.RECORD_TYPE);
    }

    database.close();
  }
예제 #14
0
 public static boolean docIsAFile(ODocument doc) {
   String className = doc.getClassName();
   return fileClasses.contains(className);
 }