Package com.orientechnologies.orient.core.sql

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


  @Test
  public void testEncryptPassword() throws IOException {
    database.open("admin", "admin");

    Integer updated = database.command(new OCommandSQL("update ouser set password = 'test' where name = 'reader'")).execute();
    Assert.assertEquals(updated.intValue(), 1);

    List<ODocument> result = database.query(new OSQLSynchQuery<Object>("select from ouser where name = 'reader'"));
    Assert.assertFalse(result.get(0).field("password").equals("test"));

    // RESET OLD PASSWORD
    updated = database.command(new OCommandSQL("update ouser set password = 'reader' where name = 'reader'")).execute();
    Assert.assertEquals(updated.intValue(), 1);

    result = database.query(new OSQLSynchQuery<Object>("select from ouser where name = 'reader'"));
    Assert.assertFalse(result.get(0).field("password").equals("reader"));
View Full Code Here


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

    Assert.assertTrue((Integer) database.command(new OCommandSQL("CREATE CLASS POST")).execute() > 0);
    Assert
        .assertTrue(database.command(new OCommandSQL("INSERT INTO POST (id, title) VALUES ( 10, 'NoSQL movement' );")).execute() instanceof ODocument);
    Assert
        .assertTrue(database.command(new OCommandSQL("INSERT INTO POST (id, title) VALUES ( 20, 'New OrientDB' )")).execute() instanceof ODocument);

    Assert.assertTrue((Integer) database.command(new OCommandSQL("CREATE CLASS COMMENT")).execute() > 0);
    Assert.assertTrue(database.command(new OCommandSQL("INSERT INTO COMMENT (id, postId, text) VALUES ( 0, 10, 'First' )"))
        .execute() instanceof ODocument);
    Assert.assertTrue(database.command(new OCommandSQL("INSERT INTO COMMENT (id, postId, text) VALUES ( 1, 10, 'Second' )"))
        .execute() instanceof ODocument);
    Assert.assertTrue(database.command(new OCommandSQL("INSERT INTO COMMENT (id, postId, text) VALUES ( 21, 10, 'Another' )"))
        .execute() instanceof ODocument);
    Assert.assertTrue(database.command(new OCommandSQL("INSERT INTO COMMENT (id, postId, text) VALUES ( 41, 20, 'First again' )"))
        .execute() instanceof ODocument);
    Assert.assertTrue(database.command(new OCommandSQL("INSERT INTO COMMENT (id, postId, text) VALUES ( 82, 20, 'Second Again' )"))
        .execute() instanceof ODocument);

    Assert.assertEquals(((Number) database.command(new OCommandSQL("CREATE LINK comments FROM comment.postId To post.id INVERSE"))
        .execute()).intValue(), 5);

    Assert.assertEquals(((Number) database.command(new OCommandSQL("UPDATE comment REMOVE postId")).execute()).intValue(), 5);

    database.close();
  }
View Full Code Here

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

    database.command(new OCommandSQL("insert into Profile (sex, salary) values ('female', 2100)")).execute();

    final Long total = database.countClass("Profile");

    final List<ODocument> resultset = database.query(new OSQLSynchQuery<Object>(
        "select from Profile where sex = 'female' and salary = 2100"));

    final Number records = (Number) database.command(new OCommandSQL("delete from Profile where sex = 'female' and salary = 2100"))
        .execute();

    Assert.assertEquals(records.intValue(), resultset.size());

    Assert.assertEquals(database.countClass("Profile"), total - records.intValue());
View Full Code Here

    final List<ODocument> resultset = db.query(new OSQLSynchQuery<Object>(
        "select from Profile where sex = 'male' and salary > 120 and salary <= 133"));

    final Number records = (Number) db.command(
        new OCommandSQL("delete from Profile where sex = 'male' and salary > 120 and salary <= 133")).execute();

    Assert.assertEquals(records.intValue(), resultset.size());

    Assert.assertEquals(db.countClass("Profile"), total - records.intValue());
View Full Code Here

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

    ODocument doc = (ODocument) database.command(
        new OCommandSQL("insert into Profile (name, surname, salary, location, dummy) values ('Luca','Smith', 109.9, 13:3, name)"))
        .execute();

    Assert.assertTrue(doc != null);

    database.close();
View Full Code Here

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

    ODocument doc = (ODocument) database.command(
        new OCommandSQL("insert into Profile (name, surname, salary, location, dummy) values (?,?,?,?,?)")).execute("Marc",
        "Smith", 120.0, new ORecordId(13, 3), "hooray");

    Assert.assertTrue(doc != null);
    Assert.assertEquals(doc.field("name"), "Marc");
    Assert.assertEquals(doc.field("surname"), "Smith");
View Full Code Here

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

    database.command(new OCommandSQL("create property account.timesheet string")).execute();

    Assert.assertEquals(database.getMetadata().getSchema().getClass("account").getProperty("timesheet").getType(), OType.STRING);

    database.close();
  }
View Full Code Here

  @Test(dependsOnMethods = "createProperty")
  public void createLinkedClassProperty() {
    database.open("admin", "admin");

    database.command(new OCommandSQL("create property account.knows embeddedmap account")).execute();

    Assert.assertEquals(database.getMetadata().getSchema().getClass("account").getProperty("knows").getType(), OType.EMBEDDEDMAP);
    Assert.assertEquals(database.getMetadata().getSchema().getClass("account").getProperty("knows").getLinkedClass(), database
        .getMetadata().getSchema().getClass("account"));
View Full Code Here

  @Test(dependsOnMethods = "createLinkedClassProperty")
  public void createLinkedTypeProperty() {
    database.open("admin", "admin");

    database.command(new OCommandSQL("create property account.tags embeddedlist string")).execute();

    Assert.assertEquals(database.getMetadata().getSchema().getClass("account").getProperty("tags").getType(), OType.EMBEDDEDLIST);
    Assert.assertEquals(database.getMetadata().getSchema().getClass("account").getProperty("tags").getLinkedType(), OType.STRING);

    database.close();
View Full Code Here

  @Test(dependsOnMethods = "createLinkedTypeProperty")
  public void removeProperty() {
    database.open("admin", "admin");

    database.command(new OCommandSQL("drop property account.timesheet")).execute();
    database.command(new OCommandSQL("drop property account.tags")).execute();

    Assert.assertFalse(database.getMetadata().getSchema().getClass("account").existsProperty("timesheet"));
    Assert.assertFalse(database.getMetadata().getSchema().getClass("account").existsProperty("tags"));

    database.close();
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.