Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#23395 [CUBRID] Extend navigator to display db_server information #23457

Open
wants to merge 10 commits into
base: devel
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ tree.reference_columns.node.name=Reference columns
tree.references.node.name=References
tree.schemas.node.name=Schemas
tree.schemas.node.tip=Schemas
tree.server.node.name=Server
tree.servers.node.name=Servers
tree.servers.node.tip=Servers
tree.system_tables.node.name=System Tables
tree.system_table.node.tip=System Tables
tree.system_views.node.name=System Views
Expand All @@ -44,6 +47,14 @@ meta.org.jkiss.dbeaver.ext.cubrid.model.CubridUser.name.name=Name
meta.org.jkiss.dbeaver.ext.cubrid.model.CubridUser.comment.name=Comment
meta.org.jkiss.dbeaver.ext.cubrid.model.CubridTable.schema.name=Owner
meta.org.jkiss.dbeaver.ext.cubrid.model.CubridView.schema.name=Owner
meta.org.jkiss.dbeaver.ext.cubrid.model.CubridServer.dbName.name=Database Name
meta.org.jkiss.dbeaver.ext.cubrid.model.CubridServer.description.name=Description
meta.org.jkiss.dbeaver.ext.cubrid.model.CubridServer.host.name=Host
meta.org.jkiss.dbeaver.ext.cubrid.model.CubridServer.name.name=Link Name
meta.org.jkiss.dbeaver.ext.cubrid.model.CubridServer.owner.name=Owner
meta.org.jkiss.dbeaver.ext.cubrid.model.CubridServer.port.name=Port
meta.org.jkiss.dbeaver.ext.cubrid.model.CubridServer.properties.name=Properties
meta.org.jkiss.dbeaver.ext.cubrid.model.CubridServer.userName.name=User Name
meta.org.jkiss.dbeaver.ext.cubrid.model.plan.CubridPlanNode.cardinality.name=Cardinality
meta.org.jkiss.dbeaver.ext.cubrid.model.plan.CubridPlanNode.fullText.name=Full Text

Expand Down
3 changes: 3 additions & 0 deletions plugins/org.jkiss.dbeaver.ext.cubrid/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
</folder>
</items>
</folder>
<folder type="org.jkiss.dbeaver.ext.cubrid.model.CubridServer" label="%tree.servers.node.name" icon="#folder_server" description="%tree.servers.node.tip" visibleIf="object.supportsServer()">
<items label="%tree.server.node.name" path="cubridServer" property="cubridServers" icon="#server"/>
</folder>
<folder id="users" type="org.jkiss.dbeaver.ext.cubrid.model.CubridUser" label="%tree.users.node.name" icon="#folder_user"
description="%tree.users.node.tip">
<items label="%tree.user.node.name" path="cubridUser" property="cubridUsers" icon="#user"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public class CubridConstants

public static final String OWNER_NAME = "owner_name";
public static final String IS_SYSTEM_CLASS = "is_system_class";
public static final String COMMENT = "comment";
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@
import org.jkiss.dbeaver.ext.generic.model.GenericTableBase;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.dpi.DPIContainer;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement;
import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCObjectCache;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSDataType;
import org.jkiss.dbeaver.model.struct.DBSObject;

import java.sql.SQLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand All @@ -39,13 +46,15 @@ public class CubridDataSource extends GenericDataSource
private final CubridMetaModel metaModel;
private final CubridObjectContainer structureContainer;
private boolean supportMultiSchema;
private final CubridServerCache serverCache;

public CubridDataSource(DBRProgressMonitor monitor, DBPDataSourceContainer container, CubridMetaModel metaModel)
throws DBException
{
super(monitor, container, metaModel, new CubridSQLDialect());
this.metaModel = new CubridMetaModel();
this.structureContainer = new CubridObjectContainer(this);
this.serverCache = new CubridServerCache();
}

