Search in sources :

Example 46 with DatabaseInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.

the class CreateViewDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    parentComp = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(parentComp, SWT.NONE);
    {
        final GridData gdComposite = new GridData(SWT.FILL, SWT.FILL, true, true);
        composite.setLayoutData(gdComposite);
        GridLayout layout = new GridLayout();
        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
        layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
        layout.numColumns = 1;
        composite.setLayout(layout);
    }
    tabFolder = new TabFolder(composite, SWT.NONE);
    final GridData gdTabFolder = new GridData(SWT.FILL, SWT.FILL, true, true);
    tabFolder.setLayoutData(gdTabFolder);
    final TabItem generalTabItem = new TabItem(tabFolder, SWT.NONE);
    generalTabItem.setText(Messages.tabItemGeneral);
    final Composite compositeGenaral = createGeneralComposite();
    generalTabItem.setControl(compositeGenaral);
    final TabItem ddlTabItem = new TabItem(tabFolder, SWT.NONE);
    ddlTabItem.setText(Messages.tabItemSQLScript);
    final Composite sqlScriptComp = createSQLScriptComposite();
    ddlTabItem.setControl(sqlScriptComp);
    tabFolder.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            boolean isFirstTab = tabFolder.getSelectionIndex() == 0;
            boolean isLastTab = tabFolder.getSelectionIndex() == tabFolder.getItemCount() - 1;
            if (isFirstTab) {
                tableText.setFocus();
            } else if (isLastTab) {
                StringBuilder sb = new StringBuilder();
                String dropSql = makeDropSQLScript();
                if (dropSql.length() > 0) {
                    sb.append(dropSql);
                    sb.append(StringUtil.NEWLINE);
                    sb.append(StringUtil.NEWLINE);
                    sb.append(StringUtil.NEWLINE);
                }
                sb.append(makeCreateSQLScript());
                String ownerNew = ownerCombo.getText();
                String ownerOld = null;
                if (isNewTableFlag) {
                    DatabaseInfo dbInfo = database.getDatabaseInfo();
                    ownerOld = dbInfo.getAuthLoginedDbUserInfo().getName();
                } else {
                    ownerOld = classInfo.getOwnerName();
                }
                boolean isSameUser = StringUtil.isEqualIgnoreCase(ownerOld, ownerNew);
                if (!isSameUser) {
                    sb.append(";");
                    sb.append(StringUtil.NEWLINE);
                    sb.append(StringUtil.NEWLINE);
                    sb.append(StringUtil.NEWLINE);
                    sb.append(makeChangeOwnerSQLScript()).append(";");
                    sb.append(StringUtil.NEWLINE);
                }
                sqlText.setText(formatSql(sb.toString()));
            }
        }
    });
    init();
    tableText.setFocus();
    return parent;
}
Also used : TabItem(org.eclipse.swt.widgets.TabItem) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) TabFolder(org.eclipse.swt.widgets.TabFolder) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 47 with DatabaseInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.

the class CreateViewDialog method getViewComment.

/**
	 * get view's comment
	 *
	 * @return
	 */
private String getViewComment() {
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    SchemaComment schemaComment = null;
    String viewName = tableText.getText();
    try {
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        conn = JDBCConnectionManager.getConnection(dbInfo, true);
        schemaComment = SchemaCommentHandler.loadObjectDescription(dbInfo, conn, viewName, CommentType.VIEW);
    } catch (SQLException e) {
        LOGGER.error(e.getMessage());
        CommonUITool.openErrorBox(e.getMessage());
    } finally {
        QueryUtil.freeQuery(stmt, rs);
    }
    return schemaComment.getDescription();
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment)

Example 48 with DatabaseInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.

the class TableEditorPart method okPressed.

