Search in sources :

Example 71 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class SQLDropClassTest method testSimpleDrop.

@Test
public void testSimpleDrop() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + SQLDropClassTest.class.getName());
    db.create();
    try {
        Assert.assertFalse(db.getMetadata().getSchema().existsClass("testSimpleDrop"));
        db.command(new OCommandSQL("create class testSimpleDrop")).execute();
        Assert.assertTrue(db.getMetadata().getSchema().existsClass("testSimpleDrop"));
        db.command(new OCommandSQL("Drop class testSimpleDrop")).execute();
        Assert.assertFalse(db.getMetadata().getSchema().existsClass("testSimpleDrop"));
    } finally {
        db.drop();
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.testng.annotations.Test)

Example 72 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class SQLDropClassTest method testIfExists.

@Test
public void testIfExists() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + SQLDropClassTest.class.getName() + "_ifNotExists");
    db.create();
    try {
        Assert.assertFalse(db.getMetadata().getSchema().existsClass("testIfExists"));
        db.command(new OCommandSQL("create class testIfExists if not exists")).execute();
        db.getMetadata().getSchema().reload();
        Assert.assertTrue(db.getMetadata().getSchema().existsClass("testIfExists"));
        db.command(new OCommandSQL("drop class testIfExists if exists")).execute();
        db.getMetadata().getSchema().reload();
        Assert.assertFalse(db.getMetadata().getSchema().existsClass("testIfExists"));
        db.command(new OCommandSQL("drop class testIfExists if exists")).execute();
        db.getMetadata().getSchema().reload();
        Assert.assertFalse(db.getMetadata().getSchema().existsClass("testIfExists"));
    } finally {
        db.drop();
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.testng.annotations.Test)

Example 73 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class TestOrderBy method testGermanOrderBy.

@Test
public void testGermanOrderBy() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:testGermanOrderBy");
    db.set(ATTRIBUTES.LOCALECOUNTRY, Locale.GERMANY.getCountry());
    db.set(ATTRIBUTES.LOCALELANGUAGE, Locale.GERMANY.getLanguage());
    db.create();
    try {
        db.getMetadata().getSchema().createClass("test");
        ORecord res1 = db.save(new ODocument("test").field("name", "Ähhhh"));
        ORecord res2 = db.save(new ODocument("test").field("name", "Ahhhh"));
        ORecord res3 = db.save(new ODocument("test").field("name", "Zebra"));
        List<?> queryRes = db.query(new OSQLSynchQuery<Object>("select from test order by name"));
        assertEquals(queryRes.get(0), res2);
        assertEquals(queryRes.get(1), res1);
        assertEquals(queryRes.get(2), res3);
        queryRes = db.query(new OSQLSynchQuery<Object>("select from test order by name desc "));
        assertEquals(queryRes.get(0), res3);
        assertEquals(queryRes.get(1), res1);
        assertEquals(queryRes.get(2), res2);
    } finally {
        db.drop();
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ORecord(com.orientechnologies.orient.core.record.ORecord) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 74 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class ODeleteStatementTest method deleteFromSubqueryWithWhereTest.

public void deleteFromSubqueryWithWhereTest() {
    ODatabaseDocument database = new ODatabaseDocumentTx("memory:ODeleteStatementTestFromSubqueryWithWhereTest");
    database.create();
    try {
        database.command(new OCommandSQL("create class Foo")).execute();
        database.command(new OCommandSQL("create class Bar")).execute();
        final ODocument doc1 = new ODocument("Foo").field("k", "key1");
        final ODocument doc2 = new ODocument("Foo").field("k", "key2");
        final ODocument doc3 = new ODocument("Foo").field("k", "key3");
        doc1.save();
        doc2.save();
        doc3.save();
        List<ODocument> list = new ArrayList<ODocument>();
        list.add(doc1);
        list.add(doc2);
        list.add(doc3);
        final ODocument bar = new ODocument("Bar").field("arr", list);
        bar.save();
        database.command(new OCommandSQL("delete from (select expand(arr) from Bar) where k = 'key2'")).execute();
        List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from Foo"));
        Assert.assertNotNull(result);
        Assert.assertEquals(result.size(), 2);
        for (ODocument doc : result) {
            Assert.assertNotEquals(doc.field("k"), "key2");
        }
    } finally {
        database.close();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ArrayList(java.util.ArrayList) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 75 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class OrientJdbcStatementDMLtest method shoulCreateClassWithProperties.

@Test
public void shoulCreateClassWithProperties() throws IOException, SQLException {
    Statement stmt = conn.createStatement();
    stmt.executeUpdate("CREATE CLASS Account ");
    stmt.executeUpdate("CREATE PROPERTY Account.id INTEGER ");
    stmt.executeUpdate("CREATE PROPERTY Account.birthDate DATE ");
    stmt.executeUpdate("CREATE PROPERTY Account.binary BINARY ");
    stmt.close();
    // double value test pattern?
    ODatabaseDocument database = conn.getDatabase();
    assertThat(database.getClusterIdByName("account")).isNotNull();
    OClass account = database.getMetadata().getSchema().getClass("Account");
    assertThat(account).isNotNull();
    assertThat(account.getProperty("id").getType()).isEqualTo(OType.INTEGER);
    assertThat(account.getProperty("birthDate").getType()).isEqualTo(OType.DATE);
    assertThat(account.getProperty("binary").getType()).isEqualTo(OType.BINARY);
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) Statement(java.sql.Statement) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.junit.Test)

Aggregations

ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)187 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)81 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)68 Test (org.testng.annotations.Test)53 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)47 ORecordId (com.orientechnologies.orient.core.id.ORecordId)23 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)17 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)16 ORecord (com.orientechnologies.orient.core.record.ORecord)14 Test (org.junit.Test)14 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)12 ORID (com.orientechnologies.orient.core.id.ORID)11 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)10 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)9 OValidationException (com.orientechnologies.orient.core.exception.OValidationException)9 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)9 ArrayList (java.util.ArrayList)9 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)8 HashSet (java.util.HashSet)8