本文整理汇总了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();
}
}
}
示例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();
}
}
}
示例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);
}
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
}
示例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();
}
示例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();
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}