use of com.cubrid.common.core.schemacomment.model.SchemaComment in project cubrid-manager by CUBRID.
the class AlterTriggerAction method run.
/**
* edit trigger
* @param database
* @param node
* @return
*/
public int run(final CubridDatabase database, final ISchemaNode node) {
// FIXME move this logic to core module
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
for (ITask task : taskList) {
task.execute();
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
Trigger trigger = null;
if (task instanceof GetTriggerListTask) {
GetTriggerListTask getTriggerListTask = (GetTriggerListTask) task;
List<Trigger> triggerList = getTriggerListTask.getTriggerInfoList();
for (int i = 0; triggerList != null && i < triggerList.size(); i++) {
Trigger trig = triggerList.get(i);
if (node.getName().equals(trig.getName())) {
trigger = trig;
break;
}
}
} else if (task instanceof JDBCGetTriggerInfoTask) {
JDBCGetTriggerInfoTask getTriggerInfoTask = (JDBCGetTriggerInfoTask) task;
trigger = getTriggerInfoTask.getTriggerInfo(node.getLabel());
}
if (trigger == null) {
openErrorBox(shell, Messages.errNameNoExist, monitor);
return false;
}
// getting comment for version after 10.0
if (CompatibleUtil.isCommentSupports(database.getDatabaseInfo())) {
try {
SchemaComment schemaComment = SchemaCommentHandler.loadObjectDescription(database.getDatabaseInfo(), JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true), trigger.getName(), CommentType.TRIGGER);
trigger.setDescription(schemaComment.getDescription());
} catch (SQLException e) {
CommonUITool.openErrorBox(e.getMessage());
}
}
node.setModelObj(trigger);
}
return true;
}
};
ITask task = null;
if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
task = new GetTriggerListTask(database.getServer().getServerInfo());
((GetTriggerListTask) task).setDbName(database.getName());
} else {
task = new JDBCGetTriggerInfoTask(database.getDatabaseInfo());
}
taskExcutor.addTask(task);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (!taskExcutor.isSuccess()) {
return IDialogConstants.CANCEL_ID;
}
CreateTriggerDialog dialog = new CreateTriggerDialog(getShell(), node.getDatabase(), (Trigger) node.getAdapter(Trigger.class));
if (dialog.open() != IDialogConstants.CANCEL_ID) {
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
ActionManager.getInstance().fireSelectionChanged(getSelection());
return IDialogConstants.OK_ID;
}
return IDialogConstants.CANCEL_ID;
}
use of com.cubrid.common.core.schemacomment.model.SchemaComment in project cubrid-manager by CUBRID.
the class ExportTableDefinitionLayoutType1 method generateTableNamesSheet.
/**
* Generate table name sheet
*
* @param wwb
* @param exportTableNames
* @throws Exception
*/
public void generateTableNamesSheet(WritableWorkbook wwb, List<String> exportTableNames) throws Exception {
WritableSheet ws = wwb.createSheet(Messages.exportTableDefinitionCell1, 0);
// Tables
ws.addCell(new jxl.write.Label(0, 0, Messages.exportTableDefinitionCell2, boldCellStyle));
ws.mergeCells(0, 0, 5, 0);
// Project
ws.addCell(new jxl.write.Label(0, 1, Messages.exportTableDefinitionCell3, boldCellStyle));
ws.addCell(new jxl.write.Label(1, 1, "", normalCellStyle));
// Date
ws.addCell(new jxl.write.Label(2, 1, Messages.exportTableDefinitionCell4, boldCellStyle));
ws.addCell(new jxl.write.Label(3, 1, dateString, normalCellStyle));
// Author
ws.addCell(new jxl.write.Label(4, 1, Messages.exportTableDefinitionCell5, boldCellStyle));
ws.addCell(new jxl.write.Label(5, 1, "", normalCellStyle));
// Table Name
ws.addCell(new jxl.write.Label(0, 2, Messages.exportTableDefinitionCell6, boldCellStyle));
// Table Description
ws.addCell(new jxl.write.Label(1, 2, Messages.exportTableDefinitionCell27, boldCellStyle));
// Description
// ws.addCell(new jxl.write.Label(2, 2, Messages.exportTableDefinitionCell8, boldCellStyle));
// Memo
// ws.addCell(new jxl.write.Label(5, 2, Messages.exportTableDefinitionCell9, boldCellStyle));
ws.mergeCells(1, 2, 5, 2);
//table name data
int rowIndex = 3;
for (String tableName : exportTableNames) {
String tableColumnText = "";
if (getProgressObject().isInstalledMetaTable()) {
SchemaComment tableComment = SchemaCommentHandler.find(getProgressObject().getSchemaCommentMap(), tableName, null);
if (tableComment != null) {
tableColumnText = tableComment.getDescription() == null ? "" : tableComment.getDescription();
}
}
ws.addCell(new jxl.write.Label(0, rowIndex, tableName, normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, tableColumnText, normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Label(2, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(5, rowIndex, "", normalCellStyle));
ws.mergeCells(1, rowIndex, 5, rowIndex);
rowIndex++;
}
ws.setRowView(0, 500);
// column width
ws.setColumnView(0, 25);
ws.setColumnView(1, 28);
ws.setColumnView(2, 15);
ws.setColumnView(3, 18);
ws.setColumnView(4, 15);
ws.setColumnView(5, 20);
}
use of com.cubrid.common.core.schemacomment.model.SchemaComment in project cubrid-manager by CUBRID.
the class ExportTableDefinitionLayoutType2 method generateTableDetailSheets.
/**
* generate table name sheet
* @param wwb
* @param conn
* @param exportSchemaInfoList
* @param monitor
* @throws Exception
*/
public void generateTableDetailSheets(WritableWorkbook wwb, Connection conn, List<SchemaInfo> exportSchemaInfoList, IProgressMonitor monitor) throws Exception {
int sheetIndex = 1;
for (SchemaInfo schemaInfo : exportSchemaInfoList) {
String tableName = schemaInfo.getClassname();
monitor.subTask(Messages.bind(Messages.exportTableDefinitionProgressTaskWriteTable, tableName));
List<SchemaInfo> supers = SuperClassUtil.getSuperClasses(getProgressObject().getDatabase().getDatabaseInfo(), schemaInfo);
WritableSheet ws = wwb.createSheet(tableName, sheetIndex++);
int rowIndex = 0;
// Title
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell10, boldCellStyle));
ws.mergeCells(0, 0, 7, 0);
rowIndex++;
// System name
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell11, boldCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, "", normalCellStyle));
// Date
ws.addCell(new jxl.write.Label(2, rowIndex, Messages.exportTableDefinitionCell4, boldCellStyle));
ws.addCell(new jxl.write.Label(3, rowIndex, dateString, normalCellStyle));
// Author
ws.addCell(new jxl.write.Label(5, rowIndex, Messages.exportTableDefinitionCell5, boldCellStyle));
ws.addCell(new jxl.write.Label(7, rowIndex, "", normalCellStyle));
ws.mergeCells(3, 1, 4, 1);
ws.mergeCells(5, 1, 6, 1);
rowIndex++;
String tableColumnText = "";
if (getProgressObject().isInstalledMetaTable()) {
SchemaComment tableComment = SchemaCommentHandler.find(getProgressObject().getSchemaCommentMap(), tableName, null);
if (tableComment != null) {
tableColumnText = tableComment.getDescription() == null ? "" : tableComment.getDescription();
}
}
// Table Name
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell6, boldCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, tableColumnText, normalLeftAlignCellStyle));
ws.mergeCells(1, 2, 7, 2);
rowIndex++;
// Table ID
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell7, boldCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, tableName, normalLeftAlignCellStyle));
ws.mergeCells(1, 3, 7, 3);
rowIndex++;
// Column name
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell12, boldCellStyle));
// Column ID
ws.addCell(new jxl.write.Label(1, rowIndex, Messages.exportTableDefinitionCell13, boldCellStyle));
// Data type
ws.addCell(new jxl.write.Label(2, rowIndex, Messages.exportTableDefinitionCell14, boldCellStyle));
// Size
ws.addCell(new jxl.write.Label(3, rowIndex, Messages.exportTableDefinitionCell15, boldCellStyle));
// Null
ws.addCell(new jxl.write.Label(4, rowIndex, Messages.exportTableDefinitionCell16, boldCellStyle));
// PK
ws.addCell(new jxl.write.Label(5, rowIndex, Messages.exportTableDefinitionCell17, boldCellStyle));
// FK
ws.addCell(new jxl.write.Label(6, rowIndex, Messages.exportTableDefinitionCell18, boldCellStyle));
// Memo
ws.addCell(new jxl.write.Label(7, rowIndex, Messages.exportTableDefinitionCell19, boldCellStyle));
rowIndex++;
// column info
for (DBAttribute columnAtt : schemaInfo.getAttributes()) {
String attrName = columnAtt.getName();
String columnText = "";
if (getProgressObject().isInstalledMetaTable()) {
SchemaComment columnComment = SchemaCommentHandler.find(getProgressObject().getSchemaCommentMap(), tableName, attrName);
if (columnComment != null) {
columnText = columnComment.getDescription() == null ? "" : columnComment.getDescription();
}
}
ws.addCell(new jxl.write.Label(0, rowIndex, columnText, normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, attrName, normalLeftAlignCellStyle));
String showType = DataType.getShownType((columnAtt.getType()));
if (showType.indexOf("(") > -1 && showType.endsWith("")) {
showType = showType.substring(0, showType.indexOf("("));
}
ws.addCell(new jxl.write.Label(2, rowIndex, showType, normalLeftAlignCellStyle));
int size = DataType.getSize(columnAtt.getType());
int scale = DataType.getScale(columnAtt.getType());
if (size < 0 && scale < 0) {
ws.addCell(new jxl.write.Label(3, rowIndex, "", normalRightAlignCellStyle));
} else if (scale < 0) {
ws.addCell(new jxl.write.Number(3, rowIndex, size, normalRightAlignCellStyle));
} else {
ws.addCell(new jxl.write.Label(3, rowIndex, Integer.toString(size) + "," + Integer.toString(scale), normalRightAlignCellStyle));
}
//get nullable
boolean isNULL = true;
if (!columnAtt.isClassAttribute()) {
if (columnAtt.getInherit().equals(tableName)) {
Constraint pk = schemaInfo.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
isNULL = false;
}
} else {
List<Constraint> pkList = schemaInfo.getInheritPK(supers);
for (Constraint inheritPK : pkList) {
if (inheritPK.getAttributes().contains(attrName)) {
isNULL = false;
}
}
}
}
if (columnAtt.isNotNull()) {
isNULL = false;
}
ws.addCell(new jxl.write.Label(4, rowIndex, isNULL ? "Y" : "", normalCellStyle));
//get pk
boolean isPk = false;
if (!columnAtt.isClassAttribute()) {
if (columnAtt.getInherit().equals(tableName)) {
Constraint pk = schemaInfo.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
isPk = true;
}
} else {
List<Constraint> pkList = schemaInfo.getInheritPK(supers);
for (Constraint inheritPK : pkList) {
if (inheritPK.getAttributes().contains(attrName)) {
isPk = true;
}
}
}
}
ws.addCell(new jxl.write.Label(5, rowIndex, isPk ? "Y" : "", normalCellStyle));
//get fk
boolean isFk = false;
for (Constraint fk : schemaInfo.getFKConstraints()) {
for (String columns : fk.getAttributes()) {
if (columns.equals(attrName)) {
isFk = true;
break;
}
}
}
ws.addCell(new jxl.write.Label(6, rowIndex, isFk ? "Y" : "", normalCellStyle));
ws.addCell(new jxl.write.Label(7, rowIndex, "", normalCellStyle));
rowIndex++;
}
// blank
for (int i = 0; i < 8; i++) {
ws.addCell(new jxl.write.Label(i, rowIndex, "", normalCellStyle));
}
rowIndex++;
// index
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell20, boldCellStyle));
ws.mergeCells(0, rowIndex, 7, rowIndex);
rowIndex++;
// NO
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell21, boldCellStyle));
// Index name
ws.addCell(new jxl.write.Label(1, rowIndex, Messages.exportTableDefinitionCell22, boldCellStyle));
// Column ID
ws.addCell(new jxl.write.Label(3, rowIndex, Messages.exportTableDefinitionCell13, boldCellStyle));
// Order
ws.addCell(new jxl.write.Label(5, rowIndex, Messages.exportTableDefinitionCell23, boldCellStyle));
// Memo
ws.addCell(new jxl.write.Label(6, rowIndex, Messages.exportTableDefinitionCell19, boldCellStyle));
ws.mergeCells(1, rowIndex, 2, rowIndex);
ws.mergeCells(3, rowIndex, 4, rowIndex);
ws.mergeCells(6, rowIndex, 7, rowIndex);
rowIndex++;
List<Constraint> constraints = getProgressObject().getIndexList(schemaInfo);
for (int i = 0; i < constraints.size(); i++) {
Constraint constraint = constraints.get(i);
int columnSize = constraint.getAttributes().size();
// mark current row index
int currentRowIndex = rowIndex;
for (int j = 0; j < columnSize; j++) {
String columnName = constraint.getAttributes().get(j);
ws.addCell(new jxl.write.Number(0, rowIndex, i + 1, normalCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, constraint.getName(), normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Label(3, rowIndex, columnName, normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Number(5, rowIndex, j + 1, normalCellStyle));
ws.addCell(new jxl.write.Label(6, rowIndex, "", normalCellStyle));
if (columnSize == 1) {
ws.mergeCells(1, rowIndex, 2, rowIndex);
}
ws.mergeCells(3, rowIndex, 4, rowIndex);
ws.mergeCells(6, rowIndex, 7, rowIndex);
rowIndex++;
}
//if multiple colulmn merge NO/Index Name CELL by vertical logic
if (columnSize > 1) {
ws.mergeCells(0, currentRowIndex, 0, currentRowIndex + columnSize - 1);
ws.mergeCells(1, currentRowIndex, 2, currentRowIndex + columnSize - 1);
}
}
// blank
ws.addCell(new jxl.write.Label(0, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(3, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(5, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(6, rowIndex, "", normalCellStyle));
ws.mergeCells(1, rowIndex, 2, rowIndex);
ws.mergeCells(3, rowIndex, 4, rowIndex);
ws.mergeCells(6, rowIndex, 7, rowIndex);
rowIndex++;
// DDL
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell24, boldCellStyle));
ws.mergeCells(0, rowIndex, 7, rowIndex);
rowIndex++;
String ddl = getProgressObject().getDDL(schemaInfo);
ws.addCell(new jxl.write.Label(0, rowIndex, ddl, normalLeftAlignCellStyle));
ws.mergeCells(0, rowIndex, 7, rowIndex);
ws.setRowView(0, 500);
int lineNumbner = ddl.split(StringUtil.NEWLINE).length;
ws.setRowView(rowIndex, lineNumbner * 350);
// column width
ws.setColumnView(0, 18);
ws.setColumnView(1, 20);
ws.setColumnView(2, 13);
ws.setColumnView(3, 13);
ws.setColumnView(4, 11);
ws.setColumnView(5, 11);
ws.setColumnView(6, 11);
ws.setColumnView(7, 20);
monitor.worked(1);
}
}
use of com.cubrid.common.core.schemacomment.model.SchemaComment in project cubrid-manager by CUBRID.
the class ERDNDController method getDescInformation.
private void getDescInformation(SchemaInfo newSchemaInfo, CubridDatabase database, Connection conn) {
// FIXME move this logic to core module
try {
IDatabaseSpec dbSpec = database.getDatabaseInfo();
boolean isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
database.getDatabaseInfo().setSupportTableComment(isSupportTableComment);
if (isSupportTableComment && newSchemaInfo != null) {
Map<String, SchemaComment> map = SchemaCommentHandler.loadDescription(dbSpec, conn, newSchemaInfo.getClassname());
for (DBAttribute attr : newSchemaInfo.getAttributes()) {
SchemaComment schemaComment = SchemaCommentHandler.find(map, newSchemaInfo.getClassname(), attr.getName());
if (schemaComment != null) {
attr.setDescription(schemaComment.getDescription());
}
}
SchemaComment schemaComment = SchemaCommentHandler.find(map, newSchemaInfo.getClassname(), null);
if (schemaComment != null) {
newSchemaInfo.setDescription(schemaComment.getDescription());
}
}
} catch (SQLException e) {
LOGGER.error("", e);
} catch (Exception e) {
LOGGER.error("", e);
}
}
use of com.cubrid.common.core.schemacomment.model.SchemaComment in project cubrid-manager by CUBRID.
the class SchemaCommentHandler method loadDescription.
public static Map<String, SchemaComment> loadDescription(IDatabaseSpec dbSpec, Connection conn, String tableName) throws SQLException {
boolean isSupportInEngine = CompatibleUtil.isCommentSupports(dbSpec);
String sql = null;
String tableCondition = null;
String columnCondition = null;
if (isSupportInEngine) {
sql = "SELECT class_name as table_name, null as column_name, comment as description " + "FROM db_class " + "WHERE is_system_class='NO' %s" + "UNION ALL " + "SELECT class_name as table_name, attr_name as column_name, comment as description " + "FROM db_attribute %s";
if (StringUtil.isNotEmpty(tableName)) {
tableCondition = "AND class_name = '" + QuerySyntax.escapeKeyword(tableName) + "' ";
columnCondition = "WHERE class_name = '" + QuerySyntax.escapeKeyword(tableName) + "'";
} else {
tableCondition = "AND comment is not null ";
columnCondition = "WHERE comment is not null";
}
sql = String.format(sql, tableCondition, columnCondition);
} else {
sql = "SELECT LOWER(table_name) as table_name, LOWER(column_name) as column_name, description" + " FROM " + ConstantsUtil.SCHEMA_DESCRIPTION_TABLE;
if (StringUtil.isNotEmpty(tableName)) {
String pureTableName = tableName.replace("\"", "");
sql += " WHERE LOWER(table_name)='" + pureTableName.toLowerCase() + "'";
}
}
// [TOOLS-2425]Support shard broker
if (dbSpec.isShard()) {
sql = dbSpec.wrapShardQuery(sql);
}
Map<String, SchemaComment> results = new HashMap<String, SchemaComment>();
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
SchemaComment meta = resultToMetaDesc(rs);
results.put(meta.getId(), meta);
}
} catch (SQLException e) {
QueryUtil.rollback(conn);
LOGGER.error(e.getMessage(), e);
throw e;
} finally {
QueryUtil.freeQuery(stmt, rs);
}
return results;
}
Aggregations