Search in sources :

Example 1 with OpenTablesDetailInfoPartProgress

use of com.cubrid.common.ui.spi.progress.OpenTablesDetailInfoPartProgress in project cubrid-manager by CUBRID.

the class TableSchemaCompareInfoPart method getTableInfoList.

/**
	 * Returns all tables detail of a database
	 *
	 * @param db
	 * @return
	 */
public List<TableDetailInfo> getTableInfoList(CubridDatabase db) {
    // FIXME logic code move to core module
    OpenTablesDetailInfoPartProgress progress = new OpenTablesDetailInfoPartProgress(db);
    List<TableDetailInfo> tableList = new ArrayList<TableDetailInfo>();
    Map<String, TableDetailInfo> map = new HashMap<String, TableDetailInfo>();
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        conn = JDBCConnectionManager.getConnection(db.getDatabaseInfo(), true);
        if (!progress.loadUserSchemaList(conn, map)) {
            return tableList;
        }
        Set<String> tableNameSet = map.keySet();
        if (tableNameSet == null) {
            return tableList;
        }
        List<String> tableNames = new ArrayList<String>();
        for (String tableName : tableNameSet) {
            tableNames.add(tableName);
        }
        Collections.sort(tableNames);
        List<String> partitionClasses = new ArrayList<String>();
        for (String tableName : tableNames) {
            TableDetailInfo info = map.get(tableName);
            if ("YES".equals(info.getPartitioned())) {
                String sql = "SELECT b.* FROM db_partition a, db_class b " + "WHERE a.class_name='" + tableName.toLowerCase(Locale.getDefault()) + "' AND LOWER(b.class_name)=LOWER(a.partition_class_name)";
                stmt = conn.createStatement();
                rs = stmt.executeQuery(sql);
                while (rs.next()) {
                    String className = rs.getString("class_name");
                    partitionClasses.add(className);
                }
                QueryUtil.freeQuery(stmt, rs);
            }
            if (info.getClassType().equals("CLASS") && !partitionClasses.contains(tableName)) {
                info.setRecordsCount(-1);
                tableList.add(info);
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    } finally {
        QueryUtil.freeQuery(conn, stmt, rs);
    }
    return tableList;
}
Also used : HashMap(java.util.HashMap) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) Connection(java.sql.Connection) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ResultSet(java.sql.ResultSet) OpenTablesDetailInfoPartProgress(com.cubrid.common.ui.spi.progress.OpenTablesDetailInfoPartProgress)

Example 2 with OpenTablesDetailInfoPartProgress

use of com.cubrid.common.ui.spi.progress.OpenTablesDetailInfoPartProgress in project cubrid-manager by CUBRID.

the class TableSchemaCompareRunner method getTableInfoList.

/**
	 * Returns all tables detail of a database
	 *
	 * @param db
	 * @return
	 */
private List<TableDetailInfo> getTableInfoList(CubridDatabase db) {
    // FIXME logic code move to core module
    OpenTablesDetailInfoPartProgress progress = new OpenTablesDetailInfoPartProgress(db);
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        conn = JDBCConnectionManager.getConnection(db.getDatabaseInfo(), true);
        Map<String, TableDetailInfo> map = new HashMap<String, TableDetailInfo>();
        if (!progress.loadUserSchemaList(conn, map)) {
            return null;
        }
        Set<String> tableNameSet = map.keySet();
        List<TableDetailInfo> tableList = new ArrayList<TableDetailInfo>();
        if (tableNameSet != null) {
            List<String> tableNames = new ArrayList<String>();
            for (String tableName : tableNameSet) {
                tableNames.add(tableName);
            }
            Collections.sort(tableNames);
            List<String> partitionClasses = new ArrayList<String>();
            for (String tableName : tableNames) {
                TableDetailInfo info = map.get(tableName);
                if (dialog.isCanceled()) {
                    return null;
                }
                if ("YES".equals(info.getPartitioned())) {
                    String sql = "SELECT b.* FROM db_partition a, db_class b " + "WHERE a.class_name='" + tableName.toLowerCase(Locale.getDefault()) + "' AND LOWER(b.class_name)=LOWER(a.partition_class_name)";
                    stmt = conn.createStatement();
                    rs = stmt.executeQuery(sql);
                    while (rs.next()) {
                        if (dialog.isCanceled()) {
                            return null;
                        }
                        String className = rs.getString("class_name");
                        partitionClasses.add(className);
                    }
                    QueryUtil.freeQuery(stmt, rs);
                }
                if ("CLASS".equals(info.getClassType()) && !partitionClasses.contains(tableName)) {
                    info.setRecordsCount(-1);
                    tableList.add(info);
                }
            }
        }
        return tableList;
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    } finally {
        QueryUtil.freeQuery(conn, stmt, rs);
    }
    return null;
}
Also used : HashMap(java.util.HashMap) Statement(java.sql.Statement) Connection(java.sql.Connection) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) OpenTablesDetailInfoPartProgress(com.cubrid.common.ui.spi.progress.OpenTablesDetailInfoPartProgress)

