use of com.cubrid.common.core.common.model.IDatabaseSpec in project cubrid-manager by CUBRID.
the class ExportTableDefinitionProgress method loadSchemaCommentData.
/**
* load schema comment data(
* @param conn
* @return
*/
public void loadSchemaCommentData(Connection conn) {
// FIXME move this logic to core module
IDatabaseSpec dbSpec = database.getDatabaseInfo();
isInstalledMetaTable = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
if (isInstalledMetaTable) {
try {
schemaCommentMap = SchemaCommentHandler.loadDescriptions(dbSpec, conn);
} catch (Exception e) {
LOGGER.error("load schema comment error", e);
}
}
}
use of com.cubrid.common.core.common.model.IDatabaseSpec 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.common.model.IDatabaseSpec in project cubrid-manager by CUBRID.
the class DropTableAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj)) {
setEnabled(false);
return;
}
// FIXME move this logic to core module
int len = obj.length;
StringBuilder sb = new StringBuilder();
ISchemaNode table = (ISchemaNode) obj[0];
String type = table.getType();
for (int i = 0; i < len && i < 100; i++) {
table = (DefaultSchemaNode) obj[i];
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(table.getName());
}
if (len > 100) {
sb.append("...");
}
String message = null;
if (NodeType.USER_TABLE.equals(type) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
message = Messages.bind(Messages.dropTable, sb.toString());
}
boolean ret = CommonUITool.openConfirmBox(message);
if (!ret) {
return;
}
String taskName = Messages.bind(Messages.dropTableTaskName, sb.toString());
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
DropTableOrViewTask task = new DropTableOrViewTask(table.getDatabase().getDatabaseInfo());
List<String> tableNameList = new ArrayList<String>();
for (int i = 0; i < len; i++) {
table = (DefaultSchemaNode) obj[i];
tableNameList.add(table.getName());
}
String[] tableNames = new String[tableNameList.size()];
tableNames = tableNameList.toArray(tableNames);
task.setTableName(tableNames);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
// delete table/column descriptions which is dropping table.
DatabaseInfo dbInfo = table.getDatabase().getDatabaseInfo();
Connection conn = null;
try {
conn = JDBCConnectionManager.getConnection(dbInfo, false);
IDatabaseSpec dbSpec = table.getDatabase().getDatabaseInfo();
boolean isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
if (isSupportTableComment) {
for (int i = 0; i < len; i++) {
table = (DefaultSchemaNode) obj[i];
SchemaCommentHandler.deleteDescription(dbInfo, conn, table.getName());
}
}
} catch (SQLException e) {
LOGGER.error(e.getMessage(), e);
} finally {
QueryUtil.freeQuery(conn);
}
ISelectionProvider provider = this.getSelectionProvider();
final TreeViewer viewer = (TreeViewer) provider;
ICubridNode parent = table.getParent();
table.getDatabase().getDatabaseInfo().removeSchema(table.getName());
for (int i = 0; i < len; i++) {
parent.removeChild((ISchemaNode) obj[i]);
/*Broadcast the view changed*/
QueryEditorUtil.fireSchemaNodeChanged((ISchemaNode) obj[i]);
}
viewer.remove(parent, obj);
viewer.setSelection(new StructuredSelection(parent), true);
//refresh user folder count label
CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
/*For bug TOOLS-3118: close opened TableEditorPart about dropped table*/
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
for (IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
IEditorPart editor = editorRef.getEditor(true);
if (editor.getEditorInput() instanceof TableEditorInput) {
TableEditorInput input = (TableEditorInput) editor.getEditorInput();
ISchemaNode tableOfEditor = input.getEditedTableNode();
for (int i = 0; i < len; i++) {
if (tableOfEditor.equals((ISchemaNode) obj[i])) {
workbenchWindow.getActivePage().closeEditor(editor, false);
break;
}
}
}
}
}
}
use of com.cubrid.common.core.common.model.IDatabaseSpec in project cubrid-manager by CUBRID.
the class ColumnViewerSorter method openTableDetail.
private void openTableDetail(TableDetailInfo info) {
//if had opend, set it selection
for (CTabItem tabItem : tabFolder.getItems()) {
if (tabItem.getText().equals(info.getTableName())) {
tabFolder.setSelection(tabItem);
return;
}
}
//if a new table info, create a new tab
TableDashboardComposite tableComp = new TableDashboardComposite(tabFolder, SWT.NONE);
tableComp.initialize();
SchemaProvider schemaProvider = new SchemaProvider(database.getDatabaseInfo(), info.getTableName());
SchemaInfo schemaInfo = schemaProvider.getSchema();
if (schemaInfo == null && StringUtil.isNotEmpty(schemaProvider.getErrorMessage())) {
String msg = Messages.bind(Messages.errGetSchemaInfo, info.getTableName());
CommonUITool.openErrorBox(msg);
return;
}
// load table descriptions
// FIXME move this logic to core module
Connection conn = null;
try {
conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
IDatabaseSpec dbSpec = database.getDatabaseInfo();
boolean isSchemaCommentInstalled = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
if (schemaInfo != null && isSchemaCommentInstalled) {
Map<String, SchemaComment> comments = SchemaCommentHandler.loadDescription(dbSpec, conn, schemaInfo.getClassname());
SchemaCommentHandler.bindSchemaInfo(comments, schemaInfo);
}
} catch (SQLException e) {
LOGGER.error(e.getMessage(), e);
} finally {
QueryUtil.freeQuery(conn);
}
tableComp.setInput(schemaInfo, database.getDatabaseInfo(), isSchemaCommentInstalled);
}
use of com.cubrid.common.core.common.model.IDatabaseSpec in project cubrid-manager by CUBRID.
the class ColumnViewerSorter method setInputs.
public void setInputs() {
tableListView.setInput(tableList);
tableListView.refresh();
Connection connection = null;
try {
connection = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
isSchemaCommentInstalled = SchemaCommentHandler.isInstalledMetaTable(database.getDatabaseInfo(), connection);
TableDashboardComposite tableComp = new TableDashboardComposite(tabFolder, SWT.NONE);
tableComp.initialize();
if (database.getDatabaseInfo().getUserTableInfoList().size() > 0) {
ClassInfo classInfo = database.getDatabaseInfo().getUserTableInfoList().get(0);
SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(connection, classInfo.getClassName());
IDatabaseSpec dbSpec = database.getDatabaseInfo();
if (schemaInfo != null && SchemaCommentHandler.isInstalledMetaTable(dbSpec, connection)) {
Map<String, SchemaComment> comments = SchemaCommentHandler.loadDescription(dbSpec, connection, classInfo.getClassName());
if (comments != null) {
SchemaCommentHandler.bindSchemaInfo(comments, schemaInfo);
}
}
tableComp.setInput(schemaInfo, database.getDatabaseInfo(), isSchemaCommentInstalled);
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
QueryUtil.freeQuery(connection);
}
if (isSchemaCommentInstalled) {
new TableEditButtonSupport(tableListView, this, 1);
}
}
Aggregations