Package com.orientechnologies.orient.core.sql

Examples of com.orientechnologies.orient.core.sql.OCommandSQL


  }

  public OPropertyImpl setMax(final String iMax) {
    getDatabase().checkSecurity(ODatabaseSecurityResources.SCHEMA, ORole.PERMISSION_UPDATE);
    final String cmd = String.format("alter property %s max %s", getFullName(), iMax);
    getDatabase().command(new OCommandSQL(cmd)).execute();
    this.max = iMax;
    checkForDateFormat(iMax);
    return this;
  }
View Full Code Here


  }

  public OPropertyImpl setRegexp(final String iRegexp) {
    getDatabase().checkSecurity(ODatabaseSecurityResources.SCHEMA, ORole.PERMISSION_UPDATE);
    final String cmd = String.format("alter property %s regexp %s", getFullName(), iRegexp);
    getDatabase().command(new OCommandSQL(cmd)).execute();
    this.regexp = iRegexp;
    return this;
  }
View Full Code Here

  }

  public OPropertyImpl setType(final OType iType) {
    getDatabase().checkSecurity(ODatabaseSecurityResources.SCHEMA, ORole.PERMISSION_UPDATE);
    final String cmd = String.format("alter property %s type %s", getFullName(), iType.toString());
    getDatabase().command(new OCommandSQL(cmd)).execute();
    type = iType;
    return this;
  }
