Search in sources :

Example 1 with ColumnInfo

use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.

the class ExprotToSqlHandler method exportFromCache.

public void exportFromCache(String tableName) throws IOException {
    if (StringUtil.isEmpty(tableName)) {
        return;
    }
    BufferedWriter fs = null;
    int exportedCount = 0;
    ResultSetDataCache resultSetDataCache = exportConfig.getResultSetDataCache();
    try {
        fs = FileUtil.getBufferedWriter(exportConfig.getDataFilePath(tableName), exportConfig.getFileCharset());
        try {
            List<ColumnInfo> columnInfos = resultSetDataCache.getColumnInfos();
            int colCount = columnInfos.size();
            StringBuffer insert = new StringBuffer("INSERT INTO ");
            insert.append(QuerySyntax.escapeKeyword(tableName));
            insert.append(" (");
            for (int i = 0; i < colCount; i++) {
                if (i > 0) {
                    insert.append(", ");
                }
                insert.append(QuerySyntax.escapeKeyword(columnInfos.get(i).getName()));
            }
            insert.append(") ");
            List<ArrayList<Object>> datas = resultSetDataCache.getDatas();
            for (ArrayList<Object> rowData : datas) {
                StringBuffer values = new StringBuffer("VALUES (");
                for (int j = 0; j < colCount; j++) {
                    if (j > 0) {
                        values.append(", ");
                    }
                    int precision = columnInfos.get(j).getPrecision();
                    String columnType = columnInfos.get(j).getType();
                    setIsHasBigValue(columnType, precision);
                    Object value = rowData.get(j);
                    if (DataType.DATATYPE_BLOB.equals(columnType) || DataType.DATATYPE_CLOB.equals(columnType)) {
                        value = DataType.VALUE_NULL;
                    }
                    values.append(value.toString());
                }
                values.append(");\n");
                fs.write(insert.toString());
                fs.write(values.toString());
                exportedCount++;
                if (exportedCount >= COMMIT_LINES) {
                    fs.flush();
                    exportDataEventHandler.handleEvent(new ExportDataSuccessEvent(tableName, exportedCount));
                    exportedCount = 0;
                }
                if (stop) {
                    break;
                }
            }
            exportDataEventHandler.handleEvent(new ExportDataSuccessEvent(tableName, exportedCount));
            exportedCount = 0;
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            exportDataEventHandler.handleEvent(new ExportDataFailedOneTableEvent(tableName));
        }
        System.gc();
    } finally {
        FileUtil.close(fs);
    }
}
Also used : ArrayList(java.util.ArrayList) ColumnInfo(com.cubrid.common.ui.query.control.ColumnInfo) IOException(java.io.IOException) SQLException(java.sql.SQLException) BufferedWriter(java.io.BufferedWriter) ExportDataFailedOneTableEvent(com.cubrid.common.ui.cubrid.table.event.ExportDataFailedOneTableEvent) ExportDataSuccessEvent(com.cubrid.common.ui.cubrid.table.event.ExportDataSuccessEvent) ResultSetDataCache(com.cubrid.common.ui.cubrid.table.export.ResultSetDataCache)

Example 2 with ColumnInfo

use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.

the class FilterChooserDialog method createComposite.

/**
	 * 
	 * Create the composite
	 * 
	 * @param parent Composite
	 */
private void createComposite(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    composite.setLayout(layout);
    Label infoLabel = new Label(composite, SWT.NONE);
    infoLabel.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
    infoLabel.setText(Messages.lblFilterChooser);
    String[] columnNames = new String[] { Messages.colColumn };
    tv = (CheckboxTableViewer) CommonUITool.createCheckBoxTableViewer(composite, null, columnNames, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, 300, 200));
    tv.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            if (!event.getChecked() && selectAllBtn.getSelection()) {
                selectAllBtn.setSelection(false);
            }
            if (colInfoList != null && colInfoList.size() == tv.getCheckedElements().length) {
                selectAllBtn.setSelection(true);
            }
        }
    });
    final List<Map<String, Object>> colNameList = new ArrayList<Map<String, Object>>();
    for (int i = 0; i < colInfoList.size(); i++) {
        ColumnInfo colInfo = colInfoList.get(i);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("0", colInfo.getName());
        map.put("1", colInfo);
        colNameList.add(map);
    }
    tv.setInput(colNameList);
    tv.getTable().setFocus();
    selectAllBtn = new Button(composite, SWT.CHECK);
    {
        selectAllBtn.setText(Messages.btnSelectAll);
        GridData gridData = new GridData();
        gridData.grabExcessHorizontalSpace = true;
        gridData.horizontalIndent = 0;
        gridData.horizontalSpan = 3;
        selectAllBtn.setLayoutData(gridData);
    }
    selectAllBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            boolean selection = selectAllBtn.getSelection();
            tv.setAllChecked(selection);
        }
    });
    for (TableItem item : tv.getTable().getItems()) {
        @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) item.getData();
        if (map != null && selectedColInfoList.contains(map.get("1"))) {
            item.setChecked(true);
        }
    }
    TableColumn[] tblCols = tv.getTable().getColumns();
    for (TableColumn tblCol : tblCols) {
        tblCol.setWidth(280);
    }
    if (colInfoList != null && selectedColInfoList != null && colInfoList.size() == selectedColInfoList.size()) {
        selectAllBtn.setSelection(true);
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) HashMap(java.util.HashMap) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) ColumnInfo(com.cubrid.common.ui.query.control.ColumnInfo) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ColumnInfo

