use of com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy in project cubrid-manager by CUBRID.
the class QueryExecuter method addTableItemData.
/**
* Add a record to data set.
*
* @param rs result set
* @return Map<String, CellValue> map type data of a table item
* @throws SQLException
*/
public Map<String, CellValue> addTableItemData(CUBRIDResultSetProxy rs, int idxInDataList) throws SQLException {
Map<String, CellValue> map = new HashMap<String, CellValue>();
int columnPos = 0, columnCount = allColumnList == null ? 0 : allColumnList.size();
if (allColumnList != null) {
for (int j = 1; j <= columnCount; j++) {
ColumnInfo columnInfo = (ColumnInfo) allColumnList.get(columnPos);
String columnType = columnInfo.getType();
String index = columnInfo.getIndex();
String showValue = null;
Object value = rs.getObject(j);
CellValue cellValue = new CellValue();
if (value != null) {
if (DataType.DATATYPE_SET.equals(columnType) || DataType.DATATYPE_MULTISET.equals(columnType) || DataType.DATATYPE_SEQUENCE.equals(columnType)) {
StringBuffer data = new StringBuffer();
Object[] set = (Object[]) rs.getCollection(j);
data.append("{");
for (int i = 0; i < set.length; i++) {
Object setI = set[i];
if (setI == null) {
data.append(DataType.VALUE_NULL);
} else if (setI.getClass() == CUBRIDOIDProxy.getCUBRIDOIDClass(rs.getJdbcVersion())) {
data.append((new CUBRIDOIDProxy(setI)).getOidString());
} else {
data.append(setI);
}
if (i < set.length - 1) {
data.append(",");
}
}
data.append("}");
showValue = data.toString();
cellValue.setShowValue(showValue);
cellValue.setValue(showValue);
} else if (DataType.DATATYPE_DATETIME.equalsIgnoreCase(columnType)) {
showValue = CommonUITool.formatDate(rs.getTimestamp(j), FieldHandlerUtils.FORMAT_DATETIME);
cellValue.setValue(rs.getTimestamp(j));
cellValue.setShowValue(showValue);
} else if (DataType.DATATYPE_BIT_VARYING.equalsIgnoreCase(columnType) || DataType.DATATYPE_BIT.equalsIgnoreCase(columnType)) {
byte[] dataTmp = rs.getBytes(j);
if (dataTmp.length > FieldHandlerUtils.BIT_TYPE_MUCH_VALUE_LENGTH) {
showValue = DataType.BIT_EXPORT_FORMAT;
} else {
showValue = "X'" + DBAttrTypeFormatter.getHexString(dataTmp, columnInfo.getPrecision()) + "'";
}
cellValue.setValue(dataTmp);
cellValue.setShowValue(showValue);
} else if (DataType.DATATYPE_FLOAT.equalsIgnoreCase(columnType)) {
float floatValue = rs.getFloat(j);
showValue = formater4Float.format(floatValue);
cellValue.setValue(floatValue);
cellValue.setShowValue(showValue);
} else if (DataType.DATATYPE_DOUBLE.equalsIgnoreCase(columnType)) {
double doubleValue = rs.getDouble(j);
showValue = formater4Double.format(doubleValue);
cellValue.setValue(doubleValue);
cellValue.setShowValue(showValue);
} else if (DataType.DATATYPE_BLOB.equalsIgnoreCase(columnType) || value instanceof Blob) {
columnInfo.setType(DataType.DATATYPE_BLOB);
loadBlobData(rs, j, cellValue);
} else if (DataType.DATATYPE_CLOB.equalsIgnoreCase(columnType) || value instanceof Clob) {
columnInfo.setType(DataType.DATATYPE_CLOB);
loadClobData(rs, j, cellValue);
} else if (DataType.DATATYPE_NCHAR.equalsIgnoreCase(columnType)) {
columnInfo.setType(DataType.DATATYPE_NCHAR);
String strValue = rs.getString(j);
showValue = "N'" + strValue + "'";
cellValue.setValue(strValue);
cellValue.setShowValue(showValue);
} else if (DataType.DATATYPE_NCHAR_VARYING.equalsIgnoreCase(columnType)) {
columnInfo.setType(DataType.DATATYPE_NCHAR_VARYING);
String strValue = rs.getString(j);
showValue = "N'" + strValue + "'";
cellValue.setValue(strValue);
cellValue.setShowValue(showValue);
} else {
showValue = rs.getString(j);
cellValue.setValue(value);
cellValue.setShowValue(showValue);
}
}
map.put(index, cellValue);
columnPos++;
}
}
if (allDataList != null) {
if (idxInDataList < 0 || idxInDataList >= allDataList.size() - 1) {
allDataList.add(map);
} else {
allDataList.add(idxInDataList, map);
}
}
return map;
}
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