com.orientechnologies.orient.core.db.ODatabase Java Examples

The following examples show how to use com.orientechnologies.orient.core.db.ODatabase. 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: ODatabaseConfigurationWidget.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
public ODatabaseConfigurationWidget(String id, IModel<Void> model, IModel<ODocument> widgetDocumentModel) {
    super(id, model, widgetDocumentModel);
    Form<ODatabase<?>> form = new Form<ODatabase<?>>("form");
    structureTable  = new OrienteerStructureTable<ODatabase<?>, String>("attributes", CurrentDatabaseModel.<ODatabase<?>>getInstance(), ODatabaseMetaPanel.ODATABASE_ATTRS) {

        @Override
        protected Component getValueComponent(String id, final IModel<String> rowModel) {
            return new ODatabaseMetaPanel<Object>(id, getModeModel(), getModel(), rowModel);
        }

    };
    structureTable.addCommand(new EditSchemaCommand<ODatabase<?>>(structureTable, getModeModel()));
    structureTable.addCommand(new SaveSchemaCommand<ODatabase<?>>(structureTable, getModeModel()));

    form.add(structureTable);
    add(form);
}
 
Example #2
Source File: OrientDbWebApplication.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #3
Source File: ODatabaseMetaPanel.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected V getValue(ODatabase<?> entity, String critery) {
	if(ATTRIBUTES.VALIDATION.name().equals(critery)) {
		Boolean value = (Boolean) entity.get(ATTRIBUTES.VALIDATION);
		if(value==null) value = ((ODatabaseDocument)entity).isValidationEnabled();
		return (V) (value!=null?value:Boolean.TRUE);
	} else if (ATTRIBUTES.CUSTOM.name().equals(critery)){
		List<OStorageEntryConfiguration> properties = (List<OStorageEntryConfiguration>) entity.get(ATTRIBUTES.CUSTOM);
		StringBuilder sb = new StringBuilder();
		if(properties!=null) {
 		for (OStorageEntryConfiguration entry : properties) {
	sb.append(entry.name).append("=").append(entry.value).append('\n');
}
		}
		return (V)sb.toString();
	}
	else {
		return (V) entity.get(ATTRIBUTES.valueOf(critery));
	}
}
 
Example #4
Source File: EntityHook.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void onOpen(final ODatabaseInternal db) {
  unregisterLiveQueryHook(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);
  }
  // reload metadata when (re-)opening a DB connection if old schema is gone
  // (can be removed after upgrading to OrientDB 2.2.33 as it does it for us)
  if (db.getMetadata().getSchema().countClasses() == 0) {
    log.debug("Reloading metadata for {} as storage has changed", db.getName());
    db.getMetadata().reload();
  }
}
 
Example #5
Source File: EntityHook.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
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();
    }
  }
}
 
Example #6
Source File: EntityHook.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Posts the given events; this will be a paired sequence of ODocument, EventKind, ODocument, EventKind, etc...
 */
private void postEvents(final ODatabase db, final List<Object> events, final String remoteNodeId) {
  final List<EntityEvent> batchedEvents = new ArrayList<>();
  for (int i = 0; i < events.size(); i += 2) {
    final EntityEvent event = newEntityEvent((ODocument) events.get(i), (EventKind) events.get(i + 1));
    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();
  }
}
 
Example #7
Source File: EntityHook.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void flushEvents(final ODatabase db) {
  final List<Object> 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);
    }
  }
}
 
Example #8
Source File: EntityHook.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Unregisters {@link OLiveQueryHook} from the opened DB to reduce overhead as we don't use this feature.
 */
private void unregisterLiveQueryHook(final ODatabase db) {
  Optional<OLiveQueryHook> liveQueryHook = db.getHooks().keySet().stream()
      .filter(hook -> hook instanceof OLiveQueryHook)
      .findFirst();

  if (liveQueryHook.isPresent()) {
    log.debug("Unregistering OLiveQueryHook");
    db.unregisterListener(liveQueryHook.get());
    db.unregisterHook(liveQueryHook.get());
  }
}
 
Example #9
Source File: DefaultODatabaseThreadLocalFactory.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to obtain {@link ODatabaseDocument} from {@link ODatabase}
 * @param db {@link ODatabase} to cast from
 * @return {@link ODatabaseDocument} for a specified {@link ODatabase}
 */
public static ODatabaseDocument castToODatabaseDocument(ODatabase<?> db)
{
	while(db!=null && !(db instanceof ODatabaseDocument))
	{
		if(db instanceof ODatabaseInternal<?>)
		{
			db = ((ODatabaseInternal<?>)db).getUnderlying();
		}
	}
	return (ODatabaseDocument)db;
}
 