protected void okPressed() {
    if (!verifyTableName()) {
        return;
    }
    if (columnsTable.getItemCount() == 0) {
        CommonUITool.openErrorBox(Messages.noAttributes);
        return;
    }
    String message = (oldSchemaInfo == null) ? Messages.msgCreateTableConfirm : Messages.msgAlterTableConfirm;
    if (!CommonUITool.openConfirmBox(message)) {
        return;
    }
    tableName = tableNameText.getText();
    owner = ownerCombo.getText();
    String tableDesc = tableDescText.getText();
    newSchemaInfo.setClassname(tableName);
    newSchemaInfo.setOwner(owner);
    newSchemaInfo.setDescription(tableDesc);
    if (reuseOIDBtn != null) {
        newSchemaInfo.setReuseOid(reuseOIDBtn.getSelection());
    }
    DatabaseInfo dbInfo = database.getDatabaseInfo();
    CommonSQLExcuterTask commonSqlTask = new CommonSQLExcuterTask(dbInfo);
    schemaDDL.setEndLineChar("$$$$");
    String ddlStr = null;
    if (isNewTableFlag) {
        ddlStr = schemaDDL.getSchemaDDL(newSchemaInfo);
    } else {
        ddlStr = schemaDDL.getSchemaDDL(oldSchemaInfo, newSchemaInfo);
    }
    boolean isExecuteCommonSqlTask = false;
    String[] sqlStr = ddlStr.split("\\$\\$\\$\\$");
    for (String sql : sqlStr) {
        String trimSql = sql.trim();
        if (trimSql.length() > 0 && !trimSql.startsWith("--")) {
            if (dbInfo.isShard()) {
                sql = dbInfo.wrapShardQuery(sql);
            }
            commonSqlTask.addSqls(sql);
            isExecuteCommonSqlTask = true;
        }
    }
    // do with table user change
    String changeOwnerDDL = getChangeOwnerDDL();
    if (StringUtil.isNotEmpty(changeOwnerDDL)) {
        changeOwnerDDL = dbInfo.wrapShardQuery(changeOwnerDDL);
        commonSqlTask.addCallSqls(changeOwnerDDL);
        isExecuteCommonSqlTask = true;
    }
    schemaDDL.setEndLineChar(";");
    // do with column null attribute change
    List<String[]> nullAttrChangedColumnList = getNotNullChangedColumn();
    // if the column is null value, when set this column for not null,need
    // change these null value for default value
    List<String> nullToDefaultChangedColumnList = new ArrayList<String>();
    List<String> defaultValList = new ArrayList<String>();
    if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
        for (Iterator<String[]> it = nullAttrChangedColumnList.iterator(); it.hasNext(); ) {
            String[] column = it.next();
            if (!Boolean.parseBoolean(column[1])) {
                continue;
            }
            nullToDefaultChangedColumnList.add(column[0]);
        }
        // if the column is null value, when set this column for not null,do
        // not need change these null value for default value
        List<String> keepNullValueColList = new ArrayList<String>();
        for (Iterator<String> it = nullToDefaultChangedColumnList.iterator(); it.hasNext(); ) {
            String nullColumn = it.next();
            DBAttribute dBAttribute = newSchemaInfo.getDBAttributeByName(nullColumn, false);
            if (dBAttribute == null) {
                continue;
            }
            String defaultVal = dBAttribute.getDefault();
            boolean isUnique = dBAttribute.isUnique();
            if (isUnique) {
                keepNullValueColList.add(nullColumn);
                it.remove();
            } else {
                if (defaultVal == null) {
                    keepNullValueColList.add(nullColumn);
                    it.remove();
                    continue;
                } else {
                    FormatDataResult result = DBAttrTypeFormatter.formatForInput(dBAttribute.getType(), defaultVal, false);
                    if (result.isSuccess()) {
                        defaultValList.add(result.getFormatResult());
                    }
                }
            }
        }
        String msg = Messages.bind(Messages.confirmSetDef, nullToDefaultChangedColumnList);
        if (!nullToDefaultChangedColumnList.isEmpty() && (!CommonUITool.openConfirmBox(msg))) {
            return;
        }
        msg = Messages.bind(Messages.confirmKeepNull, keepNullValueColList);
        if (!keepNullValueColList.isEmpty() && (!CommonUITool.openConfirmBox(msg))) {
            return;
        }
    }
    TaskJobExecutor taskJobExec = new CommonTaskJobExec(this);
    boolean hasChanges = isExecuteCommonSqlTask || !nullAttrChangedColumnList.isEmpty() || !nullToDefaultChangedColumnList.isEmpty();
    if (hasChanges) {
        if (isExecuteCommonSqlTask) {
            taskJobExec.addTask(commonSqlTask);
        }
        if (database == null || newSchemaInfo == null) {
            return;
        }
        // change all table data from null value to default value
        int nullColSize = nullToDefaultChangedColumnList.size();
        for (int colIndex = 0; colIndex < nullColSize; colIndex++) {
            UpdateNullToDefault updateNullToDefault = new UpdateNullToDefault(dbInfo);
            updateNullToDefault.setTable(tableName);
            updateNullToDefault.setColumn(nullToDefaultChangedColumnList.get(colIndex));
            updateNullToDefault.setDefaultValue(defaultValList.get(colIndex));
            taskJobExec.addTask(updateNullToDefault);
        }
    }
    List<UpdateDescriptionTask> updateDescriptionTaskList = getUpdateDescriptionTaskList(dbInfo);
    for (UpdateDescriptionTask task : updateDescriptionTaskList) {
        taskJobExec.addTask(task);
    }
    if (taskJobExec.getTaskCount() > 0) {
        String serverName = database.getServer().getName();
        String dbName = database.getDatabaseInfo().getDbName();
        String title = getSite().getShell().getText();
        jobName = title + " - " + tableName + "@" + dbName;
        JobFamily jobFamily = new JobFamily();
        jobFamily.setServerName(serverName);
        jobFamily.setDbName(dbName);
        taskJobExec.schedule(jobName, jobFamily, true, Job.SHORT);
    } else {
        getSite().getWorkbenchWindow().getActivePage().closeEditor(editor, false);
    }
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) ArrayList(java.util.ArrayList) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) Constraint(com.cubrid.common.core.common.model.Constraint) FormatDataResult(com.cubrid.cubridmanager.core.cubrid.table.model.FormatDataResult) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) UpdateNullToDefault(com.cubrid.cubridmanager.core.cubrid.table.task.UpdateNullToDefault) UpdateDescriptionTask(com.cubrid.cubridmanager.core.cubrid.table.task.UpdateDescriptionTask)

