Skip to content
Permalink
Browse files

0003216: Tibero Database Dialect

  • Loading branch information...
jumpmind-josh committed Aug 1, 2017
1 parent aaa1d51 commit a7e413932773168b207aa437798eff56774d0e23
@@ -43,6 +43,7 @@
import org.jumpmind.db.platform.redshift.RedshiftDatabasePlatform;
import org.jumpmind.db.platform.sqlanywhere.SqlAnywhereDatabasePlatform;
import org.jumpmind.db.platform.sqlite.SqliteDatabasePlatform;
import org.jumpmind.db.platform.tibero.TiberoDatabasePlatform;
import org.jumpmind.db.platform.voltdb.VoltDbDatabasePlatform;
import org.jumpmind.symmetric.db.ase.AseSymmetricDialect;
import org.jumpmind.symmetric.db.db2.Db2As400SymmetricDialect;
@@ -69,6 +70,7 @@
import org.jumpmind.symmetric.db.redshift.RedshiftSymmetricDialect;
import org.jumpmind.symmetric.db.sqlanywhere.SqlAnywhereSymmetricDialect;
import org.jumpmind.symmetric.db.sqlite.SqliteJdbcSymmetricDialect;
import org.jumpmind.symmetric.db.tibero.TiberoSymmetricDialect;
import org.jumpmind.symmetric.db.voltdb.VoltDbSymmetricDialect;
import org.jumpmind.symmetric.service.IParameterService;
import org.slf4j.Logger;
@@ -155,6 +157,8 @@ public ISymmetricDialect create() {
dialect = new SqliteJdbcSymmetricDialect(parameterService, platform);
} else if (platform instanceof VoltDbDatabasePlatform) {
dialect = new VoltDbSymmetricDialect(parameterService, platform);
} else if (platform instanceof TiberoDatabasePlatform) {
dialect = new TiberoSymmetricDialect(parameterService, platform);
} else {
dialect = new GenericSymmetricDialect(parameterService, platform);
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -209,6 +209,10 @@ private ParameterConstants() {
public final static String DBDIALECT_ORACLE_TEMPLATE_NUMBER_SPEC = "oracle.template.precision";
public final static String DBDIALECT_ORACLE_USE_HINTS = "oracle.use.hints";

public final static String DBDIALECT_TIBERO_USE_TRANSACTION_VIEW = "tibero.use.transaction.view";
public final static String DBDIALECT_TIBERO_TEMPLATE_NUMBER_SPEC = "tibero.template.precision";
public final static String DBDIALECT_TIBERO_USE_HINTS = "tibero.use.hints";

public final static String DBDIALECT_ORACLE_TRANSACTION_VIEW_CLOCK_SYNC_THRESHOLD_MS = "oracle.transaction.view.clock.sync.threshold.ms";

public final static String DATA_ID_INCREMENT_BY = "data.id.increment.by";
@@ -34,6 +34,9 @@ private ColumnTypes() {
public static final int ORACLE_TIMESTAMPTZ = -101;
public static final int ORACLE_TIMESTAMPLTZ = -102;

public static final int TIBERO_TIMESTAMPTZ = -101;
public static final int TIBERO_TIMESTAMPLTZ = -102;

public static final int MSSQL_SQL_VARIANT = -150;

public static final int MAPPED_TIMESTAMPTZ = ORACLE_TIMESTAMPTZ;
@@ -50,5 +50,6 @@ private DatabaseNamesConstants() {
public final static String MARIADB = "mariadb";
public final static String REDSHIFT = "redshift";
public final static String VOLTDB = "voltdb";
public final static String TIBERO = "tibero";

}

Large diffs are not rendered by default.

@@ -0,0 +1,70 @@
package org.jumpmind.db.platform.tibero;

import java.sql.Types;

import org.jumpmind.db.model.Column;
import org.jumpmind.db.model.TypeMap;
import org.jumpmind.db.platform.DatabaseInfo;
import org.jumpmind.db.sql.DmlStatement;

public class TiberoDmlStatement extends DmlStatement {

public TiberoDmlStatement(DmlType type, String catalogName, String schemaName, String tableName,
Column[] keysColumns, Column[] columns, boolean[] nullKeyValues,
DatabaseInfo databaseInfo, boolean useQuotedIdentifiers, String textColumnExpression) {
super(type, catalogName, schemaName, tableName, keysColumns, columns,
nullKeyValues, databaseInfo, useQuotedIdentifiers, textColumnExpression);
}

@Override
protected void appendColumnParameter(StringBuilder sql, Column column) {
String name = column.getJdbcTypeName();
if (column.isTimestampWithTimezone()) {
sql.append("TO_TIMESTAMP_TZ(?, 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM')")
.append(",");
} else if (name != null && (
name.toUpperCase().contains(TypeMap.GEOMETRY) ||
name.toUpperCase().contains(TypeMap.GEOGRAPHY))) {
sql.append("SYM_WKT2GEOM(?)").append(",");
} else {
super.appendColumnParameter(sql, column);
}
}

@Override
protected void appendColumnEquals(StringBuilder sql, Column column) {
if (column.isTimestampWithTimezone()) {
sql.append(quote).append(column.getName()).append(quote)
.append(" = TO_TIMESTAMP_TZ(?, 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM')");
} else if (column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOMETRY) ||
column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOGRAPHY)) {
sql.append(quote).append(column.getName()).append(quote).append(" = ")
.append("SYM_WKT2GEOM(?)");
} else {
super.appendColumnEquals(sql, column);
}
}

@Override
protected int getTypeCode(Column column, boolean isDateOverrideToTimestamp) {
int typeCode = super.getTypeCode(column, isDateOverrideToTimestamp);
if (column.getJdbcTypeName().startsWith("XML")) {
typeCode = Types.VARCHAR;
} else if (typeCode == Types.LONGVARCHAR) {
typeCode = Types.CLOB;
}
return typeCode;
}

@Override
protected void appendColumnNameForSql(StringBuilder sql, Column column, boolean select) {
String columnName = column.getName();
if (select && column.isTimestampWithTimezone()) {
sql.append("to_char(").append(quote).append(columnName).append(quote).append(", 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM') as ").append(columnName);
} else {
super.appendColumnNameForSql(sql, column, select);
}
}


}
@@ -56,6 +56,7 @@
import org.jumpmind.db.platform.redshift.RedshiftDatabasePlatform;
import org.jumpmind.db.platform.sqlanywhere.SqlAnywhereDatabasePlatform;
import org.jumpmind.db.platform.sqlite.SqliteDatabasePlatform;
import org.jumpmind.db.platform.tibero.TiberoDatabasePlatform;
import org.jumpmind.db.platform.voltdb.VoltDbDatabasePlatform;
import org.jumpmind.db.sql.SqlException;
import org.jumpmind.db.sql.SqlTemplateSettings;
@@ -111,6 +112,7 @@
addPlatform(platforms, "SQLite", SqliteDatabasePlatform.class);
addPlatform(platforms, DatabaseNamesConstants.REDSHIFT, RedshiftDatabasePlatform.class);
addPlatform(platforms, DatabaseNamesConstants.VOLTDB, VoltDbDatabasePlatform.class);
addPlatform(platforms, DatabaseNamesConstants.TIBERO, TiberoDatabasePlatform.class);

jdbcSubProtocolToPlatform.put(Db2DatabasePlatform.JDBC_SUBPROTOCOL, Db2DatabasePlatform.class);
jdbcSubProtocolToPlatform.put(DerbyDatabasePlatform.JDBC_SUBPROTOCOL, DerbyDatabasePlatform.class);
@@ -134,6 +136,8 @@
jdbcSubProtocolToPlatform.put(AseDatabasePlatform.JDBC_SUBPROTOCOL, AseDatabasePlatform.class);
jdbcSubProtocolToPlatform.put(FirebirdDatabasePlatform.JDBC_SUBPROTOCOL,
FirebirdDatabasePlatform.class);
jdbcSubProtocolToPlatform.put(TiberoDatabasePlatform.JDBC_SUBPROTOCOL_THIN,
TiberoDatabasePlatform.class);
}

