use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class DataCompareEditorPart method doRefresh.
private void doRefresh(boolean collectRecordCount) {
// FIXME logic code move to core module
Map<String, DataCompare> dataCompareMap = new HashMap<String, DataCompare>();
if (compareList != null) {
for (DataCompare dataCompare : compareList) {
dataCompareMap.put(dataCompare.getTableName(), dataCompare);
}
}
DatabaseInfo sourceDB = ((DataCompareEditorInput) getEditorInput()).getSourceDB();
DatabaseInfo targetDB = ((DataCompareEditorInput) getEditorInput()).getTargetDB();
if (logFileBaseName != null) {
FileUtil.delete(logFileBasePath + File.separatorChar + logFileBaseName);
logFileBaseName = null;
}
logFileBaseName = sourceDB.getDbName() + "_" + System.currentTimeMillis();
GetAllSchemaTask sourceSchemaTask = new GetAllSchemaTask(sourceDB);
GetAllSchemaTask targetSchemaTask = new GetAllSchemaTask(targetDB);
TaskExecutor taskExecutor = new CommonTaskExec(Messages.loadEntireSchemaComparison);
taskExecutor.addTask(sourceSchemaTask);
taskExecutor.addTask(targetSchemaTask);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
synchronized (compareList) {
compareList.clear();
Set<String> partitions = new HashSet<String>();
List<SchemaInfo> sourceList = sourceSchemaTask.getSchemaList();
List<SchemaInfo> targetList = targetSchemaTask.getSchemaList();
for (SchemaInfo schemaInfo : sourceList) {
if (schemaInfo.getPartitionList() != null) {
for (PartitionInfo partition : schemaInfo.getPartitionList()) {
String partClassName = partition.getPartitionClassName();
partitions.add(partClassName);
}
}
}
for (SchemaInfo schemaInfo : sourceList) {
DataCompare dataCompare = dataCompareMap.get(schemaInfo.getClassname());
if (dataCompare == null) {
dataCompare = new DataCompare();
dataCompare.setTableName(schemaInfo.getClassname());
dataCompare.setSchemaInfo(schemaInfo);
dataCompare.setRefreshed(false);
} else {
dataCompare.setMatches(0);
dataCompare.setNotExists(0);
dataCompare.setNotMatches(0);
dataCompare.setProgressPosition(0);
}
if (schemaInfo.hasPK() && !partitions.contains(schemaInfo.getClassname())) {
SchemaInfo targetSchemeInfo = getSchemeInfoByName(schemaInfo.getClassname(), targetList);
boolean isSameSchema = canCompareData(schemaInfo, targetSchemeInfo);
dataCompare.setSameSchema(isSameSchema);
compareList.add(dataCompare);
}
}
Collections.sort(compareList, new Comparator<DataCompare>() {
public int compare(DataCompare o1, DataCompare o2) {
if (o1 == null || o1.getTableName() == null) {
return -1;
} else if (o2 == null || o2.getTableName() == null) {
return 1;
}
return o1.getTableName().compareToIgnoreCase(o2.getTableName());
}
});
}
compareTableViewer.refresh();
}
if (!collectRecordCount) {
return;
}
totalRecords = 0;
completedRecords = 0;
refreshRecordCount();
refreshedRecordCounts = true;
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class DataCompareEditorPart method compareHashedCompareData.
private void compareHashedCompareData(Connection conn, DataCompare dataCompare, List<HashedCompareData> dataList) {
// FIXME logic code move to core module
if (dataList == null || dataList.size() == 0) {
// TODO error
return;
}
PreparedStatement pstmt = null;
ResultSet rs = null;
SchemaInfo schemaInfo = dataCompare.getSchemaInfo();
StringBuilder extraColumns = new StringBuilder();
StringBuilder sql = new StringBuilder();
sql.append("SELECT MD5(CONCAT(");
StringBuilder cols = new StringBuilder();
List<DBAttribute> attrs = schemaInfo.getAttributes();
// TODO Collections.sort
for (int i = 0, len = attrs.size(); i < len; i++) {
DBAttribute attr = attrs.get(i);
if (cols.length() > 0) {
cols.append(",");
}
makeColumnsClause(extraColumns, cols, attr);
}
sql.append(cols);
sql.append(")) AS _record_hash_ ");
if (extraColumns.length() > 0) {
sql.append(",");
sql.append(extraColumns);
}
String escapedTableName = QuerySyntax.escapeKeyword(schemaInfo.getClassname());
sql.append(" FROM ").append(escapedTableName);
sql.append(" WHERE ");
{
HashedCompareData data = dataList.get(0);
for (int i = 0, len = data.getPkColumns().size(); i < len; i++) {
if (i > 0) {
sql.append(" AND ");
}
String columnName = data.getPkColumns().get(i);
sql.append(QuerySyntax.escapeKeyword(columnName)).append("=?");
}
}
for (HashedCompareData data : dataList) {
if (runningState != RUNNING_SATE_ONLINE) {
return;
}
boolean exists = false;
String hash = null;
try {
pstmt = conn.prepareStatement(sql.toString());
for (int i = 0, len = data.getPkColumns().size(); i < len; i++) {
String columnValue = data.getPkValues().get(i);
pstmt.setString(i + 1, columnValue);
}
rs = pstmt.executeQuery();
if (!rs.next()) {
exists = false;
} else {
exists = true;
hash = rs.getString("_record_hash_");
}
} catch (SQLException e) {
exists = false;
printToConsoleOnWorkThread(StringUtil.NEWLINE, false);
printToConsoleOnWorkThread(e.getMessage(), true);
LOGGER.error(sql.toString(), e);
} finally {
QueryUtil.freeQuery(pstmt, rs);
}
dataCompare.increaseProgress();
if (!exists) {
dataCompare.increaseNotExists();
addLog(schemaInfo.getClassname(), data, charset);
} else {
if (data.getHash().equals(hash)) {
dataCompare.increaseMatches();
} else {
dataCompare.increaseNotMatches();
addLog(schemaInfo.getClassname(), data, charset);
}
}
completedRecords++;
refreshProgressBar();
Display.getDefault().syncExec(new Runnable() {
public void run() {
compareTableViewer.refresh();
}
});
}
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class CubridColumnNavigatorView method setFocus.
public void setFocus() {
CubridNavigatorView mainNav = CubridNavigatorView.findNavigationView();
if (mainNav != null) {
DatabaseInfo databaseInfo = mainNav.getCurrentDatabaseInfo();
SchemaInfo schemaInfo = mainNav.getCurrentSchemaInfo();
updateView(databaseInfo, schemaInfo);
}
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class AttributeTableViewerContentProvider method getElements.
/**
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
* @param inputElement the input element
* @return the array of elements to display in the viewer
*/
public Object[] getElements(Object inputElement) {
if (inputElement instanceof SchemaInfo) {
SchemaInfo schema = (SchemaInfo) inputElement;
List<DBAttribute> list = new ArrayList<DBAttribute>();
if (showClassAttribute) {
list.addAll(schema.getClassAttributes());
}
list.addAll(schema.getAttributes());
return list.toArray();
} else {
return new Object[0];
}
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class EditTableAction method doRun.
private void doRun(ISchemaNode table, int type) {
final DatabaseInfo databaseInfo = NodeUtil.findDatabaseInfo(table);
if (databaseInfo == null) {
return;
}
final String tableName = table.getName();
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;
}
}
databaseInfo.removeSchema(tableName);
SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
if (schemaInfo == null) {
openErrorBox(shell, databaseInfo.getErrorMessage(), monitor);
return false;
}
return true;
}
};
boolean supportCharset = CompatibleUtil.isSupportCreateDBByCharset(databaseInfo);
JDBCGetAllDbUserTask allUserTask = new JDBCGetAllDbUserTask(databaseInfo);
taskExcutor.addTask(allUserTask);
GetCollations collationTask = null;
if (supportCharset) {
collationTask = new GetCollations(databaseInfo);
taskExcutor.addTask(collationTask);
}
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (!taskExcutor.isSuccess()) {
return;
}
List<String> dbUserList = allUserTask.getDbUserList();
SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
TableEditorInput input = new TableEditorInput(table.getDatabase(), false, schemaInfo, table, type);
input.setDbUserList(dbUserList);
if (supportCharset) {
List<Collation> collations = collationTask.getCollations();
input.setCollationList(collations);
}
try {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
//If true, active opened editor of it and return, else open new editor.
for (IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
IEditorPart oldEditor = editorRef.getEditor(true);
if (oldEditor.getEditorInput() instanceof TableEditorInput) {
TableEditorInput oldInput = (TableEditorInput) oldEditor.getEditorInput();
ISchemaNode oldTable = oldInput.getEditedTableNode();
if (oldTable != null && oldTable.equals(table)) {
workbenchWindow.getActivePage().activate(oldEditor);
return;
}
}
}
workbenchWindow.getActivePage().openEditor(input, TableEditorPart.ID);
} catch (Exception ignore) {
}
}
Aggregations