use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.

the class TextRecordProcessor method getTextData.

/**
	 * Get text data
	 *
	 * @param dataIndex - column index
	 * @return
	 * @throws SQLException
	 */
private String getTextData(CUBRIDResultSetProxy resultSet, int dataIndex, QueryRecord queryRecord) throws SQLException {
    // FIXME move this logic to core module
    ColumnInfo columnInfo = (ColumnInfo) queryRecord.getColumnInfoList().get(dataIndex - 1);
    String columnType = columnInfo.getType();
    Object rsObj = resultSet.getObject(dataIndex);
    String dataToput = null;
    if (rsObj != null) {
        if (DataType.DATATYPE_SET.equals(columnType) || DataType.DATATYPE_MULTISET.equals(columnType) || DataType.DATATYPE_SEQUENCE.equals(columnType)) {
            StringBuffer data = new StringBuffer();
            Object[] set = (Object[]) resultSet.getCollection(dataIndex);
            data.append("{");
            for (int i = 0; i < set.length; i++) {
                Object setI = set[i];
                if (null == setI) {
                    data.append(DataType.VALUE_NULL);
                } else if (setI.getClass() == CUBRIDOIDProxy.getCUBRIDOIDClass(resultSet.getJdbcVersion())) {
                    data.append((new CUBRIDOIDProxy(setI)).getOidString());
                } else {
                    data.append(setI);
                }
                if (i < set.length - 1) {
                    data.append(",");
                }
            }
            data.append("}");
            dataToput = data.toString();
        } else if (DataType.DATATYPE_DATETIME.equalsIgnoreCase(columnType)) {
            dataToput = CommonUITool.formatDate(resultSet.getTimestamp(dataIndex), FieldHandlerUtils.FORMAT_DATETIME);
        } else if (DataType.DATATYPE_BIT_VARYING.equalsIgnoreCase(columnType) || DataType.DATATYPE_BIT.equalsIgnoreCase(columnType)) {
            byte[] dataTmp = resultSet.getBytes(dataIndex);
            if (dataTmp.length > FieldHandlerUtils.BIT_TYPE_MUCH_VALUE_LENGTH) {
                dataToput = DataType.BIT_EXPORT_FORMAT;
            } else {
                dataToput = "X'" + DBAttrTypeFormatter.getHexString(dataTmp) + "'";
            }
        } else if (DataType.DATATYPE_FLOAT.equalsIgnoreCase(columnType)) {
            formater.applyPattern(FORMAT_FLOAT);
            dataToput = formater.format(resultSet.getFloat(dataIndex));
        } else if (DataType.DATATYPE_DOUBLE.equalsIgnoreCase(columnType)) {
            formater.applyPattern(FORMAT_DOUBLE);
            dataToput = formater.format(resultSet.getDouble(dataIndex));
        } else if (DataType.DATATYPE_BLOB.equalsIgnoreCase(columnType) || rsObj instanceof Blob) {
            columnInfo.setType(DataType.DATATYPE_BLOB);
            dataToput = DataType.BLOB_EXPORT_FORMAT;
        } else if (DataType.DATATYPE_CLOB.equalsIgnoreCase(columnType) || rsObj instanceof Clob) {
            columnInfo.setType(DataType.DATATYPE_CLOB);
            dataToput = DataType.CLOB_EXPORT_FORMAT;
        } else if (DataType.DATATYPE_NCHAR.equalsIgnoreCase(columnType)) {
            columnInfo.setType(DataType.DATATYPE_NCHAR);
            dataToput = "N'" + resultSet.getString(dataIndex) + "'";
        } else if (DataType.DATATYPE_NCHAR_VARYING.equalsIgnoreCase(columnType)) {
            columnInfo.setType(DataType.DATATYPE_NCHAR_VARYING);
            dataToput = "N'" + resultSet.getString(dataIndex) + "'";
        } else {
            dataToput = resultSet.getString(dataIndex);
        }
    }
    return dataToput;
}
Also used : CUBRIDOIDProxy(com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy) Blob(java.sql.Blob) ColumnInfo(com.cubrid.common.ui.query.control.ColumnInfo) Clob(java.sql.Clob)

