use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.
the class GetSchemaDDLTask method execute.
/**
* Execute the tasks
*/
public void execute() {
try {
if (CompatibleUtil.isAfter900(databaseInfo)) {
String sql = QueryUtil.getShowCreateSQL(schemaName, isTable);
sql = DatabaseInfo.wrapShardQuery(databaseInfo, sql);
StringBuilder sb = new StringBuilder();
if (errorMsg != null && errorMsg.trim().length() > 0) {
return;
}
if (connection == null || connection.isClosed()) {
errorMsg = Messages.error_getConnection;
return;
}
String viewName = null;
stmt = connection.createStatement();
rs = (CUBRIDResultSetProxy) stmt.executeQuery(sql);
while (rs.next()) {
if (isTable) {
sb.append(rs.getString(2));
} else {
viewName = QuerySyntax.escapeKeyword(rs.getString(1));
if (sb.length() > 0) {
sb.append(" UNION ALL ");
}
sb.append(" ").append(rs.getString(2)).append(" ");
}
}
if (isTable) {
ddl = sb.toString();
} else {
ddl = "CREATE OR REPLACE VIEW " + viewName + " AS " + sb.toString() + ";";
}
} else {
StringBuilder sqlScript = new StringBuilder();
if (!isTable) {
// Get class info
GetAllClassListTask getAllClassListTask = new GetAllClassListTask(databaseInfo, connection);
getAllClassListTask.setTableName(schemaName);
getAllClassListTask.getClassInfoTaskExcute();
// If failed
if (getAllClassListTask.getErrorMsg() != null || getAllClassListTask.isCancel()) {
errorMsg = getAllClassListTask.getErrorMsg();
LOGGER.error(errorMsg);
return;
}
/*Check user cancel*/
if (monitor != null && monitor.isCanceled()) {
errorMsg = "The user canceled.";
return;
}
ClassInfo classInfo = getAllClassListTask.getClassInfo();
// Get view column
GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(databaseInfo, connection);
getAllDBVclassTask.setClassName(schemaName);
getAllDBVclassTask.getAllVclassListTaskExcute();
// If failed
if (getAllDBVclassTask.getErrorMsg() != null || getAllDBVclassTask.isCancel()) {
errorMsg = getAllDBVclassTask.getErrorMsg();
LOGGER.error(errorMsg);
return;
}
/*Check user cancel*/
if (monitor != null && monitor.isCanceled()) {
errorMsg = "The user canceled.";
return;
}
// Get query list
List<String> vclassList = getAllDBVclassTask.getAllVclassList();
List<Map<String, String>> queryListData = new ArrayList<Map<String, String>>();
for (String sql : vclassList) {
Map<String, String> map = new HashMap<String, String>();
map.put("0", sql);
queryListData.add(map);
}
/*Check user cancel*/
if (monitor != null && monitor.isCanceled()) {
errorMsg = "The user canceled.";
return;
}
// Get all attribute
GetAllAttrTask getAllAttrTask = new GetAllAttrTask(databaseInfo, connection);
getAllAttrTask.setClassName(schemaName);
getAllAttrTask.getAttrList();
// If failed
if (getAllAttrTask.getErrorMsg() != null) {
errorMsg = getAllAttrTask.getErrorMsg();
LOGGER.error(errorMsg);
return;
}
List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
List<Map<String, String>> viewColListData = GetInfoDataUtil.getViewColMapList(attrList);
sqlScript.append(GetInfoDataUtil.getViewCreateSQLScript(false, databaseInfo, classInfo, schemaName, viewColListData, queryListData));
} else {
String ddl = SQLGenerateUtils.getCreateSQL(databaseInfo, schemaName);
sqlScript.append(ddl == null ? "" : ddl);
}
ddl = sqlScript.toString();
}
} catch (SQLException e) {
LOGGER.error(e.getMessage(), e);
errorMsg = e.getMessage();
} finally {
finish();
if (StringUtil.isNotEmpty(ddl)) {
SqlFormattingStrategy formator = new SqlFormattingStrategy();
String formated = formator.format(ddl);
ddl = formated;
}
}
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.
the class TableSchemaCompareComposite method getTableSchema.
private String getTableSchema(CubridDatabase db, Map<String, SchemaInfo> schemas, String tableName) {
// FIXME logic code move to core module
String tableSchemaInfo = "";
try {
SchemaInfo schemaInfo = schemas.get(tableName);
if (schemaInfo == null) {
return "";
}
if (schemaInfo.getVirtual().equals(ClassType.VIEW.getText())) {
GetAllClassListTask getAllClassListTask = new GetAllClassListTask(db.getDatabaseInfo());
getAllClassListTask.setTableName(tableName);
getAllClassListTask.getClassInfoTaskExcute();
ClassInfo classInfo = getAllClassListTask.getClassInfo();
GetAllAttrTask getAllAttrTask = new GetAllAttrTask(db.getDatabaseInfo());
getAllAttrTask.setClassName(tableName);
getAllAttrTask.getAttrList();
List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
List<Map<String, String>> viewColListData = GetInfoDataUtil.getViewColMapList(attrList);
/*Get view column*/
GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(db.getDatabaseInfo());
getAllDBVclassTask.setClassName(tableName);
getAllDBVclassTask.getAllVclassListTaskExcute();
/*Get query list*/
List<String> vclassList = getAllDBVclassTask.getAllVclassList();
List<Map<String, String>> queryListData = new ArrayList<Map<String, String>>();
for (String sql : vclassList) {
Map<String, String> map = new HashMap<String, String>();
map.put("0", sql);
queryListData.add(map);
}
tableSchemaInfo = GetInfoDataUtil.getViewCreateSQLScript(true, db, classInfo, tableName, viewColListData, queryListData);
} else {
SchemaDDL schemaDDL = null;
schemaDDL = new SchemaDDL(null, db.getDatabaseInfo());
tableSchemaInfo = schemaDDL.getSchemaDDL(schemaInfo);
}
} catch (Exception e) {
LOGGER.error("", e);
return "";
}
return tableSchemaInfo;
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.
the class EditUserDialog method createAuthComposite.
/**
* Create auth composite
*
* @return the composite
*/
private Composite createAuthComposite() {
final Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
composite.setLayout(layout);
Label classTableDescLabel = new Label(composite, SWT.NONE);
classTableDescLabel.setText(Messages.lblUnAuthorizedTable);
final String[] columnNameArr = new String[] { Messages.tblColClassName, Messages.tblColClassSchematype, Messages.tblColClassOwner, Messages.tblColClassType };
classTableViewer = CommonUITool.createCommonTableViewer(composite, new TableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
classTableViewer.setInput(classListData);
classTable = classTableViewer.getTable();
classTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
setAuthBtnEnableDisable();
}
});
final Composite cmpControl = new Composite(composite, SWT.NONE);
final GridData gdCmpControl = new GridData(SWT.CENTER, SWT.FILL, false, false);
cmpControl.setLayoutData(gdCmpControl);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
cmpControl.setLayout(gridLayout);
grantButton = new Button(cmpControl, SWT.LEFT);
grantButton.setEnabled(false);
grantButton.setText(Messages.addClassButtonName);
grantButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
int[] idx = classTable.getSelectionIndices();
if (idx.length < 0) {
return;
}
for (int i : idx) {
String className = classTable.getItem(i).getText(0);
for (Map<String, String> map : classListData) {
if (map.get("0").equals(className)) {
classListData.remove(map);
break;
}
}
ClassAuthorizations classAuthorizations = classGrantMap.get(className);
if (classAuthorizations == null) {
classAuthorizations = new ClassAuthorizations();
classAuthorizations.setClassName(className);
classAuthorizations.setSelectPriv(true);
}
authListData.add(getItemAuthMap(classAuthorizations));
}
classTableViewer.refresh();
authTableViewer.refresh();
if (authTableViewer.getTable().getColumn(0) != null) {
authTableViewer.getTable().getColumn(0).pack();
}
setAuthBtnEnableDisable();
}
});
revokeButton = new Button(cmpControl, SWT.NONE);
revokeButton.setEnabled(false);
revokeButton.setText(Messages.deleteClassButtonName);
revokeButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
int[] idx = authTable.getSelectionIndices();
if (idx.length < 0) {
return;
}
for (int id : idx) {
String tableName = authTable.getItem(id).getText(0);
for (ClassInfo bean : allClassInfoList) {
if (tableName.equals(bean.getClassName())) {
if (bean.isSystemClass()) {
CommonUITool.openErrorBox(parentComp.getShell(), Messages.errRemoveSysClass);
return;
} else {
Map<String, String> map = new HashMap<String, String>();
map.put("0", bean.getClassName());
map.put("1", bean.isSystemClass() ? Messages.msgSystemSchema : Messages.msgUserSchema);
map.put("2", bean.getOwnerName());
map.put("3", bean.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
classListData.add(map);
}
}
}
for (Map<String, Object> map : authListData) {
String className = (String) map.get("0");
if (tableName.equals(className)) {
authListData.remove(map);
break;
}
}
}
authTableViewer.refresh();
classTableViewer.refresh();
setAuthBtnEnableDisable();
}
});
Label authTableDescLabel = new Label(composite, SWT.NONE);
authTableDescLabel.setText(Messages.lblAuthorizedTable);
final String[] authColumnNameArr = new String[] { Messages.tblColAuthTable, Messages.tblColAuthSelect, Messages.tblColAuthInsert, Messages.tblColAuthUpdate, Messages.tblColAuthDelete, Messages.tblColAuthAlter, Messages.tblColAuthIndex, Messages.tblColAuthExecute, Messages.tblColAuthGrantselect, Messages.tblColAuthGrantinsert, Messages.tblColAuthGrantupdate, Messages.tblColAuthGrantdelete, Messages.tblColAuthGrantalter, Messages.tblColAuthGrantindex, Messages.tblColAuthGrantexecute };
authTableViewer = createCommonTableViewer(composite, authColumnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
authTableViewer.setLabelProvider(new AuthTableLabelProvider());
authTableViewer.setInput(authListData);
authTable = authTableViewer.getTable();
CellEditor[] editors = new CellEditor[15];
editors[0] = null;
for (int i = 1; i < 15; i++) {
editors[i] = new CheckboxCellEditor(authTable, SWT.READ_ONLY);
}
authTableViewer.setColumnProperties(authColumnNameArr);
authTableViewer.setCellEditors(editors);
authTableViewer.setCellModifier(new ICellModifier() {
@SuppressWarnings("unchecked")
public boolean canModify(Object element, String property) {
Map<String, Object> map = (Map<String, Object>) element;
boolean isDbaAuthority = database.getDatabaseInfo().getAuthLoginedDbUserInfo().isDbaAuthority();
if (isDbaAuthority) {
return true;
}
/*Can't grant/revoke for current login user*/
if (StringUtil.isEqual(userName, currentUserInfo.getName())) {
return false;
}
String name = (String) map.get("0");
for (ClassInfo bean : allClassInfoList) {
if (name.equals(bean.getClassName())) {
if (bean.isSystemClass()) {
return false;
} else if (currentUserInfo.getName().equalsIgnoreCase(bean.getOwnerName())) {
return true;
}
}
}
ClassAuthorizations authorizations = currentUserAuthorizations.get(name);
if (authorizations == null || authorizations.isAllPriv() || authorizations.isPriv(property)) {
return true;
} else {
return false;
}
}
@SuppressWarnings("unchecked")
public Object getValue(Object element, String property) {
Map<String, Object> map = (Map<String, Object>) element;
for (int i = 1; i < 15; i++) {
if (property.equals(authColumnNameArr[i])) {
return Boolean.valueOf((Boolean) map.get("" + i));
}
}
return null;
}
@SuppressWarnings("unchecked")
public void modify(Object element, String property, Object value) {
Object elementData;
elementData = element;
if (element instanceof Item) {
elementData = ((Item) element).getData();
}
String key = "";
Map<String, Object> map = (Map<String, Object>) elementData;
for (int i = 1; i < 15; i++) {
if (property.equals(authColumnNameArr[i])) {
key = "" + i;
break;
}
}
if (value instanceof Boolean) {
map.put(key, ((Boolean) value).booleanValue());
}
authTableViewer.refresh();
}
});
authTable.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent event) {
}
public void widgetSelected(SelectionEvent event) {
setAuthBtnEnableDisable();
}
});
authTable.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent event) {
setAuthBtnEnableDisable();
}
});
return composite;
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.
the class GetPartitionedClassListTask method getAllPartitionedClassInfoList.
/**
* Get all partitioned class info list
*
* @param tableName String the table name
* @return List<ClassInfo>
*/
public List<ClassInfo> getAllPartitionedClassInfoList(String tableName) {
List<ClassInfo> allClassInfoList = new ArrayList<ClassInfo>();
try {
if (errorMsg != null && errorMsg.trim().length() > 0) {
return allClassInfoList;
}
if (connection == null || connection.isClosed()) {
errorMsg = Messages.error_getConnection;
return allClassInfoList;
}
String sql = "SELECT b.* FROM db_partition a, db_class b WHERE a.class_name=?" + " AND LOWER(b.class_name)=LOWER(a.partition_class_name)";
stmt = connection.prepareStatement(sql);
((PreparedStatement) stmt).setString(1, tableName.toLowerCase(Locale.getDefault()));
rs = ((PreparedStatement) stmt).executeQuery();
while (rs.next()) {
String className = rs.getString("class_name");
String ownerName = rs.getString("owner_name");
String classType = rs.getString("class_type");
ClassType type = ClassType.NORMAL;
if (classType != null && classType.trim().equalsIgnoreCase("VCLASS")) {
type = ClassType.VIEW;
}
String isSystemClazz = rs.getString("is_system_class");
boolean isSystemClass = false;
if (isSystemClazz != null && isSystemClazz.trim().equalsIgnoreCase("YES")) {
isSystemClass = true;
}
ClassInfo classInfo = new ClassInfo(className, ownerName, type, isSystemClass, true);
allClassInfoList.add(classInfo);
}
} catch (SQLException e) {
LOGGER.error("", e);
errorMsg = e.getMessage();
} finally {
finish();
}
return allClassInfoList;
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.
the class CQBUserEditor method initial.
/**
* Initial the data
*/
private void initial() {
if (ownerClassTableViewer == null || ownerClassTableViewer.getControl() == null || ownerClassTableViewer.getControl().isDisposed()) {
return;
}
if (memberList == null) {
memberList = new ArrayList<String>();
}
while (!memberList.isEmpty()) {
memberList.remove(0);
}
for (DbUserInfo bean : userListInfo.getUserList()) {
if (bean.getName().equalsIgnoreCase(userName)) {
userInfo = bean;
}
List<String> groups = bean.getGroups().getGroup();
if (groups != null) {
for (String g : groups) {
if (userName != null && userName.equalsIgnoreCase(g)) {
memberList.add(bean.getName());
break;
}
}
}
}
List<String> groupList = userInfo.getGroups().getGroup();
while (!ownerClassListData.isEmpty()) {
ownerClassListData.remove(0);
}
if (allClassInfoList != null) {
for (ClassInfo c : allClassInfoList) {
if (!c.getOwnerName().equalsIgnoreCase(userInfo.getName())) {
continue;
}
Map<String, String> map = new HashMap<String, String>();
map.put("0", c.getClassName());
map.put("1", c.isSystemClass() ? Messages.msgSystemSchema : Messages.msgUserSchema);
map.put("2", c.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
ownerClassListData.add(map);
}
}
while (!authListData.isEmpty()) {
authListData.remove(0);
}
Map<String, ClassAuthorizations> classGrantMap = userInfo.getUserAuthorizations();
Iterator<String> authIter = classGrantMap.keySet().iterator();
while (authIter.hasNext()) {
String className = authIter.next();
if (!partitionClassMap.containsKey(className)) {
authListData.add(getItemAuthMap(classGrantMap.get(className)));
}
}
ownerClassTableViewer.refresh();
if (!DB_DBA_USERNAME.equalsIgnoreCase(userName)) {
authTableViewer.refresh();
}
for (int i = 0; i < ownerClassTableViewer.getTable().getColumnCount(); i++) {
ownerClassTableViewer.getTable().getColumn(i).pack();
}
if (!DB_DBA_USERNAME.equalsIgnoreCase(userName)) {
for (int i = 0; i < authTableViewer.getTable().getColumnCount(); i++) {
authTableViewer.getTable().getColumn(i).pack();
}
}
StringBuffer sb = new StringBuffer();
if (groupList != null) {
for (int i = 0, n = groupList.size(); i < n; i++) {
if (i > 0) {
sb.append(", ");
}
sb.append(groupList.get(i));
}
}
lblUserGroup.setText(Messages.bind(Messages.lblGroupList, sb.length() < 1 ? Messages.lblGroupNotExist : sb.toString()));
sb = new StringBuffer();
if (memberList != null) {
for (int i = 0, n = memberList.size(); i < n; i++) {
if (i > 0) {
sb.append(", ");
}
sb.append(memberList.get(i));
}
}
lblUserMember.setText(Messages.bind(Messages.lblMemberList, sb.length() < 1 ? Messages.lblMemberNotExist : sb.toString()));
if (checkIsDba()) {
authTableViewer.getTable().setVisible(false);
GridData tableGd = (GridData) authTableViewer.getTable().getLayoutData();
tableGd.exclude = true;
CLabel clbl = new CLabel(authComp, SWT.NONE);
clbl.setBackground(topComp.getBackground());
clbl.setText(Messages.lblDbaAllAuth);
}
}
Aggregations