Java Code Examples for com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx#close()

The following examples show how to use com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LuceneInsertReadMultithreadTest.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {

  db = new ODatabaseDocumentTx(url);
  db.open("admin", "admin");
  db.declareIntent(new OIntentMassiveInsert());
  db.begin();
  for (int i = 0; i < cycle; i++) {
    ODocument doc = new ODocument("City");

    doc.field("name", "Rome");

    db.save(doc);
    if (i % commitBuf == 0) {
      db.commit();
      db.begin();
    }

  }

  db.close();
}
 
Example 2
Source File: LuceneInsertMultithreadTest.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {

  db = new ODatabaseDocumentTx(url);
  db.open("admin", "admin");
  db.declareIntent(new OIntentMassiveInsert());
  db.begin();
  for (int i = 0; i < cycle; i++) {
    ODocument doc = new ODocument("City");

    doc.field("name", "Rome");

    db.save(doc);
    if (i % commitBuf == 0) {
      db.commit();
      db.begin();
    }

  }

  db.close();
}
 
Example 3
Source File: DefaultAnalysisService.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
@Transactional
public void removeAnalysis(String analysisId) throws NotFoundException {	
	Analysis a = (Analysis)storageService.getEntityById(analysisId);
	List<Analysis> list = getAnalysisByTable(a.getTableName());
	int no = list.size();
	
	storageService.removeEntityById(analysisId);		
	
	LOG.debug("**** For table " + a.getTableName() +"  there are " + no + " analysis");
	if (no == 1) {
		//last analysis deleted, delete also the table
		ODatabaseDocumentTx db = null;
		try {
			LOG.debug("**** Delete table : " + a.getTableName());
			String prefix = SecurityUtil.getLoggedUsername() + "-";
			db = new ODatabaseDocumentTx(getDatabasePath(), false).open("admin", "admin");
			OrientDbUtils.dropClass(db, a.getTableName());
		} catch (Throwable t) {
			LOG.error(t.getMessage(), t);
		} finally {
			if (db != null) {
				db.close();
			}
		}
	}		
}
 
Example 4
Source File: AddAnalysisPanel.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
@Override
protected List<String> load() {
	ODatabaseDocumentTx db = null;
	try {
		String prefix = SecurityUtil.getLoggedUsername() + "-";
		try {
			db = new ODatabaseDocumentTx(analysisService.getDatabasePath(), false).open("admin", "admin");
		} catch (Throwable t) {
			// critical case					
			t.printStackTrace();
			LOG.error(t.getMessage(), t);
			return new ArrayList<String>();
		}
		List<ClassMetadata> result = OrientDbUtils.getDatabaseClasses(db, prefix);								
		List<String> names = new ArrayList<String>();
		for (ClassMetadata c : result) {
			if (!c.getName().contains(AnalysisUtil.FREEZE_MARKUP)) {
				names.add(c.getName().substring(prefix.length()));
			}
		}
		return names;
	} finally {
		if (db != null) {
			db.close();
		}
	}
}
 