Example 4 with ColumnInfo

use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.

the class FilterResultContrItem method select.

/**
	 *
	 * Returns whether the given element makes it through this filter.
	 *
	 * @param dataMap Map<String, Object>
	 * @param filterSetting QueryResultFilterSetting
	 * @return boolean
	 */
public boolean select(Map<String, CellValue> dataMap, QueryResultFilterSetting filterSetting) {
    if (filterSetting == null || filterSetting.getContent() == null || filterSetting.getContent().trim().length() == 0) {
        return true;
    }
    List<ColumnInfo> colInfoList = filterSetting.getFilterColumnInfoList();
    if (colInfoList == null || colInfoList.isEmpty()) {
        return true;
    }
    for (ColumnInfo colInfo : colInfoList) {
        String columnIndex = colInfo.getIndex();
        Object colValue = dataMap.get(columnIndex);
        String colStringValue = null;
        if (colValue instanceof String) {
            colStringValue = (String) colValue;
        } else if (colValue instanceof CellValue) {
            colStringValue = ((CellValue) colValue).getShowValue();
        }
        if (isMatch(filterSetting, colStringValue, null)) {
            return true;
        }
    }
    return false;
}
Also used : ColumnInfo(com.cubrid.common.ui.query.control.ColumnInfo) CellValue(com.cubrid.common.ui.spi.table.CellValue)

Example 5 with ColumnInfo

use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.

the class ExportToTxtHandler method exportFromCache.

public void exportFromCache(String tableName) throws IOException {
    BufferedWriter fs = null;
    int exportedCount = 0;
    ResultSetDataCache resultSetDataCache = exportConfig.getResultSetDataCache();
    try {
        fs = FileUtil.getBufferedWriter(exportConfig.getDataFilePath(tableName), exportConfig.getFileCharset());
        try {
            List<ColumnInfo> columnInfos = resultSetDataCache.getColumnInfos();
            int colCount = columnInfos.size();
            for (int j = 0; j < colCount; j++) {
                fs.write(surround + columnInfos.get(j).getName() + surround);
                if (j != colCount - 1) {
                    fs.write(columnSeprator);
                }
            }
            fs.write(rowSeprator);
            fs.flush();
            List<ArrayList<Object>> datas = resultSetDataCache.getDatas();
            for (ArrayList<Object> rowData : datas) {
                writeNextLine(tableName, fs, columnInfos, rowData, columnSeprator, rowSeprator, surround);
                fs.write(rowSeprator);
                exportedCount++;
                if (exportedCount >= COMMIT_LINES) {
                    fs.flush();
                    exportDataEventHandler.handleEvent(new ExportDataSuccessEvent(tableName, exportedCount));
                    exportedCount = 0;
                }
                if (stop) {
                    break;
                }
            }
            exportDataEventHandler.handleEvent(new ExportDataSuccessEvent(tableName, exportedCount));
            exportedCount = 0;
        } catch (Exception e) {
            LOGGER.error("", e);
            exportDataEventHandler.handleEvent(new ExportDataFailedOneTableEvent(tableName));
        }
        System.gc();
    } finally {
        Closer.close(fs);
    }
}
Also used : ExportDataFailedOneTableEvent(com.cubrid.common.ui.cubrid.table.event.ExportDataFailedOneTableEvent) ExportDataSuccessEvent(com.cubrid.common.ui.cubrid.table.event.ExportDataSuccessEvent) ArrayList(java.util.ArrayList) ColumnInfo(com.cubrid.common.ui.query.control.ColumnInfo) ResultSetDataCache(com.cubrid.common.ui.cubrid.table.export.ResultSetDataCache) SQLException(java.sql.SQLException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Aggregations

ColumnInfo (com.cubrid.common.ui.query.control.ColumnInfo)18 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)6 SQLException (java.sql.SQLException)6 ExportDataFailedOneTableEvent (com.cubrid.common.ui.cubrid.table.event.ExportDataFailedOneTableEvent)4 ExportDataSuccessEvent (com.cubrid.common.ui.cubrid.table.event.ExportDataSuccessEvent)4 ResultSetDataCache (com.cubrid.common.ui.cubrid.table.export.ResultSetDataCache)4 HashMap (java.util.HashMap)4 BufferedWriter (java.io.BufferedWriter)3 CellValue (com.cubrid.common.ui.spi.table.CellValue)2 FormatDataResult (com.cubrid.cubridmanager.core.cubrid.table.model.FormatDataResult)2 CUBRIDOIDProxy (com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Blob (java.sql.Blob)2 Clob (java.sql.Clob)2 Map (java.util.Map)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2