Example 3 with OpenTablesDetailInfoPartProgress

use of com.cubrid.common.ui.spi.progress.OpenTablesDetailInfoPartProgress in project cubrid-manager by CUBRID.

the class TableSchemaCompareUtil method getTableInfoList.

/**
	 * Returns all tables detail of a database
	 *
	 * @param db
	 * @return
	 */
public static List<TableDetailInfo> getTableInfoList(CubridDatabase db) {
    // FIXME logic code move to core module
    if (db.isVirtual()) {
        return new ArrayList<TableDetailInfo>();
    }
    OpenTablesDetailInfoPartProgress progress = new OpenTablesDetailInfoPartProgress(db);
    List<TableDetailInfo> tableList = null;
    Connection conn = null;
    try {
        conn = JDBCConnectionManager.getConnection(db.getDatabaseInfo(), true);
        Map<String, TableDetailInfo> map = new HashMap<String, TableDetailInfo>();
        if (!progress.loadUserSchemaList(conn, map)) {
            return null;
        }
        tableList = new ArrayList<TableDetailInfo>();
        Set<String> tableNameSet = map.keySet();
        if (tableNameSet != null) {
            List<String> tableNames = new ArrayList<String>();
            for (String tableName : tableNameSet) {
                tableNames.add(tableName);
            }
            Collections.sort(tableNames);
            for (String tableName : tableNames) {
                TableDetailInfo info = map.get(tableName);
                String classType = info.getClassType();
                if (classType.equals("CLASS") || classType.equals("VCLASS")) {
                    info.setRecordsCount(-1);
                    tableList.add(info);
                }
            }
        }
    } catch (Exception e) {
        tableList = null;
        LOGGER.error(e.getMessage(), e);
    }
    return tableList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) Connection(java.sql.Connection) OpenTablesDetailInfoPartProgress(com.cubrid.common.ui.spi.progress.OpenTablesDetailInfoPartProgress)

Example 4 with OpenTablesDetailInfoPartProgress

use of com.cubrid.common.ui.spi.progress.OpenTablesDetailInfoPartProgress in project cubrid-manager by CUBRID.

the class ColumnViewerSorter method refresh.

/**
	 * Refresh all data
	 */
private void refresh() {
    if (CommonUITool.openConfirmBox(Messages.tablesDetailInfoPartRefreshConfirm)) {
        OpenTablesDetailInfoPartProgress progress = new OpenTablesDetailInfoPartProgress(database);
        progress.loadTablesInfo();
        if (progress.isSuccess()) {
            reload(progress.getList());
            tableListView.setInput(tableList);
            tableListView.refresh();
        }
    }
}
Also used : OpenTablesDetailInfoPartProgress(com.cubrid.common.ui.spi.progress.OpenTablesDetailInfoPartProgress)

Example 5 with OpenTablesDetailInfoPartProgress

use of com.cubrid.common.ui.spi.progress.OpenTablesDetailInfoPartProgress in project cubrid-manager by CUBRID.

the class OpenTargetAction method showTableDashboard.

public void showTableDashboard(CubridDatabase database) {
    if (database == null) {
        return;
    }
    if (database.getDatabaseInfo() == null || !JDBCConnectionManager.isConnectable(database.getDatabaseInfo())) {
        return;
    }
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    TableDashboardInput input = new TableDashboardInput(database);
    TableDashboardPart tablesDetailInfoPart = (TableDashboardPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findEditor(input);
    if (tablesDetailInfoPart == null) {
        OpenTablesDetailInfoPartProgress progress = new OpenTablesDetailInfoPartProgress(database);
        progress.loadTablesInfo();
        if (progress.isSuccess()) {
            input.setTableList(progress.getList());
            try {
                window.getActivePage().openEditor(input, TableDashboardPart.ID);
            } catch (PartInitException e) {
                LOGGER.error("Can not initialize the db table list UI.", e);
            }
        }
    } else {
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(tablesDetailInfoPart);
    }
}
Also used : TableDashboardInput(com.cubrid.common.ui.cubrid.table.dashboard.control.TableDashboardInput) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) OpenTablesDetailInfoPartProgress(com.cubrid.common.ui.spi.progress.OpenTablesDetailInfoPartProgress) PartInitException(org.eclipse.ui.PartInitException) TableDashboardPart(com.cubrid.common.ui.cubrid.table.dashboard.control.TableDashboardPart)

Aggregations

OpenTablesDetailInfoPartProgress (com.cubrid.common.ui.spi.progress.OpenTablesDetailInfoPartProgress)5 TableDetailInfo (com.cubrid.common.core.common.model.TableDetailInfo)3 Connection (java.sql.Connection)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 PartInitException (org.eclipse.ui.PartInitException)2 TableDashboardInput (com.cubrid.common.ui.cubrid.table.dashboard.control.TableDashboardInput)1 TableDashboardPart (com.cubrid.common.ui.cubrid.table.dashboard.control.TableDashboardPart)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1