Skip to content
Permalink
Browse files

#1857 DB2i extension

  • Loading branch information...
serge-rider committed Jul 5, 2019
1 parent 3310296 commit efb944af49cca2c5bcd471c3ba9e691eff7732a0
@@ -25,6 +25,7 @@

<plugin id="org.jkiss.dbeaver.ext.clickhouse" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.ext.db2.zos" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.ext.db2.i" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.ext.derby" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.ext.firebird" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.ext.greenplum" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
@@ -0,0 +1,12 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.jkiss.dbeaver.ext.db2.i;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Release-Date: 20190708
Require-Bundle: org.jkiss.dbeaver.model,
org.jkiss.dbeaver.ext.generic
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: %Bundle-Vendor
Bundle-ClassPath: .
@@ -0,0 +1,3 @@
#Properties file for org.jkiss.dbeaver.ext.db2.i
Bundle-Vendor = JKISS
Bundle-Name = DBeaver IBM DB2 for iSeries / AS400
@@ -0,0 +1,7 @@
source.. = src/
output.. = target/classes/
bin.includes = .,\
META-INF/,\
OSGI-INF/,\
icons/,\
plugin.xml
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>

<plugin>

<extension point="org.jkiss.dbeaver.dataSourceProvider">

<!-- DB2 i -->

<datasource
class="org.jkiss.dbeaver.ext.db2.i.DB2IDataSourceProvider"
description="%datasource.db2_i.description"
id="db2_i"
parent="generic"
label="DB2 iSeries"
icon="icons/db2_i_icon.png">
<drivers managable="true">

<driver
id="db2_iseries"
label="DB2 iSeries/AS 400"
icon="icons/db2_icon.png"
iconBig="icons/db2_icon_big.png"
category="DB2"
class="com.ibm.as400.access.AS400JDBCDriver"
sampleURL="jdbc:as400://{host};[libraries={database};]"
defaultPort="446"
description="IBM DB2 iSeries/AS 400 driver"
categories="sql">
<replace provider="generic" driver="db2_iseries"/>

<file type="jar" path="maven:/net.sf.jt400:jt400:RELEASE" bundle="!drivers.jt400"/>

<file type="license" path="drivers/db2-jt400/LICENSE.txt" bundle="drivers.jt400"/>
<file type="jar" path="drivers/db2-jt400/jt400.jar" bundle="drivers.jt400"/>

<parameter name="query-get-active-db" value="SELECT CURRENT_SCHEMA FROM SYSIBM.SYSDUMMY1"/>
<parameter name="query-set-active-db" value="SET SCHEMA ?"/>
<parameter name="omit-catalog" value="true"/>
<parameter name="schema-filters-enabled" value="false"/>

<!-- Enable table/column descriptions -->
<property name="translate binary" value="true"/>
<property name="metadata source" value="0"/>
</driver>

</drivers>

</datasource>
</extension>

</plugin>
@@ -0,0 +1,14 @@
<?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.db2.i</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
@@ -0,0 +1,27 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* 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.db2.i;

import org.jkiss.dbeaver.ext.generic.GenericDataSourceProvider;

public class DB2IDataSourceProvider extends GenericDataSourceProvider {

public DB2IDataSourceProvider()
{
}

}
@@ -0,0 +1,36 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* 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.db2.i.model;

import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.generic.model.GenericDataSource;
import org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaModel;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;

public class DB2IDataSource extends GenericDataSource {

private static final Log log = Log.getLog(DB2IDataSource.class);

public DB2IDataSource(DBRProgressMonitor monitor, DBPDataSourceContainer container, GenericMetaModel metaModel)
throws DBException
{
super(monitor, container, metaModel, new DB2ISQLDialect());
}

}
@@ -0,0 +1,105 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* 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.db2.i.model;

import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.generic.model.GenericDataSource;
import org.jkiss.dbeaver.ext.generic.model.GenericTableBase;
import org.jkiss.dbeaver.ext.generic.model.GenericView;
import org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaModel;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
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 java.sql.Clob;
import java.sql.SQLException;
import java.util.Map;

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

public DB2IMetaModel() {
super();
}

@Override
public GenericDataSource createDataSourceImpl(DBRProgressMonitor monitor, DBPDataSourceContainer container) throws DBException {
return new DB2IDataSource(monitor, container, this);
}

@Override
public String getTableDDL(DBRProgressMonitor monitor, GenericTableBase sourceObject, Map<String, Object> options) throws DBException {
if (!sourceObject.isView()) {
return super.getTableDDL(monitor, sourceObject, options);
}
GenericDataSource dataSource = sourceObject.getDataSource();
try (JDBCSession session = DBUtils.openMetaSession(monitor, sourceObject, "Read DB2 z/OS view source")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement(
"SELECT STATEMENT FROM SYSIBM.SYSVIEWS\n" +
"WHERE CREATOR = ? AND NAME = ?\n" +
"WITH UR"))
{
dbStat.setString(1, sourceObject.getSchema().getName());
dbStat.setString(2, sourceObject.getName());
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.next()) {
Clob ddlStmt = dbResult.getClob(1);
try {
String ddl = ddlStmt.getSubString(1, (int) ddlStmt.length());
return normalizeDDL(ddl);
} finally {
try {
ddlStmt.free();
} catch (Throwable e) {
log.debug("Error freeing CLOB: " + e.getMessage());
}
}
} else {
return "-- View definition not found in system catalog";
}
}
}
} catch (SQLException e) {
throw new DBException(e, dataSource);
}
}

private String normalizeDDL(String ddl) {
int declStart = ddl.indexOf("(");
int declEnd = ddl.indexOf(") ENGINE");
if (declEnd == -1) {
declEnd = ddl.length() - 1;
}
return
ddl.substring(0, declStart) + "(\n" +
ddl.substring(declStart + 1, declEnd).replace(",", ",\n") + "\n" +
ddl.substring(declEnd);
}

public String getViewDDL(DBRProgressMonitor monitor, GenericView sourceObject, Map<String, Object> options) throws DBException {
return getTableDDL(monitor, sourceObject, options);
}

}
@@ -0,0 +1,37 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* 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.db2.i.model;

import org.jkiss.dbeaver.ext.generic.model.GenericSQLDialect;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCDatabaseMetaData;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource;

public class DB2ISQLDialect extends GenericSQLDialect {

public DB2ISQLDialect() {
super("IBM DB2 i");
}

@Override
public boolean supportsOrderByIndex() {
return false;
}

public void initDriverSettings(JDBCDataSource dataSource, JDBCDatabaseMetaData metaData) {
super.initDriverSettings(dataSource, metaData);
}
}
@@ -23,7 +23,7 @@
public class DB2ZOSSQLDialect extends GenericSQLDialect {

public DB2ZOSSQLDialect() {
super("Clickhouse SQL");
super("DB2 for z/OS");
}

@Override
@@ -53,6 +53,7 @@
<module>org.jkiss.dbeaver.ext.clickhouse</module>
<module>org.jkiss.dbeaver.ext.db2</module>
<module>org.jkiss.dbeaver.ext.db2.zos</module>
<module>org.jkiss.dbeaver.ext.db2.i</module>
<module>org.jkiss.dbeaver.ext.derby</module>
<module>org.jkiss.dbeaver.ext.erd</module>
<module>org.jkiss.dbeaver.ext.es.ui</module>

0 comments on commit efb944a

Please sign in to comment.
You can’t perform that action at this time.