Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
0004352: Sybase dialect should enable row locking and set identity gap
  • Loading branch information
erilong committed Apr 28, 2020
1 parent 8d410bd commit 900b651
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
Expand Up @@ -25,15 +25,19 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.sql.IConnectionCallback;
import org.jumpmind.db.sql.ISqlTemplate;
import org.jumpmind.db.sql.ISqlTransaction;
import org.jumpmind.db.sql.JdbcSqlTemplate;
import org.jumpmind.db.sql.JdbcSqlTransaction;
import org.jumpmind.db.sql.SqlException;
import org.jumpmind.db.util.BinaryEncoding;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.common.TableConstants;
import org.jumpmind.symmetric.db.AbstractSymmetricDialect;
import org.jumpmind.symmetric.db.ISymmetricDialect;
import org.jumpmind.symmetric.model.Trigger;
Expand Down Expand Up @@ -61,13 +65,58 @@ public AseSymmetricDialect(IParameterService parameterService, IDatabasePlatform
}

@Override
public void createRequiredDatabaseObjects() {
public boolean createOrAlterTablesIfNecessary(String... tableNames) {
boolean altered = super.createOrAlterTablesIfNecessary(tableNames);
ISqlTemplate sqlTemplate = platform.getSqlTemplate();
String prefix = getTablePrefix();

try {
int changeIdentityGap = parameterService.getInt(ParameterConstants.SYBASE_CHANGE_IDENTITY_GAP, 1000);
if (changeIdentityGap > 0) {
String dataTable = TableConstants.getTableName(prefix, TableConstants.SYM_DATA).toLowerCase();
String sql = "select max(i.identitygap) from sysindexes i inner join sysobjects t on t.id = i.id where t.name = ?";
long identityGap = sqlTemplate.queryForLong(sql, dataTable);
if (identityGap != changeIdentityGap) {
log.info("Changing identity gap for {} to {}", dataTable, changeIdentityGap);
sqlTemplate.update("sp_chgattribute " + dataTable + ", 'identity_gap', " + changeIdentityGap);
altered = true;
}
}
} catch (Exception e) {
log.warn("Failed to alter identity gap: {}", e.getMessage());
log.debug("", e);
}

try {
if (parameterService.is(ParameterConstants.SYBASE_ROW_LEVEL_LOCKS_ONLY, true)) {
List<String> tables = new ArrayList<String>();
tables.add(TableConstants.getTableName(prefix, TableConstants.SYM_DATA).toLowerCase());
tables.add(TableConstants.getTableName(prefix, TableConstants.SYM_DATA_EVENT).toLowerCase());
tables.add(TableConstants.getTableName(prefix, TableConstants.SYM_OUTGOING_BATCH).toLowerCase());
tables.add(TableConstants.getTableName(prefix, TableConstants.SYM_MONITOR_EVENT).toLowerCase());
String sql = "select case (sysstat2 & 57344) when 32768 then 1 else 0 end from sysobjects where name = ?";

for (String table : tables) {
if (sqlTemplate.queryForInt(sql, table) == 0) {
log.info("Altering {} for row-level locking", table);
sqlTemplate.update("alter table " + table + " lock datarows");
altered = true;
}
}
}
} catch (Exception e) {
log.warn("Failed to alter row-level locking: {}", e.getMessage());
log.debug("", e);
}
return altered;
}

@Override
public void dropRequiredDatabaseObjects() {
public void createRequiredDatabaseObjects() {
}

@Override
public void dropRequiredDatabaseObjects() {
}

@Override
Expand Down
Expand Up @@ -421,6 +421,9 @@ private ParameterConstants() {
public final static String MSSQL_BULK_LOAD_ROW_TERMINATOR = "mssql.bulk.load.row.terminator";
public final static String MSSQL_BULK_LOAD_FIELD_TERMINATOR = "mssql.bulk.load.field.terminator";

public final static String SYBASE_ROW_LEVEL_LOCKS_ONLY = "sybase.allow.only.row.level.locks.on.runtime.tables";
public final static String SYBASE_CHANGE_IDENTITY_GAP = "sybase.change.identity.gap.on.runtime.tables";

public final static String SQLITE_TRIGGER_FUNCTION_TO_USE = "sqlite.trigger.function.to.use";

public final static String AS400_CAST_CLOB_TO = "as400.cast.clob.to";
Expand Down
17 changes: 17 additions & 0 deletions symmetric-core/src/main/resources/symmetric-default.properties
Expand Up @@ -2340,6 +2340,23 @@ mssql.include.catalog.in.triggers=true
# Tags: other, mssql
db.master.collation=

# Automatically alter data, data_event and outgoing_batch tables to allow only
# row level locking.
#
# DatabaseOverridable: true
# Tags: other, sybase
# Type: boolean
sybase.allow.only.row.level.locks.on.runtime.tables=true

# Automatically change attribute on data, data_event and outgoing_batch tables to set the identity gap
# to the number provided. This prevents skipping a large number of identities that can cause routing to stop.
# Use 0 to disable.
#
# DatabaseOverridable: true
# Tags: other, sybase
# Type: integer
sybase.change.identity.gap.on.runtime.tables=1000

# Spring xml configuration for extension points. This property enables maintaining
# Spring extension point configuration in the database. After changing this property
# a server restart is required.
Expand Down

0 comments on commit 900b651

Please sign in to comment.