当前位置: 首页>>代码示例>>Java>>正文


Java ODatabase类代码示例

本文整理汇总了Java中com.orientechnologies.orient.core.db.ODatabase的典型用法代码示例。如果您正苦于以下问题:Java ODatabase类的具体用法?Java ODatabase怎么用?Java ODatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ODatabase类属于com.orientechnologies.orient.core.db包,在下文中一共展示了ODatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fix

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
public static void fix(MeshOptions options) {
	File graphDir = new File(options.getStorageOptions().getDirectory(), "storage");
	if (graphDir.exists()) {
		log.info("Checking database {" + graphDir + "}");
		OrientGraphFactory factory = new OrientGraphFactory("plocal:" + graphDir.getAbsolutePath()).setupPool(5, 100);
		try {
			// Enable the patched security class
			factory.setProperty(ODatabase.OPTIONS.SECURITY.toString(), OSecuritySharedPatched.class);
			ODatabaseDocumentTx tx = factory.getDatabase();
			try {
				OClass userClass = tx.getMetadata().getSchema().getClass("OUser");
				if (userClass == null) {
					log.info("OrientDB user credentials not found. Recreating needed roles and users.");
					tx.getMetadata().getSecurity().create();
					tx.commit();
				} else {
					log.info("OrientDB user credentials found. Skipping fix.");
				}
			} finally {
				tx.close();
			}
		} finally {
			factory.close();
		}
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:27,代码来源:MissingOrientCredentialFixer.java

示例2: withActiveDb

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
private static <T> T withActiveDb(final ODatabase db, final Supplier<T> supplier) {
  @SuppressWarnings("resource")
  final ODatabaseDocumentInternal currentDb = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
  if (db.equals(currentDb) || !(db instanceof ODatabaseDocumentInternal)) {
    return supplier.get();
  }
  try {
    ODatabaseRecordThreadLocal.INSTANCE.set((ODatabaseDocumentInternal) db);
    return supplier.get();
  }
  finally {
    if (currentDb != null) {
      ODatabaseRecordThreadLocal.INSTANCE.set(currentDb);
    }
    else {
      ODatabaseRecordThreadLocal.INSTANCE.remove();
    }
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:20,代码来源:EntityHook.java

示例3: flushEvents

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
private void flushEvents(final ODatabase db) {
  final Map<ODocument, EventKind> events = dbEvents.remove(db);
  if (events != null) {
    final UnitOfWork work = UnitOfWork.pause();
    final String remoteNodeId = isRemote.get();
    try {
      if (remoteNodeId == null) {
        postEvents(db, events, null);
      }
      else {
        // posting events from remote node, mark current thread as replicating
        EventHelper.asReplicating(() -> postEvents(db, events, remoteNodeId));
      }
    }
    catch (Throwable e) { // NOSONAR
      // exceptions as a result of posting events should not affect the commit,
      // so log and swallow them rather than let them propagate back to Orient
      log.error("Failed to post entity events", e);
    }
    finally {
      UnitOfWork.resume(work);
    }
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:25,代码来源:EntityHook.java

示例4: postEvents

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
private void postEvents(final ODatabase db, final Map<ODocument, EventKind> events, final String remoteNodeId) {
  final List<EntityEvent> batchedEvents = new ArrayList<>();
  for (final Entry<ODocument, EventKind> entry : events.entrySet()) {
    final EntityEvent event = newEntityEvent(entry.getKey(), entry.getValue());
    if (event != null) {
      event.setRemoteNodeId(remoteNodeId);
      eventManager.post(event);
      db.activateOnCurrentThread();
      if (event instanceof Batchable) {
        batchedEvents.add(event);
      }
    }
  }

  if (!batchedEvents.isEmpty()) {
    eventManager.post(new EntityBatchEvent(batchedEvents));
    db.activateOnCurrentThread();
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:20,代码来源:EntityHook.java

示例5: initDatabase

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
public static void initDatabase(@NonNull final ODatabase db) {
    final JsonLog info = JsonLog.newInfoLog(Logger.getLogger(EventLogRepository.class.getName()), EventLogRepository.class.getName());
    try {
        OClass timestampedClass = db.getMetadata().getSchema().getClass(Timestamped.class.getSimpleName());
        if (timestampedClass == null) {
            timestampedClass = db.getMetadata().getSchema().createAbstractClass(Timestamped.class.getSimpleName());
            timestampedClass.createProperty(Timestamped.Field.created_on.name(), OType.DATETIME);
            timestampedClass.createProperty(Timestamped.Field.updated_on.name(), OType.DATETIME);
            info.log("startUp", () -> Json.createObjectBuilder().add("class", Timestamped.class.getSimpleName()).add("created", true).build());
        } else {
            info.log("startUp", () -> Json.createObjectBuilder().add("class", Timestamped.class.getSimpleName()).build());
        }

        OClass logRecordClass = db.getMetadata().getSchema().getClass(EventLogRecord.class.getSimpleName());
        if (logRecordClass == null) {
            logRecordClass = db.getMetadata().getSchema().createClass(EventLogRecord.class.getSimpleName()).setSuperClasses(ImmutableList.of(timestampedClass));
            logRecordClass.createProperty(EventLogRecord.Field.event.name(), OType.STRING);
            info.log("startUp", () -> Json.createObjectBuilder().add("class", EventLogRecord.class.getSimpleName()).add("created", true).build());
        } else {
            info.log("startUp", () -> Json.createObjectBuilder().add("class", EventLogRecord.class.getSimpleName()).build());
        }

    } finally {
        db.close();
    }
}
 
开发者ID:runrightfast,项目名称:runrightfast-vertx,代码行数:27,代码来源:EventLogRepository.java

示例6: testSavingEventLogRecord

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
private void testSavingEventLogRecord(final ODatabase db, final String testName) throws Exception {
    db.registerHook(new SetCreatedOnAndUpdatedOn());

    final EventLogRecord eventLogRecord = new EventLogRecord();
    try {
        db.begin();
        eventLogRecord.setEvent("app.started");
        eventLogRecord.save();
        db.commit();
    } catch (final Exception e) {
        db.rollback();
        throw e;
    }

    log.logp(INFO, CLASS_NAME, testName, String.format("doc = %s", eventLogRecord.toJSON()));
    assertThat(eventLogRecord.getCreatedOn(), is(notNullValue()));
    assertThat(eventLogRecord.getUpdatedOn(), is(notNullValue()));
}
 
开发者ID:runrightfast,项目名称:runrightfast-vertx,代码行数:19,代码来源:RunRightFastOrientDBLifeCycleListenerTest.java

示例7: initDatabase

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
private static void initDatabase() {
    final OServerAdmin admin = service.getServerAdmin();
    try {
        OrientDBUtils.createDatabase(admin, CLASS_NAME);
    } finally {
        admin.close();
    }

    final Optional<ODatabaseDocumentTxSupplier> dbSupplier = service.getODatabaseDocumentTxSupplier(CLASS_NAME);
    assertThat(dbSupplier.isPresent(), is(true));

    try (final ODatabase db = dbSupplier.get().get()) {
        final OClass timestampedClass = db.getMetadata().getSchema().createAbstractClass(Timestamped.class.getSimpleName());
        timestampedClass.createProperty(Timestamped.Field.created_on.name(), OType.DATETIME);
        timestampedClass.createProperty(Timestamped.Field.updated_on.name(), OType.DATETIME);

        final OClass logRecordClass = db.getMetadata().getSchema().createClass(EventLogRecord.class.getSimpleName()).setSuperClasses(ImmutableList.of(timestampedClass));
        logRecordClass.createProperty(EventLogRecord.Field.event.name(), OType.STRING);
    }
}
 
开发者ID:runrightfast,项目名称:runrightfast-vertx,代码行数:21,代码来源:EmbeddedOrientDBServiceWithSSLTest.java

示例8: initDatabase

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
private static void initDatabase() {
    final OServerAdmin admin = service.getServerAdmin();
    try {
        OrientDBUtils.createDatabase(admin, CLASS_NAME);
    } finally {
        admin.close();
    }
    try (final ODatabase db = service.getODatabaseDocumentTxSupplier(CLASS_NAME).get().get()) {
        final OClass timestampedClass = db.getMetadata().getSchema().createAbstractClass(Timestamped.class.getSimpleName());
        timestampedClass.createProperty(Timestamped.Field.created_on.name(), OType.DATETIME);
        timestampedClass.createProperty(Timestamped.Field.updated_on.name(), OType.DATETIME);

        final OClass logRecordClass = db.getMetadata().getSchema().createClass(EventLogRecord.class.getSimpleName()).setSuperClasses(ImmutableList.of(timestampedClass));
        logRecordClass.createProperty(EventLogRecord.Field.event.name(), OType.STRING);
    }
}
 
开发者ID:runrightfast,项目名称:runrightfast-vertx,代码行数:17,代码来源:OrientDBHazelcastPluginTest.java

示例9: initDatabase

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
public void initDatabase() {
    try (final ODatabase db = dbSupplier.get()) {
        OClass timestampedClass = db.getMetadata().getSchema().getClass(Timestamped.class.getSimpleName());
        if (timestampedClass == null) {
            timestampedClass = db.getMetadata().getSchema().createAbstractClass(Timestamped.class.getSimpleName());
            timestampedClass.createProperty(Timestamped.Field.created_on.name(), OType.DATETIME);
            timestampedClass.createProperty(Timestamped.Field.updated_on.name(), OType.DATETIME);
            info.log("startUp", () -> Json.createObjectBuilder().add("class", Timestamped.class.getSimpleName()).add("created", true).build());
        } else {
            info.log("startUp", () -> Json.createObjectBuilder().add("class", Timestamped.class.getSimpleName()).build());
        }

        OClass logRecordClass = db.getMetadata().getSchema().getClass(EventLogRecord.class.getSimpleName());
        if (logRecordClass == null) {
            logRecordClass = db.getMetadata().getSchema().createClass(EventLogRecord.class.getSimpleName()).setSuperClasses(ImmutableList.of(timestampedClass));
            logRecordClass.createProperty(EventLogRecord.Field.event.name(), OType.STRING);
            info.log("startUp", () -> Json.createObjectBuilder().add("class", EventLogRecord.class.getSimpleName()).add("created", true).build());
        } else {
            info.log("startUp", () -> Json.createObjectBuilder().add("class", EventLogRecord.class.getSimpleName()).build());
        }
    }
}
 
开发者ID:runrightfast,项目名称:runrightfast-vertx,代码行数:23,代码来源:EventLogRepository.java

示例10: fixOrientDBRights

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
/**
 * Required for explicit update of rights due to changes in OrientDB 2.2.23
 * Related issue: https://github.com/orientechnologies/orientdb/issues/7549
 * @param db - database to apply fix on
 */
public void fixOrientDBRights(ODatabase<?> db) {
	OSecurity security = db.getMetadata().getSecurity();
	ORole readerRole = security.getRole("reader");
	readerRole.grant(ResourceGeneric.CLUSTER, "orole", ORole.PERMISSION_READ);
	readerRole.grant(ResourceGeneric.CLUSTER, "ouser", ORole.PERMISSION_READ);
	readerRole.grant(ResourceGeneric.CLASS, "orole", ORole.PERMISSION_READ);
	readerRole.grant(ResourceGeneric.CLASS, "ouser", ORole.PERMISSION_READ);
	readerRole.grant(ResourceGeneric.SYSTEM_CLUSTERS, null, ORole.PERMISSION_READ);
	readerRole.save();
	ORole writerRole = security.getRole("writer");
	writerRole.grant(ResourceGeneric.CLUSTER, "orole", ORole.PERMISSION_READ);
	writerRole.grant(ResourceGeneric.CLUSTER, "ouser", ORole.PERMISSION_READ);
	writerRole.grant(ResourceGeneric.CLASS, "orole", ORole.PERMISSION_READ);
	writerRole.grant(ResourceGeneric.CLASS, "ouser", ORole.PERMISSION_READ);
	writerRole.grant(ResourceGeneric.SYSTEM_CLUSTERS, null, ORole.PERMISSION_READ);
	writerRole.save();
}
 
开发者ID:OrienteerBAP,项目名称:wicket-orientdb,代码行数:23,代码来源:OrientDbWebApplication.java

示例11: doStart

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
	OrientDBEndpoint endpoint = (OrientDBEndpoint)getEndpoint();
	ODatabase<?> db = endpoint.databaseOpen();
	Object dbResult = db.command(new OCommandSQL(endpoint.getSQLQuery())).execute();
	
	Object out = endpoint.makeOutObject(dbResult);
	endpoint.databaseClose(db);
	
	Exchange exchange = getEndpoint().createExchange();
	exchange.getIn().setBody(out);
	getProcessor().process(exchange);
	
	super.doStart();
}
 
开发者ID:OrienteerBAP,项目名称:camel-orientdb,代码行数:16,代码来源:OrientDBConsumer.java

示例12: processList

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
private List<Object> processList(List<?> inputList,OrientDBEndpoint endpoint,ODatabase<?> db) throws Exception{
	List<Object> outputList = new ArrayList<Object>();
	for (Object inputElement : inputList) {
		Object dbResult = processSingleObject(inputElement,endpoint,db);
		if (dbResult instanceof List){
			outputList.addAll((List<?>)dbResult);
		}else{
			outputList.add(dbResult);
		}
	}
	return outputList;
}
 
开发者ID:OrienteerBAP,项目名称:camel-orientdb,代码行数:13,代码来源:OrientDBProducer.java

示例13: databaseOpen

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
public ODatabase<?> databaseOpen() throws Exception{
	String url = getCamelContext().getProperty(OrientDBComponent.DB_URL);
	String username = getCamelContext().getProperty(OrientDBComponent.DB_USERNAME);
	String password = getCamelContext().getProperty(OrientDBComponent.DB_PASSWORD);
	
	if(url!=null && username!=null) {
		return dbPool.get(url, username, password).acquire();
	}else{
		throw new Exception("Cannot connect to OrientDB server without properties "+OrientDBComponent.DB_URL+" and "+OrientDBComponent.DB_USERNAME);
	}
}
 
开发者ID:OrienteerBAP,项目名称:camel-orientdb,代码行数:12,代码来源:OrientDBEndpoint.java

示例14: onOpen

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
@Override
public void onOpen(final ODatabaseInternal db) {
  if (OSecurityNull.class.equals(db.getProperty(ODatabase.OPTIONS.SECURITY.toString()))) {
    return; // ignore maintenance operations which run without security, such as index repair
  }
  if (!startRecording(db)) {
    pendingDbs.add(db);
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:10,代码来源:EntityHook.java

示例15: startRecording

import com.orientechnologies.orient.core.db.ODatabase; //导入依赖的package包/类
private boolean startRecording(final ODatabase db) {
  if (recordingDatabases.contains(db.getName())) {
    db.registerListener(this);
    // this call must be made with the given db active on this thread
    withActiveDb(db, () -> db.registerHook(this, HOOK_POSITION.LAST));
    return true;
  }
  return false;
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:10,代码来源:EntityHook.java


注:本文中的com.orientechnologies.orient.core.db.ODatabase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。