View Full Code Here

      record = database.newInstance();
      database.declareIntent(new OIntentMassiveInsert());
      database.begin(TXTYPE.NOTX);

      synchronized (LocalCreateDocumentMultiThreadIndexedSpeedTest.class) {
        database.command(new OCommandSQL("truncate class account")).execute();

        OClass c = database.getMetadata().getSchema().getClass("Account");
        if (c == null)
          c = database.getMetadata().getSchema().createClass("Account");
View Full Code Here

    Assert.assertTrue(result.size() > 0);
  }

  @Test
  public void testIndexSQL() {
    database.command(new OCommandSQL("create index idx unique")).execute();
    database.getMetadata().getIndexManager().reload();
    Assert.assertNotNull(database.getMetadata().getIndexManager().getIndex("idx"));

    database.command(new OCommandSQL("insert into index:IDX (key,rid) values (10,#3:0)")).execute();
    database.command(new OCommandSQL("insert into index:IDX (key,rid) values (20,#3:1)")).execute();

    List<ODocument> result = database.command(new OCommandSQL("select from index:IDX")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 2);
    for (ODocument d : result) {
      Assert.assertTrue(d.containsField("key"));
      Assert.assertTrue(d.containsField("rid"));

      if (d.field("key").equals(10))
        Assert.assertEquals(d.rawField("rid"), new ORecordId("#3:0"));
      else if (d.field("key").equals(20))
        Assert.assertEquals(d.rawField("rid"), new ORecordId("#3:1"));
      else
        Assert.assertTrue(false);
    }

    result = database.command(new OCommandSQL("select key, rid from index:IDX")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 2);
    for (ODocument d : result) {
      Assert.assertTrue(d.containsField("key"));
      Assert.assertTrue(d.containsField("rid"));

      if (d.field("key").equals(10))
        Assert.assertEquals(d.rawField("rid"), new ORecordId("#3:0"));
      else if (d.field("key").equals(20))
        Assert.assertEquals(d.rawField("rid"), new ORecordId("#3:1"));
      else
        Assert.assertTrue(false);
    }

    result = database.command(new OCommandSQL("select key from index:IDX")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 2);
    for (ODocument d : result) {
      Assert.assertTrue(d.containsField("key"));
      Assert.assertFalse(d.containsField("rid"));
    }

    result = database.command(new OCommandSQL("select rid from index:IDX")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 2);
    for (ODocument d : result) {
      Assert.assertFalse(d.containsField("key"));
      Assert.assertTrue(d.containsField("rid"));
    }

    result = database.command(new OCommandSQL("select rid from index:IDX where key = 10")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 1);
    for (ODocument d : result) {
      Assert.assertFalse(d.containsField("key"));
      Assert.assertTrue(d.containsField("rid"));
View Full Code Here

    }
  }

  @Test(dependsOnMethods = "populateIndexDocuments")
  public void testValuesMajor() {
    database.command(new OCommandSQL("create index equalityIdx unique")).execute();

    database.getMetadata().getIndexManager().reload();
    Assert.assertNotNull(database.getMetadata().getIndexManager().getIndex("equalityIdx"));

    for (int key = 0; key <= 5; key++) {
      database.command(new OCommandSQL("insert into index:equalityIdx (key,rid) values (" + key + ",#10:" + key + ")")).execute();
    }

    final OIndex index = database.getMetadata().getIndexManager().getIndex("equalityIdx");

    final Collection<Long> valuesMajorResults = new ArrayList<Long>(Arrays.asList(4L, 5L));
    Collection<OIdentifiable> indexCollection = index.getValuesMajor(3, false);
    Assert.assertEquals(indexCollection.size(), 2);
    for (OIdentifiable identifiable : indexCollection) {
      valuesMajorResults.remove(identifiable.getIdentity().getClusterPosition());
    }
    Assert.assertEquals(valuesMajorResults.size(), 0);

    final Collection<Long> valuesMajorInclusiveResults = new ArrayList<Long>(Arrays.asList(3L, 4L, 5L));
    indexCollection = index.getValuesMajor(3, true);
    Assert.assertEquals(indexCollection.size(), 3);
    for (OIdentifiable identifiable : indexCollection) {
      valuesMajorInclusiveResults.remove(identifiable.getIdentity().getClusterPosition());
    }
    Assert.assertEquals(valuesMajorInclusiveResults.size(), 0);

    indexCollection = index.getValuesMajor(5, true);
    Assert.assertEquals(indexCollection.size(), 1);
    Assert.assertEquals(indexCollection.iterator().next().getIdentity().getClusterPosition(), 5L);

    indexCollection = index.getValuesMajor(5, false);
    Assert.assertEquals(indexCollection.size(), 0);

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }
View Full Code Here

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }

  @Test(dependsOnMethods = "populateIndexDocuments")
  public void testEntriesMajor() {
    database.command(new OCommandSQL("create index equalityIdx unique")).execute();

    database.getMetadata().getIndexManager().reload();
    Assert.assertNotNull(database.getMetadata().getIndexManager().getIndex("equalityIdx"));

    for (int key = 0; key <= 5; key++) {
      database.command(new OCommandSQL("insert into index:equalityIdx (key,rid) values (" + key + ",#10:" + key + ")")).execute();
    }

    final OIndex index = database.getMetadata().getIndexManager().getIndex("equalityIdx");

    final Collection<Integer> valuesMajorResults = new ArrayList<Integer>(Arrays.asList(4, 5));
    Collection<ODocument> indexCollection = index.getEntriesMajor(3, false);
    Assert.assertEquals(indexCollection.size(), 2);
    for (ODocument doc : indexCollection) {
      valuesMajorResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(valuesMajorResults.size(), 0);

    final Collection<Integer> valuesMajorInclusiveResults = new ArrayList<Integer>(Arrays.asList(3, 4, 5));
    indexCollection = index.getEntriesMajor(3, true);
    Assert.assertEquals(indexCollection.size(), 3);
    for (ODocument doc : indexCollection) {
      valuesMajorInclusiveResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(valuesMajorInclusiveResults.size(), 0);

    indexCollection = index.getEntriesMajor(5, true);
    Assert.assertEquals(indexCollection.size(), 1);
    Assert.assertEquals(indexCollection.iterator().next().<Integer> field("key"), Integer.valueOf(5));
    Assert.assertEquals(indexCollection.iterator().next().<ORecordId> rawField("rid"), new ORecordId(10, 5));

    indexCollection = index.getEntriesMajor(5, false);
    Assert.assertEquals(indexCollection.size(), 0);

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }
View Full Code Here

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }

  @Test(dependsOnMethods = "populateIndexDocuments")
  public void testValuesMinor() {
    database.command(new OCommandSQL("create index equalityIdx unique")).execute();

    database.getMetadata().getIndexManager().reload();
    Assert.assertNotNull(database.getMetadata().getIndexManager().getIndex("equalityIdx"));

    for (int key = 0; key <= 5; key++) {
      database.command(new OCommandSQL("insert into index:equalityIdx (key,rid) values (" + key + ",#10:" + key + ")")).execute();
    }

    final OIndex index = database.getMetadata().getIndexManager().getIndex("equalityIdx");

    final Collection<Long> valuesMinorResults = new ArrayList<Long>(Arrays.asList(0L, 1L, 2L));
    Collection<OIdentifiable> indexCollection = index.getValuesMinor(3, false);
    Assert.assertEquals(indexCollection.size(), 3);
    for (OIdentifiable identifiable : indexCollection) {
      valuesMinorResults.remove(identifiable.getIdentity().getClusterPosition());
    }
    Assert.assertEquals(valuesMinorResults.size(), 0);

    final Collection<Long> valuesMinorInclusiveResults = new ArrayList<Long>(Arrays.asList(0L, 1L, 2L, 3L));
    indexCollection = index.getValuesMinor(3, true);
    Assert.assertEquals(indexCollection.size(), 4);
    for (OIdentifiable identifiable : indexCollection) {
      valuesMinorInclusiveResults.remove(identifiable.getIdentity().getClusterPosition());
    }
    Assert.assertEquals(valuesMinorInclusiveResults.size(), 0);

    indexCollection = index.getValuesMinor(0, true);
    Assert.assertEquals(indexCollection.size(), 1);
    Assert.assertEquals(indexCollection.iterator().next().getIdentity().getClusterPosition(), 0L);

    indexCollection = index.getValuesMinor(0, false);
    Assert.assertEquals(indexCollection.size(), 0);

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }
View Full Code Here

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }

  @Test(dependsOnMethods = "populateIndexDocuments")
  public void testEntriesMinor() {
    database.command(new OCommandSQL("create index equalityIdx unique")).execute();

    database.getMetadata().getIndexManager().reload();
    Assert.assertNotNull(database.getMetadata().getIndexManager().getIndex("equalityIdx"));

    for (int key = 0; key <= 5; key++) {
      database.command(new OCommandSQL("insert into index:equalityIdx (key,rid) values (" + key + ",#10:" + key + ")")).execute();
    }

    final OIndex index = database.getMetadata().getIndexManager().getIndex("equalityIdx");

    final Collection<Integer> valuesMinorResults = new ArrayList<Integer>(Arrays.asList(0, 1, 2));
    Collection<ODocument> indexCollection = index.getEntriesMinor(3, false);
    Assert.assertEquals(indexCollection.size(), 3);
    for (ODocument doc : indexCollection) {
      valuesMinorResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(valuesMinorResults.size(), 0);

    final Collection<Integer> valuesMinorInclusiveResults = new ArrayList<Integer>(Arrays.asList(0, 1, 2, 3));
    indexCollection = index.getEntriesMinor(3, true);
    Assert.assertEquals(indexCollection.size(), 4);
    for (ODocument doc : indexCollection) {
      valuesMinorInclusiveResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(valuesMinorInclusiveResults.size(), 0);

    indexCollection = index.getEntriesMinor(0, true);
    Assert.assertEquals(indexCollection.size(), 1);
    Assert.assertEquals(indexCollection.iterator().next().<Integer> field("key"), Integer.valueOf(0));
    Assert.assertEquals(indexCollection.iterator().next().<ORecordId> rawField("rid"), new ORecordId(10, 0));

    indexCollection = index.getEntriesMinor(0, false);
    Assert.assertEquals(indexCollection.size(), 0);

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }
View Full Code Here

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }

  @Test(dependsOnMethods = "populateIndexDocuments")
  public void testBetweenEntries() {
    database.command(new OCommandSQL("create index equalityIdx unique integer")).execute();

    database.getMetadata().getIndexManager().reload();
    Assert.assertNotNull(database.getMetadata().getIndexManager().getIndex("equalityIdx"));

    for (int key = 0; key <= 5; key++) {
      database.command(new OCommandSQL("insert into index:equalityIdx (key,rid) values (" + key + ",#10:" + key + ")")).execute();
    }

    final OIndex index = database.getMetadata().getIndexManager().getIndex("equalityIdx");

    final Collection<Integer> betweenResults = new ArrayList<Integer>(Arrays.asList(1, 2, 3));
    Collection<ODocument> indexCollection = index.getEntriesBetween(1, 3);
    Assert.assertEquals(indexCollection.size(), 3);
    for (ODocument doc : indexCollection) {
      betweenResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(betweenResults.size(), 0);

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.sql.OCommandSQL

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.