Example 5
Source File: OOrientDBLoader.java    From orientdb-etl with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(final OETLProcessor iProcessor, final ODocument iConfiguration, final OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);

  if (iConfiguration.containsField("dbURL"))
    dbURL = (String) resolve(iConfiguration.field("dbURL"));
  if (iConfiguration.containsField("dbUser"))
    dbUser = (String) resolve(iConfiguration.field("dbUser"));
  if (iConfiguration.containsField("dbPassword"))
    dbPassword = (String) resolve(iConfiguration.field("dbPassword"));
  if (iConfiguration.containsField("dbType"))
    dbType = DB_TYPE.valueOf(iConfiguration.field("dbType").toString().toUpperCase());
  if (iConfiguration.containsField("tx"))
    tx = (Boolean) iConfiguration.field("tx");
  if (iConfiguration.containsField("wal"))
    wal = (Boolean) iConfiguration.field("wal");
  if (iConfiguration.containsField("txUseLog"))
    txUseLog = (Boolean) iConfiguration.field("txUseLog");
  if (iConfiguration.containsField("batchCommit"))
    batchCommit = (Integer) iConfiguration.field("batchCommit");
  if (iConfiguration.containsField("dbAutoCreate"))
    dbAutoCreate = (Boolean) iConfiguration.field("dbAutoCreate");
  if (iConfiguration.containsField("dbAutoDropIfExists"))
    dbAutoDropIfExists = (Boolean) iConfiguration.field("dbAutoDropIfExists");
  if (iConfiguration.containsField("dbAutoCreateProperties"))
    dbAutoCreateProperties = (Boolean) iConfiguration.field("dbAutoCreateProperties");
  if (iConfiguration.containsField("useLightweightEdges"))
    useLightweightEdges = (Boolean) iConfiguration.field("useLightweightEdges");
  if (iConfiguration.containsField("standardElementConstraints"))
    standardElementConstraints = (Boolean) iConfiguration.field("standardElementConstraints");

  clusterName = iConfiguration.field("cluster");
  className = iConfiguration.field("class");
  indexes = iConfiguration.field("indexes");
  classes = iConfiguration.field("classes");

  if (iConfiguration.containsField("settings")) {
    final ODocument settings = (ODocument) iConfiguration.field("settings");
    settings.setAllowChainedAccess(false);
    for (String s : settings.fieldNames()) {
      final OGlobalConfiguration v = OGlobalConfiguration.findByKey(s);
      if (v != null)
        v.setValue(settings.field(s));
    }
  }

  if (!wal)
    OGlobalConfiguration.USE_WAL.setValue(wal);

  switch (dbType) {
  case DOCUMENT:
    final ODatabaseDocumentTx documentDatabase = new ODatabaseDocumentTx(dbURL);
    if (documentDatabase.exists() && dbAutoDropIfExists) {
      log(OETLProcessor.LOG_LEVELS.INFO, "Dropping existent database '%s'...", dbURL);
      documentDatabase.open(dbUser, dbPassword);
      documentDatabase.drop();
    }

    if (documentDatabase.exists()) {
      log(OETLProcessor.LOG_LEVELS.DEBUG, "Opening database '%s'...", dbURL);
      documentDatabase.open(dbUser, dbPassword);
    } else if (dbAutoCreate) {
      documentDatabase.create();
    } else
      throw new IllegalArgumentException("Database '" + dbURL + "' not exists and 'dbAutoCreate' setting is false");

    documentDatabase.close();
    break;

  case GRAPH:
    final OrientGraphFactory factory = new OrientGraphFactory(dbURL, dbUser, dbPassword);
    if (dbAutoDropIfExists && factory.exists()) {
      log(OETLProcessor.LOG_LEVELS.INFO, "Dropping existent database '%s'...", dbURL);
      factory.drop();
    }

    final OrientBaseGraph graphDatabase = tx ? factory.getTx() : factory.getNoTx();
    graphDatabase.shutdown();
    break;
  }
}
 
Example 6
Source File: DefaultAnalysisService.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
@Transactional
public void freeze(final Analysis analysis) {
	final String message = new StringResourceModel("Analysis.freezed", null, new Object[] {analysis.getName()}).getString();		
	final ReportService service = reportService;
	Runnable r = new Runnable() {
		
		@Override
		public void run() {				
			ODatabaseDocumentTx db = null;
			ReportResultEvent event = null;
			String freezeClassName;
			try {
				db = new ODatabaseDocumentTx(getDatabasePath(), false).open("admin", "admin");
				freezeClassName = analysis.getTableName() + AnalysisUtil.FREEZE_MARKUP + UUID.randomUUID();
				OrientDbUtils.duplicateClass(db, analysis.getTableName(), freezeClassName);

				analysis.setFreezed(true);
				analysis.setTableName(freezeClassName);
				modifyAnalysis(analysis);
				event = new ReportResultEvent(analysis.getCreatedBy(), analysis.getName(), AnalysisUtil.FREEZE_ACTION,
						message);
			} catch (Throwable t) {
				// critical case
				t.printStackTrace();
				LOG.error(t.getMessage(), t);
				// freezed unsuccessfull
				analysis.setFreezed(false);
				modifyAnalysis(analysis);
				event = new ReportResultEvent(analysis.getCreatedBy(), analysis.getName(), AnalysisUtil.FREEZE_ACTION,
						AnalysisUtil.FREEZE_FAILED + t.getMessage());
			} finally {
				if (db != null) {
					db.close();
					db = null;
				}
			}
			service.notifyReportListener(event);														
		}
	};
	new Thread(r).start();
		   
}