use of com.cubrid.jdbc.proxy.driver.CUBRIDResultSetProxy in project cubrid-manager by CUBRID.
the class AbsExportDataHandler method getCurrentValueFromSystemTable.
/**
* get current value from system table
*
* @param serialName
* @param conn
* @return
*/
public static String getCurrentValueFromSystemTable(String serialName, DatabaseInfo dbInfo, Connection conn) {
// FIXME move this logic to core module
Statement stmt = null;
CUBRIDResultSetProxy rs = null;
StringBuilder sqlbuf = new StringBuilder();
sqlbuf.append("SELECT ");
sqlbuf.append(QuerySyntax.escapeKeyword("current_val")).append(", ");
sqlbuf.append(QuerySyntax.escapeKeyword("increment_val")).append(", ");
sqlbuf.append(QuerySyntax.escapeKeyword("started"));
sqlbuf.append(" FROM db_serial WHERE name = '").append(serialName).append("'");
String sql = DatabaseInfo.wrapShardQuery(dbInfo, sqlbuf.toString());
String currentStringValue = "1";
try {
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
rs = (CUBRIDResultSetProxy) stmt.executeQuery(sql.toString());
if (rs.next()) {
currentStringValue = rs.getString(1);
String incrementStringValue = rs.getString(2);
String started = rs.getString(3);
//Because first insert value does not use current value ,so add incrementValue as current value
if (StringUtil.isNotEmpty(incrementStringValue) && "1".equals(started)) {
double currentValue = Double.valueOf(currentStringValue);
double incrementValue = Double.valueOf(incrementStringValue);
currentValue += incrementValue;
currentStringValue = new DecimalFormat("#").format(currentValue);
}
}
} catch (Exception e) {
LOGGER.error("", e);
} finally {
QueryUtil.freeQuery(stmt, rs);
}
return currentStringValue;
}
use of com.cubrid.jdbc.proxy.driver.CUBRIDResultSetProxy in project cubrid-manager by CUBRID.
the class GetInfoDataTask method addTableItemData.
/**
* add a record to data set.
*
* @param rs result set
* @return Map<String, Object> map type data of a table item
* @throws SQLException
*/
private Map<String, Object> addTableItemData(CUBRIDResultSetProxy rs, int idxInDataList) throws SQLException {
// FIXME move this logic to core module
DecimalFormat formater = new DecimalFormat();
Map<String, Object> map = new HashMap<String, Object>();
int columnPos = 0, columnCount = allColumnList == null ? 0 : allColumnList.size();
if (doesGetOidInfo) {
CUBRIDOIDProxy oid = ((CUBRIDResultSetProxy) rs).getOID();
if (oid == null || oid.getProxyObject() == null || oid.getOidString() == null) {
map.put("0", DataType.VALUE_NONE);
} else {
map.put("0", oid.getOidString());
}
columnPos++;
columnCount--;
}
if (allColumnList != null) {
for (int j = 1; j <= columnCount; j++) {
Object dataToput = null;
ColumnInfo columnInfo = (ColumnInfo) allColumnList.get(columnPos);
String columnType = columnInfo.getType();
String index = columnInfo.getIndex();
Object rsObj = rs.getObject(j);
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[]) rs.getCollection(j);
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(rs.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(rs.getTimestamp(j), FieldHandlerUtils.FORMAT_DATETIME);
} 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) {
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(rs.getFloat(j));
} else if (DataType.DATATYPE_DOUBLE.equalsIgnoreCase(columnType)) {
formater.applyPattern(FORMAT_DOUBLE);
dataToput = formater.format(rs.getDouble(j));
} 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 {
dataToput = rs.getString(j);
}
}
map.put(index, dataToput);
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.CUBRIDResultSetProxy 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