use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class PstmtDataDialog method createInsertPstmtSQL.
/**
* Create inserted prepared statement SQL
*
* @return String
*/
protected String createInsertPstmtSQL() {
// FIXME move this logic to core module
StringBuffer columns = new StringBuffer("");
StringBuffer values = new StringBuffer("");
int n = schemaInfo == null ? 0 : schemaInfo.getAttributes().size();
for (int i = 0; i < n; i++) {
DBAttribute da = (DBAttribute) schemaInfo.getAttributes().get(i);
if (values.length() > 0) {
columns.append(", ");
values.append(", ");
}
columns.append(QuerySyntax.escapeKeyword(da.getName()));
values.append("?");
}
StringBuffer sql = new StringBuffer("");
if (columns.length() > 0) {
sql.append("INSERT INTO ");
sql.append(QuerySyntax.escapeKeyword(tableName));
sql.append(" (");
sql.append(columns);
sql.append(") VALUES (");
sql.append(values);
sql.append(");");
}
return sql.toString();
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class PstmtDataDialog method initial.
protected void initial() {
int n = schemaInfo == null ? 0 : schemaInfo.getAttributes().size();
for (int i = 0; i < n; i++) {
DBAttribute da = (DBAttribute) schemaInfo.getAttributes().get(i);
TableItem item = new TableItem(parameterTable, SWT.NONE);
item.setText(0, da.getName());
item.setText(1, DataType.getShownType(da.getType()));
}
packTable();
String sql = "";
if (tableName != null && isInsert) {
sql = createInsertPstmtSQL();
} else if (tableName != null) {
sql = createSelectPstmtSQL();
}
sqlTxt.setText(sql);
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class ExportTableDefinitionLayoutType2 method generateTableDetailSheets.
/**
* generate table name sheet
* @param wwb
* @param conn
* @param exportSchemaInfoList
* @param monitor
* @throws Exception
*/
public void generateTableDetailSheets(WritableWorkbook wwb, Connection conn, List<SchemaInfo> exportSchemaInfoList, IProgressMonitor monitor) throws Exception {
int sheetIndex = 1;
for (SchemaInfo schemaInfo : exportSchemaInfoList) {
String tableName = schemaInfo.getClassname();
monitor.subTask(Messages.bind(Messages.exportTableDefinitionProgressTaskWriteTable, tableName));
List<SchemaInfo> supers = SuperClassUtil.getSuperClasses(getProgressObject().getDatabase().getDatabaseInfo(), schemaInfo);
WritableSheet ws = wwb.createSheet(tableName, sheetIndex++);
int rowIndex = 0;
// Title
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell10, boldCellStyle));
ws.mergeCells(0, 0, 7, 0);
rowIndex++;
// System name
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell11, boldCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, "", normalCellStyle));
// Date
ws.addCell(new jxl.write.Label(2, rowIndex, Messages.exportTableDefinitionCell4, boldCellStyle));
ws.addCell(new jxl.write.Label(3, rowIndex, dateString, normalCellStyle));
// Author
ws.addCell(new jxl.write.Label(5, rowIndex, Messages.exportTableDefinitionCell5, boldCellStyle));
ws.addCell(new jxl.write.Label(7, rowIndex, "", normalCellStyle));
ws.mergeCells(3, 1, 4, 1);
ws.mergeCells(5, 1, 6, 1);
rowIndex++;
String tableColumnText = "";
if (getProgressObject().isInstalledMetaTable()) {
SchemaComment tableComment = SchemaCommentHandler.find(getProgressObject().getSchemaCommentMap(), tableName, null);
if (tableComment != null) {
tableColumnText = tableComment.getDescription() == null ? "" : tableComment.getDescription();
}
}
// Table Name
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell6, boldCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, tableColumnText, normalLeftAlignCellStyle));
ws.mergeCells(1, 2, 7, 2);
rowIndex++;
// Table ID
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell7, boldCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, tableName, normalLeftAlignCellStyle));
ws.mergeCells(1, 3, 7, 3);
rowIndex++;
// Column name
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell12, boldCellStyle));
// Column ID
ws.addCell(new jxl.write.Label(1, rowIndex, Messages.exportTableDefinitionCell13, boldCellStyle));
// Data type
ws.addCell(new jxl.write.Label(2, rowIndex, Messages.exportTableDefinitionCell14, boldCellStyle));
// Size
ws.addCell(new jxl.write.Label(3, rowIndex, Messages.exportTableDefinitionCell15, boldCellStyle));
// Null
ws.addCell(new jxl.write.Label(4, rowIndex, Messages.exportTableDefinitionCell16, boldCellStyle));
// PK
ws.addCell(new jxl.write.Label(5, rowIndex, Messages.exportTableDefinitionCell17, boldCellStyle));
// FK
ws.addCell(new jxl.write.Label(6, rowIndex, Messages.exportTableDefinitionCell18, boldCellStyle));
// Memo
ws.addCell(new jxl.write.Label(7, rowIndex, Messages.exportTableDefinitionCell19, boldCellStyle));
rowIndex++;
// column info
for (DBAttribute columnAtt : schemaInfo.getAttributes()) {
String attrName = columnAtt.getName();
String columnText = "";
if (getProgressObject().isInstalledMetaTable()) {
SchemaComment columnComment = SchemaCommentHandler.find(getProgressObject().getSchemaCommentMap(), tableName, attrName);
if (columnComment != null) {
columnText = columnComment.getDescription() == null ? "" : columnComment.getDescription();
}
}
ws.addCell(new jxl.write.Label(0, rowIndex, columnText, normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, attrName, normalLeftAlignCellStyle));
String showType = DataType.getShownType((columnAtt.getType()));
if (showType.indexOf("(") > -1 && showType.endsWith("")) {
showType = showType.substring(0, showType.indexOf("("));
}
ws.addCell(new jxl.write.Label(2, rowIndex, showType, normalLeftAlignCellStyle));
int size = DataType.getSize(columnAtt.getType());
int scale = DataType.getScale(columnAtt.getType());
if (size < 0 && scale < 0) {
ws.addCell(new jxl.write.Label(3, rowIndex, "", normalRightAlignCellStyle));
} else if (scale < 0) {
ws.addCell(new jxl.write.Number(3, rowIndex, size, normalRightAlignCellStyle));
} else {
ws.addCell(new jxl.write.Label(3, rowIndex, Integer.toString(size) + "," + Integer.toString(scale), normalRightAlignCellStyle));
}
//get nullable
boolean isNULL = true;
if (!columnAtt.isClassAttribute()) {
if (columnAtt.getInherit().equals(tableName)) {
Constraint pk = schemaInfo.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
isNULL = false;
}
} else {
List<Constraint> pkList = schemaInfo.getInheritPK(supers);
for (Constraint inheritPK : pkList) {
if (inheritPK.getAttributes().contains(attrName)) {
isNULL = false;
}
}
}
}
if (columnAtt.isNotNull()) {
isNULL = false;
}
ws.addCell(new jxl.write.Label(4, rowIndex, isNULL ? "Y" : "", normalCellStyle));
//get pk
boolean isPk = false;
if (!columnAtt.isClassAttribute()) {
if (columnAtt.getInherit().equals(tableName)) {
Constraint pk = schemaInfo.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
isPk = true;
}
} else {
List<Constraint> pkList = schemaInfo.getInheritPK(supers);
for (Constraint inheritPK : pkList) {
if (inheritPK.getAttributes().contains(attrName)) {
isPk = true;
}
}
}
}
ws.addCell(new jxl.write.Label(5, rowIndex, isPk ? "Y" : "", normalCellStyle));
//get fk
boolean isFk = false;
for (Constraint fk : schemaInfo.getFKConstraints()) {
for (String columns : fk.getAttributes()) {
if (columns.equals(attrName)) {
isFk = true;
break;
}
}
}
ws.addCell(new jxl.write.Label(6, rowIndex, isFk ? "Y" : "", normalCellStyle));
ws.addCell(new jxl.write.Label(7, rowIndex, "", normalCellStyle));
rowIndex++;
}
// blank
for (int i = 0; i < 8; i++) {
ws.addCell(new jxl.write.Label(i, rowIndex, "", normalCellStyle));
}
rowIndex++;
// index
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell20, boldCellStyle));
ws.mergeCells(0, rowIndex, 7, rowIndex);
rowIndex++;
// NO
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell21, boldCellStyle));
// Index name
ws.addCell(new jxl.write.Label(1, rowIndex, Messages.exportTableDefinitionCell22, boldCellStyle));
// Column ID
ws.addCell(new jxl.write.Label(3, rowIndex, Messages.exportTableDefinitionCell13, boldCellStyle));
// Order
ws.addCell(new jxl.write.Label(5, rowIndex, Messages.exportTableDefinitionCell23, boldCellStyle));
// Memo
ws.addCell(new jxl.write.Label(6, rowIndex, Messages.exportTableDefinitionCell19, boldCellStyle));
ws.mergeCells(1, rowIndex, 2, rowIndex);
ws.mergeCells(3, rowIndex, 4, rowIndex);
ws.mergeCells(6, rowIndex, 7, rowIndex);
rowIndex++;
List<Constraint> constraints = getProgressObject().getIndexList(schemaInfo);
for (int i = 0; i < constraints.size(); i++) {
Constraint constraint = constraints.get(i);
int columnSize = constraint.getAttributes().size();
// mark current row index
int currentRowIndex = rowIndex;
for (int j = 0; j < columnSize; j++) {
String columnName = constraint.getAttributes().get(j);
ws.addCell(new jxl.write.Number(0, rowIndex, i + 1, normalCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, constraint.getName(), normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Label(3, rowIndex, columnName, normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Number(5, rowIndex, j + 1, normalCellStyle));
ws.addCell(new jxl.write.Label(6, rowIndex, "", normalCellStyle));
if (columnSize == 1) {
ws.mergeCells(1, rowIndex, 2, rowIndex);
}
ws.mergeCells(3, rowIndex, 4, rowIndex);
ws.mergeCells(6, rowIndex, 7, rowIndex);
rowIndex++;
}
//if multiple colulmn merge NO/Index Name CELL by vertical logic
if (columnSize > 1) {
ws.mergeCells(0, currentRowIndex, 0, currentRowIndex + columnSize - 1);
ws.mergeCells(1, currentRowIndex, 2, currentRowIndex + columnSize - 1);
}
}
// blank
ws.addCell(new jxl.write.Label(0, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(3, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(5, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(6, rowIndex, "", normalCellStyle));
ws.mergeCells(1, rowIndex, 2, rowIndex);
ws.mergeCells(3, rowIndex, 4, rowIndex);
ws.mergeCells(6, rowIndex, 7, rowIndex);
rowIndex++;
// DDL
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell24, boldCellStyle));
ws.mergeCells(0, rowIndex, 7, rowIndex);
rowIndex++;
String ddl = getProgressObject().getDDL(schemaInfo);
ws.addCell(new jxl.write.Label(0, rowIndex, ddl, normalLeftAlignCellStyle));
ws.mergeCells(0, rowIndex, 7, rowIndex);
ws.setRowView(0, 500);
int lineNumbner = ddl.split(StringUtil.NEWLINE).length;
ws.setRowView(rowIndex, lineNumbner * 350);
// column width
ws.setColumnView(0, 18);
ws.setColumnView(1, 20);
ws.setColumnView(2, 13);
ws.setColumnView(3, 13);
ws.setColumnView(4, 11);
ws.setColumnView(5, 11);
ws.setColumnView(6, 11);
ws.setColumnView(7, 20);
monitor.worked(1);
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method changeForEditElement.
/**
* Make a change log for editing attribute
*
* @param attrName
* @param editingCol ERD column to be changed by the user
* @param oldCol ERD column
* @return
*/
public boolean changeForEditElement(String attrName, ERTableColumn editingCol, ERTableColumn oldCol) {
// FIXME move this logic to core module
SchemaInfo newSchemaInfo = getNewSchemaInfo();
if (database == null || editingCol == null) {
return false;
}
editingCol.getAttr().setInherit(newSchemaInfo.getClassname());
String newAttrName = editingCol.getAttr().getName();
if (oldCol == null) {
oldCol = new ERTableColumn(newERTable, editingCol.getAttr(), false);
oldCol.setIsNew(true);
}
DBAttribute oldAttr = oldCol.getAttr();
DBAttribute editingAttr = editingCol.getAttr();
if (!oldAttr.isUnique() && newSchemaInfo.getUniqueByAttrName(editingAttr.getName()) == null && editingAttr.isUnique()) {
Constraint unique = new Constraint(true);
unique.setType(Constraint.ConstraintType.UNIQUE.getText());
unique.addAttribute(newAttrName);
unique.addRule(newAttrName + " ASC");
unique.setName(ConstraintNamingUtil.getUniqueName(newSchemaInfo.getClassname(), unique.getRules()));
newSchemaInfo.addConstraint(unique);
} else if (oldAttr.isUnique() && !editingAttr.isUnique()) {
newSchemaInfo.removeUniqueByAttrName(attrName);
} else if (!oldAttr.isUnique() && !editingAttr.isUnique()) {
newSchemaInfo.removeUniqueByAttrName(attrName);
}
indexTableView.setInput(newSchemaInfo);
fkTableView.setInput(newSchemaInfo);
if (database != null && database.getDatabaseInfo() != null && newSchemaInfo != null) {
SuperClassUtil.fireSuperClassChanged(database.getDatabaseInfo(), oldSchemaInfo, newSchemaInfo, newSchemaInfo.getSuperClasses());
}
attrLabelProvider.setSchema(newSchemaInfo);
loadColumnData();
columnTableView.setSelection(new StructuredSelection(editingCol), true);
columnsTable.setFocus();
handleSelectionChangeInColumnTable();
return true;
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method addNewColumn.
public void addNewColumn() {
SchemaInfo newSchemaInfo = getNewSchemaInfo();
if (newSchemaInfo == null) {
return;
}
// boolean hasNotFinishedColumn = false;
boolean hasDuplicatedColumn = false;
List<ERTableColumn> items = newERTable.getColumns();
if (items != null && items.size() > 0) {
Set<String> matches = new HashSet<String>();
// check whether there is no name column
for (ERTableColumn col : items) {
if (col == null) {
continue;
}
if (StringUtil.isEmpty(col.getName(erSchema.isPhysicModel()))) {
continue;
}
if (matches.contains(col.getName(erSchema.isPhysicModel()))) {
hasDuplicatedColumn = true;
break;
}
matches.add(col.getName(erSchema.isPhysicModel()));
}
}
if (hasDuplicatedColumn) {
CommonUITool.openErrorBox(Messages.errSameNameOnEditTableAddColumn);
return;
}
String collation = null;
if (newSchemaInfo != null && newSchemaInfo.getCollation() != null) {
collation = newSchemaInfo.getCollation();
} else {
collation = Collation.DEFAULT_COLLATION;
}
DBAttribute addAttribute = new DBAttribute("", DataType.DATATYPE_CHAR, newSchemaInfo.getClassname(), false, false, false, false, null, collation);
ERTableColumn column = new ERTableColumn(newERTable, addAttribute, false);
column.setIsNew(true);
tempERColumnList.add(column);
loadColumnData();
columnTableView.setSelection(new StructuredSelection(addAttribute), true);
columnsTable.setFocus();
handleSelectionChangeInColumnTable();
}
Aggregations