Search in sources :

Example 36 with OCommandScript

use of com.orientechnologies.orient.core.command.script.OCommandScript in project orientdb by orientechnologies.

the class TestGraphTransactionOnBatch method testReferToInTxCreatedAndDeletedVertex.

@Test
public void testReferToInTxCreatedAndDeletedVertex() {
    try {
        db.command(new OCommandScript("sql", "begin \n LET t0 = create vertex V set Mid = '1' \n" + "LET t1 = delete vertex V where Mid = '1' \n LET t2 = create vertex V set Mid = '2' \n" + "LET t4 = create edge E from $t2 to $t0 \n commit \n return [$t4] ")).execute();
        Assert.fail("it should go in exception because referring to a in transaction delete vertex");
    } catch (Exception ex) {
    }
    List<ODocument> res = db.query(new OSQLSynchQuery("select from E"));
    Assert.assertEquals(res.size(), 0);
}
Also used : OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 37 with OCommandScript

use of com.orientechnologies.orient.core.command.script.OCommandScript in project orientdb by orientechnologies.

the class TestGraphTransactionOnBatch method testDuplicateRollback.

@Test
public void testDuplicateRollback() {
    OClass clazz = db.getMetadata().getSchema().createClass("Test");
    clazz.setSuperClass(V);
    clazz.createProperty("id", OType.STRING).createIndex(INDEX_TYPE.UNIQUE);
    try {
        db.command(new OCommandScript("sql", "BEGIN \n LET a = create vertex Test SET id = \"12345678\" \n LET b = create vertex Test SET id = \"4kkrPhGe\" \n LET c =create vertex Test SET id = \"4kkrPhGe\" \n COMMIT \n RETURN $b ")).execute();
        Assert.fail("expected record duplicate exception");
    } catch (ORecordDuplicatedException ex) {
    }
    try {
        db.command(new OCommandScript("sql", "BEGIN \n LET a = create vertex Test content {\"id\": \"12345678\"} \n LET b = create vertex Test content {\"id\": \"4kkrPhGe\"} \n LET c =create vertex Test content { \"id\": \"4kkrPhGe\"} \n COMMIT \n RETURN $b ")).execute();
        Assert.fail("expected record duplicate exception");
    } catch (ORecordDuplicatedException ex) {
    }
    List<ODocument> res = db.query(new OSQLSynchQuery("select from Test"));
    Assert.assertEquals(0, res.size());
}
Also used : ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) 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.junit.Test)

Example 38 with OCommandScript

use of com.orientechnologies.orient.core.command.script.OCommandScript in project orientdb by orientechnologies.

the class TestBatchRemoteResultSet method runBatchQuery.

@Test
public void runBatchQuery() {
    String batchQuery = "begin; LET t0 = CREATE VERTEX V set mame=\"a\" ;\n LET t1 = CREATE VERTEX V set name=\"b\" ;\n" + "LET t2 = CREATE EDGE E FROM $t0 TO $t1 ;\n commit retry 100\n" + "return [$t0,$t1,$t2]";
    OrientGraph graph = new OrientGraph("remote:localhost:3064/" + OrientGraphRemoteTest.class.getSimpleName(), "root", "root");
    Iterable<OIdentifiable> res = graph.getRawGraph().command(new OCommandScript("sql", batchQuery)).execute();
    Iterator iter = res.iterator();
    assertTrue(iter.next() instanceof OIdentifiable);
    assertTrue(iter.next() instanceof OIdentifiable);
    Object edges = iter.next();
    assertTrue(edges instanceof Collection);
    assertTrue(((Collection) edges).iterator().next() instanceof OIdentifiable);
}
Also used : OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) Iterator(java.util.Iterator) Collection(java.util.Collection) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Test(org.junit.Test)

Example 39 with OCommandScript

use of com.orientechnologies.orient.core.command.script.OCommandScript in project orientdb by orientechnologies.

the class LuceneVsLuceneTest method init.

@Before
public void init() {
    InputStream stream = ClassLoader.getSystemResourceAsStream("testLuceneIndex.sql");
    db.command(new OCommandScript("sql", getScriptFromStream(stream))).execute();
    OSchema schema = db.getMetadata().getSchema();
    OFileUtils.deleteRecursively(getPath().getAbsoluteFile());
    try {
        Directory dir = getDirectory();
        analyzer = new OLucenePerFieldAnalyzerWrapper(new StandardAnalyzer());
        analyzer.add("title", new StandardAnalyzer()).add("Song.title", new StandardAnalyzer());
        IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
        iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
        indexWriter = new IndexWriter(dir, iwc);
    } catch (IOException e) {
        e.printStackTrace();
    }
    db.command(new OCommandSQL("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE")).execute();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OLucenePerFieldAnalyzerWrapper(com.orientechnologies.lucene.analyzer.OLucenePerFieldAnalyzerWrapper) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) IndexWriter(org.apache.lucene.index.IndexWriter) InputStream(java.io.InputStream) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) IOException(java.io.IOException) Directory(org.apache.lucene.store.Directory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 40 with OCommandScript

use of com.orientechnologies.orient.core.command.script.OCommandScript in project orientdb by orientechnologies.

the class LuceneCreateIndexTest method loadAndTest.

@Test
public void loadAndTest() {
    InputStream stream = ClassLoader.getSystemResourceAsStream("testLuceneIndex.sql");
    db.command(new OCommandScript("sql", getScriptFromStream(stream))).execute();
    db.command(new OCommandSQL("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE METADATA {\"analyzer\":\"" + StandardAnalyzer.class.getName() + "\"}")).execute();
    db.command(new OCommandSQL("create index Song.author on Song (author) FULLTEXT ENGINE LUCENE METADATA {\"analyzer\":\"" + StandardAnalyzer.class.getName() + "\"}")).execute();
    ODocument doc = new ODocument("Song");
    doc.field("title", "Local");
    doc.field("author", "Local");
    db.save(doc);
    testMetadata();
    assertQuery();
    assertNewQuery();
    db.close();
    db.open("admin", "admin");
    assertQuery();
    assertNewQuery();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) InputStream(java.io.InputStream) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)43 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)21 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)18 Test (org.junit.Test)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)9 InputStream (java.io.InputStream)9 Test (org.testng.annotations.Test)9 Before (org.junit.Before)8 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)6 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)4 IOException (java.io.IOException)4 Collection (java.util.Collection)3 List (java.util.List)3 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)3 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)2 OException (com.orientechnologies.common.exception.OException)2 OCommandRequest (com.orientechnologies.orient.core.command.OCommandRequest)2