Java源码示例:com.orientechnologies.common.log.OLogManager

示例1
public static void main(final String[] args) throws Exception {

    // tweak levels to provide a smoother console experience
    LogManager.getLogManager().readConfiguration(Main.class.getResourceAsStream("/logging.properties"));

    OLogManager.instance().installCustomFormatter();

    // support property-based configuration of PbeCompression
    Injector injector = Guice.createInjector(new WireModule(binder -> {
      binder.bind(PbeCipherFactory.class).to(PbeCipherFactoryImpl.class);
      binder.bind(CryptoHelper.class).to(CryptoHelperImpl.class);
      binder.bind(PbeCompression.class);
    }));

    // register support for PBE compression; needed to work with the security database
    OCompressionFactory.INSTANCE.register(injector.getInstance(PbeCompression.class));

    // register 'ConflictHook' strategy but leave it disabled; needed to load databases that set it as a strategy
    Orient.instance().getRecordConflictStrategy().registerImplementation(ConflictHook.NAME, new ConflictHook(false));

    OConsoleDatabaseApp.main(args);
  }
 
示例2
@Override
public boolean execute(OHttpRequest iRequest, OHttpResponse iResponse)
		throws Exception
{
	logger.info("Importer called");

	ImportJob importJob = getImportJobFromRequest(iRequest);
	(new ImportCSVRunnable(importJob)).run();

	iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", null,
			OHttpUtils.CONTENT_TEXT_PLAIN, "");

	OLogManager.instance().warn(this, "Response sent.");

	return false;
}
 
示例3
protected void initIndex(String indexName, OIndexDefinition indexDefinition, String clusterIndexName,
    OStreamSerializer valueSerializer, boolean isAutomatic, ODocument metadata) {
  this.index = indexDefinition;
  this.indexName = indexName;
  this.serializer = valueSerializer;
  this.automatic = isAutomatic;
  this.clusterIndexName = clusterIndexName;
  this.metadata = metadata;
  try {

    this.index = indexDefinition;

    checkCollectionIndex(indexDefinition);
    reOpen(metadata);

  } catch (IOException e) {
    OLogManager.instance().error(this, "Error on initializing Lucene index", e);
  }
}
 
示例4
protected void closeIndex() throws IOException {
  OLogManager.instance().debug(this, "Closing Lucene index '" + this.indexName + "'...");

  if (nrt != null) {
    nrt.interrupt();
    nrt.close();
  }

  if (searcherManager != null)
    searcherManager.close();

  if (mgrWriter != null) {
    mgrWriter.getIndexWriter().commit();
    mgrWriter.getIndexWriter().close();
  }
}
 
示例5
@Override
public Object get(Object key) {
  try {
    if (key instanceof OSpatialCompositeKey) {
      final OSpatialCompositeKey newKey = (OSpatialCompositeKey) key;

      final SpatialOperation strategy = newKey.getOperation() != null ? newKey.getOperation() : SpatialOperation.Intersects;

      if (SpatialOperation.Intersects.equals(strategy))
        return searchIntersect(newKey, newKey.getMaxDistance(), newKey.getContext());
      else if (SpatialOperation.IsWithin.equals(strategy))
        return searchWithin(newKey, newKey.getContext());

    } else if (key instanceof OCompositeKey)
      return searchIntersect((OCompositeKey) key, 0, null);

  } catch (IOException e) {
    OLogManager.instance().error(this, "Error on getting entry against Lucene index", e);
  }

  return null;
}
 
示例6
private void fetchFirstBatch() {
  try {

    switch (queryContext.cfg) {

    case NO_FILTER_NO_SORT:
      topDocs = queryContext.searcher.search(query, PAGE_SIZE);
      break;
    case FILTER_SORT:
      topDocs = queryContext.searcher.search(query, queryContext.filter, PAGE_SIZE, queryContext.sort);
      break;
    case FILTER:
      topDocs = queryContext.searcher.search(query, queryContext.filter, PAGE_SIZE);
      break;
    case SORT:
      topDocs = queryContext.searcher.search(query, PAGE_SIZE, queryContext.sort);
      break;
    }
  } catch (IOException e) {
    OLogManager.instance().error(this, "Error on fetching document by query '%s' to Lucene index", e, query);
  }
}
 
示例7
/**
 * Until OrientDB cleans up its logging infrastructure, this synchronizes its global minimum log level to the minimum
 * log level configured for any of its loggers.
 * 
 * @see http://www.prjhub.com/#/issues/3744
 * @see http://www.prjhub.com/#/issues/5327
 */