Example 49 with DatabaseInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.

the class ERSchemaEditor method compareTableSchemas.

public void compareTableSchemas(final String modelName, final Map<String, TableSchema> tableSchema, final Map<String, SchemaInfo> schemaInfos) {
    final List<TableSchemaCompareModelInputLazy> input = new ArrayList<TableSchemaCompareModelInputLazy>();
    ITask reportBugTask = new AbstractUITask() {

        private boolean success = false;

        public void cancel() {
        }

        public void finish() {
        }

        public boolean isCancel() {
            return false;
        }

        public boolean isSuccess() {
            return success;
        }

        public void execute(IProgressMonitor monitor) {
            CubridDatabase database = erSchema.getCubridDatabase();
            List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(database);
            final CubridDatabase virtualDb = new CubridDatabase(modelName, modelName);
            virtualDb.setVirtual(true);
            DatabaseInfo info = database.getDatabaseInfo();
            virtualDb.setDatabaseInfo(info);
            WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info);
            wrappedDatabaseInfo.addSchemaInfos(schemaInfos);
            wrappedDatabaseInfo.addTableSchemas(tableSchema);
            ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
            TableSchemaModel leftModel = TableSchemaCompareUtil.createTableSchemaModel(leftDbTableInfoList);
            TableSchemaModel rightModel = new TableSchemaModel();
            rightModel.getTableSchemaMap().putAll(tableSchema);
            TableSchemaComparator comparator = new TableSchemaComparator(database, virtualDb);
            TableSchemaCompareModel model = comparator.compare(leftModel, rightModel);
            model.setSourceDB(database);
            model.setTargetDB(virtualDb);
            input.add(new TableSchemaCompareModelInputLazy(model));
            success = true;
        }
    };
    TaskExecutor taskExecutor = new CommonTaskExec(com.cubrid.common.ui.common.Messages.titleSchemaComparison);
    taskExecutor.addTask(reportBugTask);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (taskExecutor.isSuccess()) {
        try {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input.get(0), TableSchemaCompareInfoPart.ID);
        } catch (Exception e) {
        }
    }
}
Also used : TableSchemaCompareModelInputLazy(com.cubrid.common.ui.compare.schema.control.TableSchemaCompareModelInputLazy) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) ERVirtualDatabaseInfo(com.cubrid.common.ui.er.model.ERVirtualDatabaseInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) TableSchemaComparator(com.cubrid.common.ui.compare.schema.TableSchemaComparator) ArrayList(java.util.ArrayList) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) TableSchemaModel(com.cubrid.common.ui.compare.schema.model.TableSchemaModel) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 50 with DatabaseInfo

