use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ColumnProposalAdvisor method loadProposal.
/**
* load proposal for database
*
* @param databaseInfo
*/
private void loadProposal(final DatabaseInfo databaseInfo) {
final String key = makeKey(databaseInfo);
Job job = new Job("Load database schema information job") {
protected IStatus run(IProgressMonitor monitor) {
List<String> tableNames = new ArrayList<String>();
Map<String, List<ColumnProposalDetailInfo>> columns = new HashMap<String, List<ColumnProposalDetailInfo>>();
GetAllSchemaTask task = null;
try {
task = new GetAllSchemaTask(databaseInfo, monitor);
task.setNeedCollationInfo(false);
task.execute();
/*Check is canceled*/
if (task.isCancel()) {
return Status.CANCEL_STATUS;
}
if (task.isSuccess()) {
Map<String, SchemaInfo> schemas = task.getSchemas();
Map<String, SchemaComment> descriptions = task.getComments();
List<String> fetchedTableNames = new ArrayList<String>();
for (SchemaInfo schemaInfo : schemas.values()) {
if (schemaInfo.isSystemClass()) {
continue;
}
String tableName = schemaInfo.getClassname();
if (ConstantsUtil.isExtensionalSystemTable(tableName)) {
continue;
}
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;
}
if (descriptions != null) {
SchemaComment schemaComment = SchemaCommentHandler.find(descriptions, tableName, null);
if (schemaComment != null) {
String description = schemaComment.getDescription();
schemaInfo.setDescription(description);
}
}
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);
}
/*Cache the data*/
ColumnProposal proposal = new ColumnProposal();
proposal.setTableNames(tableNames);
proposal.setColumns(columns);
synchronized (ColumnProposalAdvisor.class) {
cachedMap.put(key, proposal);
}
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
synchronized (ColumnProposalAdvisor.class) {
collectingKeys.remove(key);
}
task.finish();
}
return Status.OK_STATUS;
}
};
/*Record collecting key*/
synchronized (ColumnProposalAdvisor.class) {
collectingKeys.add(key);
job.schedule();
}
}
use of com.cubrid.common.core.common.model.SchemaInfo 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.SchemaInfo 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.SchemaInfo in project cubrid-manager by CUBRID.
the class TableDashboardComposite method getData.
/**
* Get the data that displaying
*/
public SchemaInfo getData() {
if (columnTableView != null && !columnTableView.getTable().isDisposed()) {
Object ob = columnTableView.getInput();
SchemaInfo schema = (SchemaInfo) ob;
return schema;
}
return null;
}
use of com.cubrid.common.core.common.model.SchemaInfo 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