Skip to content

Commit

Permalink
dbeaver#18437 Support of InterSystems IRIS VIEW definition
Browse files Browse the repository at this point in the history
To implement getViewDDL I added a plugin for InterSystems IRIS
  • Loading branch information
adaptun committed May 16, 2024
1 parent 7495dbd commit 5655264
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 0 deletions.
1 change: 1 addition & 0 deletions features/org.jkiss.dbeaver.db.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<plugin id="org.jkiss.dbeaver.ext.hive" version="0.0.0" />
<plugin id="org.jkiss.dbeaver.ext.hsqldb" version="0.0.0" />
<plugin id="org.jkiss.dbeaver.ext.informix" version="0.0.0" />
<plugin id="org.jkiss.dbeaver.ext.intersystems" version="0.0.0" />
<plugin id="org.jkiss.dbeaver.ext.kognitio" version="0.0.0" />
<plugin id="org.jkiss.dbeaver.ext.netezza" version="0.0.0" />
<plugin id="org.jkiss.dbeaver.ext.oceanbase" version="0.0.0" />
Expand Down
15 changes: 15 additions & 0 deletions plugins/org.jkiss.dbeaver.ext.intersystems/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: DBeaver InterSystems Support
Bundle-SymbolicName: org.jkiss.dbeaver.ext.intersystems;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Release-Date: 20240520
Require-Bundle: org.jkiss.dbeaver.model,
org.jkiss.dbeaver.ext.generic
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-Vendor: DBeaver Corp
Bundle-ClassPath: .
Automatic-Module-Name: org.jkiss.dbeaver.ext.intersystems
Export-Package: org.jkiss.dbeaver.ext.intersystems.model
Import-Package: org.jkiss.dbeaver.model.sql.format
5 changes: 5 additions & 0 deletions plugins/org.jkiss.dbeaver.ext.intersystems/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/
output.. = target/classes/
bin.includes = .,\
META-INF/,\
plugin.xml
10 changes: 10 additions & 0 deletions plugins/org.jkiss.dbeaver.ext.intersystems/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>

<plugin>

<extension point="org.jkiss.dbeaver.generic.meta">
<meta id="intersystems" class="org.jkiss.dbeaver.ext.intersystems.model.InterSystemsMetaModel" driverClass="com.intersystems.jdbc.IRISDriver"/>
</extension>

</plugin>
38 changes: 38 additions & 0 deletions plugins/org.jkiss.dbeaver.ext.intersystems/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jkiss.dbeaver</groupId>
<artifactId>plugins</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>org.jkiss.dbeaver.ext.intersystems</artifactId>
<packaging>eclipse-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.jkiss.dbeaver</groupId>
<artifactId>org.jkiss.dbeaver.model</artifactId>
<version>1.1.24-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jkiss.dbeaver</groupId>
<artifactId>org.jkiss.dbeaver.ext.generic</artifactId>
<version>2.3.217-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jkiss.dbeaver</groupId>
<artifactId>org.jkiss.dbeaver.model.jdbc</artifactId>
<version>1.0.24-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jkiss.dbeaver</groupId>
<artifactId>org.jkiss.dbeaver.model.sql</artifactId>
<version>1.0.121-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.intersystems.model;

import java.util.Map;

import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.generic.model.GenericView;
import org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaModel;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBUtils;
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.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;

public class InterSystemsMetaModel extends GenericMetaModel
{
private static final Log log = Log.getLog(InterSystemsMetaModel.class);

public InterSystemsMetaModel() {
super();
}

public String getViewDDL(
@NotNull DBRProgressMonitor monitor,
@NotNull GenericView view,
@NotNull Map<String, Object> options) throws DBException {
String sqlStatement = "SELECT View_Definition "
+ " FROM INFORMATION_SCHEMA.VIEWS "
+ "where TABLE_NAME=? and TABLE_SCHEMA=? ";
try (JDBCSession session = DBUtils.openMetaSession(monitor, view, "Load source code")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement(sqlStatement)) {
dbStat.setString(1, view.getName());
dbStat.setString(2, view.getContainer().getSchema().getName());
log.debug("Searching for view '%s' in schema '%s' ".formatted(view.getName(), view.getContainer().getSchema().getName()));
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.nextRow()) {
String viewplain = dbResult.getString(1);
return SQLFormatUtils.formatSQL(view.getDataSource(), viewplain);
}
}
}
} catch (Exception e) {
throw new DBException("Can't read source code of '" + view.getFullyQualifiedName(DBPEvaluationContext.DDL) + "'", e);
}
return super.getViewDDL(monitor, view, options);
}
}
1 change: 1 addition & 0 deletions plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<module>org.jkiss.dbeaver.ext.hive</module>
<module>org.jkiss.dbeaver.ext.hsqldb</module>
<module>org.jkiss.dbeaver.ext.informix</module>
<module>org.jkiss.dbeaver.ext.intersystems</module>
<module>org.jkiss.dbeaver.ext.mssql</module>
<module>org.jkiss.dbeaver.ext.mysql</module>
<module>org.jkiss.dbeaver.ext.netezza</module>
Expand Down

0 comments on commit 5655264

Please sign in to comment.