use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.

the class ERSchemaEditor method syncComments.

/**
	 * sync table comments to db tables.
	* 
	* @return void
	 */
public void syncComments() {
    DatabaseInfo info = database.getDatabaseInfo();
    if (info == null) {
        CommonUITool.openErrorBox(Messages.errNoDatabase);
        return;
    }
    if (!info.isLogined()) {
        CommonUITool.openErrorBox(Messages.msgDBNotLogin);
        return;
    }
    ServerInfo serverInfo = info.getServerInfo();
    if (serverInfo != null && !serverInfo.isConnected()) {
        CommonUITool.openErrorBox(Messages.msgDBNotLogin);
        return;
    }
    boolean isSupportTableComment = false;
    Connection conn = null;
    try {
        conn = JDBCConnectionManager.getConnection(info, false);
        isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(info, conn);
        if (!isSupportTableComment) {
            CommonUITool.openErrorBox(Messages.cannotSyncComments);
            return;
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    } finally {
        QueryUtil.freeQuery(conn);
    }
    if (!CommonUITool.openConfirmBox(getSite().getShell(), Messages.bind(Messages.msgConfirmSyncComments, database.getLabel()))) {
        return;
    }
    CommonTaskExec taskJobExec = new CommonTaskExec(null);
    List<UpdateDescriptionTask> updateDescTasks = getUpdateDescriptionTaskList(info);
    for (UpdateDescriptionTask task : updateDescTasks) {
        taskJobExec.addTask(task);
    }
    if (updateDescTasks.size() == 0) {
        CommonUITool.openInformationBox(Messages.msgNoComments);
        return;
    }
    new ExecTaskWithProgress(taskJobExec).exec();
    Set<String> failTables = new HashSet<String>();
    for (UpdateDescriptionTask task : updateDescTasks) {
        if (!task.isSuccess()) {
            failTables.add(task.getTableName());
        }
    }
    if (failTables.size() == 0) {
        CommonUITool.openInformationBox(Messages.msgSuccessSyncComments);
    } else {
        CommonUITool.openErrorBox(Messages.bind(Messages.errSyncComments, failTables.toString()));
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ERVirtualDatabaseInfo(com.cubrid.common.ui.er.model.ERVirtualDatabaseInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) Connection(java.sql.Connection) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) UpdateDescriptionTask(com.cubrid.cubridmanager.core.cubrid.table.task.UpdateDescriptionTask) HashSet(java.util.HashSet)

Aggregations

DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)188 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)79 ArrayList (java.util.ArrayList)45 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)35 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)31 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)30 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)30 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)25 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)24 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)24 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)23 ITask (com.cubrid.common.core.task.ITask)20 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)18 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)18 Map (java.util.Map)15 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)14 HashMap (java.util.HashMap)14 Composite (org.eclipse.swt.widgets.Composite)14 UpdateCMUserTask (com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask)13 GridLayout (org.eclipse.swt.layout.GridLayout)13