Search in sources :

Example 81 with CubridDatabase

use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.

the class ActionSupportUtil method isSupportMultiSelCheckDbUser.

/**
	 * 
	 * Return whether support the multi selection and all selection type is
	 * equal <code>type</code> and the all selection owner is equal to logined
	 * database user
	 * 
	 * @param obj Object
	 * @param type String
	 * @return boolean
	 */
public static boolean isSupportMultiSelCheckDbUser(Object obj, String type) {
    if (obj instanceof ISchemaNode) {
        ISchemaNode schemaNode = (ISchemaNode) obj;
        if (!type.equals(schemaNode.getType())) {
            return false;
        }
        CubridDatabase database = schemaNode.getDatabase();
        if (isNotRunningAndNotLogin(database)) {
            return false;
        }
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        if (dbInfo == null) {
            LOGGER.error("The database.getDatabaseInfo() is a null.");
            return false;
        }
        DbUserInfo userInfo = dbInfo.getAuthLoginedDbUserInfo();
        if (userInfo == null) {
            LOGGER.error("The dbInfo.getAuthLoginedDbUserInfo() is a null.");
            return false;
        }
        if (userInfo.isDbaAuthority()) {
            return true;
        }
        boolean isSameUser = StringUtil.isEqualIgnoreCase(userInfo.getName(), getOwner(schemaNode));
        if (isSameUser) {
            return true;
        }
    } else if (obj instanceof Object[]) {
        Object[] objArr = (Object[]) obj;
        if (objArr.length == 0) {
            return false;
        }
        CubridDatabase database = null;
        for (Object object : objArr) {
            //Check every object whether support
            if (!isSupportMultiSelCheckDbUser(object, type)) {
                return false;
            }
            //Check whether they are in the same database
            ISchemaNode node = (ISchemaNode) object;
            CubridDatabase db = node.getDatabase();
            if (database == null) {
                database = db;
            } else if (!database.getId().equals(db.getId())) {
                return false;
            }
        }
        //Check the database whether login and running
        if (isNotRunningAndNotLogin(database)) {
            return false;
        }
        return true;
    }
    return false;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 82 with CubridDatabase

use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.

the class LayoutUtil method checkAllQueryEditor.

/**
	 * 
	 * When server disconnect or delete,check query editor whether some
	 * transaction are not commit
	 * 
	 * @param cubridServer the CubridServer object
	 * @return <code>true</code> if transaction is commited;<code>false</code>
	 *         otherwise
	 */
public static boolean checkAllQueryEditor(CubridServer cubridServer) {
    IWorkbenchPage page = getActivePage();
    if (page == null) {
        return true;
    }
    IEditorReference[] editorRefArr = page.getEditorReferences();
    if (editorRefArr == null || editorRefArr.length == 0) {
        return true;
    }
    boolean isContinue = true;
    for (IEditorReference editorRef : editorRefArr) {
        String editorId = editorRef.getId();
        if (editorId != null && editorId.equals(QueryEditorPart.ID)) {
            QueryEditorPart queryEditor = (QueryEditorPart) editorRef.getEditor(false);
            CubridDatabase db = queryEditor.getSelectedDatabase();
            if (db != null && db.getServer() != null && db.getServer().getId().equals(cubridServer.getId())) {
                isContinue = queryEditor.resetJDBCConnection();
            }
        }
    }
    return isContinue;
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 83 with CubridDatabase

use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.

the class LayoutUtil method checkAllQueryEditor.

/**
	 * 
	 * When database logout or stop,check query editor whether some transaction
	 * are not commit
	 * 
	 * @param databaseNode the CubridDatabase object
	 * @return <code>true</code> if transaction is commited;<code>false</code>
	 *         otherwise
	 */
public static boolean checkAllQueryEditor(CubridDatabase databaseNode) {
    IWorkbenchPage page = getActivePage();
    if (page == null) {
        return true;
    }
    boolean isContinue = true;
    IEditorReference[] editorRefArr = page.getEditorReferences();
    if (editorRefArr == null || editorRefArr.length == 0) {
        return true;
    }
    for (IEditorReference editorRef : editorRefArr) {
        String editorId = editorRef.getId();
        if (editorId != null && editorId.equals(QueryEditorPart.ID)) {
            QueryEditorPart queryEditor = (QueryEditorPart) editorRef.getEditor(false);
            CubridDatabase db = queryEditor.getSelectedDatabase();
            if (db != null && db.getId().equals(databaseNode.getId())) {
                isContinue = queryEditor.resetJDBCConnection();
            }
        }
    }
    return isContinue;
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 84 with CubridDatabase

use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.

the class SQLGenerateUtils method generateCloneTableSql.

public static String generateCloneTableSql(DefaultSchemaNode schemaNode, String newName) {
    CubridDatabase database = schemaNode.getDatabase();
    String tableName = schemaNode.getName();
    SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
    if (schemaInfo == null) {
        CommonUITool.openErrorBox(Messages.bind(Messages.errGetSchemaInfo, tableName));
        LOGGER.debug("Can't get the SchemaInfo:" + tableName);
        return "";
    }
    int columnCounts = schemaInfo == null ? 0 : schemaInfo.getAttributes().size();
    StringBuilder columns = new StringBuilder();
    if (columnCounts > 0) {
        for (int i = 0; i < columnCounts; i++) {
            DBAttribute da = (DBAttribute) schemaInfo.getAttributes().get(i);
            if (columns.length() > 0) {
                columns.append(", ");
            }
            columns.append(QuerySyntax.escapeKeyword(da.getName()));
        }
    } else {
        columns.append("*");
    }
    StringBuffer sql = new StringBuffer();
    sql.append("CREATE TABLE ");
    sql.append(QuerySyntax.escapeKeyword(newName));
    sql.append(" AS ").append(StringUtil.NEWLINE).append("SELECT ");
    sql.append(columns);
    sql.append(StringUtil.NEWLINE).append("FROM ");
    sql.append(QuerySyntax.escapeKeyword(tableName));
    sql.append(";");
    return format(sql.toString());
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 85 with CubridDatabase

use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.

the class LoginQueryEditDialog method fillDatabaseCombo.

/**
	 * 
	 * Fill in the database combo
	 * 
	 * @param list the database list
	 */
private void fillDatabaseCombo(List<CubridDatabase> list) {
    selectDatabase = null;
    connectionComp.getDatabaseCombo().removeAll();
    if (list == null || list.isEmpty()) {
        //For Cubrid Manager, if the server host is disconnected or has no database, 'demodb' will be set as default.
        connectionComp.getDatabaseCombo().setText("demodb");
        return;
    }
    CubridDatabase firstDb = null;
    for (CubridDatabase db : list) {
        DatabaseInfo databaseInfo = db.getDatabaseInfo();
        if (databaseInfo == null) {
            continue;
        }
        connectionComp.getDatabaseCombo().add(databaseInfo.getDbName());
        firstDb = firstDb == null ? db : firstDb;
        if (selDatabaseName != null && selDatabaseName.equals(databaseInfo.getDbName())) {
            selectDatabase = db;
        }
    }
    if (selectDatabase == null && firstDb != null) {
        selectDatabase = firstDb;
        selDatabaseName = selectDatabase.getDatabaseInfo() == null ? "" : selectDatabase.getDatabaseInfo().getDbName();
    }
    if (selectDatabase == null || null == selectDatabase.getDatabaseInfo()) {
        return;
    }
    connectionComp.getDatabaseCombo().setText(selectDatabase.getDatabaseInfo().getDbName());
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)278 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)104 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)79 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)67 ArrayList (java.util.ArrayList)45 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)43 TreeViewer (org.eclipse.jface.viewers.TreeViewer)42 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)36 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)33 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)30 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)29 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)28 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)25 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)22 Shell (org.eclipse.swt.widgets.Shell)22 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)19 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)18 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)18 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)18 ITask (com.cubrid.common.core.task.ITask)17