private void configureOrientMinimumLogLevel() {
  int minimumLevel = getOrientMininumLogLevel();
  log.debug("Configuring OrientDB global minimum log level to {}", minimumLevel);
  OLogManager logManager = OLogManager.instance();
  logManager.setDebugEnabled(minimumLevel <= Level.FINE.intValue());
  logManager.setInfoEnabled(minimumLevel <= Level.INFO.intValue());
  logManager.setWarnEnabled(minimumLevel <= Level.WARNING.intValue());
  logManager.setErrorEnabled(minimumLevel <= Level.SEVERE.intValue());
}
 
示例8
protected OrientDbDriver() throws IOException {
	super();

	OLogManager.instance().setWarnEnabled(false);
	OLogManager.instance().setInfoEnabled(false);
	OLogManager.instance().setDebugEnabled(false);
	graph = OrientGraph.open();
}
 
示例9
public OETLComponentFactory registerSource(final Class<? extends OSource> iComponent) {
  try {
    sources.put(iComponent.newInstance().getName(), iComponent);
  } catch (Exception e) {
    OLogManager.instance().error(this, "Error on registering source: %s", iComponent.getName());
  }
  return this;
}
 
示例10
public OETLComponentFactory registerBlock(final Class<? extends OBlock> iComponent) {
  try {
    blocks.put(iComponent.newInstance().getName(), iComponent);
  } catch (Exception e) {
    OLogManager.instance().error(this, "Error on registering block: %s", iComponent.getName());
  }
  return this;
}
 
示例11
public OETLComponentFactory registerExtractor(final Class<? extends OExtractor> iComponent) {
  try {
    extractors.put(iComponent.newInstance().getName(), iComponent);
  } catch (Exception e) {
    OLogManager.instance().error(this, "Error on registering extractor: %s", iComponent.getName());
  }
  return this;
}
 
示例12
public OETLComponentFactory registerTransformer(final Class<? extends OTransformer> iComponent) {
  try {
    transformers.put(iComponent.newInstance().getName(), iComponent);
  } catch (Exception e) {
    OLogManager.instance().error(this, "Error on registering transformer: %s", iComponent.getName());
  }
  return this;
}
 
示例13
public OETLComponentFactory registerLoader(final Class<? extends OLoader> iComponent) {
  try {
    loaders.put(iComponent.newInstance().getName(), iComponent);
  } catch (Exception e) {
    OLogManager.instance().error(this, "Error on registering loader: %s", iComponent.getName());
  }
  return this;
}
 
示例14
@Override
public void startup() {
  super.startup();
  Orient.instance().addDbLifecycleListener(this);

  OIndexes.registerFactory(new OLuceneIndexFactory(true));
  OSQLEngine.registerOperator(new OLuceneTextOperator());
  OSQLEngine.registerOperator(new OLuceneWithinOperator());
  OSQLEngine.registerOperator(new OLuceneNearOperator());
  OLogManager.instance().info(this, "Lucene index plugin installed and active. Lucene version: %s",
      OLuceneIndexManagerAbstract.LUCENE_VERSION);
}
 
示例15
@Override
public void onDrop(final ODatabaseInternal iDatabase) {
  OLogManager.instance().info(this, "Dropping Lucene indexes...");
  for (OIndex idx : iDatabase.getMetadata().getIndexManager().getIndexes()) {
    if (idx.getInternal() instanceof OLuceneIndex) {
      OLogManager.instance().info(this, "- index '%s'", idx.getName());
      idx.delete();
    }
  }
}
 
示例16
@Override
public IndexWriter createIndexWriter(Directory directory, ODocument metadata) throws IOException {

  Analyzer analyzer = getAnalyzer(metadata);
  Version version = getLuceneVersion(metadata);
  IndexWriterConfig iwc = new IndexWriterConfig(version, analyzer);
  iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);

  facetManager = new OLuceneFacetManager(this, metadata);

  OLogManager.instance().debug(this, "Creating Lucene index in '%s'...", directory);

  return new IndexWriter(directory, iwc);
}
 
示例17
@Override
public IndexWriter openIndexWriter(Directory directory, ODocument metadata) throws IOException {
  Analyzer analyzer = getAnalyzer(metadata);
  Version version = getLuceneVersion(metadata);
  IndexWriterConfig iwc = new IndexWriterConfig(version, analyzer);
  iwc.setOpenMode(IndexWriterConfig.OpenMode.APPEND);

  OLogManager.instance().debug(this, "Opening Lucene index in '%s'...", directory);

  return new IndexWriter(directory, iwc);
}
 
示例18
public void addDocument(Document doc) {
  try {

    reopenToken = mgrWriter.addDocument(doc);
  } catch (IOException e) {
    OLogManager.instance().error(this, "Error on adding new document '%s' to Lucene index", e, doc);
  }
}
 
示例19
public void deleteDocument(Query query) {
  try {
    reopenToken = mgrWriter.deleteDocuments(query);
    if (!mgrWriter.getIndexWriter().hasDeletions()) {
      OLogManager.instance().error(this, "Error on deleting document by query '%s' to Lucene index",
          new OIndexException("Error deleting document"), query);
    }
  } catch (IOException e) {
    OLogManager.instance().error(this, "Error on deleting document by query '%s' to Lucene index", e, query);
  }
}
 
