use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.
the class RowDetailDialog method export.
/**
* Export data to file
*
* @param filePath String
* @param oidStr String
* @param value String
* @param fileCharset String
* @throws IOException The exception
* @throws SQLException The exception
*/
private void export(final String filePath, String oidStr, String value, String fileCharset) throws IOException, SQLException {
// FIXME move this logic to core module
OutputStream fs = null;
Writer writer = null;
InputStream in = null;
Reader reader = null;
ResultSet rs = null;
try {
ColumnInfo columnInfo = columnInfoList.get(selComboIndex);
String type = columnInfo.getType();
String completedType = columnInfo.getComleteType();
String colName = columnInfo.getName();
if (DataType.DATATYPE_BLOB.equals(type) && DataType.BLOB_EXPORT_FORMAT.equals(value)) {
CUBRIDOIDProxy oidPxory = CUBRIDOIDProxy.getNewInstance((CUBRIDConnectionProxy) qe.getQueryEditor().getConnection().checkAndConnect(), oidStr);
rs = oidPxory.getValues(new String[] { colName });
rs.next();
Blob blob = rs.getBlob(colName);
in = blob.getBinaryStream();
fs = new BufferedOutputStream(new FileOutputStream(filePath));
byte[] bArr = new byte[512];
int count = in.read(bArr);
while (count > 0) {
fs.write(bArr, 0, count);
count = in.read(bArr);
}
fs.flush();
} else {
if (DataType.DATATYPE_CLOB.equals(type) && DataType.CLOB_EXPORT_FORMAT.equals(value)) {
CUBRIDOIDProxy oidPxory = CUBRIDOIDProxy.getNewInstance((CUBRIDConnectionProxy) qe.getQueryEditor().getConnection().checkAndConnect(), oidStr);
rs = oidPxory.getValues(new String[] { colName });
rs.next();
Clob clob = rs.getClob(colName);
reader = clob.getCharacterStream();
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), fileCharset));
char[] charArr = new char[512];
int count = reader.read(charArr);
while (count > 0) {
writer.write(charArr, 0, count);
count = reader.read(charArr);
}
writer.flush();
} else if (DataType.DATATYPE_BIT.equals(type) || DataType.DATATYPE_BIT_VARYING.equals(type)) {
byte[] bArr = null;
if (DataType.BIT_EXPORT_FORMAT.equals(value)) {
CUBRIDOIDProxy oidPxory = CUBRIDOIDProxy.getNewInstance((CUBRIDConnectionProxy) qe.getQueryEditor().getConnection().checkAndConnect(), oidStr);
rs = oidPxory.getValues(new String[] { colName });
rs.next();
bArr = rs.getBytes(colName);
} else {
FormatDataResult result = new FormatDataResult();
DBAttrTypeFormatter.formatBit(completedType, value, result, dbCharset);
bArr = (byte[]) result.getFormatedJavaObj();
}
fs = new BufferedOutputStream(new FileOutputStream(filePath));
fs.write(bArr);
fs.flush();
} else {
byte[] bArr = value.getBytes(fileCharset);
fs = new BufferedOutputStream(new FileOutputStream(filePath));
fs.write(bArr);
fs.flush();
}
}
} finally {
if (fs != null) {
try {
fs.close();
fs = null;
} catch (IOException e) {
LOGGER.error("", e);
}
}
if (writer != null) {
try {
writer.close();
writer = null;
} catch (IOException e) {
LOGGER.error("", e);
}
}
if (rs != null) {
try {
rs.close();
rs = null;
} catch (SQLException e) {
LOGGER.error("", e);
}
}
if (in != null) {
try {
in.close();
in = null;
} catch (IOException e) {
LOGGER.error("", e);
}
}
if (reader != null) {
try {
reader.close();
reader = null;
} catch (IOException e) {
LOGGER.error("", e);
}
}
}
}
use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.
the class RowDetailDialog method createDialogArea.
/**
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
* @param parent the parent composite to contain the dialog area
* @return the dialog area control
*/
protected Control createDialogArea(Composite parent) {
Composite parentComp = (Composite) super.createDialogArea(parent);
final Composite composite = new Composite(parentComp, SWT.NONE);
{
GridLayout layout = new GridLayout();
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
layout.numColumns = 2;
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
}
Label columnNameLabel = new Label(composite, SWT.NONE);
columnNameLabel.setText(Messages.lblColumnName);
columnCombo = new Combo(composite, SWT.SINGLE | SWT.READ_ONLY);
columnCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
columnCombo.setVisibleItemCount(10);
columnCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
int index = columnCombo.getSelectionIndex();
if (selComboIndex >= 0 && isValueChange() && CommonUITool.openConfirmBox(getShell(), Messages.cfmUpdateChangedValue)) {
final boolean updateDB = !QueryExecuter.isNewInsertedRecordItem(dataItem);
update(columnValueText.getText(), fileCharsetCombo.getText(), dataItem.getText(1), updateDB);
setUpdateButtonEnable();
}
selComboIndex = index;
ColumnInfo columnInfo = columnInfoList.get(selComboIndex);
columnTypeTxt.setText(columnInfo.getComleteType());
String columnValue = dataItem.getText(selComboIndex + 1);
boolean isNull = DataType.VALUE_NULL.equals(dataItem.getData("" + (selComboIndex + 1)));
if (isNull) {
columnValueText.setText(DataType.NULL_EXPORT_FORMAT);
setNullBtn.setSelection(true);
} else {
columnValueText.setText(columnValue);
setNullBtn.setSelection(false);
}
importBtn.setEnabled(false);
importBtn.setVisible(false);
exportBtn.setEnabled(false);
fileCharsetCombo.setEnabled(false);
String colType = columnInfo.getType();
boolean isMuchValueType = DBAttrTypeFormatter.isMuchValueType(columnInfo.getComleteType(), -1);
boolean isByteType = DataType.DATATYPE_BLOB.equals(colType) || DataType.DATATYPE_BIT.equals(colType) || DataType.DATATYPE_BIT_VARYING.equals(colType);
boolean isCanExport = false;
if ((DataType.DATATYPE_BLOB.equals(colType) || DataType.DATATYPE_CLOB.equals(colType))) {
isCanExport = isCanUpdate() && !isNull;
} else if (DataType.DATATYPE_BIT.equals(colType) || DataType.DATATYPE_BIT_VARYING.equals(colType)) {
isCanExport = (isCanUpdate() || !DataType.BIT_EXPORT_FORMAT.equals(columnValue)) && !isNull;
} else {
isCanExport = !isNull && isMuchValueType;
}
if (isCanUpdate()) {
if (DataType.DATATYPE_OID.equals(colType) || DataType.DATATYPE_CLASS.equals(colType)) {
columnValueText.setEnabled(false);
setNullBtn.setEnabled(false);
} else {
columnValueText.setEnabled(true);
setNullBtn.setEnabled(true);
importBtn.setEnabled(isMuchValueType);
exportBtn.setEnabled(isCanExport);
boolean isCharsetEnabled = (isMuchValueType || isCanExport) && !isNull && !isByteType;
fileCharsetCombo.setEnabled(isCharsetEnabled);
}
} else {
setNullBtn.setEnabled(false);
importBtn.setEnabled(false);
exportBtn.setEnabled(isCanExport);
boolean isCharsetEnabled = isCanExport && !isNull && !isByteType;
fileCharsetCombo.setEnabled(isCharsetEnabled);
}
setUpdateButtonEnable();
}
});
Label columnTypeLabel = new Label(composite, SWT.NONE);
columnTypeLabel.setText(Messages.lblColumnType);
columnTypeTxt = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
columnTypeTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
createColumnValueGroup(composite);
createFileGroup(composite);
initial();
setTitle(Messages.titleRowDetailDialog);
setMessage(Messages.msgRowDetailDialog);
return parentComp;
}
use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.
the class QueryRecord method clone.
/**
* Clone a object. It not a deep clone
*
* @return QueryRecord
*/
public QueryRecord clone() {
QueryRecord queryRecord = null;
try {
queryRecord = (QueryRecord) super.clone();
} catch (CloneNotSupportedException e) {
}
if (queryPlan != null) {
queryRecord.setQueryPlan(queryPlan.clone());
}
if (statistics != null) {
LinkedHashMap<String, String> cloneStatistics = new LinkedHashMap<String, String>();
for (Entry<String, String> entry : statistics.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
cloneStatistics.put(key, value);
}
queryRecord.setStatistics(cloneStatistics);
}
if (queryInfo != null) {
QueryInfo clonedInfo = queryInfo.clone();
queryRecord.setQueryInfo(clonedInfo);
}
if (columnInfoList != null) {
List<ColumnInfo> cloneList = new ArrayList<ColumnInfo>();
for (ColumnInfo columnInfo : columnInfoList) {
cloneList.add(columnInfo.clone());
}
queryRecord.setColumnInfoList(columnInfoList);
}
return queryRecord;
}
use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.
the class QueryTunerJob method getColumnData.
/**
* Init table column data
* @param rs
* @return
* @throws SQLException
*/
private List<ColumnInfo> getColumnData(CUBRIDResultSetProxy rs) throws SQLException {
// FIXME move this logic to core module
List<ColumnInfo> columnInfoList = new ArrayList<ColumnInfo>();
CUBRIDResultSetMetaDataProxy rsmt = (CUBRIDResultSetMetaDataProxy) rs.getMetaData();
int cntColumn = rsmt.getColumnCount();
for (int i = 1; i <= cntColumn; i++) {
String columnName = rsmt.getColumnName(i);
String typeName = StringUtil.nvl(rsmt.getColumnTypeName(i));
int scale = rsmt.getScale(i);
int precision = rsmt.getPrecision(i);
String elementTypeName = StringUtil.nvl(rsmt.getElementTypeName(i));
if (typeName.length() == 0) {
int typeIndex = rsmt.getColumnType(i);
switch(typeIndex) {
case Types.BLOB:
typeName = DataType.DATATYPE_BLOB;
break;
case Types.CLOB:
typeName = DataType.DATATYPE_CLOB;
break;
default:
typeName = "";
}
}
String columnType = typeName.toUpperCase(Locale.getDefault());
String elementType = elementTypeName.toUpperCase(Locale.getDefault());
ColumnInfo colInfo = new ColumnInfo(String.valueOf(i), columnName, columnType, elementType, precision, scale);
columnInfoList.add(colInfo);
}
return columnInfoList;
}
use of com.cubrid.common.ui.query.control.ColumnInfo in project cubrid-manager by CUBRID.
the class FilterChooserDialog method buttonPressed.
/**
* Call this method when the button in button bar is pressed
*
* @param buttonId the button id
*/
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
selectedColInfoList.clear();
Object[] objs = tv.getCheckedElements();
if (objs != null && objs.length > 0) {
for (Object obj : objs) {
@SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) obj;
ColumnInfo colInfo = (ColumnInfo) map.get("1");
selectedColInfoList.add(colInfo);
}
}
}
super.buttonPressed(buttonId);
}
Aggregations