use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.
the class CreateViewDialog method createDialogArea.
protected Control createDialogArea(Composite parent) {
parentComp = (Composite) super.createDialogArea(parent);
Composite composite = new Composite(parentComp, SWT.NONE);
{
final GridData gdComposite = new GridData(SWT.FILL, SWT.FILL, true, true);
composite.setLayoutData(gdComposite);
GridLayout layout = new GridLayout();
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
layout.numColumns = 1;
composite.setLayout(layout);
}
tabFolder = new TabFolder(composite, SWT.NONE);
final GridData gdTabFolder = new GridData(SWT.FILL, SWT.FILL, true, true);
tabFolder.setLayoutData(gdTabFolder);
final TabItem generalTabItem = new TabItem(tabFolder, SWT.NONE);
generalTabItem.setText(Messages.tabItemGeneral);
final Composite compositeGenaral = createGeneralComposite();
generalTabItem.setControl(compositeGenaral);
final TabItem ddlTabItem = new TabItem(tabFolder, SWT.NONE);
ddlTabItem.setText(Messages.tabItemSQLScript);
final Composite sqlScriptComp = createSQLScriptComposite();
ddlTabItem.setControl(sqlScriptComp);
tabFolder.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
boolean isFirstTab = tabFolder.getSelectionIndex() == 0;
boolean isLastTab = tabFolder.getSelectionIndex() == tabFolder.getItemCount() - 1;
if (isFirstTab) {
tableText.setFocus();
} else if (isLastTab) {
StringBuilder sb = new StringBuilder();
String dropSql = makeDropSQLScript();
if (dropSql.length() > 0) {
sb.append(dropSql);
sb.append(StringUtil.NEWLINE);
sb.append(StringUtil.NEWLINE);
sb.append(StringUtil.NEWLINE);
}
sb.append(makeCreateSQLScript());
String ownerNew = ownerCombo.getText();
String ownerOld = null;
if (isNewTableFlag) {
DatabaseInfo dbInfo = database.getDatabaseInfo();
ownerOld = dbInfo.getAuthLoginedDbUserInfo().getName();
} else {
ownerOld = classInfo.getOwnerName();
}
boolean isSameUser = StringUtil.isEqualIgnoreCase(ownerOld, ownerNew);
if (!isSameUser) {
sb.append(";");
sb.append(StringUtil.NEWLINE);
sb.append(StringUtil.NEWLINE);
sb.append(StringUtil.NEWLINE);
sb.append(makeChangeOwnerSQLScript()).append(";");
sb.append(StringUtil.NEWLINE);
}
sqlText.setText(formatSql(sb.toString()));
}
}
});
init();
tableText.setFocus();
return parent;
}
use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.
the class CreateViewDialog method getViewComment.
/**
* get view's comment
*
* @return
*/
private String getViewComment() {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
SchemaComment schemaComment = null;
String viewName = tableText.getText();
try {
DatabaseInfo dbInfo = database.getDatabaseInfo();
conn = JDBCConnectionManager.getConnection(dbInfo, true);
schemaComment = SchemaCommentHandler.loadObjectDescription(dbInfo, conn, viewName, CommentType.VIEW);
} catch (SQLException e) {
LOGGER.error(e.getMessage());
CommonUITool.openErrorBox(e.getMessage());
} finally {
QueryUtil.freeQuery(stmt, rs);
}
return schemaComment.getDescription();
}
use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.
the class TableEditorPart method okPressed.
protected void okPressed() {
if (!verifyTableName()) {
return;
}
if (columnsTable.getItemCount() == 0) {
CommonUITool.openErrorBox(Messages.noAttributes);
return;
}
String message = (oldSchemaInfo == null) ? Messages.msgCreateTableConfirm : Messages.msgAlterTableConfirm;
if (!CommonUITool.openConfirmBox(message)) {
return;
}
tableName = tableNameText.getText();
owner = ownerCombo.getText();
String tableDesc = tableDescText.getText();
newSchemaInfo.setClassname(tableName);
newSchemaInfo.setOwner(owner);
newSchemaInfo.setDescription(tableDesc);
if (reuseOIDBtn != null) {
newSchemaInfo.setReuseOid(reuseOIDBtn.getSelection());
}
DatabaseInfo dbInfo = database.getDatabaseInfo();
CommonSQLExcuterTask commonSqlTask = new CommonSQLExcuterTask(dbInfo);
schemaDDL.setEndLineChar("$$$$");
String ddlStr = null;
if (isNewTableFlag) {
ddlStr = schemaDDL.getSchemaDDL(newSchemaInfo);
} else {
ddlStr = schemaDDL.getSchemaDDL(oldSchemaInfo, newSchemaInfo);
}
boolean isExecuteCommonSqlTask = false;
String[] sqlStr = ddlStr.split("\\$\\$\\$\\$");
for (String sql : sqlStr) {
String trimSql = sql.trim();
if (trimSql.length() > 0 && !trimSql.startsWith("--")) {
if (dbInfo.isShard()) {
sql = dbInfo.wrapShardQuery(sql);
}
commonSqlTask.addSqls(sql);
isExecuteCommonSqlTask = true;
}
}
// do with table user change
String changeOwnerDDL = getChangeOwnerDDL();
if (StringUtil.isNotEmpty(changeOwnerDDL)) {
changeOwnerDDL = dbInfo.wrapShardQuery(changeOwnerDDL);
commonSqlTask.addCallSqls(changeOwnerDDL);
isExecuteCommonSqlTask = true;
}
schemaDDL.setEndLineChar(";");
// do with column null attribute change
List<String[]> nullAttrChangedColumnList = getNotNullChangedColumn();
// if the column is null value, when set this column for not null,need
// change these null value for default value
List<String> nullToDefaultChangedColumnList = new ArrayList<String>();
List<String> defaultValList = new ArrayList<String>();
if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) {
for (Iterator<String[]> it = nullAttrChangedColumnList.iterator(); it.hasNext(); ) {
String[] column = it.next();
if (!Boolean.parseBoolean(column[1])) {
continue;
}
nullToDefaultChangedColumnList.add(column[0]);
}
// if the column is null value, when set this column for not null,do
// not need change these null value for default value
List<String> keepNullValueColList = new ArrayList<String>();
for (Iterator<String> it = nullToDefaultChangedColumnList.iterator(); it.hasNext(); ) {
String nullColumn = it.next();
DBAttribute dBAttribute = newSchemaInfo.getDBAttributeByName(nullColumn, false);
if (dBAttribute == null) {
continue;
}
String defaultVal = dBAttribute.getDefault();
boolean isUnique = dBAttribute.isUnique();
if (isUnique) {
keepNullValueColList.add(nullColumn);
it.remove();
} else {
if (defaultVal == null) {
keepNullValueColList.add(nullColumn);
it.remove();
continue;
} else {
FormatDataResult result = DBAttrTypeFormatter.formatForInput(dBAttribute.getType(), defaultVal, false);
if (result.isSuccess()) {
defaultValList.add(result.getFormatResult());
}
}
}
}
String msg = Messages.bind(Messages.confirmSetDef, nullToDefaultChangedColumnList);
if (!nullToDefaultChangedColumnList.isEmpty() && (!CommonUITool.openConfirmBox(msg))) {
return;
}
msg = Messages.bind(Messages.confirmKeepNull, keepNullValueColList);
if (!keepNullValueColList.isEmpty() && (!CommonUITool.openConfirmBox(msg))) {
return;
}
}
TaskJobExecutor taskJobExec = new CommonTaskJobExec(this);
boolean hasChanges = isExecuteCommonSqlTask || !nullAttrChangedColumnList.isEmpty() || !nullToDefaultChangedColumnList.isEmpty();
if (hasChanges) {
if (isExecuteCommonSqlTask) {
taskJobExec.addTask(commonSqlTask);
}
if (database == null || newSchemaInfo == null) {
return;
}
// change all table data from null value to default value
int nullColSize = nullToDefaultChangedColumnList.size();
for (int colIndex = 0; colIndex < nullColSize; colIndex++) {
UpdateNullToDefault updateNullToDefault = new UpdateNullToDefault(dbInfo);
updateNullToDefault.setTable(tableName);
updateNullToDefault.setColumn(nullToDefaultChangedColumnList.get(colIndex));
updateNullToDefault.setDefaultValue(defaultValList.get(colIndex));
taskJobExec.addTask(updateNullToDefault);
}
}
List<UpdateDescriptionTask> updateDescriptionTaskList = getUpdateDescriptionTaskList(dbInfo);
for (UpdateDescriptionTask task : updateDescriptionTaskList) {
taskJobExec.addTask(task);
}
if (taskJobExec.getTaskCount() > 0) {
String serverName = database.getServer().getName();
String dbName = database.getDatabaseInfo().getDbName();
String title = getSite().getShell().getText();
jobName = title + " - " + tableName + "@" + dbName;
JobFamily jobFamily = new JobFamily();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
taskJobExec.schedule(jobName, jobFamily, true, Job.SHORT);
} else {
getSite().getWorkbenchWindow().getActivePage().closeEditor(editor, false);
}
}
use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.
the class ERSchemaEditor method compareTableSchemas.
public void compareTableSchemas(final String modelName, final Map<String, TableSchema> tableSchema, final Map<String, SchemaInfo> schemaInfos) {
final List<TableSchemaCompareModelInputLazy> input = new ArrayList<TableSchemaCompareModelInputLazy>();
ITask reportBugTask = new AbstractUITask() {
private boolean success = false;
public void cancel() {
}
public void finish() {
}
public boolean isCancel() {
return false;
}
public boolean isSuccess() {
return success;
}
public void execute(IProgressMonitor monitor) {
CubridDatabase database = erSchema.getCubridDatabase();
List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(database);
final CubridDatabase virtualDb = new CubridDatabase(modelName, modelName);
virtualDb.setVirtual(true);
DatabaseInfo info = database.getDatabaseInfo();
virtualDb.setDatabaseInfo(info);
WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info);
wrappedDatabaseInfo.addSchemaInfos(schemaInfos);
wrappedDatabaseInfo.addTableSchemas(tableSchema);
ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
TableSchemaModel leftModel = TableSchemaCompareUtil.createTableSchemaModel(leftDbTableInfoList);
TableSchemaModel rightModel = new TableSchemaModel();
rightModel.getTableSchemaMap().putAll(tableSchema);
TableSchemaComparator comparator = new TableSchemaComparator(database, virtualDb);
TableSchemaCompareModel model = comparator.compare(leftModel, rightModel);
model.setSourceDB(database);
model.setTargetDB(virtualDb);
input.add(new TableSchemaCompareModelInputLazy(model));
success = true;
}
};
TaskExecutor taskExecutor = new CommonTaskExec(com.cubrid.common.ui.common.Messages.titleSchemaComparison);
taskExecutor.addTask(reportBugTask);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input.get(0), TableSchemaCompareInfoPart.ID);
} catch (Exception e) {
}
}
}
use of com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo in project cubrid-manager by CUBRID.
the class ERSchemaEditor method syncComments.
/**
* sync table comments to db tables.
*
* @return void
*/
public void syncComments() {
DatabaseInfo info = database.getDatabaseInfo();
if (info == null) {
CommonUITool.openErrorBox(Messages.errNoDatabase);
return;
}
if (!info.isLogined()) {
CommonUITool.openErrorBox(Messages.msgDBNotLogin);
return;
}
ServerInfo serverInfo = info.getServerInfo();
if (serverInfo != null && !serverInfo.isConnected()) {
CommonUITool.openErrorBox(Messages.msgDBNotLogin);
return;
}
boolean isSupportTableComment = false;
Connection conn = null;
try {
conn = JDBCConnectionManager.getConnection(info, false);
isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(info, conn);
if (!isSupportTableComment) {
CommonUITool.openErrorBox(Messages.cannotSyncComments);
return;
}
} catch (Exception e) {
LOGGER.error("", e);
} finally {
QueryUtil.freeQuery(conn);
}
if (!CommonUITool.openConfirmBox(getSite().getShell(), Messages.bind(Messages.msgConfirmSyncComments, database.getLabel()))) {
return;
}
CommonTaskExec taskJobExec = new CommonTaskExec(null);
List<UpdateDescriptionTask> updateDescTasks = getUpdateDescriptionTaskList(info);
for (UpdateDescriptionTask task : updateDescTasks) {
taskJobExec.addTask(task);
}
if (updateDescTasks.size() == 0) {
CommonUITool.openInformationBox(Messages.msgNoComments);
return;
}
new ExecTaskWithProgress(taskJobExec).exec();
Set<String> failTables = new HashSet<String>();
for (UpdateDescriptionTask task : updateDescTasks) {
if (!task.isSuccess()) {
failTables.add(task.getTableName());
}
}
if (failTables.size() == 0) {
CommonUITool.openInformationBox(Messages.msgSuccessSyncComments);
} else {
CommonUITool.openErrorBox(Messages.bind(Messages.errSyncComments, failTables.toString()));
}
}
Aggregations