/*
@@ -0,0 +1,116 @@
package org.jumpmind.db.platform.tibero;

import javax.sql.DataSource;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.model.Column;
import org.jumpmind.db.platform.AbstractJdbcDatabasePlatform;
import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.platform.PermissionResult;
import org.jumpmind.db.platform.PermissionResult.Status;
import org.jumpmind.db.platform.PermissionType;
import org.jumpmind.db.platform.tibero.TiberoDdlBuilder;
import org.jumpmind.db.platform.tibero.TiberoDdlReader;
import org.jumpmind.db.platform.tibero.TiberoJdbcSqlTemplate;
import org.jumpmind.db.platform.tibero.TiberoLobHandler;
import org.jumpmind.db.sql.ISqlTemplate;
import org.jumpmind.db.sql.SqlException;
import org.jumpmind.db.sql.SqlTemplateSettings;

public class TiberoDatabasePlatform extends AbstractJdbcDatabasePlatform {

public static final String JDBC_DRIVER = "com.tmax.tibero.jdbc.TbDriver";

public static final String JDBC_SUBPROTOCOL_THIN = "tibero:thin";

/*
* Creates a new platform instance.
*/
public TiberoDatabasePlatform(DataSource dataSource, SqlTemplateSettings settings) {
super(dataSource, settings);
}