示例20
public void commit() {
  try {
    mgrWriter.getIndexWriter().commit();
  } catch (IOException e) {
    OLogManager.instance().error(this, "Error on committing Lucene index", e);
  }
}
 
示例21
public Iterator<Map.Entry<Object, V>> iterator() {
  try {
    IndexReader reader = getSearcher().getIndexReader();
    return new OLuceneMapEntryIterator<Object, V>(reader, index);

  } catch (IOException e) {
    OLogManager.instance().error(this, "Error on creating iterator against Lucene index", e);
  }
  return new HashSet<Map.Entry<Object, V>>().iterator();
}
 
示例22
public void clear() {
  try {
    mgrWriter.getIndexWriter().deleteAll();
  } catch (IOException e) {
    OLogManager.instance().error(this, "Error on clearing Lucene index", e);
  }
}
 
示例23
@Override
public void close() {
  try {
    closeIndex();
  } catch (Throwable e) {
    OLogManager.instance().error(this, "Error on closing Lucene index", e);
  }
}
 
示例24
public void rollback() {
  try {
    mgrWriter.getIndexWriter().rollback();
    reOpen(metadata);
  } catch (IOException e) {
    OLogManager.instance().error(this, "Error on rolling back Lucene index", e);
  }
}
 
示例25
public long size(final ValuesTransformer<V> transformer) {

    IndexReader reader = null;
    IndexSearcher searcher = null;
    try {
      reader = getSearcher().getIndexReader();
    } catch (IOException e) {
      OLogManager.instance().error(this, "Error on getting size of Lucene index", e);
    } finally {
      if (searcher != null) {
        release(searcher);
      }
    }
    return reader.numDocs();
  }
 
示例26
public void release(IndexSearcher searcher) {
  try {
    searcherManager.release(searcher);
  } catch (IOException e) {
    OLogManager.instance().error(this, "Error on releasing index searcher  of Lucene index", e);
  }
}
 
示例27
public IndexSearcher getSearcher() throws IOException {
  try {
    nrt.waitForGeneration(reopenToken);
  } catch (InterruptedException e) {
    OLogManager.instance().error(this, "Error on get searcher from Lucene index", e);
  }
  return searcherManager.acquire();
}
 
示例28
@Override
public Map.Entry<K, V> next() {
  try {
    Document doc = reader.document(currentIdx);
    String val = "";
    if (definition.getFields().size() > 0) {
      for (String field : definition.getFields()) {
        val += doc.get(field);
      }
    } else {
      val = doc.get(OLuceneIndexManagerAbstract.KEY);
    }
    final String finalVal = val;
    final ORecordId id = new ORecordId(doc.get(OLuceneIndexManagerAbstract.RID));
    currentIdx++;
    return new Map.Entry<K, V>() {
      @Override
      public K getKey() {
        return (K) finalVal;
      }

      @Override
      public V getValue() {
        return (V) id;
      }

      @Override
      public V setValue(V value) {
        return null;
      }
    };
  } catch (IOException e) {
    OLogManager.instance().error(this, "Error on iterating Lucene result", e);
  }
  return null;
}
 
示例29
@Override
public void onDrop(final ODatabaseInternal iDatabase) {
  try {
    OLogManager.instance().debug(this, "Dropping Lucene indexes...");
    for (OIndex idx : iDatabase.getMetadata().getIndexManager().getIndexes()) {
      if (idx.getInternal() instanceof OLuceneIndex) {
        OLogManager.instance().debug(this, "- index '%s'", idx.getName());
        idx.delete();
      }
    }
  } catch (Exception e) {
    OLogManager.instance().warn(this, "Error on dropping Lucene indexes", e);
  }
}
 
示例30
private void fetchMoreResult() {

      TopDocs topDocs = null;
      try {

        switch (queryContext.cfg) {

        case NO_FILTER_NO_SORT:
          topDocs = queryContext.searcher.searchAfter(array[array.length - 1], query, PAGE_SIZE);
          break;
        case FILTER_SORT:
          topDocs = queryContext.searcher.searchAfter(array[array.length - 1], query, queryContext.filter, PAGE_SIZE,
              queryContext.sort);
          break;
        case FILTER:
          topDocs = queryContext.searcher.searchAfter(array[array.length - 1], query, queryContext.filter, PAGE_SIZE);
          break;
        case SORT:
          topDocs = queryContext.searcher.searchAfter(array[array.length - 1], query, PAGE_SIZE, queryContext.sort);
          break;
        }
        array = topDocs.scoreDocs;
      } catch (IOException e) {
        OLogManager.instance().error(this, "Error on fetching document by query '%s' to Lucene index", e, query);
      }

    }