Search in sources :

Example 26 with ODatabaseDocumentInternal

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

the class OSQLNonBlockingQuery method execute.

@Override
public <RET> RET execute(final Object... iArgs) {
    final ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.INSTANCE.get();
    final ONonBlockingQueryFuture future = new ONonBlockingQueryFuture();
    if (database instanceof ODatabaseDocumentTx) {
        ODatabaseDocumentInternal currentThreadLocal = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
        final ODatabaseDocumentInternal db = ((ODatabaseDocumentTx) database).copy();
        if (currentThreadLocal != null) {
            currentThreadLocal.activateOnCurrentThread();
        } else {
            ODatabaseRecordThreadLocal.INSTANCE.set(null);
        }
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                db.activateOnCurrentThread();
                try {
                    OSQLAsynchQuery<T> query = new OSQLAsynchQuery<T>(OSQLNonBlockingQuery.this.getText(), OSQLNonBlockingQuery.this.getResultListener());
                    query.setFetchPlan(OSQLNonBlockingQuery.this.getFetchPlan());
                    query.setLimit(OSQLNonBlockingQuery.this.getLimit());
                    query.execute(iArgs);
                } catch (RuntimeException e) {
                    if (getResultListener() != null) {
                        getResultListener().end();
                    }
                    throw e;
                } finally {
                    if (db != null) {
                        try {
                            db.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    try {
                        synchronized (future) {
                            future.finished = true;
                            future.notifyAll();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        t.start();
        return (RET) future;
    } else {
        // TODO
        throw new RuntimeException("cannot run non blocking query with non tx db");
    }
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 27 with ODatabaseDocumentInternal

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

the class OSQLQuery method run.

/**
 * Delegates to the OQueryExecutor the query execution.
 */
@SuppressWarnings("unchecked")
public List<T> run(final Object... iArgs) {
    final ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.INSTANCE.get();
    if (database == null)
        throw new OQueryParsingException("No database configured");
    ((OMetadataInternal) database.getMetadata()).makeThreadLocalSchemaSnapshot();
    try {
        setParameters(iArgs);
        return (List<T>) database.getStorage().command(this);
    } finally {
        ((OMetadataInternal) database.getMetadata()).clearThreadLocalSchemaSnapshot();
    }
}
Also used : OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException) ArrayList(java.util.ArrayList) List(java.util.List) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 28 with ODatabaseDocumentInternal

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

the class OLuceneStorage method reOpen.

private void reOpen() throws IOException {
    if (mgrWriter != null) {
        OLogManager.instance().info(this, "index storage is open don't reopen");
        return;
    }
    ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.INSTANCE.get();
    final OAbstractPaginatedStorage storageLocalAbstract = (OAbstractPaginatedStorage) database.getStorage().getUnderlying();
    Directory dir = null;
    if (storageLocalAbstract instanceof OLocalPaginatedStorage) {
        String pathname = getIndexPath((OLocalPaginatedStorage) storageLocalAbstract);
        OLogManager.instance().info(this, "Opening NIOFS Lucene db=%s, path=%s", database.getName(), pathname);
        dir = NIOFSDirectory.open(new File(pathname).toPath());
    } else {
        OLogManager.instance().info(this, "Opening RAM Lucene index db=%s", database.getName());
        dir = new RAMDirectory();
    }
    final IndexWriter indexWriter = createIndexWriter(dir);
    mgrWriter = new TrackingIndexWriter(indexWriter);
    searcherManager = new SearcherManager(indexWriter, true, null);
    if (nrt != null) {
        nrt.close();
    }
    nrt = new ControlledRealTimeReopenThread(mgrWriter, searcherManager, 60.00, 0.1);
    nrt.setDaemon(true);
    nrt.start();
    flush();
    OLogManager.instance().info(this, "REOPEN DONE");
}
Also used : ControlledRealTimeReopenThread(org.apache.lucene.search.ControlledRealTimeReopenThread) TrackingIndexWriter(org.apache.lucene.index.TrackingIndexWriter) IndexWriter(org.apache.lucene.index.IndexWriter) TrackingIndexWriter(org.apache.lucene.index.TrackingIndexWriter) OLocalPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage) SearcherManager(org.apache.lucene.search.SearcherManager) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) File(java.io.File) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) RAMDirectory(org.apache.lucene.store.RAMDirectory) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory)

Example 29 with ODatabaseDocumentInternal

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

the class OLuceneFacetManager method buildFacetIndexIfNeeded.

protected void buildFacetIndexIfNeeded() throws IOException {
    if (metadata != null && metadata.containsField(FACET_FIELDS)) {
        ODatabaseDocumentInternal database = owner.getDatabase();
        Iterable<String> iterable = metadata.field(FACET_FIELDS);
        if (iterable != null) {
            Directory dir = getTaxDirectory(database);
            taxonomyWriter = new DirectoryTaxonomyWriter(dir, IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
            for (String s : iterable) {
                facetField = s;
                // facetField = "facet_" + s;
                // facetDim = s;
                // config.setIndexFieldName(s, "facet_" + s);
                config.setHierarchical(s, true);
            }
        }
    }
}
Also used : DirectoryTaxonomyWriter(org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory)

Example 30 with ODatabaseDocumentInternal

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

the class ORemoteImportTest method testImport.

@Test
public void testImport() throws UnsupportedEncodingException {
    ODatabaseDocumentInternal db = new ODatabaseDocumentTx("remote:localhost/" + ORemoteImportTest.class.getSimpleName());
    db.open("admin", "admin");
    try {
        String content = "{\"records\": [{\"@type\": \"d\", \"@rid\": \"#9:0\",\"@version\": 1,\"@class\": \"V\"}]}";
        OStorageRemote storage = (OStorageRemote) db.getStorage();
        final StringBuffer buff = new StringBuffer();
        storage.importDatabase("-merge=true", new ByteArrayInputStream(content.getBytes("UTF8")), "data.json", new OCommandOutputListener() {

            @Override
            public void onMessage(String iText) {
                buff.append(iText);
            }
        });
        assertTrue(buff.toString().contains("Database import completed"));
    } finally {
        db.close();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) OStorageRemote(com.orientechnologies.orient.client.remote.OStorageRemote) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) Test(org.junit.Test)

Aggregations

ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)149 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)42 OStorage (com.orientechnologies.orient.core.storage.OStorage)31 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)26 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)20 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)18 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)18 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)16 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)16 ORID (com.orientechnologies.orient.core.id.ORID)14 OException (com.orientechnologies.common.exception.OException)13 IOException (java.io.IOException)13 ORecordId (com.orientechnologies.orient.core.id.ORecordId)12 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)10 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)10 ORecord (com.orientechnologies.orient.core.record.ORecord)8 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)7 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)6 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)5 OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)5