use of org.jumpmind.symmetric.service.IParameterService in project symmetric-ds by JumpMind.
the class ConfigurationChangedDatabaseWriterFilter method beforeWrite.
@Override
public boolean beforeWrite(DataContext context, Table table, CsvData data) {
IParameterService parameterService = engine.getParameterService();
if (context.getBatch().getBatchId() == Constants.VIRTUAL_BATCH_FOR_REGISTRATION) {
if (parameterService.is(ParameterConstants.REGISTRATION_REINITIALIZE_ENABLED) && !Boolean.TRUE.equals(context.get(CTX_KEY_REINITIALIZED))) {
log.info("Reinitializing the database because the {} parameter was set to true", ParameterConstants.REGISTRATION_REINITIALIZE_ENABLED);
engine.uninstall();
engine.setupDatabase(true);
engine.start();
context.put(CTX_KEY_REINITIALIZED, Boolean.TRUE);
}
}
return true;
}
use of org.jumpmind.symmetric.service.IParameterService in project symmetric-ds by JumpMind.
the class DataGapRouteReader method prepareCursor.
protected ISqlReadCursor<Data> prepareCursor() {
IParameterService parameterService = engine.getParameterService();
int numberOfGapsToQualify = parameterService.getInt(ParameterConstants.ROUTING_MAX_GAPS_TO_QUALIFY_IN_SQL, 100);
int maxGapsBeforeGreaterThanQuery = parameterService.getInt(ParameterConstants.ROUTING_DATA_READER_THRESHOLD_GAPS_TO_USE_GREATER_QUERY, 100);
boolean useGreaterThanDataId = false;
if (maxGapsBeforeGreaterThanQuery > 0 && this.dataGaps.size() > maxGapsBeforeGreaterThanQuery) {
useGreaterThanDataId = true;
}
String channelId = context.getChannel().getChannelId();
String sql = null;
Boolean lastSelectUsedGreaterThanQuery = lastSelectUsedGreaterThanQueryByEngineName.get(parameterService.getEngineName());
if (lastSelectUsedGreaterThanQuery == null) {
lastSelectUsedGreaterThanQuery = Boolean.FALSE;
}
if (useGreaterThanDataId) {
sql = getSql("selectDataUsingStartDataId", context.getChannel().getChannel());
if (!lastSelectUsedGreaterThanQuery) {
log.info("Switching to select from the data table where data_id >= start gap because there were {} gaps found " + "which was more than the configured threshold of {}", dataGaps.size(), maxGapsBeforeGreaterThanQuery);
lastSelectUsedGreaterThanQueryByEngineName.put(parameterService.getEngineName(), Boolean.TRUE);
}
} else {
sql = qualifyUsingDataGaps(dataGaps, numberOfGapsToQualify, getSql("selectDataUsingGapsSql", context.getChannel().getChannel()));
if (lastSelectUsedGreaterThanQuery) {
log.info("Switching to select from the data table where data_id between gaps");
lastSelectUsedGreaterThanQueryByEngineName.put(parameterService.getEngineName(), Boolean.FALSE);
}
}
if (parameterService.is(ParameterConstants.ROUTING_DATA_READER_ORDER_BY_DATA_ID_ENABLED, true)) {
sql = String.format("%s %s", sql, engine.getRouterService().getSql("orderByDataId"));
}
ISqlTemplate sqlTemplate = engine.getSymmetricDialect().getPlatform().getSqlTemplate();
Object[] args = null;
int[] types = null;
int dataIdSqlType = engine.getSymmetricDialect().getSqlTypeForIds();
if (useGreaterThanDataId) {
args = new Object[] { channelId, dataGaps.get(0).getStartId() };
types = new int[] { Types.VARCHAR, dataIdSqlType };
} else {
int numberOfArgs = 1 + 2 * (numberOfGapsToQualify < dataGaps.size() ? numberOfGapsToQualify : dataGaps.size());
args = new Object[numberOfArgs];
types = new int[numberOfArgs];
args[0] = channelId;
types[0] = Types.VARCHAR;
for (int i = 0; i < numberOfGapsToQualify && i < dataGaps.size(); i++) {
DataGap gap = dataGaps.get(i);
args[i * 2 + 1] = gap.getStartId();
types[i * 2 + 1] = dataIdSqlType;
if ((i + 1) == numberOfGapsToQualify && (i + 1) < dataGaps.size()) {
/*
* there were more gaps than we are going to use in the SQL.
* use the last gap as the end data id for the last range
*/
args[i * 2 + 2] = dataGaps.get(dataGaps.size() - 1).getEndId();
} else {
args[i * 2 + 2] = gap.getEndId();
}
types[i * 2 + 2] = dataIdSqlType;
}
}
this.currentGap = dataGaps.remove(0);
return sqlTemplate.queryForCursor(sql, new ISqlRowMapper<Data>() {
public Data mapRow(Row row) {
return engine.getDataService().mapData(row);
}
}, args, types);
}
use of org.jumpmind.symmetric.service.IParameterService in project symmetric-ds by JumpMind.
the class AuditTableDataRouter method routeToNodes.
public Set<String> routeToNodes(SimpleRouterContext context, DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) {
DataEventType eventType = dataMetaData.getData().getDataEventType();
if (eventType == DataEventType.INSERT || eventType == DataEventType.UPDATE || eventType == DataEventType.DELETE) {
IParameterService parameterService = engine.getParameterService();
IDatabasePlatform platform = engine.getDatabasePlatform();
TriggerHistory triggerHistory = dataMetaData.getTriggerHistory();
Table table = dataMetaData.getTable().copyAndFilterColumns(triggerHistory.getParsedColumnNames(), triggerHistory.getParsedPkColumnNames(), true);
String tableName = table.getFullyQualifiedTableName();
Table auditTable = auditTables.get(tableName);
if (auditTable == null) {
auditTable = toAuditTable(table);
if (parameterService.is(ParameterConstants.AUTO_CONFIGURE_DATABASE)) {
platform.alterTables(true, auditTable);
}
auditTable = platform.getTableFromCache(auditTable.getCatalog(), auditTable.getSchema(), auditTable.getName(), false);
auditTables.put(tableName, auditTable);
}
DatabaseInfo dbInfo = platform.getDatabaseInfo();
String auditTableName = auditTable.getQualifiedTableName(dbInfo.getDelimiterToken(), dbInfo.getCatalogSeparator(), dbInfo.getSchemaSeparator());
ISqlTemplate template = platform.getSqlTemplate();
Map<String, Object> values = null;
if (eventType != DataEventType.DELETE) {
values = new HashMap<String, Object>(getNewDataAsObject(null, dataMetaData, engine.getSymmetricDialect(), false));
} else {
values = new HashMap<String, Object>(getOldDataAsObject(null, dataMetaData, engine.getSymmetricDialect(), false));
}
Long sequence = (Long) context.get(auditTableName);
if (sequence == null) {
sequence = 1l + template.queryForLong(String.format("select max(%s) from %s", auditTable.getColumnWithName(COLUMN_AUDIT_ID).getName(), auditTableName));
} else {
sequence = 1l + sequence;
}
context.put(auditTable.getName(), sequence);
values.put(auditTable.getColumnWithName(COLUMN_AUDIT_ID).getName(), sequence);
values.put(auditTable.getColumnWithName(COLUMN_AUDIT_TIME).getName(), new Date());
values.put(auditTable.getColumnWithName(COLUMN_AUDIT_EVENT).getName(), eventType.getCode());
DmlStatement statement = platform.createDmlStatement(DmlType.INSERT, auditTable, null);
int[] types = statement.getTypes();
Object[] args = statement.getValueArray(values);
String sql = statement.getSql();
template.update(sql, args, types);
}
return null;
}
use of org.jumpmind.symmetric.service.IParameterService in project symmetric-ds by JumpMind.
the class JavaColumnTransformTest method setUp.
@Before
public void setUp() throws Exception {
ISqlTransaction sqlTransaction = mock(ISqlTransaction.class);
platform = mock(IDatabasePlatform.class);
ISymmetricEngine engine = mock(ISymmetricEngine.class);
IParameterService parameterService = mock(IParameterService.class);
IDatabasePlatform platform = mock(IDatabasePlatform.class);
ISymmetricDialect dialect = mock(ISymmetricDialect.class);
when(dialect.getPlatform()).thenReturn(platform);
when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
when(engine.getParameterService()).thenReturn(parameterService);
when(engine.getSymmetricDialect()).thenReturn(dialect);
extensionService = new ExtensionService(engine);
when(engine.getExtensionService()).thenReturn(extensionService);
context = mock(DataContext.class);
when(context.findTransaction()).thenReturn(sqlTransaction);
}
use of org.jumpmind.symmetric.service.IParameterService in project symmetric-ds by JumpMind.
the class AbstractTriggerRouterServiceTest method test06InitialLoadSql.
@Test
public void test06InitialLoadSql() throws Exception {
ITriggerRouterService triggerRouterService = getTriggerRouterService();
IParameterService parameterService = getParameterService();
parameterService.saveParameter(ParameterConstants.INITIAL_LOAD_CONCAT_CSV_IN_SQL_ENABLED, true, "unittest");
TriggerRouter triggerRouter = triggerRouterService.getTriggerRouterForTableForCurrentNode(null, null, TEST_TRIGGERS_TABLE, true).iterator().next();
Table table = getDbDialect().getPlatform().getTableFromCache(triggerRouter.getTrigger().getSourceTableName(), true);
Trigger trigger = triggerRouter.getTrigger();
String sql = getDbDialect().createInitialLoadSqlFor(new Node("1", null, "1.0"), triggerRouter, table, triggerRouterService.getNewestTriggerHistoryForTrigger(trigger.getTriggerId(), trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName()), getConfigurationService().getChannel(triggerRouter.getTrigger().getChannelId()), null);
List<String> csvStrings = getSqlTemplate().query(sql, new StringMapper());
assertTrue(csvStrings.size() > 0);
String csvString = csvStrings.get(0);
// DB2 captures decimal differently
csvString = csvString.replaceFirst("\"00001\\.\"", "\"1\"");
// Informix captures decimal differently
csvString = csvString.replaceFirst("\"1.0000000000000000\"", "\"1\"");
// ASA captures decimal differently
csvString = csvString.replaceFirst("\"1.000000\"", "\"1\"");
assertTrue(csvString.endsWith(EXPECTED_INSERT1_CSV_ENDSWITH), "Received " + csvString + ", Expected the string to end with " + EXPECTED_INSERT1_CSV_ENDSWITH);
}
Aggregations