use of com.cubrid.cubridmanager.core.cubrid.table.task.UpdateDescriptionTask 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.table.task.UpdateDescriptionTask in project cubrid-manager by CUBRID.
the class TableEditorPart method getUpdateDescriptionTaskList.
/**
* Get UpdateDescriptionTaskList
*
* @param dbInfo
* @return
*/
private List<UpdateDescriptionTask> getUpdateDescriptionTaskList(DatabaseInfo dbInfo) {
// FIXME move this logic to core module
List<UpdateDescriptionTask> updateDescriptionTaskList = new ArrayList<UpdateDescriptionTask>();
if (isSupportTableComment) {
for (DBAttribute newAttr : newSchemaInfo.getAttributes()) {
DBAttribute oldAttr = null;
if (oldSchemaInfo != null) {
oldAttr = oldSchemaInfo.getDBAttributeByName(newAttr.getName(), newAttr.isClassAttribute());
}
if (oldAttr != null && StringUtil.isEqual(oldAttr.getDescription(), newAttr.getDescription())) {
continue;
} else {
updateDescriptionTaskList.add(new UpdateDescriptionTask(Messages.updateDescriptionTask, dbInfo, tableName, newAttr.getName(), newAttr.getDescription()));
}
}
boolean notSameDescription = false;
if (oldSchemaInfo != null) {
notSameDescription = !StringUtil.isEqualNotIgnoreNull(oldSchemaInfo.getDescription(), newSchemaInfo.getDescription());
}
if (oldSchemaInfo == null || notSameDescription) {
UpdateDescriptionTask task = new UpdateDescriptionTask(Messages.updateDescriptionTask, dbInfo, tableName, null, newSchemaInfo.getDescription());
updateDescriptionTaskList.add(task);
}
}
return updateDescriptionTaskList;
}
use of com.cubrid.cubridmanager.core.cubrid.table.task.UpdateDescriptionTask 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()));
}
}
use of com.cubrid.cubridmanager.core.cubrid.table.task.UpdateDescriptionTask in project cubrid-manager by CUBRID.
the class ERSchemaEditor method getUpdateDescriptionTaskList.
/**
* Get UpdateDescriptionTaskList
*
* @param dbInfo
* @return
*/
private List<UpdateDescriptionTask> getUpdateDescriptionTaskList(DatabaseInfo dbInfo) {
List<UpdateDescriptionTask> updateDescriptionTaskList = new ArrayList<UpdateDescriptionTask>();
Map<String, SchemaInfo> schemaInfos = erSchema.getAllSchemaInfo();
Collection<SchemaInfo> erdSchemaInfos = schemaInfos.values();
GetAllSchemaTask task = new GetAllSchemaTask(dbInfo);
task.execute();
Map<String, SchemaInfo> dbSchemaInfoMap = task.getSchemas();
String taskName = com.cubrid.common.ui.cubrid.table.Messages.updateDescriptionTask;
for (SchemaInfo newSchemaInfo : erdSchemaInfos) {
String tableName = newSchemaInfo.getClassname();
SchemaInfo dbSchemaInfo = dbSchemaInfoMap.get(tableName);
if (dbSchemaInfo == null) {
continue;
}
for (DBAttribute newAttr : newSchemaInfo.getAttributes()) {
DBAttribute oldAttr = dbSchemaInfo.getDBAttributeByName(newAttr.getName(), newAttr.isClassAttribute());
if (oldAttr == null || StringUtil.isEqual(oldAttr.getDescription(), newAttr.getDescription())) {
continue;
}
updateDescriptionTaskList.add(new UpdateDescriptionTask(taskName, dbInfo, tableName, newAttr.getName(), newAttr.getDescription()));
}
if (!StringUtil.isEqual(dbSchemaInfo.getDescription(), newSchemaInfo.getDescription())) {
updateDescriptionTaskList.add(new UpdateDescriptionTask(taskName, dbInfo, tableName, "", newSchemaInfo.getDescription()));
}
}
return updateDescriptionTaskList;
}
Aggregations