use of com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy 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.jdbc.proxy.driver.CUBRIDOIDProxy in project cubrid-manager by CUBRID.
the class QueryEditorPart method updateResult.
/**
* Update row data on result table
*
* @param strOid String
* @param column String[]
* @param value String[]
* @throws SQLException if failed
*/
public void updateResult(String strOid, String[] column, Object[] value) throws SQLException {
connection.checkAndConnectQuietly();
if (isAutocommit) {
queryAction(QUERY_ACTION.AUTOCOMMIT, true);
} else {
queryAction(QUERY_ACTION.AUTOCOMMIT, false);
}
CUBRIDOIDProxy oid = CUBRIDOIDProxy.getNewInstance((CUBRIDConnectionProxy) connection.getConnection(), strOid);
for (int i = 0; value != null && i < value.length; i++) {
if (DataType.VALUE_NULL.equals(value[i])) {
value[i] = null;
}
}
oid.setValues(column, value);
if (isAutocommit) {
queryAction(QUERY_ACTION.COMMIT);
}
Display.getDefault().syncExec(new Runnable() {
public void run() {
setHaveActiveTransaction(true);
}
});
}
use of com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy 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.jdbc.proxy.driver.CUBRIDOIDProxy in project cubrid-manager by CUBRID.
the class OIDNavigatorDialog method searchOID.
/**
*
* Get tree constructor by the result of execute oid
*
* @param strOid the oid string
* @param parent the parent treeitem
* @return <code>true</code> if found;<code>false</code> otherwise
*/
private boolean searchOID(String strOid, TreeItem parent) {
CUBRIDOIDProxy oid = null;
String tblName = null;
String[] columnName;
String[] typeName;
String[] value;
String[] oidSet = null;
boolean[] isOid = null;
int cntColumn = 0;
try {
oid = CUBRIDOIDProxy.getNewInstance((CUBRIDConnectionProxy) conn, strOid);
if (oid == null) {
return false;
}
tblName = oid.getTableName();
} catch (Exception e) {
CommonUITool.openErrorBox(getShell(), Messages.errOIDValue2);
return false;
}
if (tblName == null) {
CommonUITool.openErrorBox(getShell(), Messages.errOIDValue2);
return false;
}
parent.setText(strOid);
TreeItem item = new TreeItem(parent, SWT.NONE);
item.setText("table name: " + tblName);
String sql = "SELECT * FROM " + QuerySyntax.escapeKeyword(tblName) + " WHERE ROWNUM = 1";
stmt = null;
CUBRIDResultSetProxy rs = null;
try {
stmt = conn.createStatement();
rs = (CUBRIDResultSetProxy) stmt.executeQuery(sql);
ResultSetMetaData rsmt = rs.getMetaData();
cntColumn = rsmt.getColumnCount();
columnName = new String[cntColumn];
typeName = new String[cntColumn];
value = new String[cntColumn];
for (int i = 0; i < cntColumn; i++) {
columnName[i] = rsmt.getColumnName(i + 1);
typeName[i] = rsmt.getColumnTypeName(i + 1);
}
rs.close();
rs = (CUBRIDResultSetProxy) oid.getValues(columnName);
while (rs.next()) {
for (int i = 0; i < columnName.length; i++) {
if (rs.getObject(columnName[i]) == null) {
value[i] = "NULL";
} else {
if ("SET".equals(typeName[i]) || "MULTISET".equals(typeName[i]) || "SEQUENCE".equals(typeName[i])) {
Object[] set = (Object[]) rs.getCollection(columnName[i]);
oidSet = new String[set.length];
isOid = new boolean[set.length];
value[i] = "{";
if (set.length > 0) {
for (int j = 0; j < set.length; j++) {
if (set[j].getClass() == oid.getCUBRIDOIDClass()) {
value[i] += (new CUBRIDOIDProxy(set[j])).getOidString();
oidSet[j] = (new CUBRIDOIDProxy(set[j])).getOidString();
isOid[j] = true;
} else {
value[i] += set[j];
oidSet[j] = null;
isOid[j] = false;
}
if (i < set.length - 1) {
value[i] += ", ";
}
}
}
value[i] += "}";
} else {
value[i] = rs.getString(columnName[i]);
}
}
}
}
rs.close();
for (int i = 0; i < value.length; i++) {
if ("CLASS".equals(typeName[i]) && !"NULL".equals(value[i])) {
item = new TreeItem(parent, SWT.NONE);
item.setText(columnName[i] + ": " + value[i]);
TreeItem treeItem = new TreeItem(item, SWT.NONE);
treeItem.setText(value[i]);
treeItem.setData(OID_ITEM_FLAG, value[i]);
TreeItem dumyItem = new TreeItem(treeItem, SWT.NONE);
dumyItem.setData(DUMY_ITEM_FLAG, DUMY_ITEM_FLAG);
} else if ("SET".equals(typeName[i]) || "MULTISET".equals(typeName[i]) || "SEQUENCE".equals(typeName[i])) {
item = new TreeItem(parent, SWT.NONE);
item.setText(columnName[i] + ": " + value[i]);
if (isOid != null) {
for (int j = 0; j < oidSet.length; j++) {
if (isOid[j]) {
TreeItem treeItem = new TreeItem(item, SWT.NONE);
treeItem.setData(OID_ITEM_FLAG, oidSet[j]);
treeItem.setText(oidSet[j]);
TreeItem dumyItem = new TreeItem(treeItem, SWT.NONE);
dumyItem.setData(DUMY_ITEM_FLAG, DUMY_ITEM_FLAG);
}
}
}
} else {
(new TreeItem(parent, SWT.NONE)).setText(columnName[i] + ": " + value[i]);
}
}
} catch (SQLException e) {
CommonUITool.openErrorBox(getShell(), Messages.bind(com.cubrid.common.ui.common.Messages.errCommonTip, e.getErrorCode(), e.getMessage()));
LOGGER.error("", e);
return false;
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
} catch (SQLException e) {
LOGGER.error(e.getMessage(), e);
}
}
return true;
}
use of com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy in project cubrid-manager by CUBRID.
the class GetUserListTask method buildUserInfo.
/**
*
* Build the database user information
*
* @param dbUserInfoList DbUserInfoList
* @throws SQLException The exception
*/
private void buildUserInfo(DbUserInfoList dbUserInfoList) {
Map<String, String> oidMap = new HashMap<String, String>();
Map<String, List<String>> groupMap = new HashMap<String, List<String>>();
String sql = "SELECT db_user, name, groups FROM db_user";
// [TOOLS-2425]Support shard broker
sql = databaseInfo.wrapShardQuery(sql);
try {
stmt = connection.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
String oidStr = rs.getString(1);
String name = rs.getString(2);
CUBRIDResultSetProxy cubridRS = (CUBRIDResultSetProxy) rs;
Object[] objs = (Object[]) cubridRS.getCollection(3);
List<String> groups = new ArrayList<String>();
for (Object obj : objs) {
if (obj != null && obj.getClass() == CUBRIDOIDProxy.getCUBRIDOIDClass(cubridRS.getJdbcVersion())) {
groups.add((new CUBRIDOIDProxy(obj)).getOidString());
}
}
if (name != null) {
name = name.toLowerCase(Locale.getDefault());
}
oidMap.put(oidStr, name);
groupMap.put(name, groups);
DbUserInfo dbUserInfo = new DbUserInfo();
dbUserInfo.setDbName(databaseInfo.getDbName());
dbUserInfo.setName(name);
dbUserInfo.addAuthorization(new HashMap<String, String>());
dbUserInfoList.addUser(dbUserInfo);
}
} catch (SQLException ex) {
errorMsg = ex.getMessage();
} finally {
QueryUtil.freeQuery(stmt, rs);
}
// get the group user
if (dbUserInfoList.getUserList() != null) {
for (DbUserInfo userInfo : dbUserInfoList.getUserList()) {
UserGroup userGroup = userInfo.getGroups();
if (userGroup == null) {
userGroup = new UserGroup();
userInfo.addGroups(userGroup);
}
List<String> groupOIDList = groupMap.get(userInfo.getName());
for (String groupOID : groupOIDList) {
String groupUser = oidMap.get(groupOID);
if (groupUser != null) {
userInfo.getGroups().addGroup(groupUser);
}
}
}
}
//get the member user
// for (DbUserInfo userInfo : dbUserInfoList.getUserList()) {
// List<String> groupNameList = userInfo.getGroupList();
// for (String groupName : groupNameList) {
// User groupUser = catalog.getUserByName(groupName);
// if (groupUser != null) {
// ((CUBRIDUser) groupUser).addMember(user.getName());
// }
// }
// }
}
Aggregations