use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableSchemaCompareUpdateDDL method setPositionAlterDDL.
/**
* Compare table Attributes Positions
*/
public void setPositionAlterDDL() {
// FIXME logic code move to core module
List<DBAttribute> targetDBAttributes = targetTableSchema.getAttributes();
List<DBAttribute> sourceDBAttributes = sourceTableSchema.getAttributes();
for (DBAttribute targetAttr : targetDBAttributes) {
String targetAttrName = targetAttr.getName();
int targetPosition = targetDBAttributes.indexOf(targetAttr);
DBAttribute sourceAttr = sourceTableSchema.getDBAttributeByName(targetAttrName, false);
int sourcePosition = sourceDBAttributes.indexOf(sourceAttr);
if (sourceAttr != null && sourcePosition != targetPosition) {
changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceAttr.getName(), targetAttr.getName(), SchemeInnerType.TYPE_POSITION));
}
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class TableSchemaCompareUpdateDDL method setAttributesAlterDDL.
/**
* Compare table attributes
*/
public void setAttributesAlterDDL() {
// FIXME logic code move to core module
List<DBAttribute> sourceDBAttributes = sourceTableSchema.getAttributes();
List<DBAttribute> targetDBAttributes = targetTableSchema.getAttributes();
for (DBAttribute targetAttr : targetDBAttributes) {
String targetAttrName = targetAttr.getName().toLowerCase();
DBAttribute sourceAttr = sourceTableSchema.getDBAttributeByName(targetAttrName, false);
if (sourceAttr != null) {
if (!targetAttr.equals(sourceAttr)) {
changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceAttr.getName(), targetAttrName, SchemeInnerType.TYPE_ATTRIBUTE));
changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceAttr.getName(), targetAttrName, SchemeInnerType.TYPE_POSITION));
}
} else {
changeManager.addSchemeChangeLog(new SchemaChangeLog(null, targetAttrName, SchemeInnerType.TYPE_ATTRIBUTE));
changeManager.addSchemeChangeLog(new SchemaChangeLog(targetAttrName, targetAttrName, SchemeInnerType.TYPE_POSITION));
}
}
for (DBAttribute sourceAttr : sourceDBAttributes) {
String sourceAttrName = sourceAttr.getName();
DBAttribute targetAttr = targetTableSchema.getDBAttributeByName(sourceAttrName, false);
if (targetAttr == null) {
changeManager.addSchemeChangeLog(new SchemaChangeLog(sourceAttrName, null, SchemeInnerType.TYPE_ATTRIBUTE));
}
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class FileToTableMappingComposite method parseData.
@SuppressWarnings("unchecked")
private void parseData(final Map<String, String> tableToFile) throws Exception {
allTableList = (List<ICubridNode>) treeViewer.getInput();
final List<ICubridNode> newMappedNodeList = new ArrayList<ICubridNode>();
final ImportConfig importConfig = importSettingPage.getImportDataWizard().getImportConfig();
ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
progress.setCancelable(true);
progress.run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
monitor.beginTask(Messages.taskParsingData, tableToFile.size());
for (Entry<String, String> entry : tableToFile.entrySet()) {
// FIXME move this logic to core module
String tableName = entry.getKey();
String filePath = entry.getValue();
File file = new File(filePath);
String fileName = file.getName();
monitor.subTask(Messages.bind(Messages.taskParsingFile, fileName));
List<String> fileColumnList = new ArrayList<String>();
List<String> firstRowColsLst = new ArrayList<String>();
List<String> colNameList = new ArrayList<String>();
List<String> colTypeList = new ArrayList<String>();
int totalLine = 0;
List<Integer> itemsNumberOfSheets = null;
/*Find the class node*/
ICubridNode classNode = getTableNode(tableName);
/*Process file*/
ImportFileHandler importFileHandler = ImportFileHandlerFactory.getHandler(file.getAbsolutePath(), importConfig);
ImportFileDescription ifd = getFileDescription(importFileHandler);
firstRowColsLst.addAll(ifd.getFirstRowCols());
totalLine = ifd.getTotalCount();
itemsNumberOfSheets = ifd.getItemsNumberOfSheets();
boolean isFirstLineAsColumnName = isFirstLineAsColumnName(tableName);
fillInFromList(fileColumnList, firstRowColsLst, isFirstLineAsColumnName);
if (isFirstLineAsColumnName) {
handleSelectEventForFirstRowAsColBtn(itemsNumberOfSheets, fileColumnList, firstRowColsLst, totalLine, isFirstLineAsColumnName);
}
if (classNode != null) {
Object isNew = classNode.getData(ImportObjectLabelProvider.IS_NEW);
if (isNew == null || !(Boolean) isNew) {
SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
List<DBAttribute> attributes = schemaInfo == null ? null : schemaInfo.getAttributes();
if (attributes == null) {
return;
}
for (DBAttribute attr : attributes) {
String column = attr.getName();
String dataType = attr.getType();
colNameList.add(column);
colTypeList.add(dataType);
}
} else {
removeClassNode(classNode);
classNode = createClassNode(tableName, isFirstLineAsColumnName(tableName), firstRowColsLst, colNameList, colTypeList);
}
} else if (importConfig.isCreateTableAccordingData()) {
classNode = createClassNode(tableName, isFirstLineAsColumnName(tableName), firstRowColsLst, colNameList, colTypeList);
} else {
failedFileList.add(file.getAbsolutePath());
continue;
}
if (fileColumnList.size() == colNameList.size()) {
classNode.setData(ImportObjectLabelProvider.IS_MAPPED, true);
classNode.setData(ImportObjectLabelProvider.FILE_PAHT, fileName);
classNode.setData(ImportObjectLabelProvider.ROW_COUNT, totalLine);
List<PstmtParameter> parameterList = new ArrayList<PstmtParameter>();
for (int i = 0; i < fileColumnList.size(); i++) {
PstmtParameter pstmtParameter = new PstmtParameter(colNameList.get(i), i + 1, colTypeList.get(i), String.valueOf(i));
pstmtParameter.setFileColumnName(fileColumnList.get(i));
parameterList.add(pstmtParameter);
}
TableConfig tableConfig = new TableConfig(classNode.getName());
tableConfig.setPstmList(parameterList);
tableConfig.setFilePath(file.getAbsolutePath());
tableConfig.setInsertDML(getInsertDML(classNode, colNameList, colTypeList));
tableConfig.setLineCount(totalLine);
tableConfig.setMapped(true);
Object isNew = classNode.getData(ImportObjectLabelProvider.IS_NEW);
if (isNew != null && (Boolean) isNew) {
tableConfig.setCreateDDL(classNode.getData(ImportObjectLabelProvider.CREATE_DDL).toString());
}
importConfig.addTableConfig(tableConfig);
newMappedNodeList.add(classNode);
} else {
classNode.setData(ImportObjectLabelProvider.IS_MAPPED, false);
classNode.setData(ImportObjectLabelProvider.FILE_PAHT, fileName);
classNode.setData(ImportObjectLabelProvider.ROW_COUNT, totalLine);
TableConfig tableConfig = importConfig.getSelectedMap().get(classNode.getName());
if (tableConfig != null) {
tableConfig.setMapped(false);
tableConfig.setFilePath(filePath);
tableConfig.setLineCount(totalLine);
tableConfig.getPstmList().clear();
tableConfig.setInsertDML("");
}
failedFileList.add(fileName);
}
monitor.worked(1);
if (monitor.isCanceled()) {
return;
}
}
}
});
for (ICubridNode node : allTableList) {
if (newMappedNodeList.contains(node)) {
treeViewer.setChecked(node, true);
}
}
treeViewer.refresh();
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class PstmtSQLDialog method buttonPressed.
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
if (validate()) {
// FIXME move this logic to core module
List<List<PstmtParameter>> jobList = new ArrayList<List<PstmtParameter>>();
for (int j = 0; j < valueList.size(); j++) {
ParamValueObject paramValueObject = valueList.get(j);
//don't execute the empty line
if (paramValueObject.isEmpty()) {
continue;
}
List<PstmtParameter> parameterList = new ArrayList<PstmtParameter>();
for (int i = 1; i < parameterTypeTable.getColumnCount(); i++) {
String type = parameterTypeTable.getItem(0).getText(i);
;
if (columnTypeMap.get(type) != null) {
type = columnTypeMap.get(type);
}
type = type.toUpperCase();
String name = parameterTypeTable.getColumn(i).getText();
String value = paramValueObject.getValue().get(i);
//parse default value
if (isInsert && (value.equals("") || value.equals(DataType.NULL_EXPORT_FORMAT))) {
DBAttribute da = (DBAttribute) schemaInfo.getAttributes().get(i - 1);
value = da.getDefault() == null ? "" : da.getDefault();
}
if (DataType.NULL_EXPORT_FORMAT.equals(value)) {
value = null;
}
//parse nchar nvchar null value
if ((type.startsWith(DataType.DATATYPE_NCHAR) || type.startsWith(DataType.DATATYPE_NATIONAL_CHARACTER)) && "".equals(value)) {
value = null;
}
PstmtParameter pstmtParameter = new PstmtParameter(name, i, type, value);
boolean isFile = DBAttrTypeFormatter.isFilePath(value);
if (isFile) {
pstmtParameter.setCharSet(charSet);
}
parameterList.add(pstmtParameter);
}
jobList.add(parameterList);
}
if (jobList.size() == 0) {
setErrorMessage(Messages.errRunPstmtNoJob);
return;
}
if (TableUtil.isHasResultSet(database, sqlTxt.getText())) {
//only execute one select sql
showResultSet(jobList.get(0));
} else {
updateData(jobList);
}
}
} else if (buttonId == IDialogConstants.CANCEL_ID) {
super.buttonPressed(buttonId);
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class PstmtSQLDialog method analyzeTable.
/**
* Analyse table name and the table's column name and type
*
* @param sql
*/
public void analyzeTable(String sql) {
// FIXME move this logic to core module
if (sql == null) {
return;
}
String upperSQL = sql.trim().toUpperCase();
String tableNameStartString = "";
if (upperSQL.startsWith("SELECT") && upperSQL.indexOf("FROM") > -1) {
tableNameStartString = upperSQL.substring(upperSQL.indexOf("FROM") + "FROM".length()).trim();
} else if (upperSQL.startsWith("UPDATE") && upperSQL.indexOf("SET") > -1) {
tableNameStartString = upperSQL.substring(upperSQL.indexOf("UPDATE") + "UPDATE".length()).trim();
} else if (upperSQL.startsWith("DELETE") && upperSQL.indexOf("FROM") > -1) {
tableNameStartString = upperSQL.substring(upperSQL.indexOf("FROM") + "FROM".length()).trim();
} else if (upperSQL.startsWith("INSERT INTO")) {
tableNameStartString = upperSQL.substring(upperSQL.indexOf("INSERT INTO") + "INSERT INTO".length()).trim();
}
//can't analyse it's table name
if (tableNameStartString.length() == 0) {
this.tableName = "";
columnTypeMap.clear();
}
int index = 0;
char currChar = '\0';
String tempTableName = "";
StringBuilder sb = new StringBuilder();
while (index < tableNameStartString.length() && !isKeywordSeparator(currChar = tableNameStartString.charAt(index))) {
sb.append(Character.toLowerCase(currChar));
index++;
}
tempTableName = sb.toString();
//if the table name is embraced in "" ,cut it
if (tempTableName.startsWith("\"")) {
tempTableName = tempTableName.substring(1);
}
if (tempTableName.endsWith("\"")) {
tempTableName = tempTableName.substring(0, tempTableName.length() - 1);
}
this.schemaInfo = this.database == null ? null : this.database.getDatabaseInfo().getSchemaInfo(tableName);
int n = schemaInfo == null ? 0 : schemaInfo.getAttributes().size();
if (n > 0) {
tableName = tempTableName;
} else {
this.tableName = "";
columnTypeMap.clear();
}
for (int i = 0; i < n; i++) {
DBAttribute da = (DBAttribute) schemaInfo.getAttributes().get(i);
columnTypeMap.put(da.getName(), da.getType());
}
}
Aggregations