@Override
protected TiberoDdlBuilder createDdlBuilder() {
return new TiberoDdlBuilder();
}

@Override
protected TiberoDdlReader createDdlReader() {
return new TiberoDdlReader(this);
}

@Override
protected TiberoJdbcSqlTemplate createSqlTemplate() {
return new TiberoJdbcSqlTemplate(dataSource, settings, new TiberoLobHandler(), getDatabaseInfo());
}

@Override
protected ISqlTemplate createSqlTemplateDirty() {
return sqlTemplate;
}

public String getName() {
return DatabaseNamesConstants.TIBERO;
}

public String getDefaultCatalog() {
return null;
}

public String getDefaultSchema() {
if (StringUtils.isBlank(defaultSchema)) {
defaultSchema = (String) getSqlTemplate().queryForObject(
"SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual", String.class);
}
return defaultSchema;
}

@Override
public boolean canColumnBeUsedInWhereClause(Column column) {
String jdbcTypeName = column.getJdbcTypeName();
return !column.isOfBinaryType() || "RAW".equals(jdbcTypeName);
}

@Override
public PermissionResult getCreateSymTriggerPermission() {
String delimiter = getDatabaseInfo().getDelimiterToken();
delimiter = delimiter != null ? delimiter : "";

String triggerSql = "CREATE OR REPLACE TRIGGER TEST_TRIGGER AFTER UPDATE ON " + delimiter + PERMISSION_TEST_TABLE_NAME + delimiter + " BEGIN END";

PermissionResult result = new PermissionResult(PermissionType.CREATE_TRIGGER, Status.FAIL);

try {
getSqlTemplate().update(triggerSql);
result.setStatus(Status.PASS);
} catch (SqlException e) {
result.setException(e);
result.setSolution("Grant CREATE TRIGGER permission or TRIGGER permission");
}

return result;
}

@Override
public PermissionResult getExecuteSymPermission() {
String delimiter = getDatabaseInfo().getDelimiterToken();
delimiter = delimiter != null ? delimiter : "";

String executeSql = "SELECT DBMS_LOB.GETLENGTH('TEST'), UTL_RAW.CAST_TO_RAW('TEST') FROM DUAL";

PermissionResult result = new PermissionResult(PermissionType.EXECUTE, Status.FAIL);

try {
getSqlTemplate().update(executeSql);
result.setStatus(Status.PASS);
} catch (SqlException e) {
result.setException(e);
result.setSolution("Grant EXECUTE on DBMS_LOB and UTL_RAW");
}

return result;
}

}

0 comments on commit a7e4139

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