Search in sources :

Example 26 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class SQLDropClassIndexTest method beforeClass.

@BeforeClass
public void beforeClass() {
    database = new ODatabaseDocumentTx(url);
    if (database.isClosed())
        database.open("admin", "admin");
    final OSchema schema = database.getMetadata().getSchema();
    final OClass oClass = schema.createClass("SQLDropClassTestClass");
    oClass.createProperty("prop1", EXPECTED_PROP1_TYPE);
    oClass.createProperty("prop2", EXPECTED_PROP2_TYPE);
    schema.save();
    database.close();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)

Example 27 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class SQLDropIndexTest method beforeClass.

@BeforeClass
public void beforeClass() {
    database = new ODatabaseDocumentTx(url);
    if (database.isClosed())
        database.open("admin", "admin");
    final OSchema schema = database.getMetadata().getSchema();
    final OClass oClass = schema.createClass("SQLDropIndexTestClass");
    oClass.createProperty("prop1", EXPECTED_PROP1_TYPE);
    oClass.createProperty("prop2", EXPECTED_PROP2_TYPE);
    schema.save();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)

Example 28 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class SQLSelectByLinkedPropertyIndexReuseTest method createSchemaForTest.

private void createSchemaForTest() {
    final OSchema schema = database.getMetadata().getSchema();
    if (!schema.existsClass("lpirtStudent")) {
        final OClass curatorClass = schema.createClass("lpirtCurator");
        curatorClass.createProperty("name", OType.STRING).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
        curatorClass.createProperty("salary", OType.INTEGER).createIndex(OClass.INDEX_TYPE.UNIQUE, new ODocument().field("ignoreNullValues", true));
        curatorClass.createIndex("curotorCompositeIndex", OClass.INDEX_TYPE.UNIQUE.name(), null, new ODocument().field("ignoreNullValues", true), new String[] { "salary", "name" });
        final OClass groupClass = schema.createClass("lpirtGroup");
        groupClass.createProperty("name", OType.STRING).createIndex(OClass.INDEX_TYPE.UNIQUE, new ODocument().field("ignoreNullValues", true));
        groupClass.createProperty("curator", OType.LINK, curatorClass).createIndex(OClass.INDEX_TYPE.UNIQUE, new ODocument().field("ignoreNullValues", true));
        final OClass diplomaClass = schema.createClass("lpirtDiploma");
        diplomaClass.createProperty("GPA", OType.DOUBLE).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
        diplomaClass.createProperty("thesis", OType.STRING).createIndex(OClass.INDEX_TYPE.FULLTEXT);
        diplomaClass.createProperty("name", OType.STRING).createIndex(OClass.INDEX_TYPE.UNIQUE, new ODocument().field("ignoreNullValues", true));
        diplomaClass.createIndex("diplomaThesisUnique", OClass.INDEX_TYPE.UNIQUE.name(), null, new ODocument().field("ignoreNullValues", true), new String[] { "thesis" });
        final OClass transcriptClass = schema.createClass("lpirtTranscript");
        transcriptClass.createProperty("id", OType.STRING).createIndex(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, new ODocument().field("ignoreNullValues", true));
        final OClass skillClass = schema.createClass("lpirtSkill");
        skillClass.createProperty("name", OType.STRING).createIndex(OClass.INDEX_TYPE.UNIQUE, new ODocument().field("ignoreNullValues", true));
        final OClass studentClass = schema.createClass("lpirtStudent");
        studentClass.createProperty("name", OType.STRING).createIndex(OClass.INDEX_TYPE.UNIQUE, new ODocument().field("ignoreNullValues", true));
        studentClass.createProperty("group", OType.LINK, groupClass).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
        studentClass.createProperty("diploma", OType.LINK, diplomaClass);
        studentClass.createProperty("transcript", OType.LINK, transcriptClass).createIndex(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, new ODocument().field("ignoreNullValues", true));
        studentClass.createProperty("skill", OType.LINK, skillClass);
        final ODocument metadata = new ODocument().field("ignoreNullValues", false);
        studentClass.createIndex("studentDiplomaAndNameIndex", OClass.INDEX_TYPE.UNIQUE.toString(), null, metadata.copy(), new String[] { "diploma", "name" });
        studentClass.createIndex("studentSkillAndGroupIndex", OClass.INDEX_TYPE.NOTUNIQUE_HASH_INDEX.toString(), null, metadata.copy(), new String[] { "skill", "group" });
        schema.save();
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 29 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class SQLInsertTest method insertAvoidingSubQuery.

@Test
public void insertAvoidingSubQuery() {
    final OSchema schema = database.getMetadata().getSchema();
    if (schema.getClass("test") == null)
        schema.createClass("test");
    ODocument doc = (ODocument) database.command(new OCommandSQL("INSERT INTO test(text) VALUES ('(Hello World)')")).execute();
    Assert.assertTrue(doc != null);
    Assert.assertEquals(doc.field("text"), "(Hello World)");
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 30 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class SQLSelectHashIndexReuseTest method testReuseOfIndexOnSeveralClassesFields.

@Test
public void testReuseOfIndexOnSeveralClassesFields() {
    final OSchema schema = database.getMetadata().getSchema();
    final OClass superClass = schema.createClass("sqlSelectHashIndexReuseTestSuperClass");
    superClass.createProperty("prop0", OType.INTEGER);
    final OClass oClass = schema.createClass("sqlSelectHashIndexReuseTestChildClass", superClass);
    oClass.createProperty("prop1", OType.INTEGER);
    oClass.createIndex("sqlSelectHashIndexReuseTestOnPropertiesFromClassAndSuperclass", OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, "prop0", "prop1");
    schema.save();
    long oldIndexUsage = profiler.getCounter("db.demo.query.indexUsed");
    long oldcompositeIndexUsed = profiler.getCounter("db.demo.query.compositeIndexUsed");
    long oldcompositeIndexUsed2 = profiler.getCounter("db.demo.query.compositeIndexUsed.2");
    final ODocument docOne = new ODocument("sqlSelectHashIndexReuseTestChildClass");
    docOne.field("prop0", 0);
    docOne.field("prop1", 1);
    docOne.save();
    final ODocument docTwo = new ODocument("sqlSelectHashIndexReuseTestChildClass");
    docTwo.field("prop0", 2);
    docTwo.field("prop1", 3);
    docTwo.save();
    final List<ODocument> result = database.command(new OSQLSynchQuery<ODocument>("select * from sqlSelectHashIndexReuseTestChildClass where prop0 = 0 and prop1 = 1")).execute();
    Assert.assertEquals(result.size(), 1);
    assertProfileCount(profiler.getCounter("db.demo.query.indexUsed"), oldIndexUsage, 1);
    assertProfileCount(profiler.getCounter("db.demo.query.compositeIndexUsed"), oldcompositeIndexUsed, 1);
    assertProfileCount(profiler.getCounter("db.demo.query.compositeIndexUsed.2"), oldcompositeIndexUsed2, 1);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Aggregations

OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)203 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)165 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)122 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)54 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)46 Test (org.testng.annotations.Test)35 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)31 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)23 Test (org.junit.Test)19 Before (org.junit.Before)16 ORID (com.orientechnologies.orient.core.id.ORID)15 OIndex (com.orientechnologies.orient.core.index.OIndex)15 Collection (java.util.Collection)15 Set (java.util.Set)15 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)9 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 BeforeClass (org.testng.annotations.BeforeClass)9 OStorage (com.orientechnologies.orient.core.storage.OStorage)6 ArrayList (java.util.ArrayList)5 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)4