Search in sources :

Example 1 with DefaultSchemaNode

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

the class FileToTableMappingComposite method computeLineCount.

/**
	 * Compute all line count
	 */
private void computeLineCount() {
    ImportConfig importConfig = importSettingPage.getImportDataWizard().getImportConfig();
    /*Compute all the record count*/
    lineCount = 0;
    Object[] itemArray = treeViewer.getCheckedElements();
    for (Object object : itemArray) {
        DefaultSchemaNode node = (DefaultSchemaNode) object;
        TableConfig tableConfig = importConfig.getTableConfig(node.getName());
        if (tableConfig != null) {
            lineCount += tableConfig.getLineCount();
        }
    }
}
Also used : DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode)

Example 2 with DefaultSchemaNode

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

the class ExportSettingForLoadDBPage method initTableColumnInfo.

/**
	 * load tables and columns
	 */
public void initTableColumnInfo() {
    // FIXME move this logic to core module
    try {
        ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
        progress.setCancelable(true);
        progress.run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                monitor.beginTask(Messages.taskLoading, 2);
                tablesOrViewLst = new ArrayList<ICubridNode>();
                List<String> tableNames = new ArrayList<String>();
                Connection conn = null;
                Statement stmt = null;
                ResultSet rs = null;
                StringBuilder sql = new StringBuilder();
                sql.append("SELECT c.class_name, c.class_type ");
                sql.append("FROM db_class c, db_attribute a ");
                sql.append("WHERE c.class_name=a.class_name AND c.is_system_class='NO' ");
                sql.append("AND a.from_class_name IS NULL ");
                sql.append("GROUP BY c.class_name, c.class_type ");
                sql.append("ORDER BY c.class_type, c.class_name");
                String query = sql.toString();
                // [TOOLS-2425]Support shard broker
                if (getDatabase() != null) {
                    query = DatabaseInfo.wrapShardQuery(getDatabase().getDatabaseInfo(), query);
                }
                try {
                    monitor.subTask(Messages.taskLoadingTable);
                    conn = JDBCConnectionManager.getConnection(getDatabase().getDatabaseInfo(), true);
                    stmt = conn.createStatement();
                    rs = stmt.executeQuery(query);
                    while (rs.next()) {
                        //$NON-NLS-1$
                        String tableName = rs.getString(1);
                        //$NON-NLS-1$
                        String tableType = rs.getString(2);
                        if (ConstantsUtil.isExtensionalSystemTable(tableName)) {
                            continue;
                        }
                        String iconPath = "icons/navigator/schema_table_item.png";
                        if ("VCLASS".equalsIgnoreCase(tableType)) {
                            //export all view now so don't need select view node
                            continue;
                        }
                        ICubridNode classNode = new DefaultSchemaNode(tableName, tableName, iconPath);
                        classNode.setContainer(true);
                        classNode.setType(NodeType.TABLE_COLUMN_FOLDER);
                        tablesOrViewLst.add(classNode);
                        tableNames.add(tableName);
                    }
                    QueryUtil.freeQuery(rs);
                    monitor.worked(1);
                } catch (SQLException e) {
                    CommonUITool.openErrorBox(getShell(), e.getErrorCode() + System.getProperty("line.separator") + Messages.importErrorHead + e.getMessage());
                    LOGGER.error("", e);
                } finally {
                    QueryUtil.freeQuery(conn, stmt, rs);
                }
            }
        });
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SQLException(java.sql.SQLException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ResultSet(java.sql.ResultSet) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with DefaultSchemaNode

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

the class ExportSettingPage method initTableColumnInfo.

/**
	 * load tables and columns
	 */
public void initTableColumnInfo() {
    // FIXME move this logic to core module
    tableColumMap.clear();
    try {
        ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
        progress.setCancelable(true);
        progress.run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                monitor.beginTask(Messages.taskLoading, 2);
                tablesOrViewLst = new ArrayList<ICubridNode>();
                Connection conn = null;
                Statement stmt = null;
                ResultSet rs = null;
                StringBuilder sql = new StringBuilder();
                sql.append("SELECT c.class_name, c.class_type ");
                sql.append("FROM db_class c, db_attribute a ");
                sql.append("WHERE c.class_name=a.class_name AND c.is_system_class='NO' ");
                sql.append("AND a.from_class_name IS NULL ");
                sql.append("GROUP BY c.class_name, c.class_type ");
                sql.append("ORDER BY c.class_type, c.class_name");
                String query = sql.toString();
                // [TOOLS-2425]Support shard broker
                if (CubridDatabase.hasValidDatabaseInfo(getDatabase())) {
                    query = getDatabase().getDatabaseInfo().wrapShardQuery(query);
                }
                try {
                    monitor.subTask(Messages.taskLoadingTable);
                    conn = JDBCConnectionManager.getConnection(getDatabase().getDatabaseInfo(), true);
                    stmt = conn.createStatement();
                    rs = stmt.executeQuery(query);
                    while (rs.next()) {
                        //$NON-NLS-1$
                        String tableName = rs.getString(1);
                        //$NON-NLS-1$
                        String tableType = rs.getString(2);
                        if (ConstantsUtil.isExtensionalSystemTable(tableName)) {
                            continue;
                        }
                        String iconPath = "icons/navigator/schema_table_item.png";
                        if ("VCLASS".equalsIgnoreCase(tableType)) {
                            //export all view now so don't need select view node
                            continue;
                        }
                        ICubridNode classNode = new DefaultSchemaNode(tableName, tableName, iconPath);
                        if ("VCLASS".equalsIgnoreCase(tableType)) {
                            classNode.setData(VIEWNODEFLAG, "true");
                        } else {
                            classNode.setData(VIEWNODEFLAG, "false");
                        }
                        classNode.setContainer(true);
                        classNode.setType(NodeType.TABLE_COLUMN_FOLDER);
                        tablesOrViewLst.add(classNode);
                    }
                    QueryUtil.freeQuery(rs);
                    monitor.worked(1);
                    monitor.subTask(Messages.taskLoadingColumn);
                } catch (SQLException e) {
                    String msg = e.getErrorCode() + StringUtil.NEWLINE + Messages.importErrorHead + e.getMessage();
                    CommonUITool.openErrorBox(getShell(), msg);
                    LOGGER.error("", e);
                } finally {
                    QueryUtil.freeQuery(conn, stmt, rs);
                }
            }
        });
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ResultSet(java.sql.ResultSet)

