Search in sources :

Example 66 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class DBNModel method getNodeByObject.

@Nullable
public DBNDatabaseNode getNodeByObject(DBRProgressMonitor monitor, DBSObject object, boolean addFiltered) {
    DBNDatabaseNode node = getNodeByObject(object);
    if (node != null) {
        return node;
    }
    DBSObject[] path = DBUtils.getObjectPath(object, true);
    for (int i = 0; i < path.length - 1; i++) {
        DBSObject item = path[i];
        DBSObject nextItem = path[i + 1];
        node = getNodeByObject(item);
        if (node == null) {
            return null;
        }
        try {
            cacheNodeChildren(monitor, node, nextItem, addFiltered);
        } catch (DBException e) {
            log.error(e.getMessage());
            return null;
        }
    }
    return getNodeByObject(object);
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) Nullable(org.jkiss.code.Nullable)

Example 67 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class DBVModel method findEntity.

/**
     * Search for virtual entity descriptor
     *
     * @param entity    entity
     * @param createNew create new entity if missing
     * @return entity virtual entity
     */
public DBVEntity findEntity(DBSEntity entity, boolean createNew) {
    DBSObject[] path = DBUtils.getObjectPath(entity, false);
    if (path.length == 0) {
        log.warn("Empty entity path");
        return null;
    }
    if (path[0] != dataSourceContainer) {
        log.warn("Entity's root must be datasource container '" + dataSourceContainer.getName() + "'");
        return null;
    }
    DBVContainer container = this;
    for (int i = 1; i < path.length; i++) {
        DBSObject item = path[i];
        container = container.getContainer(item.getName(), createNew);
        if (container == null) {
            return null;
        }
    }
    return container.getEntity(entity.getName(), createNew);
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Example 68 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class SQLStructEditor method createObjectReferences.

protected void createObjectReferences(DBRProgressMonitor monitor, DBECommandContext commandContext, ObjectCreateCommand createCommand) throws DBException {
    OBJECT_TYPE object = createCommand.getObject();
    final DBERegistry editorsRegistry = object.getDataSource().getContainer().getPlatform().getEditorsRegistry();
    for (Class childType : getChildTypes()) {
        Collection<? extends DBSObject> children = getChildObjects(monitor, object, childType);
        if (!CommonUtils.isEmpty(children)) {
            SQLObjectEditor<DBSObject, CONTAINER_TYPE> nestedEditor = getObjectEditor(editorsRegistry, childType);
            if (nestedEditor != null) {
                for (DBSObject child : children) {
                    ObjectCreateCommand childCreateCommand = (ObjectCreateCommand) nestedEditor.makeCreateCommand(child);
                    //((StructCreateCommand)createCommand).aggregateCommand(childCreateCommand);
                    commandContext.addCommand(childCreateCommand, null, false);
                }
            }
        }
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Aggregations

DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)68 DBException (org.jkiss.dbeaver.DBException)19 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)13 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)12 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)9 ISelection (org.eclipse.jface.viewers.ISelection)8 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)8 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)8 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)7 ArrayList (java.util.ArrayList)6 GridData (org.eclipse.swt.layout.GridData)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)5 DBEObjectMaker (org.jkiss.dbeaver.model.edit.DBEObjectMaker)4 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)4 DBSObjectSelector (org.jkiss.dbeaver.model.struct.DBSObjectSelector)4 DBSWrapper (org.jkiss.dbeaver.model.struct.DBSWrapper)4 ToolWizardDialog (org.jkiss.dbeaver.ui.dialogs.tools.ToolWizardDialog)4