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);
}
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations