Skip to content

Commit

Permalink
DB2 z/OS support
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.code.sf.net/p/jailer/code/trunk@1143 3dd849cd-670e-4645-a7cd-dd197c8d0e81
  • Loading branch information
rwisser committed Jan 19, 2017
1 parent 43642ff commit d321a3a
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 8 deletions.
58 changes: 57 additions & 1 deletion jailer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema
</property>
</bean>

<!-- for IBM DB2 -->
<!-- for IBM DB2 LUW -->
<bean class="net.sf.jailer.Configuration">
<property name="urlPattern" value="jdbc:db2.*" />
<property name="testQuery" value="Select A, B, C from (values (1, '2', 3), (4, '5', 6)) E(A, B, C)" />

<property name="dbms" value="DB2"/>

Expand Down Expand Up @@ -211,6 +212,61 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema
<property name="virtualColumnsQuery" value="SELECT TABNAME, COLNAME from syscat.columns WHERE TABSCHEMA='${SCHEMA}' AND GENERATED='A'" />
</bean>

<!-- for IBM DB2 z/OS -->
<bean class="net.sf.jailer.Configuration">
<property name="urlPattern" value="jdbc:db2.*" />

<property name="dbms" value="DB2_ZOS"/>

<!-- NOLOGGING, TABLESPACE-spec., etc. -->
<property name="tableProperties" value="NOT LOGGED INITIALLY" />

<property name="sqlDialect">
<bean class="net.sf.jailer.database.SQLDialect">
<property name="supportsMultiRowInserts" value="true"/>
<property name="needsValuesKeywordForDeletes" value="true"/>
<property name="supportsInClauseForDeletes" value="false"/>
<property name="upsertMode" value="FROM_SYSDUMMY1"/>
</bean>
</property>
<property name="typeReplacement">
<map>
<entry key="graphic" value="varchar"/>
<entry key="GRAPHIC" value="VARCHAR"/>
</map>
</property>
<property name="stringLiteralEscapeSequences">
<map>
<entry key="'" value="''"/>
<entry key="\n" value="' || chr(10) || '"/>
<entry key="\r" value="' || chr(13) || '"/>
</map>
</property>
<property name="sqlLimitSuffix" value="fetch first %s rows only" />
<property name="statisticRenovator">
<bean class="net.sf.jailer.database.SqlScriptBasedStatisticRenovator">
<constructor-arg value="script/db2/update_statistics.sql" />
</bean>
</property>
<property name="emptyCLOBValue" value="clob('')" />
<property name="emptyBLOBValue" value="blob('')" />
<property name="toBlob" value="blob('%s')" />
<property name="toClob" value="clob('%s')" />
<property name="embeddedLobSizeLimit" value="32000" />
<property name="sessionTemporaryTableManager">
<bean class="net.sf.jailer.database.DefaultTemporaryTableManager">
<property name="dmlTableReferencePrefix" value="SESSION." />
<property name="createTablePrefix" value="DECLARE GLOBAL TEMPORARY TABLE " />
<property name="createTableSuffix" value="ON COMMIT PRESERVE ROWS NOT LOGGED" />
<property name="createIndexPrefix" value="CREATE INDEX SESSION." />
<property name="createIndexSuffix" value="" />
<property name="indexTablePrefix" value="SESSION." />
<property name="dropTablePrefix" value="DROP TABLE SESSION." />
</bean>
</property>
<property name="virtualColumnsQuery" value="SELECT TABNAME, COLNAME from syscat.columns WHERE TABSCHEMA='${SCHEMA}' AND GENERATED='A'" />
</bean>

<!-- for Oracle -->
<bean class="net.sf.jailer.Configuration">
<property name="urlPattern" value="jdbc:oracle.*" />
Expand Down
58 changes: 56 additions & 2 deletions src/main/net/sf/jailer/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package net.sf.jailer;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
Expand Down Expand Up @@ -58,6 +60,11 @@ public class Configuration {
*/
private String urlPattern;

/**
* Test-query for the DBMS for which this holds the configuration.
*/
private String testQuery;

/**
* The {@link StatisticRenovator}.
*/
Expand Down Expand Up @@ -351,8 +358,25 @@ public static synchronized Configuration forDbms(Session session) {
List<Configuration> cs = (List<Configuration>) getContext().getBean("dbms-configuration");
for (Configuration c: cs) {
if (Pattern.matches(c.urlPattern, session.dbUrl)) {
perUrl.put(session.dbUrl, c);
return c;
boolean ok = true;
if (c.getTestQuery() != null) {
boolean wasSilent = session.getSilent();
session.setSilent(true);
try {
session.executeQuery(c.getTestQuery(), new Session.AbstractResultSetReader() {
@Override
public void readCurrentRow(ResultSet resultSet) throws SQLException {
}
});
} catch (SQLException e) {
ok = false;
}
session.setSilent(wasSilent);
}
if (ok) {
perUrl.put(session.dbUrl, c);
return c;
}
}
}
}
Expand All @@ -363,6 +387,28 @@ public static synchronized Configuration forDbms(Session session) {
/**
* Gets DBMS specific configuration.
*
* @param dbUrl URL
* @return configuration for the DBMS with given URL
*/
@SuppressWarnings("unchecked")
public static Configuration forDbms(String dbUrl) {
if (dbUrl == null) {
return defaultConfiguration;
}
if (getContext().containsBean("dbms-configuration")) {
List<Configuration> cs = (List<Configuration>) getContext().getBean("dbms-configuration");
for (Configuration c: cs) {
if (Pattern.matches(c.urlPattern, dbUrl)) {
return c;
}
}
}
return defaultConfiguration;
}

/**
* Gets DBMS specific configuration.
*
* @param dbms the DBMS
* @return configuration for the DBMS
*/
Expand Down Expand Up @@ -717,4 +763,12 @@ public void setIdentifierQuoteString(String identifierQuoteString) {
this.identifierQuoteString = identifierQuoteString;
}

public String getTestQuery() {
return testQuery;
}

public void setTestQuery(String testQuery) {
this.testQuery = testQuery;
}

}
3 changes: 2 additions & 1 deletion src/main/net/sf/jailer/database/DBMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public enum DBMS {

ORACLE("Oracle"),
MSSQL("MS SQL Server"),
DB2("IBM DB2"),
DB2("DB2 LUW"),
DB2_ZOS("DB2 z/OS"),
MySQL("MySQL"),
POSTGRESQL("PostgreSQL"),
SQLITE("SQLite"),
Expand Down
11 changes: 9 additions & 2 deletions src/main/net/sf/jailer/database/DMLTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public void readCurrentRow(ResultSet resultSet) throws SQLException {
String item = "Select " + valuesWONull + " From " +
(currentDialect.upsertMode == UPSERT_MODE.FROM_DUAL ||
currentDialect.upsertMode == UPSERT_MODE.MERGE? // oracle table with lobs
"dual" : SQLDialect.DUAL_TABLE);
"dual" : currentDialect.upsertMode == UPSERT_MODE.FROM_SYSDUMMY1? "sysibm.sysdummy1" : SQLDialect.DUAL_TABLE);
StringBuffer terminator = new StringBuffer(" Where not exists (Select * from " + qualifiedTableName(table) + " T "
+ "Where ");
terminator.append(where + ");\n");
Expand Down Expand Up @@ -488,7 +488,14 @@ public void readCurrentRow(ResultSet resultSet) throws SQLException {
}
}
} else {
if (targetDBMSConfiguration.dbms == DBMS.ORACLE && maxBodySize > 1) {
if (targetDBMSConfiguration.dbms == DBMS.DB2_ZOS && maxBodySize > 1) {
String insertSchema = "Insert into " + qualifiedTableName(table) + "(" + labelCSL + ") ";
String item = "\n Select " + valueList + " From sysibm.sysdummy1";
if (!insertStatementBuilder.isAppendable(insertSchema, item)) {
writeToScriptFile(insertStatementBuilder.build(), true);
}
insertStatementBuilder.append(insertSchema, item, " Union all ", ";\n");
} else if (targetDBMSConfiguration.dbms == DBMS.ORACLE && maxBodySize > 1) {
String insertSchema = "Insert into " + qualifiedTableName(table) + "(" + labelCSL + ") ";
String item = "\n Select " + valueList + " From DUAL";
if (!insertStatementBuilder.isAppendable(insertSchema, item)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/net/sf/jailer/database/DeletionTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void readCurrentRow(ResultSet resultSet) throws SQLException {
writeToScriptFile(deleteStatementBuilder.build());
}
deleteStatementBuilder.append(deleteHead, item, ") or (", ");\n");
} else {
} else {
String deleteHead;
String item;
if (table.primaryKey.getColumns().size() == 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/net/sf/jailer/database/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public Connection getConnection() throws SQLException {

if (con == null) {
try {
Map<String, String> jdbcProperties = Configuration.forDbms(Session.this).getJdbcProperties();
Map<String, String> jdbcProperties = Configuration.forDbms(Session.this.dbUrl).getJdbcProperties();
if (jdbcProperties != null) {
try {
java.util.Properties info = new java.util.Properties();
Expand Down
1 change: 1 addition & 0 deletions src/main/net/sf/jailer/database/UPSERT_MODE.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum UPSERT_MODE {
DB2("Select * From (values (1, 2), (3, 4)) as Q(c1, c2) Where not exists (Select * from $ T Where T.c1=Q.c1)"),
FROM_DUAL("Select 1, 2 From dual where not exists(Select * from $ T where T.c1=1)"),
FROM_JL_DUAL("Select 1, 2 From $ where not exists(Select * from $ T where T.c1=1)"),
FROM_SYSDUMMY1("Select 1, 2 From sysibm.sysdummy1 where not exists(Select * from $ T where T.c1=1)"),
MERGE("MERGE INTO $ T " +
"USING (SELECT 1 c1, 2 c2 from dual) incoming " +
"ON (T.c1 = incoming.c1) " +
Expand Down

0 comments on commit d321a3a

Please sign in to comment.