Search in sources :

Example 91 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 92 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)

Example 93 with OSchema

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

the class MathTest method main.

public static final void main(String[] args) {
    final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:test").create();
    final OSchema schema = db.getMetadata().getSchema();
    final OClass clazz = schema.createClass("test");
    clazz.createProperty("numericAtt", OType.DOUBLE);
    db.command(new OCommandSQL("INSERT INTO test(numericAtt) VALUES (28.23)")).execute();
    final List<ODocument> docs = db.query(new OSQLSynchQuery("SELECT FROM test"));
    Double value = (Double) docs.get(0).field("numericAtt");
    System.out.println(value);
    Assert.assertEquals(new Double(28.23), new Float(28.23).doubleValue());
    Assert.assertEquals(new Float(28.23), new Double(28.23).floatValue());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 94 with OSchema

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

the class IndexUniqueTest method indexUniqueTest.

public void indexUniqueTest() throws Exception {
    String[] indexNames = new String[10];
    Random random = new Random();
    char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
    for (int i = 0; i < indexNames.length; i++) {
        String nm = "";
        for (int k = 0; k < 10; k++) nm += chars[random.nextInt(chars.length)];
        indexNames[i] = nm;
    }
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:./uniqueIndexTest");
    final int cores = Runtime.getRuntime().availableProcessors();
    if (db.exists()) {
        db.open("admin", "admin");
        db.drop();
    }
    for (int i = 0; i < propValues.length; i++) propValues[i] = new AtomicInteger();
    db.create();
    db.set(ODatabase.ATTRIBUTES.MINIMUMCLUSTERS, cores);
    OSchema schema = db.getMetadata().getSchema();
    OClass oClass = schema.createClass("indexTest");
    for (int i = 0; i < 10; i++) {
        oClass.createProperty("prop" + i, OType.INTEGER);
        oClass.createIndex(indexNames[i], OClass.INDEX_TYPE.UNIQUE, "prop" + i);
    }
    ExecutorService executor = Executors.newCachedThreadPool();
    List<Future<Integer>> futures = new ArrayList<Future<Integer>>();
    for (int i = 0; i < cores; i++) {
        phaser.register();
        futures.add(executor.submit(new Populator("plocal:./uniqueIndexTest", random.nextBoolean())));
    }
    int sum = 0;
    for (Future<Integer> future : futures) sum += future.get();
    System.out.println("Total documents " + sum);
    Assert.assertEquals(db.countClass("indexTest"), sum);
    Set<Integer>[] props = new Set[10];
    for (int i = 0; i < props.length; i++) {
        props[i] = new HashSet<Integer>();
    }
    for (ODocument document : db.browseClass("indexTest")) {
        for (int i = 0; i < 10; i++) {
            Set<Integer> propValues = props[i];
            Assert.assertTrue(propValues.add(document.<Integer>field("prop" + i)));
        }
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OConcurrentResultSet(com.orientechnologies.orient.core.sql.query.OConcurrentResultSet) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 95 with OSchema

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

the class MultipleDBAlignmentOnNodesJoining method onAfterDatabaseCreation.

/**
   * Event called right after the database has been created. It builds the schema and populates the db.
   *
   * @param db Current database
   */
protected void onAfterDatabaseCreation(final OrientBaseGraph db, String databaseURL) {
    String databaseName = db.getRawGraph().getName();
    System.out.println("Creating database schema for " + databaseName + "...");
    ODatabaseRecordThreadLocal.INSTANCE.set(db.getRawGraph());
    // building basic schema
    OClass personClass = db.getRawGraph().getMetadata().getSchema().createClass("Person");
    personClass.createProperty("id", OType.STRING);
    personClass.createProperty("name", OType.STRING);
    personClass.createProperty("birthday", OType.DATE);
    personClass.createProperty("children", OType.STRING);
    final OSchema schema = db.getRawGraph().getMetadata().getSchema();
    OClass person = schema.getClass("Person");
    idx = person.createIndex("Person.name", OClass.INDEX_TYPE.UNIQUE, "name");
    // populating db
    try {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Callable writer = createWriter(databaseName, databaseURL);
        Future f = executor.submit(writer);
        f.get();
        assertTrue(f.isDone());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Callable(java.util.concurrent.Callable) OCallable(com.orientechnologies.common.util.OCallable) IOException(java.io.IOException)

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