use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.
the class AbstractRouterServiceTest method insert.
protected void insert(final String tableName, final int count, boolean transactional, final String node2disable, final String routingVarcharFieldValue, final boolean rollback) {
ISymmetricDialect dialect = getDbDialect();
IDatabasePlatform platform = dialect.getPlatform();
String columnName = platform.alterCaseToMatchDatabaseDefaultCase("ROUTING_VARCHAR");
ISqlTransaction transaction = null;
try {
transaction = platform.getSqlTemplate().startSqlTransaction();
if (node2disable != null) {
dialect.disableSyncTriggers(transaction, node2disable);
}
transaction.prepare(String.format("insert into %s (%s) values(?)", tableName, columnName));
for (int i = 0; i < count; i++) {
transaction.addRow(i, new Object[] { routingVarcharFieldValue }, new int[] { Types.VARCHAR });
if (!transactional) {
transaction.commit();
}
}
if (node2disable != null) {
dialect.enableSyncTriggers(transaction);
}
if (rollback) {
transaction.rollback();
} else {
transaction.flush();
transaction.commit();
}
} finally {
if (transaction != null) {
transaction.close();
}
}
}
use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.
the class RouterServiceTest method setup.
@Before
public void setup() {
ISymmetricEngine engine = mock(ISymmetricEngine.class);
IParameterService parameterService = mock(IParameterService.class);
ISymmetricDialect symmetricDialect = mock(ISymmetricDialect.class);
IDatabasePlatform databasePlatform = mock(IDatabasePlatform.class);
IExtensionService extensionService = mock(IExtensionService.class);
when(databasePlatform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
when(symmetricDialect.getPlatform()).thenReturn(databasePlatform);
when(engine.getDatabasePlatform()).thenReturn(databasePlatform);
when(engine.getParameterService()).thenReturn(parameterService);
when(engine.getSymmetricDialect()).thenReturn(symmetricDialect);
when(engine.getExtensionService()).thenReturn(extensionService);
routerService = new RouterService(engine);
}
use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method setUp.
@Before
public void setUp() throws Exception {
sqlTemplate = mock(ISqlTemplate.class);
sqlTransaction = mock(ISqlTransaction.class);
when(sqlTemplate.startSqlTransaction()).thenReturn(sqlTransaction);
IDatabasePlatform platform = mock(IDatabasePlatform.class);
when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
when(platform.getSqlTemplate()).thenReturn(sqlTemplate);
symmetricDialect = mock(AbstractSymmetricDialect.class);
when(symmetricDialect.getPlatform()).thenReturn(platform);
when(symmetricDialect.supportsTransactionViews()).thenReturn(false);
when(symmetricDialect.getDatabaseTime()).thenReturn(0L);
parameterService = mock(ParameterService.class);
when(parameterService.getEngineName()).thenReturn(ENGINE_NAME);
when(parameterService.getLong(ParameterConstants.ROUTING_STALE_DATA_ID_GAP_TIME)).thenReturn(60000000L);
when(parameterService.getInt(ParameterConstants.DATA_ID_INCREMENT_BY)).thenReturn(1);
when(parameterService.getLong(ParameterConstants.ROUTING_LARGEST_GAP_SIZE)).thenReturn(50000000L);
when(parameterService.getLong(ParameterConstants.DBDIALECT_ORACLE_TRANSACTION_VIEW_CLOCK_SYNC_THRESHOLD_MS)).thenReturn(60000L);
when(parameterService.getLong(ParameterConstants.ROUTING_STALE_GAP_BUSY_EXPIRE_TIME)).thenReturn(60000L);
when(parameterService.is(ParameterConstants.ROUTING_DETECT_INVALID_GAPS)).thenReturn(true);
when(parameterService.getInt(ParameterConstants.ROUTING_MAX_GAP_CHANGES)).thenReturn(1000);
IExtensionService extensionService = mock(ExtensionService.class);
ISymmetricEngine engine = mock(AbstractSymmetricEngine.class);
when(engine.getParameterService()).thenReturn(parameterService);
when(engine.getStatisticManager()).thenReturn(statisticManager);
when(engine.getNodeService()).thenReturn(nodeService);
when(engine.getDataService()).thenReturn(dataService);
when(engine.getSymmetricDialect()).thenReturn(symmetricDialect);
when(engine.getExtensionService()).thenReturn(extensionService);
routerService = new RouterService(engine);
when(engine.getRouterService()).thenReturn(routerService);
contextService = mock(ContextService.class);
dataService = mock(DataService.class);
statisticManager = mock(StatisticManager.class);
when(statisticManager.newProcessInfo((ProcessInfoKey) any())).thenReturn(new ProcessInfo());
nodeService = mock(NodeService.class);
when(nodeService.findIdentity()).thenReturn(new Node(NODE_ID, NODE_GROUP_ID));
detector = newGapDetector();
detector.setFullGapAnalysis(false);
}
use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.
the class AuditTableDataRouter method toAuditTable.
protected Table toAuditTable(Table table) {
IDatabasePlatform platform = engine.getDatabasePlatform();
Table auditTable = table.copy();
auditTable.setName(String.format("%s_%s", auditTable.getName(), platform.alterCaseToMatchDatabaseDefaultCase("AUDIT")));
Column[] columns = auditTable.getColumns();
auditTable.removeAllColumns();
auditTable.addColumn(new Column(COLUMN_AUDIT_ID, true, Types.BIGINT, 0, 0));
auditTable.addColumn(new Column(COLUMN_AUDIT_TIME, false, Types.TIMESTAMP, 0, 0));
auditTable.addColumn(new Column(COLUMN_AUDIT_EVENT, false, Types.CHAR, 1, 0));
for (Column column : columns) {
column.setRequired(false);
column.setPrimaryKey(false);
column.setAutoIncrement(false);
auditTable.addColumn(column);
}
auditTable.removeAllForeignKeys();
auditTable.removeAllIndices();
platform.alterCaseToMatchDatabaseDefaultCase(auditTable);
return auditTable;
}
use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.
the class DbExportImportTest method importUniqueKeywordTable.
@Test
public void importUniqueKeywordTable() throws Exception {
ISymmetricEngine engine = getSymmetricEngine();
DbImport dbImport = new DbImport(engine.getDatabasePlatform());
dbImport.setFormat(DbImport.Format.XML);
dbImport.setDropIfExists(true);
dbImport.setAlterCaseToMatchDatabaseDefaultCase(true);
dbImport.importTables(getClass().getResourceAsStream("/test-dbimport-unique.xml"));
IDatabasePlatform platform = engine.getSymmetricDialect().getPlatform();
Database testTables = platform.readDatabaseFromXml("/test-dbimport-unique.xml", true);
Table table = testTables.findTable("test_db_import_unique", false);
Assert.assertEquals(0, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
Assert.assertEquals(table.getColumnWithName("string_required_value").isUnique(), true);
DbImport importCsv = new DbImport(engine.getDatabasePlatform());
importCsv.setFormat(DbImport.Format.SQL);
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-unique-good.sql"));
Assert.assertEquals(5, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
dbImport.importTables(getClass().getResourceAsStream("/test-dbimport-unique.xml"));
try {
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-unique-bad-line-2.sql"));
Assert.fail("Expected a sql exception");
} catch (SqlException ex) {
}
Assert.assertEquals(0, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
importCsv.setCommitRate(1);
importCsv.setForceImport(true);
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-unique-bad-line-2.sql"));
Assert.assertEquals(4, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
}
Aggregations