@DPIContainer
Expand All @@ -61,6 +70,21 @@ public List<GenericSchema> getCubridUsers(DBRProgressMonitor monitor) throws DBE
return this.getSchemas();
}

@Nullable
public List<CubridServer> getCubridServers(@NotNull DBRProgressMonitor monitor) throws DBException {
return serverCache.getAllObjects(monitor, this);
}

@NotNull
public CubridServer getCubridServer(@NotNull DBRProgressMonitor monitor, @Nullable String name) throws DBException {
return serverCache.getObject(monitor, this, name);
}

@NotNull
public boolean supportsServer() {
return getSupportMultiSchema();
}

@Nullable
@Override
public GenericTableBase findTable(
Expand Down Expand Up @@ -105,6 +129,14 @@ public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException
super.initialize(monitor);
}

@NotNull
@Override
public DBSObject refreshObject(@NotNull DBRProgressMonitor monitor) throws DBException {
super.refreshObject(monitor);
serverCache.clearCache();
return this;
}

public boolean getSupportMultiSchema()
{
return this.supportMultiSchema;
Expand All @@ -114,4 +146,27 @@ public void setSupportMultiSchema(boolean supportMultiSchema)
{
this.supportMultiSchema = supportMultiSchema;
}

public class CubridServerCache extends JDBCObjectCache<CubridDataSource, CubridServer> {
@NotNull
@Override
protected JDBCStatement prepareObjectsStatement(
@NotNull JDBCSession session,
@NotNull CubridDataSource container)
throws SQLException {
String sql = "select * from db_server";
final JDBCPreparedStatement dbStat = session.prepareStatement(sql);
return dbStat;
}

@Nullable
@Override
protected CubridServer fetchObject(
@NotNull JDBCSession session,
@NotNull CubridDataSource container,
@NotNull JDBCResultSet dbResult)
throws SQLException, DBException {
return new CubridServer(container, dbResult);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.cubrid.model;

import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.ext.cubrid.CubridConstants;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.struct.DBSObject;

public class CubridServer implements DBSObject {
private String linkName;
private String host;
private String port;
private String dbName;
private String userName;
private String properties;
private String owner;
private String description;
private CubridDataSource container;

public CubridServer(@NotNull CubridDataSource container, @NotNull JDBCResultSet dbResult) {
this.container = container;
this.linkName = JDBCUtils.safeGetString(dbResult, "link_name");
this.host = JDBCUtils.safeGetString(dbResult, "host");
this.port = JDBCUtils.safeGetString(dbResult, "port");
this.dbName = JDBCUtils.safeGetString(dbResult, "db_name");
this.userName = JDBCUtils.safeGetString(dbResult, "user_name");
this.properties = JDBCUtils.safeGetString(dbResult, "properties");
this.owner = JDBCUtils.safeGetString(dbResult, "owner");
this.description = JDBCUtils.safeGetString(dbResult, CubridConstants.COMMENT);
}

@NotNull
@Property(viewable = true, order = 1)
public String getName() {
return linkName;
}

@NotNull
@Property(viewable = true, order = 2)
public String getHost() {
return host;
}

@NotNull
@Property(viewable = true, order = 3)
public String getPort() {
return port;
}

@NotNull
@Property(viewable = true, order = 4)
public String getDbName() {
return dbName;
}

@NotNull
@Property(viewable = true, order = 5)
public String getUserName() {
return userName;
}

@Nullable
@Property(viewable = true, order = 6)
public String getProperties() {
return properties;
}

@NotNull
@Property(viewable = true, order = 7)
public String getOwner() {
return owner;
}

@Nullable
@Override
@Property(viewable = true, order = 8)
longhaseng52 marked this conversation as resolved.
Show resolved Hide resolved
public String getDescription() {
return description;
}

@NotNull
@Override
public boolean isPersisted() {
return true;
}

@Override
public DBSObject getParentObject() {
return container;
}

@Override
public DBPDataSource getDataSource() {
return container;
}
}