Package com.orientechnologies.orient.core.sql

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


    // CLASS.PROPERTY NAME
    cmd.append(name);
    cmd.append('.');
    cmd.append(iPropertyName);

    document.getDatabase().command(new OCommandSQL(cmd.toString())).execute();

    if (existsProperty(iPropertyName))
      properties.remove(lowerName);
  }
View Full Code Here


      // TYPE
      cmd.append(' ');
      cmd.append(iLinkedClass.getName());
    }

    document.getDatabase().command(new OCommandSQL(cmd.toString())).execute();

    if (existsProperty(iPropertyName))
      return properties.get(lowerName);
    else
      // ADD IT LOCALLY AVOIDING TO RELOAD THE ENTIRE SCHEMA
View Full Code Here

  }

  public OClass setOverSize(final float overSize) {
    document.getDatabase().checkSecurity(ODatabaseSecurityResources.SCHEMA, ORole.PERMISSION_UPDATE);
    final String cmd = String.format("alter class %s oversize %f", name, overSize);
    document.getDatabase().command(new OCommandSQL(cmd)).execute();
    setOverSizeInternal(overSize);
    return this;
  }
View Full Code Here

    return rid;
  }

  private OCommandRequest formatCommand(final String iTemplate, final Object... iArgs) {
    final String text = String.format(iTemplate, iArgs);
    return new OCommandSQL(text);
  }
View Full Code Here

    final Object response;

    try {
      db = getProfiledDatabaseInstance(iRequest);

      response = db.command(new OCommandSQL(text)).execute();

    } finally {
      if (db != null)
        OSharedDocumentDatabase.release(db);
    }
View Full Code Here

  }

  public synchronized OIndex createIndex(final String iName, final String iType, final int[] iClusterIdsToIndex,
      OIndexCallback iCallback, final OProgressListener iProgressListener, final boolean iAutomatic) {
    final String text = String.format(QUERY_CREATE, iName, iType);
    final ORecordId rid = getDatabase().command(new OCommandSQL(text)).execute();

    document.setIdentity(rid);
    reload();

    return indexes.get(iName.toLowerCase());
View Full Code Here

    return indexes.get(iName.toLowerCase());
  }

  public synchronized OIndexManager dropIndex(final String iIndexName) {
    final String text = String.format(QUERY_DROP, iIndexName);
    getDatabase().command(new OCommandSQL(text)).execute();

    // REMOVE THE INDEX LOCALLY
    indexes.remove(iIndexName.toLowerCase());

    return this;
View Full Code Here

    return this;
  }

  public <DB extends ODatabase> DB setStatus(final STATUS status) {
    final String cmd = String.format("alter database status %s", status.toString());
    command(new OCommandSQL(cmd)).execute();
    return (DB) this;
  }
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

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.