Example #10
Source File: EntityHook.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the current DB connection. Normally this is whichever connection is active on the thread.
 * But when performing a commit we always return the connection which is being committed, so we can
 * track changes even when another connection is used to "fix" records during that commit.
 */
private ODatabaseDocumentInternal getCurrrentDb() {
  ODatabase db = commitDb.get();
  if (db == null) {
    db = ODatabaseRecordThreadLocal.instance().get();
  }
  return (ODatabaseDocumentInternal) db;
}
 
Example #11
Source File: EntityHook.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #12
Source File: ODatabaseMetaPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
protected void setValue(ODatabase<?> entity, String critery, V value) {
    ODatabaseDocument db = OrientDbWebSession.get().getDatabase();
    db.commit();
    try
    {
        if(ATTRIBUTES.CLUSTERSELECTION.name().equals(critery))
        {
            if(value!=null) entity.set(ATTRIBUTES.valueOf(critery), value.toString());
        } else if(ATTRIBUTES.CUSTOM.name().equals(critery)) { 
        	if(value!=null) {
        		String stringValue = value.toString();
        		String[] customs = stringValue.split("\\r?\\n");
        		for (String custom : customs) {
		if(custom.indexOf('=')>0) entity.set(ATTRIBUTES.CUSTOM, custom);
	}
        	} else {
        		entity.set(ATTRIBUTES.CUSTOM, "clear");
        	}
        }else {
            entity.set(ATTRIBUTES.valueOf(critery), value);
        }
    } finally
    {
        db.begin();
    }
}
 
Example #13
Source File: DatabaseListenerSupport.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void onBeforeTxCommit(final ODatabase db) {
  // no-op
}
 
Example #14
Source File: OLuceneWithinOperator.java    From orientdb-lucene with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<OIdentifiable> filterRecords(ODatabase<?> iRecord, List<String> iTargetClasses, OSQLFilterCondition iCondition,
    Object iLeft, Object iRight) {
  return null;
}
 
Example #15
Source File: OLuceneNearOperator.java    From orientdb-lucene with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<OIdentifiable> filterRecords(ODatabase<?> iRecord, List<String> iTargetClasses, OSQLFilterCondition iCondition,
    Object iLeft, Object iRight) {
  return null;
}
 
Example #16
Source File: OLuceneTextOperator.java    From orientdb-lucene with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<OIdentifiable> filterRecords(ODatabase<?> iRecord, List<String> iTargetClasses, OSQLFilterCondition iCondition,
    Object iLeft, Object iRight) {
  return null;
}
 
Example #17
Source File: ODatabaseMetaPanel.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
public ODatabaseMetaPanel(String id, IModel<DisplayMode> modeModel, IModel<ODatabase<?>> entityModel,
                          IModel<String> criteryModel) {
    super(id, modeModel, entityModel, criteryModel);
}
 
Example #18
Source File: CurrentDatabaseModel.java    From wicket-orientdb with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <D extends ODatabase<?>> CurrentDatabaseModel<D> getInstance() {
	return (CurrentDatabaseModel<D>)INSTANCE;
}
 
Example #19
Source File: EntityAdapter.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Only allow detaching when we have no DB context or it is from a different DB.
 * If we have a valid context from the same DB then we don't need to detach yet.
 */
private boolean allowDetach() {
  ODatabase<?> db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
  return db == null || !getDbName().equals(db.getName());
}
 
Example #20
Source File: DatabaseListenerSupport.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean onCorruptionRepairDatabase(final ODatabase db, final String reason, final String action) {
  return false;
}
 
Example #21
Source File: DatabaseListenerSupport.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void onAfterTxRollback(ODatabase iDatabase) {
  // no-op
}
 
Example #22
Source File: DatabaseListenerSupport.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void onBeforeTxRollback(final ODatabase db) {
  // no-op
}
 
Example #23
Source File: DatabaseListenerSupport.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void onAfterTxCommit(ODatabase iDatabase) {
  // no-op
}
 
Example #24
Source File: DatabaseListenerSupport.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void onBeforeTxBegin(final ODatabase db) {
  // no-op
}
 
Example #25
Source File: DatabaseListenerSupport.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void onClose(final ODatabase db) {
  // no-op
}
 
Example #26
Source File: DatabaseListenerSupport.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void onOpen(final ODatabase db) {
  // no-op
}
 
Example #27
Source File: DatabaseListenerSupport.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void onDelete(final ODatabase db) {
  // no-op
}
 
Example #28
Source File: DatabaseListenerSupport.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void onCreate(final ODatabase db) {
  // no-op
}
 
Example #29
Source File: EntityHook.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private void stopRecording(final ODatabase db) {
  db.unregisterHook(this);
  db.unregisterListener(this);
}
 
Example #30
Source File: EntityHook.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void onAfterTxRollback(final ODatabase db) {
  commitDb.remove();
  dbEvents.remove(db);
}