use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class ActionSupportUtil method isSupportMultiSelCheckDbUser.
/**
*
* Return whether support the multi selection and all selection type is
* equal <code>type</code> and the all selection owner is equal to logined
* database user
*
* @param obj Object
* @param type String
* @return boolean
*/
public static boolean isSupportMultiSelCheckDbUser(Object obj, String type) {
if (obj instanceof ISchemaNode) {
ISchemaNode schemaNode = (ISchemaNode) obj;
if (!type.equals(schemaNode.getType())) {
return false;
}
CubridDatabase database = schemaNode.getDatabase();
if (isNotRunningAndNotLogin(database)) {
return false;
}
DatabaseInfo dbInfo = database.getDatabaseInfo();
if (dbInfo == null) {
LOGGER.error("The database.getDatabaseInfo() is a null.");
return false;
}
DbUserInfo userInfo = dbInfo.getAuthLoginedDbUserInfo();
if (userInfo == null) {
LOGGER.error("The dbInfo.getAuthLoginedDbUserInfo() is a null.");
return false;
}
if (userInfo.isDbaAuthority()) {
return true;
}
boolean isSameUser = StringUtil.isEqualIgnoreCase(userInfo.getName(), getOwner(schemaNode));
if (isSameUser) {
return true;
}
} else if (obj instanceof Object[]) {
Object[] objArr = (Object[]) obj;
if (objArr.length == 0) {
return false;
}
CubridDatabase database = null;
for (Object object : objArr) {
//Check every object whether support
if (!isSupportMultiSelCheckDbUser(object, type)) {
return false;
}
//Check whether they are in the same database
ISchemaNode node = (ISchemaNode) object;
CubridDatabase db = node.getDatabase();
if (database == null) {
database = db;
} else if (!database.getId().equals(db.getId())) {
return false;
}
}
//Check the database whether login and running
if (isNotRunningAndNotLogin(database)) {
return false;
}
return true;
}
return false;
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class LayoutUtil method checkAllQueryEditor.
/**
*
* When server disconnect or delete,check query editor whether some
* transaction are not commit
*
* @param cubridServer the CubridServer object
* @return <code>true</code> if transaction is commited;<code>false</code>
* otherwise
*/
public static boolean checkAllQueryEditor(CubridServer cubridServer) {
IWorkbenchPage page = getActivePage();
if (page == null) {
return true;
}
IEditorReference[] editorRefArr = page.getEditorReferences();
if (editorRefArr == null || editorRefArr.length == 0) {
return true;
}
boolean isContinue = true;
for (IEditorReference editorRef : editorRefArr) {
String editorId = editorRef.getId();
if (editorId != null && editorId.equals(QueryEditorPart.ID)) {
QueryEditorPart queryEditor = (QueryEditorPart) editorRef.getEditor(false);
CubridDatabase db = queryEditor.getSelectedDatabase();
if (db != null && db.getServer() != null && db.getServer().getId().equals(cubridServer.getId())) {
isContinue = queryEditor.resetJDBCConnection();
}
}
}
return isContinue;
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class LayoutUtil method checkAllQueryEditor.
/**
*
* When database logout or stop,check query editor whether some transaction
* are not commit
*
* @param databaseNode the CubridDatabase object
* @return <code>true</code> if transaction is commited;<code>false</code>
* otherwise
*/
public static boolean checkAllQueryEditor(CubridDatabase databaseNode) {
IWorkbenchPage page = getActivePage();
if (page == null) {
return true;
}
boolean isContinue = true;
IEditorReference[] editorRefArr = page.getEditorReferences();
if (editorRefArr == null || editorRefArr.length == 0) {
return true;
}
for (IEditorReference editorRef : editorRefArr) {
String editorId = editorRef.getId();
if (editorId != null && editorId.equals(QueryEditorPart.ID)) {
QueryEditorPart queryEditor = (QueryEditorPart) editorRef.getEditor(false);
CubridDatabase db = queryEditor.getSelectedDatabase();
if (db != null && db.getId().equals(databaseNode.getId())) {
isContinue = queryEditor.resetJDBCConnection();
}
}
}
return isContinue;
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class SQLGenerateUtils method generateCloneTableSql.
public static String generateCloneTableSql(DefaultSchemaNode schemaNode, String newName) {
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 columnCounts = schemaInfo == null ? 0 : schemaInfo.getAttributes().size();
StringBuilder columns = new StringBuilder();
if (columnCounts > 0) {
for (int i = 0; i < columnCounts; i++) {
DBAttribute da = (DBAttribute) schemaInfo.getAttributes().get(i);
if (columns.length() > 0) {
columns.append(", ");
}
columns.append(QuerySyntax.escapeKeyword(da.getName()));
}
} else {
columns.append("*");
}
StringBuffer sql = new StringBuffer();
sql.append("CREATE TABLE ");
sql.append(QuerySyntax.escapeKeyword(newName));
sql.append(" AS ").append(StringUtil.NEWLINE).append("SELECT ");
sql.append(columns);
sql.append(StringUtil.NEWLINE).append("FROM ");
sql.append(QuerySyntax.escapeKeyword(tableName));
sql.append(";");
return format(sql.toString());
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class LoginQueryEditDialog method fillDatabaseCombo.
/**
*
* Fill in the database combo
*
* @param list the database list
*/
private void fillDatabaseCombo(List<CubridDatabase> list) {
selectDatabase = null;
connectionComp.getDatabaseCombo().removeAll();
if (list == null || list.isEmpty()) {
//For Cubrid Manager, if the server host is disconnected or has no database, 'demodb' will be set as default.
connectionComp.getDatabaseCombo().setText("demodb");
return;
}
CubridDatabase firstDb = null;
for (CubridDatabase db : list) {
DatabaseInfo databaseInfo = db.getDatabaseInfo();
if (databaseInfo == null) {
continue;
}
connectionComp.getDatabaseCombo().add(databaseInfo.getDbName());
firstDb = firstDb == null ? db : firstDb;
if (selDatabaseName != null && selDatabaseName.equals(databaseInfo.getDbName())) {
selectDatabase = db;
}
}
if (selectDatabase == null && firstDb != null) {
selectDatabase = firstDb;
selDatabaseName = selectDatabase.getDatabaseInfo() == null ? "" : selectDatabase.getDatabaseInfo().getDbName();
}
if (selectDatabase == null || null == selectDatabase.getDatabaseInfo()) {
return;
}
connectionComp.getDatabaseCombo().setText(selectDatabase.getDatabaseInfo().getDbName());
}
Aggregations