Search in sources :

Example 21 with CellValue

use of com.cubrid.common.ui.spi.table.CellValue in project cubrid-manager by CUBRID.

the class QueryExecuter method deleteValues.

/**
	 * Delete values on the query result editor.
	 *
	 * @param queryConn Connection
	 * @throws SQLException the exception
	 */
private Map<String, Map<String, CellValue>> deleteValues() throws SQLException, ParamSetException {
    ParamSetter paramSetter = new ParamSetter();
    Map<String, Map<String, CellValue>> successedMap = new HashMap<String, Map<String, CellValue>>();
    Connection conn = connection.checkAndConnect();
    try {
        String tableName = UIQueryUtil.getTableNameFromQuery(conn, query);
        String escapedTable = QuerySyntax.escapeKeyword(tableName);
        if (tableName == null) {
            CommonUITool.openErrorBox(Messages.errModifiedOneTable);
            return successedMap;
        }
        PreparedStatement pstmt = null;
        List<ColumnInfo> allColumnList = getAllColumnList();
        for (String key : delValues.keySet()) {
            Map<String, CellValue> valuesMap = delValues.get(key);
            if (valuesMap == null) {
                continue;
            }
            try {
                List<ColumnInfo> colInfoList = new ArrayList<ColumnInfo>();
                List<ColumnInfo> unPColInfoList = new ArrayList<ColumnInfo>();
                for (int i = 0; i < allColumnList.size(); i++) {
                    ColumnInfo colInfo = allColumnList.get(i);
                    if (queryEditor.isIgnoreType(colInfo.getType())) {
                        continue;
                    }
                    CellValue value = valuesMap.get(colInfo.getIndex());
                    if (value == null || value.getValue() == null) {
                        continue;
                    }
                    if (DataType.DATATYPE_NATIONAL_CHARACTER.equalsIgnoreCase(colInfo.getType()) || DataType.DATATYPE_NCHAR_VARYING.equalsIgnoreCase(colInfo.getType()) || DataType.DATATYPE_NCHAR.equalsIgnoreCase(colInfo.getType())) {
                        unPColInfoList.add(colInfo);
                        continue;
                    }
                    if ((DataType.DATATYPE_BIT.equalsIgnoreCase(colInfo.getType()) || DataType.DATATYPE_BIT_VARYING.equalsIgnoreCase(colInfo.getType())) && value.getValue() instanceof String) {
                        unPColInfoList.add(colInfo);
                        continue;
                    }
                    colInfoList.add(colInfo);
                }
                StringBuilder sqlBuffer = new StringBuilder();
                sqlBuffer.append("DELETE FROM ").append(QuerySyntax.escapeKeyword(escapedTable)).append(" WHERE ");
                List<PstmtParameter> pstmtParaList = new ArrayList<PstmtParameter>();
                int paramCount = 1;
                for (ColumnInfo columnInfo : colInfoList) {
                    if (paramCount > 1) {
                        sqlBuffer.append(" AND ");
                    }
                    sqlBuffer.append(QuerySyntax.escapeKeyword(columnInfo.getName())).append(" = ? ");
                    CellValue value = valuesMap.get(columnInfo.getIndex());
                    PstmtParameter pstmtParameter = new PstmtParameter(columnInfo.getName(), paramCount, columnInfo.getComleteType(), value.getValue());
                    pstmtParaList.add(pstmtParameter);
                    paramCount++;
                }
                for (ColumnInfo columnInfo : unPColInfoList) {
                    if (paramCount > 1) {
                        sqlBuffer.append(" AND ");
                    }
                    sqlBuffer.append(QuerySyntax.escapeKeyword(columnInfo.getName())).append("=");
                    CellValue cellValue = valuesMap.get(columnInfo.getIndex());
                    String dataType = DataType.makeType(columnInfo.getType(), columnInfo.getChildElementType(), columnInfo.getPrecision(), columnInfo.getScale());
                    FormatDataResult result = DBAttrTypeFormatter.format(dataType, cellValue.getStringValue(), null, false, charset, false);
                    if (result.isSuccess()) {
                        sqlBuffer.append(result.getFormatedString());
                    } else {
                        throw new ParamSetException("Format data \"" + cellValue.getStringValue() + "\"error for data type " + dataType);
                    }
                    paramCount++;
                }
                pstmt = conn.prepareStatement(sqlBuffer.toString());
                for (PstmtParameter pstmtParameter : pstmtParaList) {
                    paramSetter.handle(pstmt, pstmtParameter);
                }
                pstmt.executeUpdate();
                successedMap.put(key, valuesMap);
                if (!connection.isAutoCommit() && queryEditor.getConnection() == connection) {
                    queryEditor.setHaveActiveTransaction(true);
                }
            } catch (SQLException ex) {
                if (successedMap.containsKey(key)) {
                    successedMap.remove(key);
                }
                LOGGER.error("", ex);
                throw ex;
            } finally {
                QueryUtil.freeQuery(pstmt);
            }
        }
    } finally {
        if (connection != null && connection.isAutoClosable()) {
            connection.commit();
            connection.close();
        }
    }
    return successedMap;
}
Also used : HashMap(java.util.HashMap) ParamSetException(com.cubrid.common.ui.spi.util.paramSetter.ParamSetException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DBConnection(com.cubrid.cubridmanager.core.common.jdbc.DBConnection) ArrayList(java.util.ArrayList) ParamSetter(com.cubrid.common.ui.spi.util.paramSetter.ParamSetter) PreparedStatement(java.sql.PreparedStatement) Point(org.eclipse.swt.graphics.Point) PstmtParameter(com.cubrid.common.ui.cubrid.table.dialog.PstmtParameter) FormatDataResult(com.cubrid.cubridmanager.core.cubrid.table.model.FormatDataResult) CellValue(com.cubrid.common.ui.spi.table.CellValue) Map(java.util.Map) HashMap(java.util.HashMap)

Example 22 with CellValue

use of com.cubrid.common.ui.spi.table.CellValue in project cubrid-manager by CUBRID.

the class ColumnComparator method compare.

/**
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
	 * @param o1 the first object to be compared.
	 * @param o2 the second object to be compared.
	 * @return a negative integer, zero, or a positive integer as the first
	 *         argument is less than, equal to, or greater than the second.
	 */
public int compare(Object o1, Object o2) {
    CellValue value1 = null, value2 = null;
    Map map1 = (Map) o1;
    Map map2 = (Map) o2;
    if (map1 != null) {
        value1 = (CellValue) map1.get(columnIndex);
    }
    if (map2 != null) {
        value2 = (CellValue) map2.get(columnIndex);
    }
    String str1 = getStrValue(value1);
    String str2 = getStrValue(value2);
    return FieldHandlerUtils.comparedDBValues(columnType, str1, str2, isAsc);
}
Also used : CellValue(com.cubrid.common.ui.spi.table.CellValue) Map(java.util.Map)

Example 23 with CellValue

use of com.cubrid.common.ui.spi.table.CellValue in project cubrid-manager by CUBRID.

the class QueryExecuter method fillTextData.

public void fillTextData() {
    int columnCount = 0;
    StringBuilder sb = new StringBuilder();
    if (allColumnList != null) {
        columnCount = allColumnList.size();
    }
    if (allDataList != null) {
        for (Map<String, CellValue> data : allDataList) {
            for (int i = 1; i <= columnCount; i++) {
                CellValue value = data.get(String.valueOf(i));
                if (value != null && value.getStringValue() != null) {
                    sb.append(value.getStringValue());
                }
                if (i + 1 <= columnCount) {
                    sb.append("\t");
                }
            }
            sb.append(StringUtil.NEWLINE);
        }
    }
    queryInfo = new QueryInfo(allDataList.size(), pageLimit);
    queryInfo.setCurrentPage(1);
    textData = sb.toString().replace("\n", StringUtil.NEWLINE);
}
Also used : CellValue(com.cubrid.common.ui.spi.table.CellValue) Point(org.eclipse.swt.graphics.Point)

Example 24 with CellValue

use of com.cubrid.common.ui.spi.table.CellValue in project cubrid-manager by CUBRID.

the class QueryExecuter method compareTableItemData.

/**
	 * Compare data and mart item foreground
	 */
private void compareTableItemData(TableItem item, int row, String columnIndex) {
    boolean dataDiff = false, extraRow = false, extraColumn = false;
    CellValue cellValue0 = executer.getAllDataList().get(row).get(columnIndex);
    int baseRowSize = baseQueryExecuter.getAllDataList().size();
    if (row < baseRowSize) {
        int baseColumnSize = baseQueryExecuter.getAllDataList().get(row).size();
        if (Integer.parseInt(columnIndex) <= baseColumnSize) {
            CellValue cellValue1 = baseQueryExecuter.getAllDataList().get(row).get(columnIndex);
            if (isCellValueEqual(cellValue0, cellValue1)) {
                dataDiff = false;
            } else {
                dataDiff = true;
            }
        } else {
            extraColumn = true;
        }
    } else {
        extraRow = true;
    }
    if (dataDiff == true) {
        item.setForeground(Integer.parseInt(columnIndex), RED_COLOR);
    } else if (extraColumn == true) {
        item.setForeground(Integer.parseInt(columnIndex), GREEN_COLOR);
    } else if (extraRow) {
        item.setForeground(Integer.parseInt(columnIndex), BLUE_COLOR);
    }
}
Also used : CellValue(com.cubrid.common.ui.spi.table.CellValue) Point(org.eclipse.swt.graphics.Point)

Aggregations

CellValue (com.cubrid.common.ui.spi.table.CellValue)24 Point (org.eclipse.swt.graphics.Point)11 HashMap (java.util.HashMap)9 Map (java.util.Map)8 ArrayList (java.util.ArrayList)7 SQLException (java.sql.SQLException)6 TableItem (org.eclipse.swt.widgets.TableItem)6 ParamSetException (com.cubrid.common.ui.spi.util.paramSetter.ParamSetException)5 FormatDataResult (com.cubrid.cubridmanager.core.cubrid.table.model.FormatDataResult)4 PstmtParameter (com.cubrid.common.ui.cubrid.table.dialog.PstmtParameter)3 ParamSetter (com.cubrid.common.ui.spi.util.paramSetter.ParamSetter)3 DBConnection (com.cubrid.cubridmanager.core.common.jdbc.DBConnection)3 File (java.io.File)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 Calendar (java.util.Calendar)3 Date (java.util.Date)3 ColumnInfo (com.cubrid.common.ui.query.control.ColumnInfo)2 IOException (java.io.IOException)2 DateTimeComponent (com.cubrid.common.ui.query.control.DateTimeComponent)1