use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.
the class DbExportImportTest method testInsertBigIntIntoOracleIntField.
@Test
public void testInsertBigIntIntoOracleIntField() {
if (getPlatform().getName().equals(DatabaseNamesConstants.ORACLE)) {
ISymmetricEngine engine = getSymmetricEngine();
IDatabasePlatform platform = engine.getDatabasePlatform();
Table table = new Table("TEST_ORACLE_INTEGER");
table.addColumn(new Column("A", false, Types.INTEGER, -1, -1));
platform.alterCaseToMatchDatabaseDefaultCase(table);
platform.createTables(true, false, table);
DbImport importer = new DbImport(platform);
importer.setFormat(DbImport.Format.CSV);
importer.importTables("\"A\"\n1149140000100490", table.getName());
Assert.assertEquals(1149140000100490l, platform.getSqlTemplate().queryForLong("select A from TEST_ORACLE_INTEGER"));
}
}
use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.
the class TestSetupUtil method dropAndCreateDatabaseTables.
public static void dropAndCreateDatabaseTables(String databaseType, ISymmetricEngine engine) {
IDatabasePlatform platform = dropDatabaseTables(databaseType, engine);
Database testDb = platform.readDatabaseFromXml("/test-schema.xml", true);
platform.createDatabase(testDb, false, true);
}
use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.
the class DbExportImportTest method testExportCsvToDirectory.
@Test
public void testExportCsvToDirectory() throws Exception {
ISymmetricEngine engine = getSymmetricEngine();
IDatabasePlatform platform = engine.getSymmetricDialect().getPlatform();
DbImport importXml = new DbImport(platform);
importXml.setFormat(DbImport.Format.XML);
importXml.importTables(getClass().getResourceAsStream("/test-dbexportimport-3-tables.xml"));
File dir = new File("target/test");
FileUtils.deleteDirectory(dir);
Assert.assertFalse(dir.exists());
DbExport exportCsv = new DbExport(platform);
exportCsv.setComments(true);
exportCsv.setFormat(Format.CSV);
exportCsv.setDir(dir.getAbsolutePath());
exportCsv.exportTables(new String[] { "a", "b", "c" });
Assert.assertTrue(dir.exists());
Assert.assertTrue(dir.isDirectory());
File a = new File(dir, platform.getTableFromCache("a", false).getName() + ".csv");
Assert.assertTrue(a.exists());
Assert.assertTrue(a.isFile());
List<String> lines = FileUtils.readLines(a);
Assert.assertEquals(9, lines.size());
Assert.assertEquals("\"id\",\"string_value\"", lines.get(5));
Assert.assertEquals("\"1\",\"This is a test of a\"", lines.get(6));
Assert.assertEquals("\"2\",\"This is a test of a\"", lines.get(7));
File b = new File(dir, platform.getTableFromCache("b", false).getName() + ".csv");
Assert.assertTrue(b.exists());
Assert.assertTrue(b.isFile());
lines = FileUtils.readLines(b);
Assert.assertEquals(10, lines.size());
Assert.assertEquals("\"id\",\"string_value\"", lines.get(5));
Assert.assertEquals("\"1\",\"This is a test of b\"", lines.get(6));
Assert.assertEquals("\"2\",\"This is a test of b\"", lines.get(7));
Assert.assertEquals("\"3\",\"This is line 3 of b\"", lines.get(8));
File c = new File(dir, platform.getTableFromCache("c", false).getName() + ".csv");
Assert.assertTrue(c.exists());
Assert.assertTrue(c.isFile());
lines = FileUtils.readLines(c);
Assert.assertEquals(9, lines.size());
Assert.assertEquals("\"id\",\"string_value\"", lines.get(5));
Assert.assertEquals("\"1\",\"This is a test of c\"", lines.get(6));
Assert.assertEquals("\"2\",\"This is a test of c\"", lines.get(7));
}
use of org.jumpmind.db.platform.IDatabasePlatform 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.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.
the class DataGapRouteReaderTest method buildReader.
protected DataGapRouteReader buildReader(int peekAheadMemoryThreshold, List<DataGap> dataGaps) throws Exception {
when(parameterService.getEngineName()).thenReturn(ENGINE_NAME);
when(parameterService.is(ParameterConstants.SYNCHRONIZE_ALL_JOBS)).thenReturn(true);
when(parameterService.getInt(ParameterConstants.ROUTING_WAIT_FOR_DATA_TIMEOUT_SECONDS)).thenReturn(330);
when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_MEMORY_THRESHOLD)).thenReturn(peekAheadMemoryThreshold);
when(parameterService.getInt(ParameterConstants.ROUTING_MAX_GAPS_TO_QUALIFY_IN_SQL)).thenReturn(100);
when(parameterService.getInt(ParameterConstants.ROUTING_DATA_READER_THRESHOLD_GAPS_TO_USE_GREATER_QUERY)).thenReturn(100);
when(parameterService.is(ParameterConstants.ROUTING_DATA_READER_ORDER_BY_DATA_ID_ENABLED)).thenReturn(true);
IStatisticManager statisticManager = mock(StatisticManager.class);
when(statisticManager.newProcessInfo((ProcessInfoKey) any())).thenReturn(new ProcessInfo());
INodeService nodeService = mock(NodeService.class);
when(nodeService.findIdentity()).thenReturn(new Node(NODE_ID, NODE_GROUP_ID));
IDatabasePlatform platform = mock(IDatabasePlatform.class);
when(platform.getSqlTemplate()).thenReturn(sqlTemplate);
when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
ISymmetricDialect symmetricDialect = mock(AbstractSymmetricDialect.class);
when(symmetricDialect.supportsTransactionId()).thenReturn(true);
when(symmetricDialect.getPlatform()).thenReturn(platform);
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);
IRouterService routerService = new RouterService(engine);
when(engine.getRouterService()).thenReturn(routerService);
ChannelRouterContext context = new ChannelRouterContext(NODE_ID, nodeChannel, mock(ISqlTransaction.class));
context.setDataGaps(dataGaps);
return new DataGapRouteReader(context, engine);
}
Aggregations