use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class SchemaCommentHandler method bindSchemaInfo.
/**
* Bind schema descriptions to SchemaInfo object.
*
* @param comments
* @param schema
*/
public static void bindSchemaInfo(Map<String, SchemaComment> comments, SchemaInfo schema) {
if (comments == null || schema == null) {
return;
}
String tableName = schema.getClassname();
SchemaComment cmt = find(comments, tableName, null);
if (cmt != null) {
schema.setDescription(cmt.getDescription());
}
if (schema.getAttributes() == null) {
return;
}
for (DBAttribute attr : schema.getAttributes()) {
if (attr.getName() == null) {
continue;
}
cmt = find(comments, tableName, attr.getName());
if (cmt != null) {
attr.setDescription(cmt.getDescription());
}
}
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class PartitionTypePage method createAttrTable.
/**
* Create attribute table information
*
* @param parent Composite
*/
private void createAttrTable(Composite parent) {
useColumnButton = new Button(parent, SWT.RADIO | SWT.LEFT);
useColumnButton.setText(Messages.btnUseColumn);
useColumnButton.setLayoutData(CommonUITool.createGridData(2, 1, -1, -1));
useColumnButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (useColumnButton.getSelection()) {
useExprButton.setSelection(false);
partitionExprText.setText("");
partitionExprText.setEnabled(false);
setErrorMessage(Messages.errNoSelectColumn);
setPageComplete(false);
attributeTable.setEnabled(true);
}
}
});
List<DBAttributeStatistic> dbAttrStatList = null;
if (!isNewTable) {
GetPartitionedClassListTask task = new GetPartitionedClassListTask(dbInfo);
dbAttrStatList = task.getColumnStatistics(schemaInfo.getClassname());
}
attrList.addAll(schemaInfo.getAttributes());
for (int i = 0; dbAttrStatList != null && i < dbAttrStatList.size(); i++) {
DBAttributeStatistic dbAttributeStatics = dbAttrStatList.get(i);
for (int j = 0; j < attrList.size(); j++) {
DBAttribute dbAttribute = attrList.get(j);
if (dbAttribute.getName().equals(dbAttributeStatics.getName())) {
attrList.remove(j);
attrList.add(dbAttributeStatics);
break;
}
}
}
attrTableView = new TableViewer(parent, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
attributeTable = attrTableView.getTable();
attributeTable.setLayout(TableViewUtil.createTableViewLayout(new int[] { 20, 20, 20, 20, 20 }));
attributeTable.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, 200));
attributeTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
validate();
}
});
attributeTable.setHeaderVisible(true);
attributeTable.setLinesVisible(true);
TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColColumnName);
TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColDataType);
TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColMiniValue);
TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColMaxValue);
TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColValueCount);
attrTableView.setContentProvider(new PartitionTypeContentProvider());
attrTableView.setLabelProvider(new PartitionTypeLabelProvider());
attrTableView.setInput(attrList);
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class EditViewAction method run.
/**
* run edit view
* @param ISchemaNode viewNode
* @param database CubridDatabase
*/
public int run(CubridDatabase database, ISchemaNode node) {
CreateViewDialog dialog = new CreateViewDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), database, false);
GetAllClassListTask getAllClassListTask = new GetAllClassListTask(database.getDatabaseInfo());
getAllClassListTask.setTableName(node.getName());
GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(database.getDatabaseInfo());
getAllDBVclassTask.setClassName(node.getName());
GetAllAttrTask getAllAttrTask = new GetAllAttrTask(database.getDatabaseInfo());
getAllAttrTask.setClassName(node.getName());
JDBCGetAllDbUserTask getAllDbUserTask = new JDBCGetAllDbUserTask(database.getDatabaseInfo());
dialog.execTask(-1, new ITask[] { getAllClassListTask, getAllDBVclassTask, getAllAttrTask, getAllDbUserTask }, true, getShell());
if (getAllClassListTask.getErrorMsg() != null || getAllDBVclassTask.getErrorMsg() != null || getAllAttrTask.getErrorMsg() != null || getAllDbUserTask.getErrorMsg() != null || getAllClassListTask.isCancel() || getAllDBVclassTask.isCancel() || getAllAttrTask.isCancel() || getAllDbUserTask.isCancel()) {
return IDialogConstants.CANCEL_ID;
}
ClassInfo classInfo = getAllClassListTask.getClassInfo();
List<String> vclassList = getAllDBVclassTask.getAllVclassList();
List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
List<String> dbUserList = getAllDbUserTask.getDbUserList();
dialog.setAttrList(attrList);
dialog.setClassInfo(classInfo);
dialog.setVclassList(vclassList);
dialog.setDbUserList(dbUserList);
if (dialog.open() == IDialogConstants.OK_ID) {
String viewName = node.getName();
String newViewName = dialog.getNewViewName();
String owner = dialog.getOwner();
node.getDatabase().getDatabaseInfo().removeSchema(viewName);
ISelectionProvider provider = getSelectionProvider();
TreeViewer treeViewer = (TreeViewer) provider;
if (!viewName.equals(newViewName)) {
ClassInfo newClassInfo = (ClassInfo) node.getAdapter(ClassInfo.class);
newClassInfo.setClassName(newViewName);
newClassInfo.setOwnerName(owner);
node.setId(node.getParent().getId() + ICubridNodeLoader.NODE_SEPARATOR + newViewName);
node.setLabel(newViewName);
treeViewer.refresh(node, true);
}
CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, node.getParent());
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
ActionManager.getInstance().fireSelectionChanged(getSelection());
/*Broadcast the view changed*/
QueryEditorUtil.fireSchemaNodeChanged(node);
return IDialogConstants.OK_ID;
}
return IDialogConstants.CANCEL_ID;
}
use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.
the class SQLGenerateUtils method getInsertSQL.
/**
* Create insert prepared statement SQL
*
* @param schemaNode DefaultSchemaNode
* @return String
*/
public static String getInsertSQL(DefaultSchemaNode schemaNode) {
StringBuffer columns = new StringBuffer("");
StringBuffer values = new StringBuffer("");
CubridDatabase database = schemaNode.getDatabase();
String tableName = schemaNode.getName();
SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(tableName);
if (schemaInfo == null) {
CommonUITool.openErrorBox(Messages.bind(Messages.errGetSchemaInfo, tableName));
LOGGER.debug("Can't get the SchemaInfo:" + tableName);
return "";
}
int n = 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(") ").append(StringUtil.NEWLINE).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 SQLGenerateUtils method getSelectSQLSimple.
/**
* Create select prepared statement SQL
*
* @param schemaNode DefaultSchemaNode
*
* @return String
*/
public static String getSelectSQLSimple(DefaultSchemaNode schemaNode) {
DatabaseInfo databaseInfo = NodeUtil.findDatabaseInfo(schemaNode);
if (databaseInfo == null) {
return "";
}
StringBuffer columns = new StringBuffer("");
StringBuffer wheres = new StringBuffer("");
String tableName = schemaNode.getName();
SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
if (schemaInfo == null) {
CommonUITool.openErrorBox(Messages.bind(Messages.errGetSchemaInfo, tableName));
LOGGER.debug("Can't get the SchemaInfo:" + tableName);
return "";
}
int n = schemaInfo.getAttributes().size();
for (int i = 0; i < n; i++) {
DBAttribute da = (DBAttribute) schemaInfo.getAttributes().get(i);
if (columns.length() > 0) {
columns.append(", ");
wheres.append(" AND ");
}
columns.append(QuerySyntax.escapeKeyword(da.getName()));
wheres.append(QuerySyntax.escapeKeyword(da.getName()) + "=?");
}
StringBuffer sql = new StringBuffer("");
if (columns.length() > 0) {
sql.append("SELECT ");
sql.append(columns);
sql.append(StringUtil.NEWLINE).append(" FROM ");
sql.append(StringUtil.NEWLINE).append(QuerySyntax.escapeKeyword(tableName));
sql.append(StringUtil.NEWLINE).append(" WHERE ");
sql.append(StringUtil.NEWLINE).append(" 1 = 1;");
}
return sql.toString();
}
Aggregations