use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class ColumnProposalDetailInfo method fillInTableColumnInfo.
/**
* Fill in the table column information
*
* @param dbInfo DatabaseInfo
* @param tableNames List<String>
* @param columns Map<String, List<ColumnProposalDetailInfo>>
*/
public static void fillInTableColumnInfo(DatabaseInfo dbInfo, List<String> tableNames, Map<String, List<ColumnProposalDetailInfo>> columns) {
try {
GetAllSchemaTask task = new GetAllSchemaTask(dbInfo);
task.setNeedCollationInfo(false);
task.execute();
Map<String, SchemaInfo> schemas = task.getSchemas();
List<String> fetchedTableNames = new ArrayList<String>();
for (SchemaInfo schemaInfo : schemas.values()) {
String tableName = schemaInfo.getClassname();
fetchedTableNames.add(tableName);
}
Collections.sort(fetchedTableNames);
for (String tableName : fetchedTableNames) {
if (!tableNames.contains(tableName)) {
tableNames.add(tableName);
}
if (columns.containsKey(tableName)) {
continue;
}
SchemaInfo schemaInfo = schemas.get(tableName);
if (schemaInfo == null) {
continue;
}
List<ColumnProposalDetailInfo> colInfoList = new ArrayList<ColumnProposalDetailInfo>();
columns.put(tableName, colInfoList);
List<DBAttribute> dbClassAttrList = schemaInfo.getClassAttributes();
for (DBAttribute attr : dbClassAttrList) {
ColumnProposalDetailInfo colInfo = new ColumnProposalDetailInfo(schemaInfo, attr);
colInfoList.add(colInfo);
}
List<DBAttribute> attrList = schemaInfo.getAttributes();
for (DBAttribute attr : attrList) {
ColumnProposalDetailInfo colInfo = new ColumnProposalDetailInfo(schemaInfo, attr);
colInfoList.add(colInfo);
}
columns.put(schemaInfo.getClassname(), colInfoList);
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class PstmtDataDialog method createSelectPstmtSQL.
/**
* Create selected prepared statement SQL
*
* @return String
*/
protected String createSelectPstmtSQL() {
// FIXME move this logic to core module
StringBuffer columns = new StringBuffer("");
StringBuffer wheres = new StringBuffer("");
int n = schemaInfo == null ? 0 : schemaInfo.getAttributes().size();
for (int i = 0; i < n; i++) {
DBAttribute da = (DBAttribute) schemaInfo.getAttributes().get(i);
if (columns.length() > 0) {
columns.append(", ");
wheres.append(" AND ");
}
columns.append(QuerySyntax.escapeKeyword(da.getName()));
wheres.append(QuerySyntax.escapeKeyword(da.getName()) + " = ?");
}
StringBuffer sql = new StringBuffer("");
if (columns.length() > 0) {
sql.append("SELECT ");
sql.append(columns);
sql.append(" FROM ");
sql.append(QuerySyntax.escapeKeyword(tableName));
sql.append(" WHERE ");
sql.append(wheres + ";");
}
return sql.toString();
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class AddFKDialog method init.
/**
* initializes some values.
*
*/
private void init() {
List<String> list = getTableList();
//List<String> foreignTablelist = schema.getForeignTables();
for (String table : list) {
//if (!foreignTablelist.contains(table)) {
foreignTableCombo.add(table);
//}
}
if (editedFK == null) {
if (defaultTableName != null) {
foreignTableCombo.setText(defaultTableName);
} else {
foreignTableCombo.select(0);
}
getPKTableData();
List<DBAttribute> attrList = schema.getLocalAttributes();
for (int i = 0, n = attrList.size(); i < n; i++) {
DBAttribute attr = attrList.get(i);
TableItem item = new TableItem(fkTable, SWT.NONE);
item.setText(0, attr.getName());
item.setText(1, DataType.getShownType(attr.getType()));
//$NON-NLS-1$
item.setText(2, "");
}
} else {
fkNameText.setText(editedFK.getName());
String refTable = "";
String delRule = "RESTRICT";
String updateRule = "RESTRICT";
String cacheRule = "";
List<String> rules = editedFK.getRules();
for (String rule : rules) {
String refStr = "REFERENCES ";
String delStr = "ON DELETE ";
String updStr = "ON UPDATE ";
String cacheStr = "ON CACHE OBJECT ";
if (rule.startsWith(refStr)) {
refTable = rule.replace(refStr, "");
} else if (rule.startsWith(delStr)) {
delRule = rule.replace(delStr, "");
} else if (rule.startsWith(updStr)) {
updateRule = rule.replace(updStr, "");
} else if (rule.startsWith(cacheStr)) {
cacheRule = rule.replace(cacheStr, "");
}
}
List<String> refPKAttrs = new ArrayList<String>();
SchemaInfo refSchema = getSchemaInfo(refTable);
List<SchemaInfo> refSupers = getRefedSupper(refSchema);
Constraint refPK = refSchema.getPK(refSupers);
if (refPK != null) {
refPKAttrs = refPK.getAttributes();
}
//Referenced foreign table name
foreignTableCombo.setText(refTable);
getPKTableData();
//Foreign table columns
List<String> fkColumns = editedFK.getAttributes();
List<DBAttribute> attrList = schema.getLocalAttributes();
for (int i = 0, n = attrList.size(); i < n; i++) {
DBAttribute attr = attrList.get(i);
TableItem item = new TableItem(fkTable, SWT.NONE);
item.setText(0, attr.getName());
item.setText(1, DataType.getShownType(attr.getType()));
if (fkColumns.contains(attr.getName())) {
int index = getPKMatchIndexInFK(attr.getName());
if (index == -1) {
index = 0;
}
item.setText(2, refPKAttrs.isEmpty() ? "" : refPKAttrs.get(index));
} else {
item.setText(2, "");
}
}
for (Button btn : updateBTNs) {
String rule = buttonMap.get(btn);
if (updateRule.equalsIgnoreCase(rule)) {
btn.setSelection(true);
} else {
btn.setSelection(false);
}
}
for (Button btn : deleteBTNs) {
String rule = buttonMap.get(btn);
if (delRule.equalsIgnoreCase(rule)) {
btn.setSelection(true);
} else {
btn.setSelection(false);
}
}
if (cacheRule != null && cacheRule.trim().length() > 0) {
onCacheObjectButton.setSelection(true);
newColumnNameText.setEnabled(true);
newColumnNameText.setText(cacheRule);
}
}
foreignTableCombo.setEnabled(canChangeTable);
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class AddIndexDialog method setInfo.
/**
* Set the information
*
*/
private void setInfo() {
indexNameText.setEnabled(true);
Map<String, String[]> ruleMap = new HashMap<String, String[]>();
if (editedIndex == null) {
setSelectIndexType(CUB_INDEX);
} else {
indexNameText.setText(editedIndex.getName());
String indexType = editedIndex.getType();
setSelectIndexType(indexType);
List<String> rules = editedIndex.getRules();
for (String rule : rules) {
String[] strs = rule.trim().split(" ");
String columnName = strs[0];
String order = strs[1];
String prefixLength = "";
if (strs[0].indexOf("(") > 0) {
columnName = strs[0].substring(0, strs[0].indexOf("("));
prefixLength = strs[0].substring(strs[0].indexOf("(") + 1, strs[0].indexOf(")"));
}
String[] ruleArr = { columnName, order, prefixLength };
ruleMap.put(columnName.toUpperCase(), ruleArr);
}
}
List<DBAttribute> attrList = schemaInfo.getLocalAttributes();
for (int i = 0, n = attrList.size(); i < n; i++) {
DBAttribute attr = attrList.get(i);
String[] ruleArr = ruleMap.get(attr.getName().toUpperCase());
TableItem item = new TableItem(columnTable, SWT.NONE);
item.setText(1, attr.getName());
item.setText(2, DataType.getShownType(attr.getType()));
item.setText(3, ruleArr == null ? IndexTableItemEditor.ORDER_ASC : ruleArr[1].toUpperCase());
item.setText(4, ruleArr == null ? "" : ruleArr[2]);
item.setForeground(ResourceManager.getColor(128, 128, 128));
item.setChecked(ruleArr != null);
}
setBtnEnable();
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableDashboardComposite method showEditDialog.
public void showEditDialog(Table table, int index) {
SchemaInfo info = getData();
if (info == null) {
return;
}
List<DBAttribute> attrs = info.getAttributes();
if (attrs == null) {
return;
}
if (index >= attrs.size()) {
return;
}
DBAttribute attr = attrs.get(index);
if (attr == null) {
return;
}
InputTextDialog dialog = new InputTextDialog(Display.getCurrent().getActiveShell(), com.cubrid.common.ui.cubrid.table.Messages.titleColumnDescEditor, com.cubrid.common.ui.cubrid.table.Messages.msgColumnDescEditor, com.cubrid.common.ui.cubrid.table.Messages.labelColumnDescEditor, attr.getDescription());
if (dialog.open() == IDialogConstants.OK_ID) {
// FIXME move this logic to core module
String tableName = info.getClassname();
String columnName = attr.getName();
String description = dialog.getResult();
Connection conn = null;
try {
conn = JDBCConnectionManager.getConnection(databaseInfo, true);
SchemaCommentHandler.updateDescription(databaseInfo, conn, tableName, columnName, description);
attr.setDescription(description);
columnTableView.setInput(info);
} catch (Exception e) {
e.printStackTrace();
} finally {
QueryUtil.commit(conn);
QueryUtil.freeQuery(conn);
}
}
}
Aggregations