Example 4 with DefaultSchemaNode

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

the class FileToTableMappingComposite method loadClassInfo.

public List<ICubridNode> loadClassInfo() {
    // FIXME move this logic to core module
    allTableList = new ArrayList<ICubridNode>();
    try {
        ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
        progress.setCancelable(true);
        progress.run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                monitor.beginTask(Messages.taskLoading, 2);
                Connection conn = null;
                Statement stmt = null;
                ResultSet rsTable = null;
                try {
                    monitor.subTask(Messages.taskLoadingTable);
                    monitor.worked(1);
                    StringBuilder sql = new StringBuilder();
                    sql.append("SELECT c.class_name ");
                    sql.append("FROM db_class c, db_attribute a ");
                    sql.append("WHERE c.class_name = a.class_name AND c.is_system_class = 'NO' ");
                    sql.append("AND a.from_class_name IS NULL ");
                    sql.append("AND c.class_type = 'CLASS' ");
                    sql.append("GROUP BY c.class_name ");
                    sql.append("ORDER BY c.class_name");
                    conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
                    stmt = conn.createStatement();
                    rsTable = stmt.executeQuery(sql.toString());
                    while (rsTable.next()) {
                        //$NON-NLS-1$
                        String tableName = rsTable.getString(1);
                        if (ConstantsUtil.isExtensionalSystemTable(tableName)) {
                            continue;
                        }
                        String iconPath = "icons/navigator/schema_table_item.png";
                        ICubridNode classNode = new DefaultSchemaNode(tableName, tableName, iconPath);
                        classNode.setContainer(true);
                        allTableList.add(classNode);
                    }
                    monitor.subTask(Messages.taskLoadingColumn);
                    monitor.worked(1);
                } catch (SQLException e) {
                    String msg = e.getErrorCode() + StringUtil.NEWLINE + Messages.importErrorHead + e.getMessage();
                    CommonUITool.openErrorBox(getShell(), msg);
                    LOGGER.error("", e);
                } finally {
                    QueryUtil.freeQuery(conn, stmt, rsTable);
                }
            }
        });
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    return allTableList;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Connection(java.sql.Connection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ResultSet(java.sql.ResultSet)

Example 5 with DefaultSchemaNode

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

the class FileToTableMappingComposite method createClassNode.

public ICubridNode createClassNode(String tableName, boolean isFirstRowAsColumnName, List<String> firstRowColsLst, List<String> colNameList, List<String> colTypeList) {
    // FIXME move this logic to core module
    int columnCount = firstRowColsLst.size();
    String iconPath = "icons/navigator/schema_table_item.png";
    ICubridNode classNode = new DefaultSchemaNode(tableName, tableName, iconPath);
    classNode.setContainer(true);
    List<String> columnNames;
    if (isFirstRowAsColumnName) {
        columnNames = firstRowColsLst;
    } else {
        columnNames = new ArrayList<String>();
        for (int i = 0; i < columnCount; i++) {
            columnNames.add("Column_" + String.valueOf(i));
        }
    }
    for (String columnName : columnNames) {
        colNameList.add(columnName);
        colTypeList.add(NEW_ATTR_TYPE);
    }
    classNode.setData(ImportObjectLabelProvider.IS_NEW, true);
    classNode.setData(ImportObjectLabelProvider.CREATE_DDL, getCreateTableDDL(classNode, colNameList, colTypeList));
    allTableList.add(classNode);
    refreshTable();
    return classNode;
}
Also used : ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode)

Aggregations

DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)88 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)62 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)33 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)22 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)21 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)18 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)17 ArrayList (java.util.ArrayList)15 TreeViewer (org.eclipse.jface.viewers.TreeViewer)10 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)9 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)9 Display (org.eclipse.swt.widgets.Display)9 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)8 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)7 File (java.io.File)5 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)4 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)4 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)4 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)4 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)4